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



commit 748611e97c9055e432b687445dda33bb01d4bd58
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

 configure.ac                  |  2 +-
 meson.build                   |  2 +-
 src/photos-gegl.c             | 20 +++++++++++
 src/photos-gegl.h             |  4 +++
 tests/unit/photos-test-gegl.c | 84 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 110 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3ba4960a..e60c233b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,7 +42,7 @@ CAIRO_MIN_VERSION=1.14.0
 DAZZLE_MIN_VERSION=3.26.0
 GDATA_MIN_VERSION=0.15.2
 GDK_PIXBUF_MIN_VERSION=2.36.8
-GEGL_MIN_VERSION=0.4.0
+GEGL_MIN_VERSION=0.4.10
 GEXIV2_MIN_VERSION=0.10.8
 GFBGRAPH_MIN_VERSION=0.2.1
 GLIB_MIN_VERSION=2.57.2
diff --git a/meson.build b/meson.build
index 9986003c..fd665904 100644
--- a/meson.build
+++ b/meson.build
@@ -151,7 +151,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 d6f6cedd..32b0d525 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -694,6 +694,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 566b256a..5de9151e 100644
--- a/src/photos-gegl.h
+++ b/src/photos-gegl.h
@@ -53,6 +53,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 9cfb04da..86603568 100644
--- a/tests/unit/photos-test-gegl.c
+++ b/tests/unit/photos-test-gegl.c
@@ -432,6 +432,19 @@ photos_test_gegl_buffer_check_zoom (PhotosTestGeglFixture *fixture, double zoom,
 }
 
 
+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_y, 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)
 {
@@ -765,6 +778,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.714285714;
+  photos_test_gegl_check_inverse_jacobian (1.4, 1.4, &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.25;
+  photos_test_gegl_check_inverse_jacobian (4.0, 4.0, &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] = 1.66666667;
+  photos_test_gegl_check_inverse_jacobian (0.6, 0.6, &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] = 4.0;
+  photos_test_gegl_check_inverse_jacobian (0.25, 0.25, &inverse_jacobian);
+}
+
+
 static void
 photos_test_gegl_legacy_convert_between_buffer_pixbuf_0 (PhotosTestGeglFixture *fixture, gconstpointer 
user_data)
 {
@@ -1094,6 +1172,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]