[gimp/gimp-2-10] app: add the segment and spline max length options for line art.



commit b1236403cf63c4d38c72a043ecb306f5f174ac56
Author: Jehan <jehan girinstud io>
Date:   Thu Nov 29 17:29:42 2018 +0100

    app: add the segment and spline max length options for line art.
    
    We can't just hardcode this. On huge images in particular, you'll want
    to increase this value.
    
    (cherry picked from commit d71efdec207141cb6b9e860248cf4550bbf61e10)

 app/core/gimpchannel-select.c             |  2 +-
 app/core/gimpdrawable-bucket-fill.c       |  8 ++++++
 app/core/gimpdrawable-bucket-fill.h       |  4 +++
 app/core/gimppickable-contiguous-region.c | 35 +++++++++++++++-------
 app/core/gimppickable-contiguous-region.h |  6 ++++
 app/pdb/drawable-edit-cmds.c              |  2 +-
 app/tools/gimpbucketfilloptions.c         | 48 +++++++++++++++++++++++++++++++
 app/tools/gimpbucketfilloptions.h         |  2 ++
 app/tools/gimpbucketfilltool.c            |  4 +++
 app/tools/gimpfuzzyselecttool.c           |  2 +-
 pdb/groups/drawable_edit.pdb              |  2 +-
 11 files changed, 100 insertions(+), 15 deletions(-)
---
diff --git a/app/core/gimpchannel-select.c b/app/core/gimpchannel-select.c
index 0ca19ce00f..d23cadcb05 100644
--- a/app/core/gimpchannel-select.c
+++ b/app/core/gimpchannel-select.c
@@ -522,7 +522,7 @@ gimp_channel_select_fuzzy (GimpChannel         *channel,
                                                     select_transparent,
                                                     select_criterion,
                                                     diagonal_neighbors,
-                                                    0.92, 3, /* TODO */
+                                                    0.92, 3, 20, 60, /* TODO */
                                                     x, y);
 
   if (! sample_merged)
