[gnome-photos/wip/rishi/buffer-decoder: 2/12] gegl: Add a function to calculate the inverse Jacobian for zooming




commit b4d09b8ba0c09be90c8425077922f303fb5e833d
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Sep 24 11:36:21 2018 +0200

    gegl: Add a function to calculate the inverse Jacobian for zooming
    
    This will be necessary to support arbitrary downscales, without keeping
    the aspect ratio, in the new codec API for GeglBuffer. It is something
    that every codec will need and is, therefore, useful to have as a
    separate utility function.
    
    Bump minimum GEGL version to 0.4.10.
    
    https://gitlab.gnome.org/GNOME/gnome-photos/issues/63

 meson.build                   |  2 +-
 src/photos-gegl.c             | 20 +++++++++++
 src/photos-gegl.h             |  4 +++
 tests/unit/photos-test-gegl.c | 84 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 109 insertions(+), 1 deletion(-)
---
diff --git a/meson.build b/meson.build
index 3901719b..3e6a24be 100644
--- a/meson.build
+++ b/meson.build
@@ -155,7 +155,7 @@ libgd_dep = libgd.get_variable('libgd_dep')
 babl_dep = dependency('babl')
 cairo_dep = dependency('cairo', version: '>= 1.14.0')
 gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>= 2.36.8')
-gegl_dep = dependency('gegl-0.4', version: '>= 0.4.0')
+gegl_dep = dependency('gegl-0.4', version: '>= 0.4.10')
 geocode_glib_dep = dependency('geocode-glib-1.0')
 gexiv_dep = dependency('gexiv2', version: '>= 0.10.8')
 gio_dep = dependency('gio-2.0')
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index 762bf9c3..ddda781f 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -744,6 +744,26 @@ photos_gegl_init_fishes (void)
 }
 
 
