[gegl] Enable the scale parameter of gegl_node_blit



commit eaf72ddb666d5f5bc13201ff16b10046d1f773b0
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Thu Oct 3 03:15:46 2013 -0700

    Enable the scale parameter of gegl_node_blit

 gegl/buffer/gegl-buffer-access.c  |   36 ++++++++++++++++++++++++++++++++++++
 gegl/buffer/gegl-buffer-private.h |    4 ++++
 gegl/graph/gegl-node.c            |   25 ++++++++++++-------------
 3 files changed, 52 insertions(+), 13 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index 8b85db6..535123f 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -1444,6 +1444,42 @@ resample_boxfilter_T  (guchar              *dest_buf,
     }
 }
 
+/* Expand roi by scale so it uncludes all pixels needed
+ * to satisfy a gegl_buffer_get() call at level 0.
+ */
+GeglRectangle
+_gegl_get_required_for_scale (const Babl          *format,
+                              const GeglRectangle *roi,
+                              gdouble              scale)
+{
+  if (GEGL_FLOAT_EQUAL (scale, 1.0))
+    return *roi;
+  else
+    {
+      gint x1 = floor (roi->x / scale + EPSILON);
+      gint x2 = ceil ((roi->x + roi->width) / scale - EPSILON);
+      gint y1 = floor (roi->y / scale + EPSILON);
+      gint y2 = ceil ((roi->y + roi->height) / scale - EPSILON);
+
+      gint pad = (1.0 / scale > 1.0) ? ceil (1.0 / scale) : 1;
+
+      if ((babl_format_get_type (format, 0) == projectionT) ||
+          (scale < 1.0))
+        {
+          return *GEGL_RECTANGLE (x1 - pad,
+                                  y1 - pad,
+                                  x2 - x1 + 2 * pad,
+                                  y2 - y1 + 2 * pad);
+        }
+      else
+        {
+          return *GEGL_RECTANGLE (x1,
+                                  y1,
+                                  x2 - x1,
+                                  y2 - y1);
+        }
+      }
+}
 
 void
 gegl_buffer_get_unlocked (GeglBuffer          *buffer,
diff --git a/gegl/buffer/gegl-buffer-private.h b/gegl/buffer/gegl-buffer-private.h
index 546f4b0..95d4ef7 100644
--- a/gegl/buffer/gegl-buffer-private.h
+++ b/gegl/buffer/gegl-buffer-private.h
@@ -186,6 +186,10 @@ struct _GeglTile
 
 void _gegl_buffer_drop_hot_tile (GeglBuffer *buffer);
 
+GeglRectangle _gegl_get_required_for_scale (const Babl          *format,
+                                            const GeglRectangle *roi,
+                                            gdouble              scale);
+
 gboolean gegl_buffer_scan_compatible (GeglBuffer *bufferA,
                                       gint        xA,
                                       gint        yA,
diff --git a/gegl/graph/gegl-node.c b/gegl/graph/gegl-node.c
index fba9b2a..31cebdd 100644
--- a/gegl/graph/gegl-node.c
+++ b/gegl/graph/gegl-node.c
@@ -925,25 +925,24 @@ gegl_node_blit (GeglNode            *self,
     {
       GeglBuffer *buffer;
 
-      buffer = gegl_node_apply_roi (self, roi);
-      if (buffer && destination_buf)
+      if (scale != 1.0)
         {
-          if (destination_buf)
-            {
-              gegl_buffer_get (buffer, roi, 1.0, format, destination_buf, rowstride, GEGL_ABYSS_NONE);
-            }
+          const GeglRectangle unscaled_roi = _gegl_get_required_for_scale (format, roi, scale);
 
-          if (scale != 1.0)
-            {
-              g_warning ("scale %f=1.0 in blit without cache", scale);
-            }
+          buffer = gegl_node_apply_roi (self, &unscaled_roi);
+        }
+      else
+        {
+          buffer = gegl_node_apply_roi (self, roi);
         }
 
+      if (buffer && destination_buf)
+        gegl_buffer_get (buffer, roi, scale, format, destination_buf, rowstride, GEGL_ABYSS_NONE);
+
       if (buffer)
         g_object_unref (buffer);
     }
-  else
-    if ((flags & GEGL_BLIT_CACHE))
+  else if (flags & GEGL_BLIT_CACHE)
     {
       GeglCache *cache = gegl_node_get_cache (self);
       if (!(flags & GEGL_BLIT_DIRTY))


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