[gimp/gimp-2-10] app: add gimp_gegl_buffer_dup()



commit c0e04c3b5ff8ae755acd1a1d3787474e212b5467
Author: Ell <ell_se yahoo com>
Date:   Tue Jul 30 20:19:21 2019 +0300

    app: add gimp_gegl_buffer_dup()
    
    ... as a drop-in replacement for gegl_buffer_dup(), which COWs all
    tiles of the source buffer, including ones that aren't fully
    included within buffer's extent.
    
    (cherry picked from commit 5798cefe1b3941274f65098c71318a8da03a789d)

 app/gegl/gimp-gegl-utils.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++
 app/gegl/gimp-gegl-utils.h |  2 ++
 2 files changed, 52 insertions(+)
---
diff --git a/app/gegl/gimp-gegl-utils.c b/app/gegl/gimp-gegl-utils.c
index a88e70f9d9..c4465bf7d9 100644
--- a/app/gegl/gimp-gegl-utils.c
+++ b/app/gegl/gimp-gegl-utils.c
@@ -29,6 +29,7 @@
 
 #include "core/gimpprogress.h"
 
+#include "gimp-gegl-loops.h"
 #include "gimp-gegl-utils.h"
 
 
@@ -230,3 +231,52 @@ gimp_gegl_param_spec_has_key (GParamSpec  *pspec,
 
   return FALSE;
 }
+
+GeglBuffer *
+gimp_gegl_buffer_dup (GeglBuffer *buffer)
+{
+  GeglBuffer          *new_buffer;
+  const GeglRectangle *extent;
+  const GeglRectangle *abyss;
+  GeglRectangle        rect;
+  gint                 shift_x;
+  gint                 shift_y;
+  gint                 tile_width;
+  gint                 tile_height;
+
+  g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
+
+  extent = gegl_buffer_get_extent (buffer);
+  abyss  = gegl_buffer_get_abyss  (buffer);
+
+  g_object_get (buffer,
+                "shift-x",     &shift_x,
+                "shift-y",     &shift_y,
+                "tile-width",  &tile_width,
+                "tile-height", &tile_height,
+                NULL);
+
+  new_buffer = g_object_new (GEGL_TYPE_BUFFER,
+                             "format",       gegl_buffer_get_format (buffer),
+                             "x",            extent->x,
+                             "y",            extent->y,
+                             "width",        extent->width,
+                             "height",       extent->height,
+                             "abyss-x",      abyss->x,
+                             "abyss-y",      abyss->y,
+                             "abyss-width",  abyss->width,
+                             "abyss-height", abyss->height,
+                             "shift-x",      shift_x,
+                             "shift-y",      shift_y,
+                             "tile-width",   tile_width,
+                             "tile-height",  tile_height,
+                             NULL);
+
+  gegl_rectangle_align_to_buffer (&rect, extent, buffer,
+                                  GEGL_RECTANGLE_ALIGNMENT_SUPERSET);
+
+  gimp_gegl_buffer_copy (buffer, &rect, GEGL_ABYSS_NONE,
+                         new_buffer, &rect);
+
+  return new_buffer;
+}
diff --git a/app/gegl/gimp-gegl-utils.h b/app/gegl/gimp-gegl-utils.h
index f568588235..e3e16fa966 100644
--- a/app/gegl/gimp-gegl-utils.h
+++ b/app/gegl/gimp-gegl-utils.h
@@ -46,5 +46,7 @@ gboolean     gimp_gegl_param_spec_has_key            (GParamSpec          *pspec
                                                       const gchar         *key,
                                                       const gchar         *value);
 
+GeglBuffer * gimp_gegl_buffer_dup                    (GeglBuffer          *buffer);
+
 
 #endif /* __GIMP_GEGL_UTILS_H__ */


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