[gimp/goat-invasion: 77/325] app: add gimp_apply_operaion() as generic buffer-to-buffer utility function



commit 66f2725c6bc46aa5d66efac52a5f2138ba731180
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 16 15:14:35 2012 +0100

    app: add gimp_apply_operaion() as generic buffer-to-buffer utility function
    
    and use it from gimpdrawable-operation.c

 app/core/Makefile.am              |    2 +
 app/core/gimp-apply-operation.c   |  105 +++++++++++++++++++++++++++++++++++++
 app/core/gimp-apply-operation.h   |   36 +++++++++++++
 app/core/gimpdrawable-operation.c |  100 +++--------------------------------
 4 files changed, 152 insertions(+), 91 deletions(-)
---
diff --git a/app/core/Makefile.am b/app/core/Makefile.am
index fbe0dcc..05f4c26 100644
--- a/app/core/Makefile.am
+++ b/app/core/Makefile.am
@@ -21,6 +21,8 @@ libappcore_a_sources = \
 	core-types.h				\
 	gimp.c					\
 	gimp.h					\
+	gimp-apply-operation.c			\
+	gimp-apply-operation.h			\
 	gimp-contexts.c				\
 	gimp-contexts.h				\
 	gimp-edit.c				\
diff --git a/app/core/gimp-apply-operation.c b/app/core/gimp-apply-operation.c
new file mode 100644
index 0000000..bfb763d
--- /dev/null
+++ b/app/core/gimp-apply-operation.c
@@ -0,0 +1,105 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimp-apply-operation.c
+ * Copyright (C) 2012 Ãyvind KolÃs <pippin gimp org>
+ *                    Sven Neumann <sven gimp org>
+ *                    Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+
+#include "core-types.h"
+
+#include "gegl/gimp-gegl-utils.h"
+
+#include "gimp-apply-operation.h"
+#include "gimpprogress.h"
+
+
+void
+gimp_apply_operation (GeglBuffer          *src_buffer,
+                      GimpProgress        *progress,
+                      const gchar         *undo_desc,
+                      GeglNode            *operation,
+                      gboolean             linear,
+                      GeglBuffer          *dest_buffer,
+                      const GeglRectangle *dest_rect)
+{
+  GeglNode      *gegl;
+  GeglNode      *src_node;
+  GeglNode      *dest_node;
+  GeglProcessor *processor;
+  GeglRectangle  rect = { 0, };
+  gdouble        value;
+
+  g_return_if_fail (GEGL_IS_BUFFER (src_buffer));
+  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
+  g_return_if_fail (progress == NULL || undo_desc != NULL);
+  g_return_if_fail (GEGL_IS_NODE (operation));
+  g_return_if_fail (GEGL_IS_BUFFER (dest_buffer));
+
+  if (dest_rect)
+    {
+      rect = *dest_rect;
+    }
+  else
+    {
+      rect.x      = 0;
+      rect.y      = 0;
+      rect.width  = gegl_buffer_get_width  (dest_buffer);
+      rect.height = gegl_buffer_get_height (dest_buffer);
+    }
+
+  gegl = gegl_node_new ();
+
+  /* Disable caching on all children of the node unless explicitly re-enabled.
+   */
+  g_object_set (gegl,
+                "dont-cache", TRUE,
+                NULL);
+
+  src_node = gegl_node_new_child (gegl,
+                                  "operation", "gegl:buffer-source",
+                                  "buffer",    src_buffer,
+                                  NULL);
+  dest_node = gegl_node_new_child (gegl,
+                                   "operation", "gegl:write-buffer",
+                                   "buffer",    dest_buffer,
+                                   NULL);
+
+  gegl_node_add_child (gegl, operation);
+
+  gegl_node_link_many (src_node, operation, dest_node, NULL);
+
+  processor = gegl_node_new_processor (dest_node, &rect);
+
+  if (progress)
+    gimp_progress_start (progress, undo_desc, FALSE);
+
+  while (gegl_processor_work (processor, &value))
+    if (progress)
+      gimp_progress_set_value (progress, value);
+
+  g_object_unref (processor);
+
+  g_object_unref (gegl);
+
+  if (progress)
+    gimp_progress_end (progress);
+}
diff --git a/app/core/gimp-apply-operation.h b/app/core/gimp-apply-operation.h
new file mode 100644
index 0000000..060aa0a
--- /dev/null
+++ b/app/core/gimp-apply-operation.h
@@ -0,0 +1,36 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimp-apply-operation.h
+ * Copyright (C) 2012 Ãyvind KolÃs <pippin gimp org>
+ *                    Sven Neumann <sven gimp org>
+ *                    Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_APPLY_OPERATION_H__
+#define __GIMP_APPLY_OPERATION_H__
+
+
+void   gimp_apply_operation (GeglBuffer          *src_buffer,
+                             GimpProgress        *progress,
+                             const gchar         *undo_desc,
+                             GeglNode            *operation,
+                             gboolean             linear,
+                             GeglBuffer          *dest_buffer,
+                             const GeglRectangle *dest_rect);
+
+
+#endif /* __GIMP_APPLY_OPERATION_H__ */
diff --git a/app/core/gimpdrawable-operation.c b/app/core/gimpdrawable-operation.c
index aae4ec5..c26c2f9 100644
--- a/app/core/gimpdrawable-operation.c
+++ b/app/core/gimpdrawable-operation.c
@@ -30,6 +30,7 @@
 
 #include "gegl/gimp-gegl-utils.h"
 
