[gimp] app: Add gimp_channel_flood() function



commit 3f04e349cf7be63b78a261652101bfbc8eea1540
Author: Ell <ell_se yahoo com>
Date:   Sun Jan 24 17:38:31 2016 +0000

    app: Add gimp_channel_flood() function
    
    This function applies the "gimp:flood" operation to the channel.

 app/core/gimpchannel.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 app/core/gimpchannel.h |    5 +++++
 app/gimpcore.def       |    1 +
 3 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index dfa771c..4ea9cda 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -224,6 +224,8 @@ static void       gimp_channel_real_shrink   (GimpChannel         *channel,
                                               gint                 radius_y,
                                               gboolean             edge_lock,
                                               gboolean             push_undo);
+static void       gimp_channel_real_flood    (GimpChannel    *channel,
+                                              gboolean             push_undo);
 
 
 G_DEFINE_TYPE_WITH_CODE (GimpChannel, gimp_channel, GIMP_TYPE_DRAWABLE,
@@ -313,6 +315,7 @@ gimp_channel_class_init (GimpChannelClass *klass)
   klass->border         = gimp_channel_real_border;
   klass->grow           = gimp_channel_real_grow;
   klass->shrink         = gimp_channel_real_shrink;
+  klass->flood          = gimp_channel_real_flood;
 
   klass->feather_desc   = C_("undo-type", "Feather Channel");
   klass->sharpen_desc   = C_("undo-type", "Sharpen Channel");
@@ -322,6 +325,7 @@ gimp_channel_class_init (GimpChannelClass *klass)
   klass->border_desc    = C_("undo-type", "Border Channel");
   klass->grow_desc      = C_("undo-type", "Grow Channel");
   klass->shrink_desc    = C_("undo-type", "Shrink Channel");
+  klass->flood_desc     = C_("undo-type", "Flood Channel");
 }
 
 static void
@@ -1544,6 +1548,33 @@ gimp_channel_real_shrink (GimpChannel *channel,
                         gimp_item_get_height (GIMP_ITEM (channel)));
 }
 
+static void
+gimp_channel_real_flood (GimpChannel *channel,
+                         gboolean     push_undo)
+{
+  gint x1, y1, x2, y2;
+
+  if (! gimp_item_bounds (GIMP_ITEM (channel), &x1, &y1, &x2, &y2))
+    return;
+
+  x2 += x1;
+  y2 += y1;
+
+  if (gimp_channel_is_empty (channel))
+    return;
+
+  if (push_undo)
+    gimp_channel_push_undo (channel,
+                            GIMP_CHANNEL_GET_CLASS (channel)->flood_desc);
+
+  gimp_gegl_apply_flood (gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
+                         NULL, NULL,
+                         gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
+                         GEGL_RECTANGLE (x1, y1, x2 - x1, y2 - y1));
+
+  gimp_drawable_update (GIMP_DRAWABLE (channel), x1, y1, x2 - x1, y2 - y1);
+}
+
 
 /*  public functions  */
 
@@ -2003,3 +2034,15 @@ gimp_channel_shrink (GimpChannel  *channel,
   GIMP_CHANNEL_GET_CLASS (channel)->shrink (channel, radius_x, radius_y,
                                             edge_lock, push_undo);
 }
+
+void
+gimp_channel_flood (GimpChannel *channel,
+                    gboolean     push_undo)
+{
+  g_return_if_fail (GIMP_IS_CHANNEL (channel));
+
+  if (! gimp_item_is_attached (GIMP_ITEM (channel)))
+    push_undo = FALSE;
+
+  GIMP_CHANNEL_GET_CLASS (channel)->flood (channel, push_undo);
+}
diff --git a/app/core/gimpchannel.h b/app/core/gimpchannel.h
index e607396..5f16c87 100644
--- a/app/core/gimpchannel.h
+++ b/app/core/gimpchannel.h
@@ -102,6 +102,8 @@ struct _GimpChannelClass
                               gint                 radius_y,
                               gboolean             edge_lock,
                               gboolean             push_undo);
+  void     (* flood)         (GimpChannel         *channel,
+                              gboolean             push_undo);
 
   const gchar *feather_desc;
   const gchar *sharpen_desc;
@@ -111,6 +113,7 @@ struct _GimpChannelClass
   const gchar *border_desc;
   const gchar *grow_desc;
   const gchar *shrink_desc;
+  const gchar *flood_desc;
 };
 
 
@@ -204,6 +207,8 @@ void          gimp_channel_shrink             (GimpChannel         *mask,
                                                gint                 radius_y,
                                                gboolean             edge_lock,
                                                gboolean             push_undo);
+void          gimp_channel_flood              (GimpChannel         *mask,
+                                               gboolean             push_undo);
 
 
 #endif /* __GIMP_CHANNEL_H__ */
diff --git a/app/gimpcore.def b/app/gimpcore.def
index 2f7d5d4..3383f8a 100644
--- a/app/gimpcore.def
+++ b/app/gimpcore.def
@@ -77,6 +77,7 @@ EXPORTS
        gimp_channel_bounds
        gimp_channel_clear
        gimp_channel_feather
+       gimp_channel_flood
        gimp_channel_get_type
        gimp_channel_grow
        gimp_channel_invert


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