app: flood isolated pixels in smart colorization fill.

The smart colorization was leaving irritating single pixels in between
colorized regions, after growing and combining. So let's just flood
these. We don't flood bigger regions (and in particular don't use
gimp_gegl_apply_flood()) on purpose, because there may be small yet
actual regions inside regions which we'd want in other colors. 1-pixel
regions is the extreme case where chances that one wanted it filled are
just higher.
This commit is contained in:
Jehan 2018-11-27 15:12:18 +01:00
parent 6bec0bc82d
commit 744d67939d
1 changed files with 47 additions and 0 deletions

View File

@ -18,6 +18,7 @@
#include "config.h"
#include <cairo.h>
#define GEGL_ITERATOR2_API
#include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
@ -286,6 +287,52 @@ gimp_drawable_get_bucket_fill_buffer (GimpDrawable *drawable,
mask_offset_y = y;
}
if (fill_criterion == GIMP_SELECT_CRITERION_LINE_ART)
{
/* The smart colorization leaves some very irritating unselected
* pixels in some edge cases. Just flood any isolated pixel inside
* the final mask.
*/
GeglBufferIterator *gi;
gi = gegl_buffer_iterator_new (new_mask, GEGL_RECTANGLE (x, y, width, height),
0, NULL, GEGL_ACCESS_READWRITE, GEGL_ABYSS_NONE, 5);
gegl_buffer_iterator_add (gi, new_mask, GEGL_RECTANGLE (x, y - 1, width, height),
0, NULL, GEGL_ACCESS_READ, GEGL_ABYSS_WHITE);
gegl_buffer_iterator_add (gi, new_mask, GEGL_RECTANGLE (x, y + 1, width, height),
0, NULL, GEGL_ACCESS_READ, GEGL_ABYSS_WHITE);
gegl_buffer_iterator_add (gi, new_mask, GEGL_RECTANGLE (x - 1, y, width, height),
0, NULL, GEGL_ACCESS_READ, GEGL_ABYSS_WHITE);
gegl_buffer_iterator_add (gi, new_mask, GEGL_RECTANGLE (x + 1, y, width, height),
0, NULL, GEGL_ACCESS_READ, GEGL_ABYSS_WHITE);
while (gegl_buffer_iterator_next (gi))
{
gfloat *m = (gfloat*) gi->items[0].data;
gfloat *py = (gfloat*) gi->items[1].data;
gfloat *ny = (gfloat*) gi->items[2].data;
gfloat *px = (gfloat*) gi->items[3].data;
gfloat *nx = (gfloat*) gi->items[4].data;
gint startx = gi->items[0].roi.x;
gint starty = gi->items[0].roi.y;
gint endy = starty + gi->items[0].roi.height;
gint endx = startx + gi->items[0].roi.width;
gint i;
gint j;
for (j = starty; j < endy; j++)
for (i = startx; i < endx; i++)
{
if (! *m && *py && *ny && *px && *nx)
*m = 1.0;
m++;
py++;
ny++;
px++;
nx++;
}
}
}
buffer = gimp_fill_options_create_buffer (options, drawable,
GEGL_RECTANGLE (0, 0,
width, height),