[gimp] app: Modify gimp_gegl_apply_border() to take a style parameter



commit 45efe6c405345921f1cef33ffb779cf939c0ae07
Author: Ell <ell_se yahoo com>
Date:   Mon Apr 4 15:11:05 2016 +0000

    app: Modify gimp_gegl_apply_border() to take a style parameter
    
    instead of the feather parameter.
    
    The BORDER_STYLE_HARD and BORDER_STYLE_FEATHERED styles are implemented
    using the "gimp:border" operation, as was done previously.  The
    BORDER_STYLE_SMOOTH style is implemented by performing a "gimp:grow" and
    a "gimp:shrink", and subtracting the shrunk image from the grown image
    using "gegl:substract".
    
    gimp_channel_border() is modified to pass either BORDER_STYLE_HARD or
    BORDER_STYLE_FEATHER, depending on its feather parameter, to maintain
    the current behavior.  The next commit replaces it with a style
    parameter as well.
    
    Mass parameter alignment changes to gimp-gegl-apply-operation.h.  Sigh...

 app/core/gimpchannel.c               |    5 +-
 app/gegl/gimp-gegl-apply-operation.c |   93 ++++++++++++---
 app/gegl/gimp-gegl-apply-operation.h |  214 +++++++++++++++++-----------------
 3 files changed, 188 insertions(+), 124 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 68a619c..27b40a9 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -1457,7 +1457,10 @@ gimp_channel_real_border (GimpChannel *channel,
                           NULL, NULL,
                           gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
                           GEGL_RECTANGLE (x1, y1, x2 - x1, y2 - y1),
-                          radius_x, radius_y, feather, edge_lock);
+                          radius_x, radius_y,
+                          ! feather ? GIMP_CHANNEL_BORDER_STYLE_HARD :
+                                      GIMP_CHANNEL_BORDER_STYLE_FEATHERED,
+                          edge_lock);
 
   channel->bounds_known = FALSE;
 
diff --git a/app/gegl/gimp-gegl-apply-operation.c b/app/gegl/gimp-gegl-apply-operation.c
index cf519be..1cfa501 100644
--- a/app/gegl/gimp-gegl-apply-operation.c
+++ b/app/gegl/gimp-gegl-apply-operation.c
@@ -343,15 +343,15 @@ gimp_gegl_apply_feather (GeglBuffer          *src_buffer,
 }
 
 void