+void
+photos_gegl_inverse_jacobian_zoom (GeglBufferMatrix2 *inverse_jacobian, gdouble zoom_x, gdouble zoom_y)
+{
+  GeglMatrix3 tmp;
+
+  g_return_if_fail (inverse_jacobian != NULL);
+
+  gegl_matrix3_identity (&tmp);
+  tmp.coeff[0][0] = zoom_x;
+  tmp.coeff[1][1] = zoom_y;
+
+  gegl_matrix3_invert (&tmp);
+
+  inverse_jacobian->coeff[0][0] = tmp.coeff[0][0];
+  inverse_jacobian->coeff[0][1] = tmp.coeff[0][1];
+  inverse_jacobian->coeff[1][0] = tmp.coeff[1][0];
+  inverse_jacobian->coeff[1][1] = tmp.coeff[1][1];
+}
+
+
 GdkPixbuf *
 photos_gegl_pixbuf_new_from_buffer (GeglBuffer *buffer)
 {
diff --git a/src/photos-gegl.h b/src/photos-gegl.h
index 20ec4e91..507c4e59 100644
--- a/src/photos-gegl.h
+++ b/src/photos-gegl.h
@@ -60,6 +60,10 @@ void             photos_gegl_init                         (void);
 
 void             photos_gegl_init_fishes                  (void);
 
+void             photos_gegl_inverse_jacobian_zoom        (GeglBufferMatrix2 *out_inverse_jacobian,
+                                                           gdouble zoom_x,
+                                                           gdouble zoom_y);
+
 GdkPixbuf       *photos_gegl_pixbuf_new_from_buffer       (GeglBuffer *buffer);
 
 void             photos_gegl_processor_process_async      (GeglProcessor *processor,
diff --git a/tests/unit/photos-test-gegl.c b/tests/unit/photos-test-gegl.c
index 9b659792..dbebd9fa 100644
--- a/tests/unit/photos-test-gegl.c
+++ b/tests/unit/photos-test-gegl.c
@@ -442,6 +442,19 @@ photos_test_gegl_buffer_check_zoom (PhotosTestGeglFixture *fixture,
 }
 
 
+static void
+photos_test_gegl_check_inverse_jacobian (gdouble zoom_x, gdouble zoom_y, GeglBufferMatrix2 *reference)
+{
+  GeglBufferMatrix2 inverse_jacobian;
+
+  photos_gegl_inverse_jacobian_zoom (&inverse_jacobian, zoom_x, zoom_y);
+  g_assert_cmpfloat_with_epsilon (inverse_jacobian.coeff[0][0], reference->coeff[0][0], PHOTOS_EPSILON);
+  g_assert_cmpfloat_with_epsilon (inverse_jacobian.coeff[0][1], reference->coeff[0][1], PHOTOS_EPSILON);
+  g_assert_cmpfloat_with_epsilon (inverse_jacobian.coeff[1][0], reference->coeff[1][0], PHOTOS_EPSILON);
+  g_assert_cmpfloat_with_epsilon (inverse_jacobian.coeff[1][1], reference->coeff[1][1], PHOTOS_EPSILON);
+}
+
+
 static void
 photos_test_gegl_buffer_apply_orientation_bottom_0 (PhotosTestGeglFixture *fixture, gconstpointer user_data)
 {
@@ -801,6 +814,71 @@ photos_test_gegl_buffer_zoom_out_1 (PhotosTestGeglFixture *fixture, gconstpointe
 }
 
 
+static void
+photos_test_gegl_inverse_jacobian_zoom_0 (void)
+{
+  GeglBufferMatrix2 inverse_jacobian;
+
+  inverse_jacobian.coeff[0][0] = 0.714285714;
+  inverse_jacobian.coeff[0][1] = 0.0;
+  inverse_jacobian.coeff[1][0] = 0.0;
+  inverse_jacobian.coeff[1][1] = 0.25;
+  photos_test_gegl_check_inverse_jacobian (1.4, 4.0, &inverse_jacobian);
+}
+
+
+static void
+photos_test_gegl_inverse_jacobian_zoom_1 (void)
+{
+  GeglBufferMatrix2 inverse_jacobian;
+
+  inverse_jacobian.coeff[0][0] = 0.25;
+  inverse_jacobian.coeff[0][1] = 0.0;
+  inverse_jacobian.coeff[1][0] = 0.0;
+  inverse_jacobian.coeff[1][1] = 0.714285714;
+  photos_test_gegl_check_inverse_jacobian (4.0, 1.4, &inverse_jacobian);
+}
+
+
+static void
+photos_test_gegl_inverse_jacobian_zoom_2 (void)
+{
+  GeglBufferMatrix2 inverse_jacobian;
+
+  inverse_jacobian.coeff[0][0] = 1.0;
+  inverse_jacobian.coeff[0][1] = 0.0;
+  inverse_jacobian.coeff[1][0] = 0.0;
+  inverse_jacobian.coeff[1][1] = 1.0;
+  photos_test_gegl_check_inverse_jacobian (1.0, 1.0, &inverse_jacobian);
+}
+
+
+static void
+photos_test_gegl_inverse_jacobian_zoom_3 (void)
+{
+  GeglBufferMatrix2 inverse_jacobian;
+
+  inverse_jacobian.coeff[0][0] = 1.66666667;
+  inverse_jacobian.coeff[0][1] = 0.0;
+  inverse_jacobian.coeff[1][0] = 0.0;
+  inverse_jacobian.coeff[1][1] = 4.0;
+  photos_test_gegl_check_inverse_jacobian (0.6, 0.25, &inverse_jacobian);
+}
+
+
+static void
+photos_test_gegl_inverse_jacobian_zoom_4 (void)
+{
+  GeglBufferMatrix2 inverse_jacobian;
+
+  inverse_jacobian.coeff[0][0] = 4.0;
+  inverse_jacobian.coeff[0][1] = 0.0;
+  inverse_jacobian.coeff[1][0] = 0.0;
+  inverse_jacobian.coeff[1][1] = 1.66666667;
+  photos_test_gegl_check_inverse_jacobian (0.25, 0.6, &inverse_jacobian);
+}
+
+
 static void
 photos_test_gegl_legacy_convert_between_buffer_pixbuf_0 (PhotosTestGeglFixture *fixture, gconstpointer 
user_data)
 {
@@ -1130,6 +1208,12 @@ main (gint argc, gchar *argv[])
               photos_test_gegl_buffer_zoom_out_1,
               photos_test_gegl_teardown);
 
+  g_test_add_func ("/gegl/inverse-jacobian-zoom-0", photos_test_gegl_inverse_jacobian_zoom_0);
+  g_test_add_func ("/gegl/inverse-jacobian-zoom-1", photos_test_gegl_inverse_jacobian_zoom_1);
+  g_test_add_func ("/gegl/inverse-jacobian-zoom-2", photos_test_gegl_inverse_jacobian_zoom_2);
+  g_test_add_func ("/gegl/inverse-jacobian-zoom-3", photos_test_gegl_inverse_jacobian_zoom_3);
+  g_test_add_func ("/gegl/inverse-jacobian-zoom-4", photos_test_gegl_inverse_jacobian_zoom_4);
+
   g_test_add ("/gegl/legacy/convert-between-buffer-pixbuf-0",
               PhotosTestGeglFixture,
               NULL,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]