[gimp] app: return GeglBuffer from gimp_image_contiguous_region_foo()



commit 46f74d9f463e4938f829d9986e2a6f175ebfa805
Author: Michael Natterer <mitch gimp org>
Date:   Tue Apr 9 01:38:24 2013 +0200

    app: return GeglBuffer from gimp_image_contiguous_region_foo()
    
    now all intermediate masks should be in "Y float" and avoid all
    conversions.

 app/core/gimpchannel-select.c          |   40 ++++++++++++++++----------------
 app/core/gimpdrawable-bucket-fill.c    |   40 ++++++++++++++++---------------
 app/core/gimpimage-contiguous-region.c |   31 +++++-------------------
 app/core/gimpimage-contiguous-region.h |   34 +++++++++++++-------------
 app/tools/gimpbycolorselecttool.c      |    6 ++--
 app/tools/gimpfuzzyselecttool.c        |    6 ++--
 app/tools/gimpregionselecttool.c       |   27 +++++++++------------
 app/tools/gimpregionselecttool.h       |    6 ++--
 8 files changed, 86 insertions(+), 104 deletions(-)
---
diff --git a/app/core/gimpchannel-select.c b/app/core/gimpchannel-select.c
index e28af8e..5dd9366 100644
--- a/app/core/gimpchannel-select.c
+++ b/app/core/gimpchannel-select.c
@@ -497,10 +497,10 @@ gimp_channel_select_fuzzy (GimpChannel         *channel,
                            gdouble              feather_radius_x,
                            gdouble              feather_radius_y)
 {
-  GimpItem    *item;
-  GimpChannel *add_on;
-  gint         add_on_x = 0;
-  gint         add_on_y = 0;
+  GimpItem   *item;
+  GeglBuffer *add_on;
+  gint        add_on_x = 0;
+  gint        add_on_y = 0;
 
   g_return_if_fail (GIMP_IS_CHANNEL (channel));
   g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (channel)));
@@ -520,12 +520,12 @@ gimp_channel_select_fuzzy (GimpChannel         *channel,
   if (! sample_merged)
     gimp_item_get_offset (GIMP_ITEM (drawable), &add_on_x, &add_on_y);
 
-  gimp_channel_select_channel (channel, C_("undo-type", "Fuzzy Select"),
-                               add_on, add_on_x, add_on_y,
-                               op,
-                               feather,
-                               feather_radius_x,
-                               feather_radius_y);
+  gimp_channel_select_buffer (channel, C_("undo-type", "Fuzzy Select"),
+                              add_on, add_on_x, add_on_y,
+                              op,
+                              feather,
+                              feather_radius_x,
+                              feather_radius_y);
   g_object_unref (add_on);
 }
 
@@ -543,10 +543,10 @@ gimp_channel_select_by_color (GimpChannel         *channel,
                               gdouble              feather_radius_x,
                               gdouble              feather_radius_y)
 {
-  GimpItem    *item;
-  GimpChannel *add_on;
-  gint         add_on_x = 0;
-  gint         add_on_y = 0;
+  GimpItem   *item;
+  GeglBuffer *add_on;
+  gint        add_on_x = 0;
+  gint        add_on_y = 0;
 
   g_return_if_fail (GIMP_IS_CHANNEL (channel));
   g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (channel)));
@@ -567,11 +567,11 @@ gimp_channel_select_by_color (GimpChannel         *channel,
   if (! sample_merged)
     gimp_item_get_offset (GIMP_ITEM (drawable), &add_on_x, &add_on_y);
 
-  gimp_channel_select_channel (channel, C_("undo-type", "Select by Color"),
-                               add_on, add_on_x, add_on_y,
-                               op,
-                               feather,
-                               feather_radius_x,
-                               feather_radius_y);
+  gimp_channel_select_buffer (channel, C_("undo-type", "Select by Color"),
+                              add_on, add_on_x, add_on_y,
+                              op,
+                              feather,
+                              feather_radius_x,
+                              feather_radius_y);
   g_object_unref (add_on);
 }
diff --git a/app/core/gimpdrawable-bucket-fill.c b/app/core/gimpdrawable-bucket-fill.c
index c4f7c7f..ee7199a 100644
--- a/app/core/gimpdrawable-bucket-fill.c
+++ b/app/core/gimpdrawable-bucket-fill.c
@@ -28,10 +28,11 @@
 #include "core-types.h"
 
 #include "gegl/gimp-gegl-apply-operation.h"
+#include "gegl/gimp-gegl-mask.h"
+#include "gegl/gimp-gegl-mask-combine.h"
 #include "gegl/gimp-gegl-utils.h"
 
 #include "gimp.h"
-#include "gimpchannel.h"
 #include "gimpchannel-combine.h"
 #include "gimpcontext.h"
 #include "gimpdrawable.h"
