[gegl] buffer: use linear sampler in cubic sampler box filtering



commit 80f7b48f582433adc1a103b906733ef2f477a78c
Author: Ell <ell_se yahoo com>
Date:   Sun Mar 4 07:29:31 2018 -0500

    buffer: use linear sampler in cubic sampler box filtering
    
    In _gegl_sampler_box_get(), make the type of sampler used for
    sampling individual points configurable.  Use a NEAREST sampler for
    the LINEAR sampler (i.e., when the LINEAR sampler does box
    filtering, it uses a NEAREST sampler to sub-sample the image), and
    a LINEAR sampler for the CUBIC sampler.  The latter is about twice
    as slow, but produces better results, in particular, it is less
    prone to aliasing in high-frequency input for not-too-big scale
    factors.
    
    This agrees with the general rule that CUBIC is better but slower
    than LINEAR, though still notably faster than the foo-halo
    samplers.

 gegl/buffer/gegl-sampler-cubic.c  |    5 +++--
 gegl/buffer/gegl-sampler-linear.c |    5 +++--
 gegl/buffer/gegl-sampler.c        |    2 +-
 gegl/buffer/gegl-sampler.h        |   25 +++++++++++++------------
 4 files changed, 20 insertions(+), 17 deletions(-)
---
diff --git a/gegl/buffer/gegl-sampler-cubic.c b/gegl/buffer/gegl-sampler-cubic.c
index beb27e6..78ab93d 100644
--- a/gegl/buffer/gegl-sampler-cubic.c
+++ b/gegl/buffer/gegl-sampler-cubic.c
@@ -160,8 +160,9 @@ gegl_sampler_cubic_get (      GeglSampler     *self,
                               void            *output,
                               GeglAbyssPolicy  repeat_mode)
 {
-  if (! _gegl_sampler_box_get (self, absolute_x, absolute_y, scale, 5,
-                               output, repeat_mode))
+  if (! _gegl_sampler_box_get (self, absolute_x, absolute_y, scale,
+                               output, repeat_mode,
+                               GEGL_SAMPLER_LINEAR, 5))
   {
     GeglSamplerCubic *cubic       = (GeglSamplerCubic*)(self);
     const gint        offsets[16] = {
diff --git a/gegl/buffer/gegl-sampler-linear.c b/gegl/buffer/gegl-sampler-linear.c
index ad4dce1..b4310fd 100644
--- a/gegl/buffer/gegl-sampler-linear.c
+++ b/gegl/buffer/gegl-sampler-linear.c
@@ -81,8 +81,9 @@ gegl_sampler_linear_get (     GeglSampler     *self,
                               void            *output,
                               GeglAbyssPolicy  repeat_mode)
 {
-  if (! _gegl_sampler_box_get (self, absolute_x, absolute_y, scale, 4,
-                               output, repeat_mode))
+  if (! _gegl_sampler_box_get (self, absolute_x, absolute_y, scale,
+                               output, repeat_mode,
+                               GEGL_SAMPLER_NEAREST, 4))
   {
     const gint pixels_per_buffer_row = GEGL_SAMPLER_MAXIMUM_WIDTH;
     const gint channels = 4;
diff --git a/gegl/buffer/gegl-sampler.c b/gegl/buffer/gegl-sampler.c
index cdd17c3..4f7eb49 100644
--- a/gegl/buffer/gegl-sampler.c
+++ b/gegl/buffer/gegl-sampler.c
@@ -242,7 +242,7 @@ dispose (GObject *gobject)
   /* This call handles unreffing the buffer and disconnecting signals */
   set_buffer (sampler, NULL);
 
-  g_clear_object (&sampler->nearest_sampler);
+  g_clear_object (&sampler->point_sampler);
 
   G_OBJECT_CLASS (gegl_sampler_parent_class)->dispose (gobject);
 }
diff --git a/gegl/buffer/gegl-sampler.h b/gegl/buffer/gegl-sampler.h
index dd68ba7..d258463 100644
--- a/gegl/buffer/gegl-sampler.h
+++ b/gegl/buffer/gegl-sampler.h
@@ -70,8 +70,8 @@ struct _GeglSampler
   const Babl        *format;
   const Babl        *interpolate_format;
   const Babl        *fish;
-  GeglSampler       *nearest_sampler;
-  GeglSamplerGetFun  nearest_sampler_get_fun;
+  GeglSampler       *point_sampler;
+  GeglSamplerGetFun  point_sampler_get_fun;
 
   GeglSamplerLevel   level[GEGL_SAMPLER_MIPMAP_LEVELS];
 };
@@ -224,9 +224,10 @@ _gegl_sampler_box_get (GeglSampler*    restrict  self,
                        const gdouble             absolute_x,
                        const gdouble             absolute_y,
                        GeglMatrix2              *scale,
-                       gint                      n_samples,
                        void*           restrict  output,
-                       GeglAbyssPolicy           repeat_mode)
+                       GeglAbyssPolicy           repeat_mode,
+                       GeglSamplerType           point_sampler_type,
+                       gint                      n_samples)
 {
   if (scale && fabs (gegl_matrix2_determinant (scale)) >= 4.0)
     {
@@ -253,13 +254,13 @@ _gegl_sampler_box_get (GeglSampler*    restrict  self,
       gint          u;
       gint          v;
 
-      if (! self->nearest_sampler)
+      if (! self->point_sampler)
         {
-          self->nearest_sampler = gegl_buffer_sampler_new (self->buffer,
-                                                           self->format,
-                                                           GEGL_SAMPLER_NEAREST);
-          self->nearest_sampler_get_fun =
-            gegl_sampler_get_fun (self->nearest_sampler);
+          self->point_sampler = gegl_buffer_sampler_new (self->buffer,
+                                                         self->format,
+                                                         point_sampler_type);
+          self->point_sampler_get_fun =
+            gegl_sampler_get_fun (self->point_sampler);
         }
 
       for (v = 0; v < v_samples; v++)
@@ -271,8 +272,8 @@ _gegl_sampler_box_get (GeglSampler*    restrict  self,
             {
               int c;
               gfloat input[4];
-              self->nearest_sampler_get_fun (self->nearest_sampler,
-                                             x, y, NULL, input, repeat_mode);
+              self->point_sampler_get_fun (self->point_sampler,
+                                           x, y, NULL, input, repeat_mode);
               for (c = 0; c < 4; c++)
                 result[c] += input[c];
 


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