[gimp] app: add a gegl:copy-buffer to GimpApplicator



commit 987d9e2800bcf3cdd403866a0ea7f58aebca7349
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jun 1 18:35:18 2014 +0200

    app: add a gegl:copy-buffer to GimpApplicator
    
    which allows to get a buffer copy of the result of the applied
    operation without the overhead of running the entire graph again just
    for this purpose.

 app/gegl/gimpapplicator.c |   47 +++++++++++++++++++-------------------------
 app/gegl/gimpapplicator.h |    2 +
 app/sanity.c              |    1 +
 3 files changed, 23 insertions(+), 27 deletions(-)
---
diff --git a/app/gegl/gimpapplicator.c b/app/gegl/gimpapplicator.c
index fdff8bd..fc85be8 100644
--- a/app/gegl/gimpapplicator.c
+++ b/app/gegl/gimpapplicator.c
@@ -150,8 +150,16 @@ gimp_applicator_new (GeglNode *parent,
 
   gegl_node_connect_to (applicator->aux_node,          "output",
                         applicator->apply_offset_node, "input");
-  gegl_node_connect_to (applicator->apply_offset_node, "output",
-                        applicator->mode_node,         "aux");
+
+  applicator->dup_apply_buffer_node =
+    gegl_node_new_child (applicator->node,
+                         "operation", "gegl:copy-buffer",
+                         NULL);
+
+  gegl_node_connect_to (applicator->apply_offset_node,     "output",
+                        applicator->dup_apply_buffer_node, "input");
+  gegl_node_connect_to (applicator->dup_apply_buffer_node, "output",
+                        applicator->mode_node,             "aux");
 
   applicator->mask_node =
     gegl_node_new_child (applicator->node,
@@ -423,37 +431,22 @@ gimp_applicator_dup_apply_buffer (GimpApplicator      *applicator,
                                   const GeglRectangle *rect)
 {
   GeglBuffer *buffer;
-  GeglNode   *offset;
-  GeglNode   *dest;
+  GeglBuffer *shifted;
 
   buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, rect->width, rect->height),
                             babl_format ("RGBA float"));
 
-  offset = gegl_node_new_child (applicator->node,
-                                "operation", "gegl:translate",
-                                "x",
-                                (gdouble) - applicator->apply_offset_x - rect->x,
-                                "y",
-                                (gdouble) - applicator->apply_offset_y - rect->y,
-                                NULL);
-
-  dest = gegl_node_new_child (applicator->node,
-                              "operation", "gegl:write-buffer",
-                              "buffer",    buffer,
-                              NULL);
-
-  gegl_node_link_many (applicator->apply_offset_node,
-                       offset,
-                       dest,
-                       NULL);
-
-  gegl_node_blit (dest, 1.0, GEGL_RECTANGLE (0, 0, rect->width, rect->height),
-                  NULL, NULL, 0, GEGL_BLIT_DEFAULT);
+  shifted = g_object_new (GEGL_TYPE_BUFFER,
+                          "source",  buffer,
+                          "shift-x", -rect->x,
+                          "shift-y", -rect->y,
+                          NULL);
 
-  gegl_node_disconnect (offset, "input");
+  gegl_node_set (applicator->dup_apply_buffer_node,
+                 "buffer", shifted,
+                 NULL);
 
-  gegl_node_remove_child (applicator->node, offset);
-  gegl_node_remove_child (applicator->node, dest);
+  g_object_unref (shifted);
 
   return buffer;
 }
diff --git a/app/gegl/gimpapplicator.h b/app/gegl/gimpapplicator.h
index 73f3720..f434bc8 100644
--- a/app/gegl/gimpapplicator.h
+++ b/app/gegl/gimpapplicator.h
@@ -48,6 +48,8 @@ struct _GimpApplicator
   gint                  apply_offset_y;
   GeglNode             *apply_offset_node;
 
+  GeglNode             *dup_apply_buffer_node;
+
   gdouble               opacity;
   GimpLayerModeEffects  paint_mode;
   gboolean              linear;
diff --git a/app/sanity.c b/app/sanity.c
index 91cdea9..e923a25 100644
--- a/app/sanity.c
+++ b/app/sanity.c
@@ -485,6 +485,7 @@ sanity_check_gegl_ops (void)
     "gegl:color-temperature",
     "gegl:color-to-alpha",
     "gegl:convolution-matrix",
+    "gegl:copy-buffer",
     "gegl:crop",
     "gegl:cubism",
     "gegl:deinterlace",


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