@@ -136,7 +137,6 @@ gimp_drawable_bucket_fill_internal (GimpDrawable        *drawable,
                                     GimpPattern         *pattern)
 {
   GimpImage   *image;
-  GimpChannel *mask;
   GeglBuffer  *buffer;
   GeglBuffer  *mask_buffer;
   gint         x1, y1, x2, y2;
@@ -164,31 +164,33 @@ gimp_drawable_bucket_fill_internal (GimpDrawable        *drawable,
    *  contiguous region. If there is a selection, calculate the
    *  intersection of this region with the existing selection.
    */
-  mask = gimp_image_contiguous_region_by_seed (image, drawable,
-                                               sample_merged,
-                                               TRUE,
-                                               threshold,
-                                               fill_transparent,
-                                               fill_criterion,
-                                               (gint) x,
-                                               (gint) y);
+  mask_buffer = gimp_image_contiguous_region_by_seed (image, drawable,
+                                                      sample_merged,
+                                                      TRUE,
+                                                      threshold,
+                                                      fill_transparent,
+                                                      fill_criterion,
+                                                      (gint) x,
+                                                      (gint) y);
 
   if (selection)
     {
-      gint off_x = 0;
-      gint off_y = 0;
+      GimpDrawable *sel;
+      gint          off_x = 0;
+      gint          off_y = 0;
 
       if (! sample_merged)
         gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
-      gimp_channel_combine_mask (mask, gimp_image_get_mask (image),
-                                 GIMP_CHANNEL_OP_INTERSECT,
-                                 -off_x, -off_y);
-    }
+      sel = GIMP_DRAWABLE (gimp_image_get_mask (image));
 
-  mask_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask));
+      gimp_gegl_mask_combine_buffer (mask_buffer,
+                                     gimp_drawable_get_buffer (sel),
+                                     GIMP_CHANNEL_OP_INTERSECT,
+                                     -off_x, -off_y);
+    }
 
-  gimp_channel_bounds (mask, &x1, &y1, &x2, &y2);
+  gimp_gegl_mask_bounds (mask_buffer, &x1, &y1, &x2, &y2);
 
   /*  make sure we handle the mask correctly if it was sample-merged  */
   if (sample_merged)
@@ -249,7 +251,7 @@ gimp_drawable_bucket_fill_internal (GimpDrawable        *drawable,
                            -mask_offset_x,
                            -mask_offset_y,
                            1.0);
