[gegl] buffer: add scale argument to gegl_sampler_get



commit b30e5104084ea0d32011c2e55efe81f199abbe4c
Author: Ãyvind KolÃs <pippin gimp org>
Date:   Sun Jul 3 17:00:30 2011 +0100

    buffer: add scale argument to gegl_sampler_get

 gegl/buffer/gegl-buffer-access.c   |    4 +---
 gegl/buffer/gegl-buffer.h          |    1 +
 gegl/buffer/gegl-sampler-cubic.c   |    2 ++
 gegl/buffer/gegl-sampler-lanczos.c |    2 ++
 gegl/buffer/gegl-sampler-linear.c  |    2 ++
 gegl/buffer/gegl-sampler-lohalo.c  |   10 ++++++----
 gegl/buffer/gegl-sampler-nearest.c |    2 ++
 gegl/buffer/gegl-sampler.c         |   35 ++++-------------------------------
 gegl/buffer/gegl-sampler.h         |    8 ++------
 operations/affine/affine.c         |    4 +---
 operations/common/map-absolute.c   |    2 +-
 operations/common/map-relative.c   |    3 ++-
 operations/workshop/whirl-pinch.c  |    3 +--
 13 files changed, 27 insertions(+), 51 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index f5c18fd..5c815fe 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -1104,10 +1104,8 @@ gegl_buffer_sample (GeglBuffer       *buffer,
       buffer->sampler_format = format;
       gegl_sampler_prepare (buffer->sampler);
     }
-  if (scale)
-    gegl_sampler_set_scale (buffer->sampler, scale);
 
-  gegl_sampler_get (buffer->sampler, x, y, dest);
+  gegl_sampler_get (buffer->sampler, x, y, scale, dest);
 }
 
 void