-gimp_gegl_apply_border (GeglBuffer          *src_buffer,
-                        GimpProgress        *progress,
-                        const gchar         *undo_desc,
-                        GeglBuffer          *dest_buffer,
-                        const GeglRectangle *dest_rect,
-                        gint                 radius_x,
-                        gint                 radius_y,
-                        gboolean             feather,
-                        gboolean             edge_lock)
+gimp_gegl_apply_border (GeglBuffer             *src_buffer,
+                        GimpProgress           *progress,
+                        const gchar            *undo_desc,
+                        GeglBuffer             *dest_buffer,
+                        const GeglRectangle    *dest_rect,
+                        gint                    radius_x,
+                        gint                    radius_y,
+                        GimpChannelBorderStyle  style,
+                        gboolean                edge_lock)
 {
   GeglNode *node;
 
@@ -359,13 +359,74 @@ gimp_gegl_apply_border (GeglBuffer          *src_buffer,
   g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
   g_return_if_fail (GEGL_IS_BUFFER (dest_buffer));
 
-  node = gegl_node_new_child (NULL,
-                              "operation", "gimp:border",
-                              "radius-x",  radius_x,
-                              "radius-y",  radius_y,
-                              "feather",   feather,
-                              "edge-lock", edge_lock,
-                              NULL);
+  switch (style)
+    {
+    case GIMP_CHANNEL_BORDER_STYLE_HARD:
+    case GIMP_CHANNEL_BORDER_STYLE_FEATHERED:
+      {
+        gboolean feather = style == GIMP_CHANNEL_BORDER_STYLE_FEATHERED;
+
+        node = gegl_node_new_child (NULL,
+                                    "operation", "gimp:border",
+                                    "radius-x",  radius_x,
+                                    "radius-y",  radius_y,
+                                    "feather",   feather,
+                                    "edge-lock", edge_lock,
+                                    NULL);
+      }
+      break;
+
+    case GIMP_CHANNEL_BORDER_STYLE_SMOOTH:
+      {
+        GeglNode *input, *output;
+        GeglNode *grow, *shrink, *subtract;
+
+        node   = gegl_node_new ();
+
+        input  = gegl_node_get_input_proxy (node, "input");
+        output = gegl_node_get_output_proxy (node, "output");
+
+        /* Duplicate special-case behavior of "gimp:border". */
+        if (radius_x == 1 && radius_y == 1)
+          {
+            grow   = gegl_node_new_child (node,
+                                          "operation", "gegl:nop",
+                                          NULL);
+            shrink = gegl_node_new_child (node,
+                                          "operation", "gimp:shrink",
+                                          "radius-x",  1,
+                                          "radius-y",  1,
+                                          "edge-lock", edge_lock,
+                                          NULL);
+          }
+        else
+          {
+            grow   = gegl_node_new_child (node,
+                                          "operation", "gimp:grow",
+                                          "radius-x",  radius_x,
+                                          "radius-y",  radius_y,
+                                          NULL);
+            shrink = gegl_node_new_child (node,
+                                          "operation", "gimp:shrink",
+                                          "radius-x",  radius_x + 1,
+                                          "radius-y",  radius_y + 1,
+                                          "edge-lock", edge_lock,
+                                          NULL);
+          }
+
+        subtract = gegl_node_new_child (node,
+                                        "operation", "gegl:subtract",
+                                        NULL);
+
+        gegl_node_link_many (input, grow, subtract, output, NULL);
+        gegl_node_link (input, shrink);
+        gegl_node_connect_to (shrink, "output", subtract, "aux");
+      }
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
 
   gimp_gegl_apply_operation (src_buffer, progress, undo_desc,
                              node, dest_buffer, dest_rect);
diff --git a/app/gegl/gimp-gegl-apply-operation.h b/app/gegl/gimp-gegl-apply-operation.h
index ad1fd91..acca14b 100644
--- a/app/gegl/gimp-gegl-apply-operation.h
+++ b/app/gegl/gimp-gegl-apply-operation.h
@@ -47,113 +47,113 @@ gboolean   gimp_gegl_apply_cached_operation (GeglBuffer          *src_buffer,
 
 /*  apply specific operations  */
 
-void   gimp_gegl_apply_color_reduction (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        gint                   bits,
-                                        gint                   dither_type);
-
-void   gimp_gegl_apply_flatten         (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        const GimpRGB         *background);
-
-void   gimp_gegl_apply_feather         (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        const GeglRectangle   *dest_rect,
-                                        gdouble                radius_x,
-                                        gdouble                radius_y);
-
-void   gimp_gegl_apply_border          (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        const GeglRectangle   *dest_rect,
-                                        gint                   radius_x,
-                                        gint                   radius_y,
-                                        gboolean               feather,
-                                        gboolean               edge_lock);
-
-void   gimp_gegl_apply_grow            (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        const GeglRectangle   *dest_rect,
-                                        gint                   radius_x,
-                                        gint                   radius_y);
-
-void   gimp_gegl_apply_shrink          (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        const GeglRectangle   *dest_rect,
-                                        gint                   radius_x,
-                                        gint                   radius_y,
-                                        gboolean               edge_lock);
-
-void   gimp_gegl_apply_flood           (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        const GeglRectangle   *dest_rect);
-
-void   gimp_gegl_apply_gaussian_blur   (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        const GeglRectangle   *dest_rect,
-                                        gdouble                std_dev_x,
-                                        gdouble                std_dev_y);
-
-void   gimp_gegl_apply_invert_gamma    (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer);
-
-void   gimp_gegl_apply_invert_linear   (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer);
-
-void   gimp_gegl_apply_opacity         (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        GeglBuffer            *mask,
-                                        gint                   mask_offset_x,
-                                        gint                   mask_offset_y,
-                                        gdouble                opacity);
-
-void   gimp_gegl_apply_scale           (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        GimpInterpolationType  interpolation_type,
-                                        gdouble                x,
-                                        gdouble                y);
-
-void   gimp_gegl_apply_set_alpha       (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        gdouble                value);
-
-void   gimp_gegl_apply_threshold       (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        gdouble                value);
-
-void   gimp_gegl_apply_transform       (GeglBuffer            *src_buffer,
-                                        GimpProgress          *progress,
-                                        const gchar           *undo_desc,
-                                        GeglBuffer            *dest_buffer,
-                                        GimpInterpolationType  interpolation_type,
-                                        GimpMatrix3           *transform);
+void   gimp_gegl_apply_color_reduction (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        gint                    bits,
+                                        gint                    dither_type);
+
+void   gimp_gegl_apply_flatten         (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        const GimpRGB          *background);
+
+void   gimp_gegl_apply_feather         (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        const GeglRectangle    *dest_rect,
+                                        gdouble                 radius_x,
+                                        gdouble                 radius_y);
+
+void   gimp_gegl_apply_border          (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        const GeglRectangle    *dest_rect,
+                                        gint                    radius_x,
+                                        gint                    radius_y,
+                                        GimpChannelBorderStyle  style,
+                                        gboolean                edge_lock);
+
+void   gimp_gegl_apply_grow            (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        const GeglRectangle    *dest_rect,
+                                        gint                    radius_x,
+                                        gint                    radius_y);
+
+void   gimp_gegl_apply_shrink          (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        const GeglRectangle    *dest_rect,
+                                        gint                    radius_x,
+                                        gint                    radius_y,
+                                        gboolean                edge_lock);
+
+void   gimp_gegl_apply_flood           (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        const GeglRectangle    *dest_rect);
+
+void   gimp_gegl_apply_gaussian_blur   (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        const GeglRectangle    *dest_rect,
+                                        gdouble                 std_dev_x,
+                                        gdouble                 std_dev_y);
+
+void   gimp_gegl_apply_invert_gamma    (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer);
+
+void   gimp_gegl_apply_invert_linear   (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer);
+
+void   gimp_gegl_apply_opacity         (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        GeglBuffer             *mask,
+                                        gint                    mask_offset_x,
+                                        gint                    mask_offset_y,
+                                        gdouble                 opacity);
+
+void   gimp_gegl_apply_scale           (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        GimpInterpolationType   interpolation_type,
+                                        gdouble                 x,
+                                        gdouble                 y);
+
+void   gimp_gegl_apply_set_alpha       (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        gdouble                 value);
+
+void   gimp_gegl_apply_threshold       (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        gdouble                 value);
+
+void   gimp_gegl_apply_transform       (GeglBuffer             *src_buffer,
+                                        GimpProgress           *progress,
+                                        const gchar            *undo_desc,
+                                        GeglBuffer             *dest_buffer,
+                                        GimpInterpolationType   interpolation_type,
+                                        GimpMatrix3            *transform);
 
 
 #endif /* __GIMP_GEGL_APPLY_OPERATION_H__ */


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