[gimp] app: fix stroke labels in gimp_lineart_estimate_stroke_width().



commit 910d7934f5bc90f48af4dda3d06953db029df733
Author: Jehan <jehan girinstud io>
Date:   Sun Oct 14 16:51:47 2018 +0200

    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.

 app/core/gimplineart.c | 48 ++++++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 22 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,26 +1715,6 @@ gimp_lineart_estimate_stroke_width (GeglBuffer* mask)
 
   labels = gimp_lineart_get_labels (mask, TRUE);
 
-  gi = gegl_buffer_iterator_new (mask, NULL, 0, NULL,
-                                 GEGL_ACCESS_READ, GEGL_ABYSS_NONE, 2);
-  gegl_buffer_iterator_add (gi, labels, NULL, 0,
-                            babl_format_n (babl_type ("u32"), 1),
-                            GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
-  while (gegl_buffer_iterator_next (gi))
-    {
-      guint8  *m = (guint8*) gi->items[0].data;
-      guint32 *l = (guint32*) gi->items[1].data;
-      gint    k;
-
-      for (k = 0; k < gi->length; k++)
-        {
-          if (! *m)
-            *l = 0;
-          m++;
-          l++;
-        }
-    }
-
   /* Check biggest label. */
   gi = gegl_buffer_iterator_new (labels, NULL, 0, NULL,
                                  GEGL_ACCESS_READ, GEGL_ABYSS_NONE, 1);
@@ -1749,7 +1729,6 @@ gimp_lineart_estimate_stroke_width (GeglBuffer* mask)
           data++;
         }
     }
-
   if (label_max == 0)
     {
       g_object_unref (labels);
@@ -1757,6 +1736,30 @@ gimp_lineart_estimate_stroke_width (GeglBuffer* mask)
       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,
+                            babl_format_n (babl_type ("u32"), 1),
+                            GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
+  while (gegl_buffer_iterator_next (gi))
+    {
+      guint8  *m = (guint8*) gi->items[0].data;
+      guint32 *l = (guint32*) gi->items[1].data;
+      gint    k;
+
+      for (k = 0; k < gi->length; k++)
+        {
+          if (! *m)
+            *l = 0;
+          else if (*l == 0)
+            *l = label_max;
+          m++;
+          l++;
+        }
+    }
+
   /* 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;
 


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