diff --git a/gegl/buffer/gegl-buffer.h b/gegl/buffer/gegl-buffer.h
index 8bb6606..78f76f6 100644
--- a/gegl/buffer/gegl-buffer.h
+++ b/gegl/buffer/gegl-buffer.h
@@ -387,6 +387,7 @@ void  gegl_sampler_set_scale   (GeglSampler *self,
 void  gegl_sampler_get         (GeglSampler *self,
                                 gdouble      x,
                                 gdouble      y,
+                                GeglMatrix2 *scale,
                                 void        *output);
 
 
diff --git a/gegl/buffer/gegl-sampler-cubic.c b/gegl/buffer/gegl-sampler-cubic.c
index be5f1ae..fe9e32c 100644
--- a/gegl/buffer/gegl-sampler-cubic.c
+++ b/gegl/buffer/gegl-sampler-cubic.c
@@ -39,6 +39,7 @@ enum
 static void      gegl_sampler_cubic_get (GeglSampler  *sampler,
                                          gdouble       x,
                                          gdouble       y,
+                                         GeglMatrix2  *scale,
                                          void         *output);
 static void      get_property           (GObject      *gobject,
                                          guint         prop_id,
@@ -126,6 +127,7 @@ void
 gegl_sampler_cubic_get (GeglSampler *self,
                         gdouble      x,
                         gdouble      y,
+                        GeglMatrix2 *scale,
                         void        *output)
 {
   GeglSamplerCubic *cubic = (GeglSamplerCubic*)(self);
diff --git a/gegl/buffer/gegl-sampler-lanczos.c b/gegl/buffer/gegl-sampler-lanczos.c
index 9d10299..1f67267 100644
--- a/gegl/buffer/gegl-sampler-lanczos.c
+++ b/gegl/buffer/gegl-sampler-lanczos.c
@@ -46,6 +46,7 @@ static void           lanczos_lookup (GeglSamplerLanczos *sampler);
 static void           gegl_sampler_lanczos_get (GeglSampler  *sampler,
                                                 gdouble       x,
                                                 gdouble       y,
+                                                GeglMatrix2  *scale,
                                                 void         *output);
 static void           get_property             (GObject      *gobject,
                                                 guint         prop_id,
@@ -145,6 +146,7 @@ void
 gegl_sampler_lanczos_get (GeglSampler *self,
                           gdouble      x,
                           gdouble      y,
+                          GeglMatrix2 *scale,
                           void        *output)
 {
   GeglSamplerLanczos      *lanczos      = GEGL_SAMPLER_LANCZOS (self);
diff --git a/gegl/buffer/gegl-sampler-linear.c b/gegl/buffer/gegl-sampler-linear.c
index d1980dc..57370bf 100644
--- a/gegl/buffer/gegl-sampler-linear.c
+++ b/gegl/buffer/gegl-sampler-linear.c
@@ -65,6 +65,7 @@ enum
 static void gegl_sampler_linear_get (GeglSampler* restrict self,
                                      const gdouble         x,
                                      const gdouble         y,
+                                     GeglMatrix2          *scale,
                                      void*        restrict output);
 
 static void set_property (GObject*      gobject,
@@ -105,6 +106,7 @@ static void
 gegl_sampler_linear_get (GeglSampler* restrict self,
                          const gdouble         absolute_x,
                          const gdouble         absolute_y,
+                         GeglMatrix2          *scale,
                          void*        restrict output)
 {
   const gint pixels_per_buffer_row = 64;
diff --git a/gegl/buffer/gegl-sampler-lohalo.c b/gegl/buffer/gegl-sampler-lohalo.c
index 6d71b15..731d344 100644
--- a/gegl/buffer/gegl-sampler-lohalo.c
+++ b/gegl/buffer/gegl-sampler-lohalo.c
@@ -257,6 +257,7 @@ enum
 static void gegl_sampler_lohalo_get (      GeglSampler* restrict self,
                                      const gdouble               absolute_x,
                                      const gdouble               absolute_y,
+                                           GeglMatrix2          *scale,
                                            void*        restrict output);
 
 
@@ -1306,6 +1307,7 @@ static void
 gegl_sampler_lohalo_get (      GeglSampler* restrict self,
                          const gdouble               absolute_x,
                          const gdouble               absolute_y,
+                         GeglMatrix2                *scale,
                                void*        restrict output)
 {
   /*
@@ -1957,10 +1959,10 @@ gegl_sampler_lohalo_get (      GeglSampler* restrict self,
        * Ellipse reference:
        * http://en.wikipedia.org/wiki/Ellipse#Canonical_form
        */
-      const gdouble a = self->inverse_jacobian?self->inverse_jacobian->coeff[0][0]:1;
-      const gdouble b = self->inverse_jacobian?self->inverse_jacobian->coeff[0][1]:0;
-      const gdouble c = self->inverse_jacobian?self->inverse_jacobian->coeff[1][0]:0;
-      const gdouble d = self->inverse_jacobian?self->inverse_jacobian->coeff[1][1]:1;
+      const gdouble a = scale?scale->coeff[0][0]:1;
+      const gdouble b = scale?scale->coeff[0][1]:0;
+      const gdouble c = scale?scale->coeff[1][0]:0;
+      const gdouble d = scale?scale->coeff[1][1]:1;
 
       /*
        * Computations are done in double precision because "direct"
diff --git a/gegl/buffer/gegl-sampler-nearest.c b/gegl/buffer/gegl-sampler-nearest.c
index 6f3d361..46fd9a1 100644
--- a/gegl/buffer/gegl-sampler-nearest.c
+++ b/gegl/buffer/gegl-sampler-nearest.c
@@ -35,6 +35,7 @@ enum
 static void    gegl_sampler_nearest_get (GeglSampler  *self,
                                          gdouble       x,
                                          gdouble       y,
+                                         GeglMatrix2  *scale,
                                          void         *output);
 static void    set_property             (GObject      *gobject,
                                          guint         prop_id,
@@ -74,6 +75,7 @@ void
 gegl_sampler_nearest_get (GeglSampler *self,
                           gdouble      x,
                           gdouble      y,
+                          GeglMatrix2 *scale,
                           void        *output)
 {
   gfloat             *sampler_bptr;
diff --git a/gegl/buffer/gegl-sampler.c b/gegl/buffer/gegl-sampler.c
index 7ead674..0e2b48b 100644
--- a/gegl/buffer/gegl-sampler.c
+++ b/gegl/buffer/gegl-sampler.c
@@ -42,7 +42,6 @@ enum
   PROP_BUFFER,
   PROP_FORMAT,
   PROP_CONTEXT_RECT,
-  PROP_SCALE,
   PROP_LAST
 };
 
@@ -100,19 +99,6 @@ gegl_sampler_class_init (GeglSamplerClass *klass)
                                         "Input pad, for image buffer input.",
                                         GEGL_TYPE_BUFFER,
                                         G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
-
-  g_object_class_install_property (
-                 object_class,
-                 PROP_SCALE,
-                 g_param_spec_pointer ("scale",
-                                       "Scale",
-"An approximation of the extent of pixels sampled in source for a pixel. "
-"The property can be varied per sampled pixel, avoid setting it if it is "
-"constant for the entire buffer; if setting it for every pixel using the "
-"C function gegl_sampler_set_scale is more efficient. "
-"Mostly the scaling factors for sampling does not need to be set if the "
-"transformation is rotating or only scaling up.",
-                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 }
 
 static void
@@ -133,6 +119,7 @@ void
 gegl_sampler_get (GeglSampler *self,
                   gdouble      x,
                   gdouble      y,
+                  GeglMatrix2 *scale,
                   void        *output)
 {
   GeglSamplerClass *klass;
@@ -144,9 +131,9 @@ gegl_sampler_get (GeglSampler *self,
   self->x = x;
   self->y = y;
 
-  klass = GEGL_SAMPLER_GET_CLASS (self);
-
-  klass->get (self, x, y, output);
+  klass = GEGL_SAMPLER_GET_CLASS (self); /*XXX: bottleneck, store the vfunc cached
+                                                in the instance instead  */
+  klass->get (self, x, y, scale, output);
 }
 
 void
@@ -505,10 +492,6 @@ get_property (GObject    *object,
         g_value_set_pointer (value, self->format);
         break;
 
-      case PROP_SCALE:
-        g_value_set_pointer (value, self->inverse_jacobian);
-        break;
-
       default:
         break;
     }
@@ -532,10 +515,6 @@ set_property (GObject      *object,
         self->format = g_value_get_pointer (value);
         break;
 
-      case PROP_SCALE:
-        self->inverse_jacobian = g_value_get_pointer (value);
-        break;
-
       default:
         break;
     }
@@ -620,9 +599,3 @@ gegl_buffer_sampler_new (GeglBuffer       *buffer,
   gegl_sampler_prepare (sampler);
   return sampler;
 }
-
-void  gegl_sampler_set_scale (GeglSampler *self,
-                              GeglMatrix2 *scale)
-{
-  self->inverse_jacobian = scale;
-}
diff --git a/gegl/buffer/gegl-sampler.h b/gegl/buffer/gegl-sampler.h
index fed7982..0fef155 100644
--- a/gegl/buffer/gegl-sampler.h
+++ b/gegl/buffer/gegl-sampler.h
@@ -47,10 +47,6 @@ struct _GeglSampler
   GeglRectangle  context_rect[GEGL_SAMPLER_MIPMAP_LEVELS];
   gpointer       sampler_buffer[GEGL_SAMPLER_MIPMAP_LEVELS];
   GeglRectangle  sampler_rectangle[GEGL_SAMPLER_MIPMAP_LEVELS];
-  GeglMatrix2   *inverse_jacobian; /* scale - which could be the inverse
-                                      inverse jacobian matrix or some other
-                                      approximation of the extent of the region
-                                      being sampled.  */
   gdouble        x; /* mirrors the currently requested */
   gdouble        y; /* coordinates in the instance     */
 };
@@ -63,6 +59,7 @@ struct _GeglSamplerClass
   void (* get)       (GeglSampler *self,
                       gdouble      x,
                       gdouble      y,
+                      GeglMatrix2 *scale,
                       void        *output);
  void  (*set_buffer) (GeglSampler  *self,
                       GeglBuffer   *buffer);
@@ -75,11 +72,10 @@ void  gegl_sampler_prepare     (GeglSampler *self);
 void  gegl_sampler_set_buffer  (GeglSampler *self,
                                 GeglBuffer  *buffer);
 
-void  gegl_sampler_set_scale   (GeglSampler *self,
-                                GeglMatrix2 *scale);
 void  gegl_sampler_get         (GeglSampler *self,
                                 gdouble      x,
                                 gdouble      y,
+                                GeglMatrix2 *scale,
                                 void        *output);
 
 gfloat * gegl_sampler_get_from_buffer (GeglSampler *sampler,
diff --git a/operations/affine/affine.c b/operations/affine/affine.c
index a9fda6a..f5660eb 100644
--- a/operations/affine/affine.c
+++ b/operations/affine/affine.c
@@ -680,8 +680,6 @@ affine_generic (GeglBuffer  *dest,
       inverse_jacobian.coeff[1][1] = inverse.coeff[1][1];
 
      /* set inverse_jacobian for samplers that support it */
-      sampler->inverse_jacobian = &inverse_jacobian;
-
       u_start = inverse.coeff[0][0] * roi->x + inverse.coeff[0][1]
                     * roi->y + inverse.coeff[0][2];
       v_start = inverse.coeff[1][0] * roi->x + inverse.coeff[1][1]
@@ -698,7 +696,7 @@ affine_generic (GeglBuffer  *dest,
 
            for (x = roi->width; x--;)
              {
-               gegl_sampler_get (sampler, u_float, v_float, dest_ptr);
+               gegl_sampler_get (sampler, u_float, v_float, &inverse_jacobian, dest_ptr);
                dest_ptr+=4;
                u_float += inverse.coeff [0][0];
                v_float += inverse.coeff [1][0];
diff --git a/operations/common/map-absolute.c b/operations/common/map-absolute.c
index 35bc5ce..dfc1250 100644
--- a/operations/common/map-absolute.c
+++ b/operations/common/map-absolute.c
@@ -97,7 +97,7 @@ process (GeglOperation       *operation,
                 }
               else
                 {
-                  gegl_sampler_get (sampler, coords[0], coords[1], out);
+                  gegl_sampler_get (sampler, coords[0], coords[1], NULL, out);
                 }
 
               coords += 2;
diff --git a/operations/common/map-relative.c b/operations/common/map-relative.c
index b10f78d..c1f6c74 100644
--- a/operations/common/map-relative.c
+++ b/operations/common/map-relative.c
@@ -106,7 +106,8 @@ process (GeglOperation       *operation,
               else
                 {
                   gegl_sampler_get (sampler, x+coords[0] * scaling,
-                                             y+coords[1] * scaling, out);
+                                             y+coords[1] * scaling,
+                                             NULL, out);
                 }
 
               coords += 2;
diff --git a/operations/workshop/whirl-pinch.c b/operations/workshop/whirl-pinch.c
index cce8519..7f2104f 100644
--- a/operations/workshop/whirl-pinch.c
+++ b/operations/workshop/whirl-pinch.c
@@ -158,8 +158,7 @@ apply_whirl_pinch (gdouble whirl, gdouble pinch, gdouble radius,
         gegl_sampler_compute_scale (scale, roi->x + col, roi->y + row);
         gegl_unmap (roi->x + col, roi->y + row, cx, cy);
 
-        gegl_sampler_set_scale (sampler, &scale);
-        gegl_sampler_get (sampler, cx, cy, &dst_buf[(row * roi->width + col) * 4]);
+        gegl_sampler_get (sampler, cx, cy, &scale, &dst_buf[(row * roi->width + col) * 4]);
     } /* for */
   } /* for */
 



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