From f15e8a1ea2a4b1a9e0680e2478b5d77fed15f3eb Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Fri, 16 Mar 2012 15:14:35 +0100 Subject: [PATCH] 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(-) create mode 100644 app/core/gimp-apply-operation.c create mode 100644 app/core/gimp-apply-operation.h diff --git a/app/core/Makefile.am b/app/core/Makefile.am index fbe0dccf8e..05f4c2610d 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 0000000000..bfb763d9fc --- /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 + * Sven Neumann + * Michael Natterer + * + * 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 . + */ + +#include "config.h" + +#include + +#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 0000000000..060aa0a2b5 --- /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 + * Sven Neumann + * Michael Natterer + * + * 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 . + */ + +#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 aae4ec5377..c26c2f9df3 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); -}