-  g_object_unref (mask);
+  g_object_unref (mask_buffer);
 
   /*  Apply it to the image  */
   gimp_drawable_apply_buffer (drawable, buffer,
diff --git a/app/core/gimpimage-contiguous-region.c b/app/core/gimpimage-contiguous-region.c
index b00b0fe..0fb5e19 100644
--- a/app/core/gimpimage-contiguous-region.c
+++ b/app/core/gimpimage-contiguous-region.c
@@ -30,7 +30,7 @@
 
 #include "gegl/gimp-babl.h"
 
-#include "gimpchannel.h"
+#include "gimpdrawable.h"
 #include "gimpimage.h"
 #include "gimpimage-contiguous-region.h"
 #include "gimppickable.h"
@@ -81,7 +81,7 @@ static void find_contiguous_region_helper (GeglBuffer          *src_buffer,
 
 /*  public functions  */
 
-GimpChannel *
+GeglBuffer *
 gimp_image_contiguous_region_by_seed (GimpImage           *image,
                                       GimpDrawable        *drawable,
                                       gboolean             sample_merged,
@@ -94,7 +94,6 @@ gimp_image_contiguous_region_by_seed (GimpImage           *image,
 {
   GimpPickable *pickable;
   GeglBuffer   *src_buffer;
-  GimpChannel  *mask;
   GeglBuffer   *mask_buffer;
   const Babl   *format;
   gint          n_components;
@@ -138,28 +137,16 @@ gimp_image_contiguous_region_by_seed (GimpImage           *image,
   mask_buffer = gegl_buffer_new (gegl_buffer_get_extent (src_buffer),
                                  babl_format ("Y float"));
 
-  gegl_buffer_clear (mask_buffer, NULL);
-
   find_contiguous_region_helper (src_buffer, mask_buffer,
                                  format, n_components, has_alpha,
                                  select_transparent, select_criterion,
                                  antialias, threshold,
                                  x, y, start_col);
 
-  /* wrap mask_buffer in a drawable and return it */
-  mask = gimp_channel_new_mask (image,
-                                gegl_buffer_get_width  (mask_buffer),
-                                gegl_buffer_get_height (mask_buffer));
-
-  gegl_buffer_copy (mask_buffer, NULL,
-                    gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)), NULL);
-
-  g_object_unref (mask_buffer);
-
-  return mask;
+  return mask_buffer;
 }
 
-GimpChannel *
+GeglBuffer *
 gimp_image_contiguous_region_by_color (GimpImage            *image,
                                        GimpDrawable         *drawable,
                                        gboolean              sample_merged,
@@ -177,7 +164,6 @@ gimp_image_contiguous_region_by_color (GimpImage            *image,
    */
   GeglBufferIterator *iter;
   GimpPickable       *pickable;
-  GimpChannel        *mask;
   GeglBuffer         *src_buffer;
   GeglBuffer         *mask_buffer;
   const Babl         *format;
@@ -218,11 +204,8 @@ gimp_image_contiguous_region_by_color (GimpImage            *image,
       select_transparent = FALSE;
     }
 
-  mask = gimp_channel_new_mask (image,
-                                gegl_buffer_get_width  (src_buffer),
-                                gegl_buffer_get_height (src_buffer));
-
-  mask_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask));
+  mask_buffer = gegl_buffer_new (gegl_buffer_get_extent (src_buffer),
+                                 babl_format ("Y float"));
 
   iter = gegl_buffer_iterator_new (src_buffer,
                                    NULL, 0, format,
@@ -253,7 +236,7 @@ gimp_image_contiguous_region_by_color (GimpImage            *image,
         }
     }
 
-  return mask;
+  return mask_buffer;
 }
 
 
diff --git a/app/core/gimpimage-contiguous-region.h b/app/core/gimpimage-contiguous-region.h
index 4a211dc..2e62187 100644
--- a/app/core/gimpimage-contiguous-region.h
+++ b/app/core/gimpimage-contiguous-region.h
@@ -19,24 +19,24 @@
 #define __GIMP_IMAGE_CONTIGUOUS_REGION_H__
 
 
-GimpChannel * gimp_image_contiguous_region_by_seed  (GimpImage           *image,
-                                                     GimpDrawable        *drawable,
-                                                     gboolean             sample_merged,
-                                                     gboolean             antialias,
-                                                     gfloat               threshold,
-                                                     gboolean             select_transparent,
-                                                     GimpSelectCriterion  select_criterion,
-                                                     gint                 x,
-                                                     gint                 y);
+GeglBuffer * gimp_image_contiguous_region_by_seed  (GimpImage           *image,
+                                                    GimpDrawable        *drawable,
+                                                    gboolean             sample_merged,
+                                                    gboolean             antialias,
+                                                    gfloat               threshold,
+                                                    gboolean             select_transparent,
+                                                    GimpSelectCriterion  select_criterion,
+                                                    gint                 x,
+                                                    gint                 y);
 
-GimpChannel * gimp_image_contiguous_region_by_color (GimpImage           *image,
-                                                     GimpDrawable        *drawable,
-                                                     gboolean             sample_merged,
-                                                     gboolean             antialias,
-                                                     gfloat               threshold,
-                                                     gboolean             select_transparent,
-                                                     GimpSelectCriterion  select_criterion,
-                                                     const GimpRGB       *color);
+GeglBuffer * gimp_image_contiguous_region_by_color (GimpImage           *image,
+                                                    GimpDrawable        *drawable,
+                                                    gboolean             sample_merged,
+                                                    gboolean             antialias,
+                                                    gfloat               threshold,
+                                                    gboolean             select_transparent,
+                                                    GimpSelectCriterion  select_criterion,
+                                                    const GimpRGB       *color);
 
 
 #endif  /*  __GIMP_IMAGE_CONTIGUOUS_REGION_H__ */
diff --git a/app/tools/gimpbycolorselecttool.c b/app/tools/gimpbycolorselecttool.c
index cae970b..8d6e764 100644
--- a/app/tools/gimpbycolorselecttool.c
+++ b/app/tools/gimpbycolorselecttool.c
@@ -45,8 +45,8 @@
 #include "gimp-intl.h"
 
 
-static GimpChannel * gimp_by_color_select_tool_get_mask (GimpRegionSelectTool *region_select,
-                                                         GimpDisplay          *display);
+static GeglBuffer * gimp_by_color_select_tool_get_mask (GimpRegionSelectTool *region_select,
+                                                        GimpDisplay          *display);
 
 
 G_DEFINE_TYPE (GimpByColorSelectTool, gimp_by_color_select_tool,
@@ -91,7 +91,7 @@ gimp_by_color_select_tool_init (GimpByColorSelectTool *by_color_select)
   gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_HAND);
 }
 
-static GimpChannel *
+static GeglBuffer *
 gimp_by_color_select_tool_get_mask (GimpRegionSelectTool *region_select,
                                     GimpDisplay          *display)
 {
diff --git a/app/tools/gimpfuzzyselecttool.c b/app/tools/gimpfuzzyselecttool.c
index 3b5f711..89f555b 100644
--- a/app/tools/gimpfuzzyselecttool.c
+++ b/app/tools/gimpfuzzyselecttool.c
@@ -43,8 +43,8 @@
 #include "gimp-intl.h"
 
 
-static GimpChannel * gimp_fuzzy_select_tool_get_mask (GimpRegionSelectTool *region_select,
-                                                      GimpDisplay          *display);
+static GeglBuffer * gimp_fuzzy_select_tool_get_mask (GimpRegionSelectTool *region_select,
+                                                     GimpDisplay          *display);
 
 
 G_DEFINE_TYPE (GimpFuzzySelectTool, gimp_fuzzy_select_tool,
@@ -90,7 +90,7 @@ gimp_fuzzy_select_tool_init (GimpFuzzySelectTool *fuzzy_select)
                                      GIMP_TOOL_CURSOR_FUZZY_SELECT);
 }
 
-static GimpChannel *
+static GeglBuffer *
 gimp_fuzzy_select_tool_get_mask (GimpRegionSelectTool *region_select,
                                  GimpDisplay          *display)
 {
diff --git a/app/tools/gimpregionselecttool.c b/app/tools/gimpregionselecttool.c
index 63c2399..3dca9fa 100644
--- a/app/tools/gimpregionselecttool.c
+++ b/app/tools/gimpregionselecttool.c
@@ -217,15 +217,15 @@ gimp_region_select_tool_button_release (GimpTool              *tool,
               gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
             }
 
-          gimp_channel_select_channel (gimp_image_get_mask (image),
-                                       GIMP_REGION_SELECT_TOOL_GET_CLASS (tool)->undo_desc,
-                                       region_sel->region_mask,
-                                       off_x,
-                                       off_y,
-                                       sel_options->operation,
-                                       sel_options->feather,
-                                       sel_options->feather_radius,
-                                       sel_options->feather_radius);
+          gimp_channel_select_buffer (gimp_image_get_mask (image),
+                                      GIMP_REGION_SELECT_TOOL_GET_CLASS (tool)->undo_desc,
+                                      region_sel->region_mask,
+                                      off_x,
+                                      off_y,
+                                      sel_options->operation,
+                                      sel_options->feather,
+                                      sel_options->feather_radius,
+                                      sel_options->feather_radius);
 
 
           gimp_image_flush (image);
@@ -343,7 +343,6 @@ gimp_region_select_tool_calculate (GimpRegionSelectTool *region_sel,
                                    gint                 *n_segs)
 {
   GimpDisplayShell *shell = gimp_display_get_shell (display);
-  GeglBuffer       *buffer;
   GimpBoundSeg     *segs;
 
   gimp_display_shell_set_override_cursor (shell, GDK_WATCH);
@@ -366,14 +365,12 @@ gimp_region_select_tool_calculate (GimpRegionSelectTool *region_sel,
   /*  calculate and allocate a new segment array which represents the
    *  boundary of the contiguous region
    */
-  buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (region_sel->region_mask));
-
-  segs = gimp_boundary_find (buffer, NULL,
+  segs = gimp_boundary_find (region_sel->region_mask, NULL,
                              babl_format ("Y float"),
                              GIMP_BOUNDARY_WITHIN_BOUNDS,
                              0, 0,
-                             gimp_item_get_width  (GIMP_ITEM (region_sel->region_mask)),
-                             gimp_item_get_height (GIMP_ITEM (region_sel->region_mask)),
+                             gegl_buffer_get_width  (region_sel->region_mask),
+                             gegl_buffer_get_height (region_sel->region_mask),
                              GIMP_BOUNDARY_HALF_WAY,
                              n_segs);
 
diff --git a/app/tools/gimpregionselecttool.h b/app/tools/gimpregionselecttool.h
index 34de05e..a95ddeb 100644
--- a/app/tools/gimpregionselecttool.h
+++ b/app/tools/gimpregionselecttool.h
@@ -44,7 +44,7 @@ struct _GimpRegionSelectTool
   gint               x, y;
   gdouble            saved_threshold;
 
-  GimpChannel       *region_mask;
+  GeglBuffer        *region_mask;
   GimpBoundSeg      *segs;
   gint               n_segs;
 };
@@ -55,8 +55,8 @@ struct _GimpRegionSelectToolClass
 
   const gchar * undo_desc;
 
-  GimpChannel * (* get_mask) (GimpRegionSelectTool *region_tool,
-                              GimpDisplay          *display);
+  GeglBuffer * (* get_mask) (GimpRegionSelectTool *region_tool,
+                             GimpDisplay          *display);
 };
 
 


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