diff --git a/app/core/gimpdrawable-bucket-fill.c b/app/core/gimpdrawable-bucket-fill.c
index 39fcaf2237..a455b9606a 100644
--- a/app/core/gimpdrawable-bucket-fill.c
+++ b/app/core/gimpdrawable-bucket-fill.c
@@ -60,6 +60,8 @@ gimp_drawable_bucket_fill (GimpDrawable         *drawable,
                            gboolean              diagonal_neighbors,
                            gfloat                line_art_stroke_threshold,
                            gint                  line_art_max_grow,
+                           gint                  line_art_segment_max_length,
+                           gint                  line_art_spline_max_length,
                            gdouble               seed_x,
                            gdouble               seed_y)
 {
@@ -82,6 +84,8 @@ gimp_drawable_bucket_fill (GimpDrawable         *drawable,
                                                  diagonal_neighbors,
                                                  line_art_stroke_threshold,
                                                  line_art_max_grow,
+                                                 line_art_segment_max_length,
+                                                 line_art_spline_max_length,
                                                  seed_x, seed_y, NULL,
                                                  &mask_x, &mask_y, &width, &height);
 
@@ -148,6 +152,8 @@ gimp_drawable_get_bucket_fill_buffer (GimpDrawable         *drawable,
                                       gboolean              diagonal_neighbors,
                                       gfloat                stroke_threshold,
                                       gint                  max_grow,
+                                      gint                  segment_max_length,
+                                      gint                  spline_max_length,
                                       gdouble               seed_x,
                                       gdouble               seed_y,
                                       GeglBuffer          **mask_buffer,
@@ -211,6 +217,8 @@ gimp_drawable_get_bucket_fill_buffer (GimpDrawable         *drawable,
                                                       diagonal_neighbors,
                                                       stroke_threshold,
                                                       max_grow,
+                                                      segment_max_length,
+                                                      spline_max_length,
                                                       (gint) seed_x,
                                                       (gint) seed_y);
   if (mask_buffer && *mask_buffer)
diff --git a/app/core/gimpdrawable-bucket-fill.h b/app/core/gimpdrawable-bucket-fill.h
index d7acbb38d2..4019d82780 100644
--- a/app/core/gimpdrawable-bucket-fill.h
+++ b/app/core/gimpdrawable-bucket-fill.h
@@ -30,6 +30,8 @@ void         gimp_drawable_bucket_fill            (GimpDrawable         *drawabl
                                                    gboolean              diagonal_neighbors,
                                                    gfloat                line_art_stroke_threshold,
                                                    gint                  line_art_max_grow,
+                                                   gint                  line_art_segment_max_length,
+                                                   gint                  line_art_spline_max_length,
                                                    gdouble               x,
                                                    gdouble               y);
 GeglBuffer * gimp_drawable_get_bucket_fill_buffer (GimpDrawable         *drawable,
@@ -43,6 +45,8 @@ GeglBuffer * gimp_drawable_get_bucket_fill_buffer (GimpDrawable         *drawabl
                                                    gboolean              diagonal_neighbors,
                                                    gfloat                line_art_stroke_threshold,
                                                    gint                  line_art_max_grow,
+                                                   gint                  line_art_segment_max_length,
+                                                   gint                  line_art_spline_max_length,
                                                    gdouble               seed_x,
                                                    gdouble               seed_y,
                                                    GeglBuffer          **mask_buffer,
diff --git a/app/core/gimppickable-contiguous-region.c b/app/core/gimppickable-contiguous-region.c
index b096c75082..472e5e32f3 100644
--- a/app/core/gimppickable-contiguous-region.c
+++ b/app/core/gimppickable-contiguous-region.c
@@ -43,6 +43,8 @@ typedef struct
   GeglBuffer *buffer;
   gboolean    select_transparent;
   gfloat      stroke_threshold;
+  gint        segment_max_length;
+  gint        spline_max_length;
 } LineArtData;
 
 typedef struct
@@ -114,7 +116,9 @@ static void     find_contiguous_region    (GeglBuffer          *src_buffer,
 
 static LineArtData   * line_art_data_new    (GeglBuffer          *buffer,
                                              gboolean             select_transparent,
-                                             gfloat               stroke_threshold);
+                                             gfloat               stroke_threshold,
+                                             gint                 segment_max_length,
+                                             gint                 spline_max_length);
 static void            line_art_data_free   (LineArtData         *data);
 static GimpPickableLineArtAsyncResult *
                        line_art_result_new  (GeglBuffer          *line_art,
@@ -200,8 +204,7 @@ gimp_pickable_contiguous_region_prepare_line_art_async_func (GimpAsync   *async,
                                 5,
                                 /*end_point_rate,*/
                                 0.85,
-                                /*spline_max_length,*/
-                                60,
+                                data->spline_max_length,
                                 /*spline_max_angle,*/
                                 90.0,
                                 /*end_point_connectivity,*/
@@ -216,8 +219,7 @@ gimp_pickable_contiguous_region_prepare_line_art_async_func (GimpAsync   *async,
                                 100,
                                 /*small_segments_from_spline_sources,*/
                                 TRUE,
-                                /*segments_max_length*/
-                                20,
+                                data->segment_max_length,
                                 &distmap);
 
   GIMP_TIMER_END("close line-art");
@@ -233,6 +235,8 @@ GeglBuffer *
 gimp_pickable_contiguous_region_prepare_line_art (GimpPickable  *pickable,
                                                   gboolean       select_transparent,
                                                   gfloat         stroke_threshold,
+                                                  gint           segment_max_length,
+                                                  gint           spline_max_length,
                                                   gfloat       **distmap)
 {
   GimpAsync                      *async;
@@ -246,8 +250,8 @@ gimp_pickable_contiguous_region_prepare_line_art (GimpPickable  *pickable,
 
   async = gimp_async_new ();
   data  = line_art_data_new (gimp_pickable_get_buffer (pickable),
-                             select_transparent,
-                             stroke_threshold);
+                             select_transparent, stroke_threshold,
+                             segment_max_length, spline_max_length);
 
   gimp_pickable_contiguous_region_prepare_line_art_async_func (async, data);
 
@@ -266,6 +270,8 @@ GimpAsync *
 gimp_pickable_contiguous_region_prepare_line_art_async (GimpPickable *pickable,
                                                         gboolean      select_transparent,
                                                         gfloat        stroke_threshold,
+                                                        gint          segment_max_length,
+                                                        gint          spline_max_length,
                                                         gint          priority)
 {
   GeglBuffer  *buffer;
@@ -278,9 +284,8 @@ gimp_pickable_contiguous_region_prepare_line_art_async (GimpPickable *pickable,
 
   buffer = gegl_buffer_dup (gimp_pickable_get_buffer (pickable));
 
-  data  = line_art_data_new (buffer,
-                             select_transparent,
-                             stroke_threshold);
+  data  = line_art_data_new (buffer, select_transparent, stroke_threshold,
+                             segment_max_length, spline_max_length);
 
   g_object_unref (buffer);
 
@@ -305,6 +310,8 @@ gimp_pickable_contiguous_region_by_seed (GimpPickable        *pickable,
                                          gboolean             diagonal_neighbors,
                                          gfloat               stroke_threshold,
                                          gint                 flooding_max,
+                                         gint                 segment_max_length,
+                                         gint                 spline_max_length,
                                          gint                 x,
                                          gint                 y)
 {
@@ -333,6 +340,8 @@ gimp_pickable_contiguous_region_by_seed (GimpPickable        *pickable,
            */
           line_art      = gimp_pickable_contiguous_region_prepare_line_art (pickable, select_transparent,
                                                                             stroke_threshold,
+                                                                            segment_max_length,
+                                                                            spline_max_length,
                                                                             &distmap);
           free_line_art = TRUE;
         }
@@ -1143,13 +1152,17 @@ find_contiguous_region (GeglBuffer          *src_buffer,
 static LineArtData *
 line_art_data_new (GeglBuffer *buffer,
                    gboolean    select_transparent,
-                   gfloat      stroke_threshold)
+                   gfloat      stroke_threshold,
+                   gint        segment_max_length,
+                   gint        spline_max_length)
 {
   LineArtData *data = g_slice_new (LineArtData);
 
   data->buffer             = g_object_ref (buffer);
   data->select_transparent = select_transparent;
   data->stroke_threshold   = stroke_threshold;
+  data->segment_max_length = segment_max_length;
+  data->spline_max_length  = spline_max_length;
 
   return data;
 }
diff --git a/app/core/gimppickable-contiguous-region.h b/app/core/gimppickable-contiguous-region.h
index 2431ebf363..772f9d3cdc 100644
--- a/app/core/gimppickable-contiguous-region.h
+++ b/app/core/gimppickable-contiguous-region.h
@@ -27,10 +27,14 @@ typedef struct
 GeglBuffer * gimp_pickable_contiguous_region_prepare_line_art       (GimpPickable        *pickable,
                                                                      gboolean             select_transparent,
                                                                      gfloat               stroke_threshold,
+                                                                     gint                 segment_max_length,
+                                                                     gint                 spline_max_length,
                                                                      gfloat             **distmap);
 GimpAsync  * gimp_pickable_contiguous_region_prepare_line_art_async (GimpPickable        *pickable,
                                                                      gboolean             select_transparent,
                                                                      gfloat               stroke_threshold,
+                                                                     gint                 segment_max_length,
+                                                                     gint                 spline_max_length,
                                                                      gint                 priority);
 
 GeglBuffer * gimp_pickable_contiguous_region_by_seed                (GimpPickable        *pickable,
@@ -43,6 +47,8 @@ GeglBuffer * gimp_pickable_contiguous_region_by_seed                (GimpPickabl
                                                                      gboolean             diagonal_neighbors,
                                                                      gfloat               
line_art_stroke_threshold,
                                                                      gint                 line_art_max_grow,
+                                                                     gint                 
line_art_segment_max_length,
+                                                                     gint                 
line_art_spline_max_length,
                                                                      gint                 x,
                                                                      gint                 y);
 
diff --git a/app/pdb/drawable-edit-cmds.c b/app/pdb/drawable-edit-cmds.c
index dde18dc373..4d7c8a9cfc 100644
--- a/app/pdb/drawable-edit-cmds.c
+++ b/app/pdb/drawable-edit-cmds.c
@@ -171,7 +171,7 @@ drawable_edit_bucket_fill_invoker (GimpProcedure         *procedure,
                                          GIMP_PDB_CONTEXT (context)->sample_threshold,
                                          GIMP_PDB_CONTEXT (context)->sample_merged,
                                          GIMP_PDB_CONTEXT (context)->diagonal_neighbors,
-                                         0.92, 3, /* TODO */
+                                         0.92, 3, 20, 60, /* TODO */
                                          x, y);
             }
           else
diff --git a/app/tools/gimpbucketfilloptions.c b/app/tools/gimpbucketfilloptions.c
index f5d604e6bf..d30b7e9b3d 100644
--- a/app/tools/gimpbucketfilloptions.c
+++ b/app/tools/gimpbucketfilloptions.c
@@ -55,6 +55,8 @@ enum
   PROP_THRESHOLD,
   PROP_LINE_ART_THRESHOLD,
   PROP_LINE_ART_MAX_GROW,
+  PROP_LINE_ART_SPLINE_MAX_LEN,
+  PROP_LINE_ART_SEGMENT_MAX_LEN,
   PROP_FILL_CRITERION
 };
 
@@ -65,6 +67,8 @@ struct _GimpBucketFillOptionsPrivate
 
   GtkWidget *line_art_threshold_scale;
   GtkWidget *line_art_grow_scale;
+  GtkWidget *line_art_segment_max_len_scale;
+  GtkWidget *line_art_spline_max_len_scale;
 };
 
 static void   gimp_bucket_fill_options_config_iface_init (GimpConfigInterface *config_iface);
@@ -170,6 +174,20 @@ gimp_bucket_fill_options_class_init (GimpBucketFillOptionsClass *klass)
                         1, 100, 3,
                         GIMP_PARAM_STATIC_STRINGS);
 
+  GIMP_CONFIG_PROP_INT (object_class, PROP_LINE_ART_SPLINE_MAX_LEN,
+                        "line-art-spline-max-len",
+                        _("Maximum curved closing length"),
+                        _("Maximum curved length (in pixels) to close the line art"),
+                        1, 1000, 60,
+                        GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_PROP_INT (object_class, PROP_LINE_ART_SEGMENT_MAX_LEN,
+                        "line-art-segment-max-len",
+                        _("Maximum straight closing length"),
+                        _("Maximum straight length (in pixels) to close the line art"),
+                        1, 1000, 20,
+                        GIMP_PARAM_STATIC_STRINGS);
+
   GIMP_CONFIG_PROP_ENUM (object_class, PROP_FILL_CRITERION,
                          "fill-criterion",
                          _("Fill by"),
@@ -230,6 +248,12 @@ gimp_bucket_fill_options_set_property (GObject      *object,
     case PROP_LINE_ART_MAX_GROW:
       options->line_art_max_grow = g_value_get_int (value);
       break;
+    case PROP_LINE_ART_SEGMENT_MAX_LEN:
+      options->line_art_segment_max_len = g_value_get_int (value);
+      break;
+    case PROP_LINE_ART_SPLINE_MAX_LEN:
+      options->line_art_spline_max_len = g_value_get_int (value);
+      break;
     case PROP_FILL_CRITERION:
       options->fill_criterion = g_value_get_enum (value);
       gimp_bucket_fill_options_update_criterion (options);
@@ -278,6 +302,12 @@ gimp_bucket_fill_options_get_property (GObject    *object,
     case PROP_LINE_ART_MAX_GROW:
       g_value_set_int (value, options->line_art_max_grow);
       break;
+    case PROP_LINE_ART_SEGMENT_MAX_LEN:
+      g_value_set_int (value, options->line_art_segment_max_len);
+      break;
+    case PROP_LINE_ART_SPLINE_MAX_LEN:
+      g_value_set_int (value, options->line_art_spline_max_len);
+      break;
     case PROP_FILL_CRITERION:
       g_value_set_enum (value, options->fill_criterion);
       break;
@@ -319,10 +349,14 @@ gimp_bucket_fill_options_update_criterion (GimpBucketFillOptions *options)
 
       gtk_widget_show (options->priv->line_art_threshold_scale);
       gtk_widget_show (options->priv->line_art_grow_scale);
+      gtk_widget_show (options->priv->line_art_segment_max_len_scale);
+      gtk_widget_show (options->priv->line_art_spline_max_len_scale);
       break;
     default:
       gtk_widget_hide (options->priv->line_art_threshold_scale);
       gtk_widget_hide (options->priv->line_art_grow_scale);
+      gtk_widget_hide (options->priv->line_art_segment_max_len_scale);
+      gtk_widget_hide (options->priv->line_art_spline_max_len_scale);
 
       gtk_widget_show (options->priv->diagonal_neighbors_checkbox);
       gtk_widget_show (options->priv->threshold_scale);
@@ -431,6 +465,20 @@ gimp_bucket_fill_options_gui (GimpToolOptions *tool_options)
   options->priv->line_art_threshold_scale = scale;
   gtk_widget_show (scale);
 
+  /*  Line Art: segment max len */
+  scale = gimp_prop_spin_scale_new (config, "line-art-segment-max-len", NULL,
+                                    1, 5, 0);
+  gtk_box_pack_start (GTK_BOX (vbox2), scale, FALSE, FALSE, 0);
+  options->priv->line_art_segment_max_len_scale = scale;
+  gtk_widget_show (scale);
+
+  /*  Line Art: spline max len */
+  scale = gimp_prop_spin_scale_new (config, "line-art-spline-max-len", NULL,
+                                    1, 5, 0);
+  gtk_box_pack_start (GTK_BOX (vbox2), scale, FALSE, FALSE, 0);
+  options->priv->line_art_spline_max_len_scale = scale;
+  gtk_widget_show (scale);
+
   /*  the fill criterion combo  */
   combo = gimp_prop_enum_combo_box_new (config, "fill-criterion", 0, 0);
   gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (combo), _("Fill by"));
diff --git a/app/tools/gimpbucketfilloptions.h b/app/tools/gimpbucketfilloptions.h
index 43fa265b02..261fc6b9d2 100644
--- a/app/tools/gimpbucketfilloptions.h
+++ b/app/tools/gimpbucketfilloptions.h
@@ -48,6 +48,8 @@ struct _GimpBucketFillOptions
 
   gdouble                       line_art_threshold;
   gint                          line_art_max_grow;
+  gint                          line_art_segment_max_len;
+  gint                          line_art_spline_max_len;
 
   GimpSelectCriterion           fill_criterion;
 
diff --git a/app/tools/gimpbucketfilltool.c b/app/tools/gimpbucketfilltool.c
index 913ccff7e9..ad0c65eb73 100644
--- a/app/tools/gimpbucketfilltool.c
+++ b/app/tools/gimpbucketfilltool.c
@@ -403,6 +403,8 @@ gimp_bucket_fill_tool_preview (GimpBucketFillTool *tool,
                                                    options->diagonal_neighbors,
                                                    options->line_art_threshold,
                                                    options->line_art_max_grow,
+                                                   options->line_art_segment_max_len,
+                                                   options->line_art_spline_max_len,
                                                    x, y, &tool->priv->fill_mask,
                                                    &x, &y, NULL, NULL);
       if (line_art)
@@ -820,6 +822,8 @@ gimp_bucket_fill_compute_line_art (GimpBucketFillTool *tool)
               pickable,
               options->fill_transparent,
               options->line_art_threshold,
+              options->line_art_segment_max_len,
+              options->line_art_spline_max_len,
               +1);
           g_signal_handlers_unblock_by_func (gimp_image_get_projection (GIMP_IMAGE (image)),
                                            G_CALLBACK (gimp_bucket_fill_tool_projection_rendered),
diff --git a/app/tools/gimpfuzzyselecttool.c b/app/tools/gimpfuzzyselecttool.c
index 63cbaed46c..de86b3c171 100644
--- a/app/tools/gimpfuzzyselecttool.c
+++ b/app/tools/gimpfuzzyselecttool.c
@@ -128,6 +128,6 @@ gimp_fuzzy_select_tool_get_mask (GimpRegionSelectTool *region_select,
                                                   options->select_transparent,
                                                   options->select_criterion,
                                                   options->diagonal_neighbors,
-                                                  0.92, 3, /* TODO */
+                                                  0.92, 3, 20, 60, /* TODO */
                                                   x, y);
 }
diff --git a/pdb/groups/drawable_edit.pdb b/pdb/groups/drawable_edit.pdb
index 3174bfa90f..2be98f4456 100644
--- a/pdb/groups/drawable_edit.pdb
+++ b/pdb/groups/drawable_edit.pdb
@@ -175,7 +175,7 @@ HELP
                                      GIMP_PDB_CONTEXT (context)->sample_threshold,
                                      GIMP_PDB_CONTEXT (context)->sample_merged,
                                      GIMP_PDB_CONTEXT (context)->diagonal_neighbors,
-                                     0.92, 3, /* TODO */
+                                     0.92, 3, 20, 60, /* TODO */
                                      x, y);
         }
       else


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