[gimp] app: some small improvements in line art code.



commit 248477a125c9e5f63cb6bf98a39b32f73e3734ea
Author: Jehan <jehan girinstud io>
Date:   Sat Feb 16 12:27:32 2019 +0100

    app: some small improvements in line art code.
    
    Mostly I am adding a counter to the insignifiant zone fill, to be double
    sure we are not going to fill huge areas (this should not happen already
    anyway) and also it is no use to sample the line art buffer in such
    case.

 app/core/gimplineart.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/app/core/gimplineart.c b/app/core/gimplineart.c
index 792184dbbc..8fc5e8933d 100644
--- a/app/core/gimplineart.c
+++ b/app/core/gimplineart.c
@@ -224,7 +224,8 @@ static GArray        * gimp_lineart_line_segment_until_hit      (const GeglBuffe
 static gfloat        * gimp_lineart_estimate_strokes_radii      (GeglBuffer             *mask);
 static void            gimp_line_art_simple_fill                (GeglBuffer             *buffer,
                                                                  gint                    x,
-                                                                 gint                    y);
+                                                                 gint                    y,
+                                                                 gint                   *counter);
 
 /* Some callback-type functions. */
 
@@ -992,7 +993,7 @@ gimp_line_art_close (GeglBuffer  *buffer,
                       gimp_line_art_allow_closure (closed, discrete_curve,
                                                    &fill_pixels,
                                                    created_regions_significant_area,
-                                                   created_regions_minimum_area - 1))
+                                                   created_regions_minimum_area))
                     {
                       for (i = 0; i < discrete_curve->len; i++)
                         {
@@ -1050,7 +1051,7 @@ gimp_line_art_close (GeglBuffer  *buffer,
                   if (segment->len &&
                       gimp_line_art_allow_closure (closed, segment, &fill_pixels,
                                                    created_regions_significant_area,
-                                                   created_regions_minimum_area - 1))
+                                                   created_regions_minimum_area))
                     {
                       gint j;
 
@@ -1076,7 +1077,8 @@ gimp_line_art_close (GeglBuffer  *buffer,
 
       for (iter = fill_pixels; iter; iter = iter->next)
         {
-          Pixel *p = iter->data;
+          Pixel *p        = iter->data;
+          gint   fill_max = created_regions_significant_area - 1;
 
           /* XXX A best approach would be to generalize
            * gimp_drawable_bucket_fill() to work on any buffer (the code
@@ -1085,7 +1087,7 @@ gimp_line_art_close (GeglBuffer  *buffer,
            * This is mostly a quick'n dirty first implementation which I
            * will improve later.
            */
-          gimp_line_art_simple_fill (closed, (gint) p->x, (gint) p->y);
+          gimp_line_art_simple_fill (closed, (gint) p->x, (gint) p->y, &fill_max);
         }
 
       g_list_free_full (fill_pixels, g_free);
@@ -1817,7 +1819,7 @@ gimp_line_art_allow_closure (GeglBuffer *mask,
    * Since we are following the edges of the area, we can therefore stop
    * earlier if we reach this number of edgels.
    */
-  const glong max_edgel_count = 2 * (minimum_size + 1);
+  const glong max_edgel_count = 2 * minimum_size;
 
   Pixel      *p = (Pixel*) pixels->data;
   GList      *fp = NULL;
@@ -1870,7 +1872,7 @@ gimp_line_art_allow_closure (GeglBuffer *mask,
                 {
                   area = gimp_edgel_region_area (mask, e);
 
-                  if (area >= significant_size && area <= minimum_size)
+                  if (area >= significant_size && area < minimum_size)
                     {
                       gint j;
 
@@ -2130,12 +2132,14 @@ gimp_lineart_estimate_strokes_radii (GeglBuffer *mask)
 static void
 gimp_line_art_simple_fill (GeglBuffer *buffer,
                            gint        x,
-                           gint        y)
+                           gint        y,
+                           gint       *counter)
 {
   guchar val;
 
-  if (x < 0 || x >= gegl_buffer_get_width (buffer) ||
-      y < 0 || y >= gegl_buffer_get_height (buffer))
+  if (x < 0 || x >= gegl_buffer_get_width (buffer)  ||
+      y < 0 || y >= gegl_buffer_get_height (buffer) ||
+      counter <= 0)
     return;
 
   gegl_buffer_sample (buffer, x, y, NULL, &val,
@@ -2146,10 +2150,11 @@ gimp_line_art_simple_fill (GeglBuffer *buffer,
       val = 1;
       gegl_buffer_set (buffer, GEGL_RECTANGLE (x, y, 1, 1), 0,
                        NULL, &val, GEGL_AUTO_ROWSTRIDE);
-      gimp_line_art_simple_fill (buffer, x + 1, y);
-      gimp_line_art_simple_fill (buffer, x - 1, y);
-      gimp_line_art_simple_fill (buffer, x, y + 1);
-      gimp_line_art_simple_fill (buffer, x, y - 1);
+      (*counter)--;
+      gimp_line_art_simple_fill (buffer, x + 1, y, counter);
+      gimp_line_art_simple_fill (buffer, x - 1, y, counter);
+      gimp_line_art_simple_fill (buffer, x, y + 1, counter);
+      gimp_line_art_simple_fill (buffer, x, y - 1, counter);
     }
 }
 


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