[gegl] gegl: add _FILTER_ prefix to scale algorithm buffer flag



commit 5ff771586d099662713b8fd8bc86c4d6b3e1acfc
Author: Øyvind Kolås <pippin gimp org>
Date:   Sun Jan 28 21:27:15 2018 +0100

    gegl: add _FILTER_ prefix to scale algorithm buffer flag

 gegl/buffer/gegl-buffer-access.c |  188 +++++++++++++++++++-------------------
 gegl/gegl-enums.h                |   19 +++-
 gegl/graph/gegl-node.c           |    2 +-
 perf/joblist                     |    2 +-
 perf/test-gegl-buffer-access.c   |    8 +-
 5 files changed, 117 insertions(+), 102 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index 785c69c..3511c19 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -1892,19 +1892,6 @@ _gegl_buffer_get_unlocked (GeglBuffer          *buffer,
                            GeglAbyssPolicy      flags)
 {
   GeglAbyssPolicy repeat_mode = flags & 0x7; /* mask off interpolation from repeat mode part of flags */
-  gint interpolation = (flags & GEGL_BUFFER_BOXFILTER); /* BOXFILTER is and of all interpols */
-
-  if (interpolation == 0)
-  {
-    /* with no specified interpolation we aim for a trade-off where
-       100-200% ends up using box-filter - which is a better transition
-       to nearest neighbor which happens beyond 200% further below.
-     */
-    if (scale > 1.0)
-      interpolation = GEGL_BUFFER_BOXFILTER;
-    else
-      interpolation = GEGL_BUFFER_BILINEAR; /*about 2x as fast as box filter*/
-  }
 
   if (gegl_cl_is_accelerated ())
     {
@@ -1987,6 +1974,9 @@ _gegl_buffer_get_unlocked (GeglBuffer          *buffer,
       gint    factor = 1;
       gint    offset = 0;
 
+      gint interpolation = (flags & GEGL_BUFFER_FILTER_ALL);
+
+
       while (scale <= 0.5)
         {
           x1 = 0 < x1 ? x1 / 2 : (x1 - 1) / 2;
@@ -2018,88 +2008,100 @@ _gegl_buffer_get_unlocked (GeglBuffer          *buffer,
       buf_width  = x2 - x1;
       buf_height = y2 - y1;
 
-      if ((interpolation != GEGL_BUFFER_NEAREST) && scale <= 1.99)
-        {
-          if (interpolation == GEGL_BUFFER_BILINEAR)
-            {
-              buf_width  += 1;
-              buf_height += 1;
-              sample_rect.width  += factor;
-              sample_rect.height += factor;
-
-              sample_buf = g_malloc (buf_height * buf_width * bpp);
-              gegl_buffer_iterate_read_dispatch (buffer, &sample_rect,
-                                         (guchar*)sample_buf,
-                                          buf_width * bpp,
-                                          format, level, repeat_mode);
-
-              sample_rect.x      = x1;
-              sample_rect.y      = y1;
-              sample_rect.width  = x2 - x1 + 1;
-              sample_rect.height = y2 - y1 + 1;
-
-              gegl_resample_bilinear (dest_buf,
-                                      sample_buf,
-                                      rect,
-                                      &sample_rect,
-                                      buf_width * bpp,
-                                      scale,
-                                      format,
-                                      rowstride);
-            }
-          else /* boxfilter */
-            {
-              buf_width  += 2;
-              buf_height += 2;
-              offset = (buf_width + 1) * bpp;
-
-              sample_buf = g_malloc (buf_height * buf_width * bpp);
-              gegl_buffer_iterate_read_dispatch (buffer, &sample_rect,
-                                         (guchar*)sample_buf + offset,
-                                          buf_width * bpp,
-                                          format, level, repeat_mode);
-
-              sample_rect.x      = x1 - 1;
-              sample_rect.y      = y1 - 1;
-              sample_rect.width  = x2 - x1 + 2;
-              sample_rect.height = y2 - y1 + 2;
-
-              gegl_resample_boxfilter (dest_buf,
-                                       sample_buf,
-                                       rect,
-                                       &sample_rect,
-                                       buf_width * bpp,
-                                       scale,
-                                       format,
-                                       rowstride);
-            }
+      if (interpolation == GEGL_BUFFER_FILTER_AUTO)
+      {
+        /* with no specified interpolation we aim for a trade-off where
+           100-200% ends up using box-filter - which is a better transition
+           to nearest neighbor which happens beyond 200% further below.
+         */
+        if (scale >= 2.0)
+          interpolation = GEGL_BUFFER_FILTER_NEAREST;
+        else if (scale > 1.0)
+          interpolation = GEGL_BUFFER_FILTER_BOX;
+        else
+          interpolation = GEGL_BUFFER_FILTER_BILINEAR;
+      }
 
-          g_free (sample_buf);
-        }
-      else if (buf_height && buf_width)
+      if (buf_height && buf_width)
+        switch(interpolation)
         {
-          sample_buf = g_malloc (buf_height * buf_width * bpp);
-
-          gegl_buffer_iterate_read_dispatch (buffer, &sample_rect,
-                                         (guchar*)sample_buf,
-                                         buf_width * bpp,
-                                         format, level, repeat_mode);
-
-          sample_rect.x      = x1;
-          sample_rect.y      = y1;
-          sample_rect.width  = x2 - x1;
-          sample_rect.height = y2 - y1;
-
-          gegl_resample_nearest (dest_buf,
-                                 sample_buf,
-                                 rect,
-                                 &sample_rect,
-                                 buf_width * bpp,
-                                 scale,
-                                 bpp,
-                                 rowstride);
-          g_free (sample_buf);
-        }
+          case GEGL_BUFFER_FILTER_NEAREST:
+            sample_buf = g_malloc (buf_height * buf_width * bpp);
+
+            gegl_buffer_iterate_read_dispatch (buffer, &sample_rect,
+                                               (guchar*)sample_buf,
+                                               buf_width * bpp,
+                                               format, level, repeat_mode);
+            sample_rect.x      = x1;
+            sample_rect.y      = y1;
+            sample_rect.width  = x2 - x1;
+            sample_rect.height = y2 - y1;
+
+            gegl_resample_nearest (dest_buf,
+                                   sample_buf,
+                                   rect,
+                                   &sample_rect,
+                                   buf_width * bpp,
+                                   scale,
+                                   bpp,
+                                   rowstride);
+            g_free (sample_buf);
+            break;
+          case GEGL_BUFFER_FILTER_BILINEAR:
+            buf_width  += 1;
+            buf_height += 1;
+            sample_rect.width  += factor;
+            sample_rect.height += factor;
+
+            sample_buf = g_malloc (buf_height * buf_width * bpp);
+            gegl_buffer_iterate_read_dispatch (buffer, &sample_rect,
+                                       (guchar*)sample_buf,
+                                        buf_width * bpp,
+                                        format, level, repeat_mode);
+
+            sample_rect.x      = x1;
+            sample_rect.y      = y1;
+            sample_rect.width  = x2 - x1 + 1;
+            sample_rect.height = y2 - y1 + 1;
+
+            gegl_resample_bilinear (dest_buf,
+                                    sample_buf,
+                                    rect,
+                                    &sample_rect,
+                                    buf_width * bpp,
+                                    scale,
+                                    format,
+                                    rowstride);
+            g_free (sample_buf);
+            break;
+          case GEGL_BUFFER_FILTER_BOX:
+          default:
+            buf_width  += 2;
+            buf_height += 2;
+            offset = (buf_width + 1) * bpp;
+
+            sample_buf = g_malloc (buf_height * buf_width * bpp);
+            gegl_buffer_iterate_read_dispatch (buffer, &sample_rect,
+                                       (guchar*)sample_buf + offset,
+                                        buf_width * bpp,
+                                        format, level, repeat_mode);
+
+            sample_rect.x      = x1 - 1;
+            sample_rect.y      = y1 - 1;
+            sample_rect.width  = x2 - x1 + 2;
+            sample_rect.height = y2 - y1 + 2;
+
+            gegl_resample_boxfilter (dest_buf,
+                                     sample_buf,
+                                     rect,
+                                     &sample_rect,
+                                     buf_width * bpp,
+                                     scale,
+                                     format,
+                                     rowstride);
+            g_free (sample_buf);
+            break;
+      }
     }
 }
 
diff --git a/gegl/gegl-enums.h b/gegl/gegl-enums.h
index 4d8aa81..ddd026d 100644
--- a/gegl/gegl-enums.h
+++ b/gegl/gegl-enums.h
@@ -37,14 +37,27 @@
 G_BEGIN_DECLS
 
 typedef enum {
+  /* this enum should be renamed GeglBufferFlags, since it contains
+   * multiple flags - and possibly more in the future
+   */
+
+  /* XXX: API tidying of the following would be to make them be
+   *      GEGL_BUFFER_EDGE_NONE or GEGL_BUFFER_REPEAT_NONE instead.
+  */
   GEGL_ABYSS_NONE  = 0,
   GEGL_ABYSS_CLAMP = 1,
   GEGL_ABYSS_LOOP  = 2,
   GEGL_ABYSS_BLACK = 3,
   GEGL_ABYSS_WHITE = 4,
-  GEGL_BUFFER_BILINEAR  = 16,
-  GEGL_BUFFER_NEAREST   = 32,
-  GEGL_BUFFER_BOXFILTER = 48,
+
+  GEGL_BUFFER_FILTER_AUTO     = 0,
+  /* auto gives bilinear for scales <1.0 box for <2.0 and nearest above */
+  GEGL_BUFFER_FILTER_BILINEAR = 16,
+  GEGL_BUFFER_FILTER_NEAREST  = 32,
+  GEGL_BUFFER_FILTER_BOX      = 48,
+  GEGL_BUFFER_FILTER_ALL      = (GEGL_BUFFER_FILTER_BILINEAR|
+                                 GEGL_BUFFER_FILTER_NEAREST|
+                                 GEGL_BUFFER_FILTER_BOX),
 } GeglAbyssPolicy;
 
 GType gegl_abyss_policy_get_type (void) G_GNUC_CONST;
diff --git a/gegl/graph/gegl-node.c b/gegl/graph/gegl-node.c
index 20dab0f..188f680 100644
--- a/gegl/graph/gegl-node.c
+++ b/gegl/graph/gegl-node.c
@@ -1136,7 +1136,7 @@ gegl_node_blit (GeglNode            *self,
                 gint                 rowstride,
                 GeglBlitFlags        flags)
 {
-  gint interpolation = flags & (GEGL_BUFFER_NEAREST | GEGL_BUFFER_BILINEAR);
+  gint interpolation = flags & (GEGL_BUFFER_FILTER_ALL);
   flags &= 0xf;
 
   g_return_if_fail (GEGL_IS_NODE (self));
diff --git a/perf/joblist b/perf/joblist
index b5d2849..28a3dea 100644
--- a/perf/joblist
+++ b/perf/joblist
@@ -1,6 +1,6 @@
 HEAD
 
-master~15..master
+master~20..master
 
 # enable multi-thread by default
 
diff --git a/perf/test-gegl-buffer-access.c b/perf/test-gegl-buffer-access.c
index 6d220c5..b523f6d 100644
--- a/perf/test-gegl-buffer-access.c
+++ b/perf/test-gegl-buffer-access.c
@@ -76,12 +76,12 @@ main (gint    argc,
     {
   /* pre-initialize */
       test_start_iter ();
-      gegl_buffer_get (buffer, &bound2, 0.333, NULL, buf, GEGL_AUTO_ROWSTRIDE, 
GEGL_ABYSS_NONE|GEGL_BUFFER_BOXFILTER);
+      gegl_buffer_get (buffer, &bound2, 0.333, NULL, buf, GEGL_AUTO_ROWSTRIDE, 
GEGL_ABYSS_NONE|GEGL_BUFFER_FILTER_BOX);
       test_end_iter ();
      }
       g_object_unref (buffer);
   }
-  test_end ("boxfilter 0.333", 1.0 * bound2.width * bound2.height * ITERATIONS * 4);
+  test_end ("box 0.333", 1.0 * bound2.width * bound2.height * ITERATIONS * 4);
 
 
   {
@@ -93,7 +93,7 @@ main (gint    argc,
     {
   /* pre-initialize */
       test_start_iter ();
-      gegl_buffer_get (buffer, &bound2, 0.333, NULL, buf, GEGL_AUTO_ROWSTRIDE, 
GEGL_ABYSS_NONE|GEGL_BUFFER_NEAREST);
+      gegl_buffer_get (buffer, &bound2, 0.333, NULL, buf, GEGL_AUTO_ROWSTRIDE, 
GEGL_ABYSS_NONE|GEGL_BUFFER_FILTER_NEAREST);
       test_end_iter ();
      }
       g_object_unref (buffer);
@@ -111,7 +111,7 @@ main (gint    argc,
     {
   /* pre-initialize */
       test_start_iter ();
-      gegl_buffer_get (buffer, &bound2, 0.333, NULL, buf, GEGL_AUTO_ROWSTRIDE, 
GEGL_ABYSS_NONE|GEGL_BUFFER_BILINEAR);
+      gegl_buffer_get (buffer, &bound2, 0.333, NULL, buf, GEGL_AUTO_ROWSTRIDE, 
GEGL_ABYSS_NONE|GEGL_BUFFER_FILTER_BILINEAR);
       test_end_iter ();
      }
       g_object_unref (buffer);


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