+#include "gimp-apply-operation.h"
 #include "gimpdrawable.h"
 #include "gimpdrawable-operation.h"
 #include "gimpdrawable-shadow.h"
@@ -37,17 +38,6 @@
 #include "gimpprogress.h"
 
 
-/*  local function prototypes  */
-
-static void   gimp_drawable_apply_operation_private (GimpDrawable        *drawable,
-                                                     GimpProgress        *progress,
-                                                     const gchar         *undo_desc,
-                                                     GeglNode            *operation,
-                                                     gboolean             linear,
-                                                     GeglBuffer          *dest_buffer,
-                                                     const GeglRectangle *rect);
-
-
 /*  public functions  */
 
 void
@@ -75,13 +65,10 @@ gimp_drawable_apply_operation (GimpDrawable *drawable,
     gimp_tile_manager_create_buffer (gimp_drawable_get_shadow_tiles (drawable),
                                      TRUE);
 
-  gimp_drawable_apply_operation_private (drawable,
-                                         progress,
-                                         undo_desc,
-                                         operation,
-                                         linear,
-                                         dest_buffer,
-                                         &rect);
+  gimp_apply_operation (gimp_drawable_get_read_buffer (drawable),
+                        progress, undo_desc,
+                        operation, linear,
+                        dest_buffer, &rect);
 
   g_object_unref (dest_buffer);
 
@@ -134,29 +121,16 @@ gimp_drawable_apply_operation_to_buffer (GimpDrawable *drawable,
                                          gboolean      linear,
                                          GeglBuffer   *dest_buffer)
 {
-  GeglRectangle rect;
-
   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
   g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
   g_return_if_fail (progress == NULL || undo_desc != NULL);
   g_return_if_fail (GEGL_IS_NODE (operation));
   g_return_if_fail (GEGL_IS_BUFFER (dest_buffer));
 
-  rect.x      = 0;
-  rect.y      = 0;
-  rect.width  = gegl_buffer_get_width  (dest_buffer);
-  rect.height = gegl_buffer_get_height (dest_buffer);
-
-  gimp_drawable_apply_operation_private (drawable,
-                                         progress,
-                                         undo_desc,
-                                         operation,
-                                         linear,
-                                         dest_buffer,
-                                         &rect);
-
-  if (progress)
-    gimp_progress_end (progress);
+  gimp_apply_operation (gimp_drawable_get_read_buffer (drawable),
+                        progress, undo_desc,
+                        operation, linear,
+                        dest_buffer, NULL);
 }
 
 void
@@ -186,59 +160,3 @@ gimp_drawable_apply_operation_to_tiles (GimpDrawable *drawable,
 
   g_object_unref (dest_buffer);
 }
-
-
-/*  private functions  */
-
-static void
-gimp_drawable_apply_operation_private (GimpDrawable        *drawable,
-                                       GimpProgress        *progress,
-                                       const gchar         *undo_desc,
-                                       GeglNode            *operation,
-                                       gboolean             linear,
-                                       GeglBuffer          *dest_buffer,
-                                       const GeglRectangle *rect)
-{
-  GeglBuffer    *src_buffer;
-  GeglNode      *gegl;
-  GeglNode      *src_node;
-  GeglNode      *dest_node;
-  GeglProcessor *processor;
-  gdouble        value;
-
-  gegl = gegl_node_new ();
-
-  /* Disable caching on all children of the node unless explicitly re-enabled.
-   */
-  g_object_set (gegl,
-                "dont-cache", TRUE,
-                NULL);
-
-  src_buffer = gimp_drawable_get_read_buffer (drawable);
-
-  src_node = gegl_node_new_child (gegl,
-                                  "operation", "gegl:buffer-source",
-                                  "buffer",    src_buffer,
-                                  NULL);
-  dest_node = gegl_node_new_child (gegl,
-                                   "operation", "gegl:write-buffer",
-                                   "buffer",    dest_buffer,
-                                   NULL);
-
-  gegl_node_add_child (gegl, operation);
-
-  gegl_node_link_many (src_node, operation, dest_node, NULL);
-
-  processor = gegl_node_new_processor (dest_node, rect);
-
-  if (progress)
-    gimp_progress_start (progress, undo_desc, FALSE);
-
-  while (gegl_processor_work (processor, &value))
-    if (progress)
-      gimp_progress_set_value (progress, value);
-
-  g_object_unref (processor);
-
-  g_object_unref (gegl);
-}



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