From 71ec6a9849a3ab3ebfea09daa854ceb99ff8368a Mon Sep 17 00:00:00 2001 From: Jehan Date: Sun, 14 Oct 2018 16:51:47 +0200 Subject: [PATCH] app: fix stroke labels in gimp_lineart_estimate_stroke_width(). I must make sure that stroke pixels are labelled 0 and non-stroke other than 0. (cherry picked from commit 910d7934f5bc90f48af4dda3d06953db029df733) --- app/core/gimplineart.c | 50 +++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/app/core/gimplineart.c b/app/core/gimplineart.c index af44d2ac79..4bedae193a 100644 --- a/app/core/gimplineart.c +++ b/app/core/gimplineart.c @@ -1715,6 +1715,29 @@ gimp_lineart_estimate_stroke_width (GeglBuffer* mask) labels = gimp_lineart_get_labels (mask, TRUE); + /* Check biggest label. */ + gi = gegl_buffer_iterator_new (labels, NULL, 0, NULL, + GEGL_ACCESS_READ, GEGL_ABYSS_NONE, 1); + while (gegl_buffer_iterator_next (gi)) + { + guint32 *data = (guint32*) gi->items[0].data; + gint k; + + for (k = 0; k < gi->length; k++) + { + label_max = MAX (*data, label_max); + data++; + } + } + if (label_max == 0) + { + g_object_unref (labels); + g_object_unref (distmap); + return 0.0; + } + + /* Make sure that stroke pixels are label 0. */ + label_max++; gi = gegl_buffer_iterator_new (mask, NULL, 0, NULL, GEGL_ACCESS_READ, GEGL_ABYSS_NONE, 2); gegl_buffer_iterator_add (gi, labels, NULL, 0, @@ -1730,33 +1753,13 @@ gimp_lineart_estimate_stroke_width (GeglBuffer* mask) { if (! *m) *l = 0; + else if (*l == 0) + *l = label_max; m++; l++; } } - /* Check biggest label. */ - gi = gegl_buffer_iterator_new (labels, NULL, 0, NULL, - GEGL_ACCESS_READ, GEGL_ABYSS_NONE, 1); - while (gegl_buffer_iterator_next (gi)) - { - guint32 *data = (guint32*) gi->items[0].data; - gint k; - - for (k = 0; k < gi->length; k++) - { - label_max = MAX (*data, label_max); - data++; - } - } - - if (label_max == 0) - { - g_object_unref (labels); - g_object_unref (distmap); - return 0.0; - } - /* Create an array of max distance per label */ dmax = g_array_sized_new (FALSE, TRUE, sizeof (gfloat), label_max); g_array_set_size (dmax, label_max); @@ -1778,7 +1781,8 @@ gimp_lineart_estimate_stroke_width (GeglBuffer* mask) for (k = 0; k < gi->length; k++) { - gimp_assert (*m == 0 || *l > 0); + gimp_assert (*m == 0 || *l); + if (*m && *d > dmax_data[*l - 1]) dmax_data[*l - 1] = *d;