Commit b1236403 authored by Jehan's avatar Jehan

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 d71efdec)
parent 1471da20
......@@ -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)
......
......@@ -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)
......
......@@ -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,
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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
......
......@@ -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"));
......
......@@ -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;
......
......@@ -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),
......
......@@ -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);
}
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment