[gegl] buffer, operations: in gegl_buffer_create_sub_buffer(), don't alias input



commit d36ec69555212e35127ae3eca7729373ee76a85f
Author: Ell <ell_se yahoo com>
Date:   Thu Sep 5 14:40:07 2019 +0300

    buffer, operations: in gegl_buffer_create_sub_buffer(), don't alias input
    
    In gegl_buffer_create_sub_buffer(), always return a new buffer
    object, even when the requested extent is equal to the input
    extent, instead of just reffing the input buffer in this case.
    This makes sure that (non-content-related) changes to the original
    buffer don't affect the sub-buffer.
    
    Adapt operations that use gegl_buffer_create_sub_buffer(), and for
    which this distinction is irrelevant, to explicitly ref the
    origianl buffer when the bounds are equal, instead of creating a
    sub-buffer.

 gegl/buffer/gegl-buffer.c       |  7 ++-----
 operations/common/buffer-sink.c |  5 ++++-
 operations/common/mblur.c       |  5 ++++-
 operations/core/crop.c          |  5 ++++-
 operations/workshop/hstack.c    | 11 +++++++++--
 5 files changed, 23 insertions(+), 10 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index a9d9d2d4b..8a482af7f 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -1062,11 +1062,8 @@ gegl_buffer_create_sub_buffer (GeglBuffer          *buffer,
 {
   g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
 
-  if (extent == NULL || gegl_rectangle_equal (extent, &buffer->extent))
-    {
-      g_object_ref (buffer);
-      return buffer;
-    }
+  if (extent == NULL)
+    extent = gegl_buffer_get_extent (buffer);
 
   if (extent->width < 0 || extent->height < 0)
     {
diff --git a/operations/common/buffer-sink.c b/operations/common/buffer-sink.c
index 9f9a56529..02185b6f6 100644
--- a/operations/common/buffer-sink.c
+++ b/operations/common/buffer-sink.c
@@ -48,7 +48,10 @@ process (GeglOperation       *operation,
     {
       GeglBuffer **output = o->buffer;
 
-      *output = gegl_buffer_create_sub_buffer (input, result);
+      if (gegl_rectangle_equal (result, gegl_buffer_get_extent (input)))
+        *output = g_object_ref (input);
+      else
+        *output = gegl_buffer_create_sub_buffer (input, result);
     }
   else if (o->buffer != NULL &&
            o->format != NULL)
diff --git a/operations/common/mblur.c b/operations/common/mblur.c
index cd85fe7c1..a3fee5fcb 100644
--- a/operations/common/mblur.c
+++ b/operations/common/mblur.c
@@ -80,7 +80,10 @@ process (GeglOperation       *operation,
     {
       GeglBuffer *temp_in;
 
-      temp_in = gegl_buffer_create_sub_buffer (input, result);
+      if (gegl_rectangle_equal (result, gegl_buffer_get_extent (input)))
+        temp_in = g_object_ref (input);
+      else
+        temp_in = gegl_buffer_create_sub_buffer (input, result);
 
       {
         gint pixels = result->width * result->height;
diff --git a/operations/core/crop.c b/operations/core/crop.c
index e8ef972d8..554012e15 100644
--- a/operations/core/crop.c
+++ b/operations/core/crop.c
@@ -189,7 +189,10 @@ gegl_crop_process (GeglOperation        *operation,
       gegl_rectangle_intersect (&extent,
                                 &extent, gegl_buffer_get_extent (input));
 
-      output = gegl_buffer_create_sub_buffer (input, &extent);
+      if (gegl_rectangle_equal (&extent, gegl_buffer_get_extent (input)))
+        output = g_object_ref (input);
+      else
+        output = gegl_buffer_create_sub_buffer (input, &extent);
 
       /* propagate forked state, meaning that in-place processing is not possible
        * due to shared nature of underlying data
diff --git a/operations/workshop/hstack.c b/operations/workshop/hstack.c
index 3f03970e9..013aa9392 100644
--- a/operations/workshop/hstack.c
+++ b/operations/workshop/hstack.c
@@ -117,8 +117,15 @@ process (GeglOperation       *operation,
    * include both input buffers
    */
 
-  temp_in = gegl_buffer_create_sub_buffer (input, result);
-  temp_aux = gegl_buffer_create_sub_buffer (aux, result);
+  if (gegl_rectangle_equal (result, gegl_buffer_get_extent (input)))
+    temp_in = g_object_ref (input);
+  else
+    temp_in = gegl_buffer_create_sub_buffer (input, result);
+
+  if (gegl_rectangle_equal (result, gegl_buffer_get_extent (aux)))
+    temp_aux = g_object_ref (aux);
+  else
+    temp_aux = gegl_buffer_create_sub_buffer (aux, result);
 
     {
       gfloat *buf  = g_new0 (gfloat, result->width * result->height * 4);


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