app: some code cleaning in gimplineart.

In particular, make simpler code in a few places, taking abyss value
into account (rather than checking the position).
This commit is contained in:
Jehan
2018-11-29 14:12:39 +01:00
parent 83dd94ba6a
commit f7a4ce1051

View File

@ -95,8 +95,7 @@ static GArray * gimp_lineart_discrete_spline (Pixel
GimpVector2 n1); GimpVector2 n1);
static gint gimp_number_of_transitions (GArray *pixels, static gint gimp_number_of_transitions (GArray *pixels,
GeglBuffer *buffer, GeglBuffer *buffer);
gboolean border_value);
static gboolean gimp_lineart_curve_creates_region (GeglBuffer *mask, static gboolean gimp_lineart_curve_creates_region (GeglBuffer *mask,
GArray *pixels, GArray *pixels,
int lower_size_limit, int lower_size_limit,
@ -372,8 +371,8 @@ gimp_lineart_close (GeglBuffer *buffer,
discrete_curve = gimp_lineart_discrete_spline (*p1, vect1, *p2, vect2); discrete_curve = gimp_lineart_discrete_spline (*p1, vect1, *p2, vect2);
transitions = allow_self_intersections ? transitions = allow_self_intersections ?
gimp_number_of_transitions (discrete_curve, strokes, FALSE) : gimp_number_of_transitions (discrete_curve, strokes) :
gimp_number_of_transitions (discrete_curve, closed, FALSE); gimp_number_of_transitions (discrete_curve, closed);
if (transitions == 2 && if (transitions == 2 &&
! gimp_lineart_curve_creates_region (closed, discrete_curve, ! gimp_lineart_curve_creates_region (closed, discrete_curve,
@ -1094,8 +1093,7 @@ gimp_lineart_discrete_spline (Pixel p0,
static gint static gint
gimp_number_of_transitions (GArray *pixels, gimp_number_of_transitions (GArray *pixels,
GeglBuffer *buffer, GeglBuffer *buffer)
gboolean border_value)
{ {
int result = 0; int result = 0;
@ -1113,24 +1111,12 @@ gimp_number_of_transitions (GArray *pixels,
/* Starts at the second element. */ /* Starts at the second element. */
for (i = 1; i < pixels->len; i++) for (i = 1; i < pixels->len; i++)
{ {
gboolean val;
it = g_array_index (pixels, Pixel, i); it = g_array_index (pixels, Pixel, i);
if (it.x >= 0 && it.x < gegl_buffer_get_width (buffer) &&
it.y >= 0 && it.y < gegl_buffer_get_height (buffer))
{
guchar value;
gegl_buffer_sample (buffer, (gint) it.x, (gint) it.y, NULL, &value, NULL, gegl_buffer_sample (buffer, (gint) it.x, (gint) it.y, NULL, &value, NULL,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE); GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
val = (gboolean) value; result += ((gboolean) value != previous);
} previous = (gboolean) value;
else
{
val = border_value;
}
result += (val != previous);
previous = val;
} }
} }
@ -1660,13 +1646,13 @@ gimp_edgelset_new (GeglBuffer *buffer)
{ {
if (*(p++)) if (*(p++))
{ {
if (y == 0 || ! *prevy) if (! *prevy)
gimp_edgelset_add (set, x, y, YMinusDirection, edgel2index); gimp_edgelset_add (set, x, y, YMinusDirection, edgel2index);
if (y == height - 1 || ! *nexty) if (! *nexty)
gimp_edgelset_add (set, x, y, YPlusDirection, edgel2index); gimp_edgelset_add (set, x, y, YPlusDirection, edgel2index);
if (x == 0 || ! *prevx) if (! *prevx)
gimp_edgelset_add (set, x, y, XMinusDirection, edgel2index); gimp_edgelset_add (set, x, y, XMinusDirection, edgel2index);
if (x == width - 1 || ! *nextx) if (! *nextx)
gimp_edgelset_add (set, x, y, XPlusDirection, edgel2index); gimp_edgelset_add (set, x, y, XPlusDirection, edgel2index);
} }
prevy++; prevy++;
@ -1771,7 +1757,6 @@ gimp_edgelset_compute_curvature (GArray *set)
const float crossp = n_prev.x * n_next.y - n_prev.y * n_next.x; const float crossp = n_prev.x * n_next.y - n_prev.y * n_next.x;
it->curvature = (crossp > 0.0f) ? c : -c; it->curvature = (crossp > 0.0f) ? c : -c;
++it;
} }
} }
@ -1804,29 +1789,26 @@ gimp_edgelset_next8 (const GeglBuffer *buffer,
Edgel *it, Edgel *it,
Edgel *n) Edgel *n)
{ {
const int lx = gegl_buffer_get_width ((GeglBuffer *) buffer) - 1; guint8 pixels[9];
const int ly = gegl_buffer_get_height ((GeglBuffer *) buffer) - 1;
guchar has_stroke;
n->x = it->x; n->x = it->x;
n->y = it->y; n->y = it->y;
n->direction = it->direction; n->direction = it->direction;
gegl_buffer_get ((GeglBuffer *) buffer,
GEGL_RECTANGLE (n->x - 1, n->y - 1, 3, 3),
1.0, NULL, pixels, GEGL_AUTO_ROWSTRIDE,
GEGL_ABYSS_NONE);
switch (n->direction) switch (n->direction)
{ {
case XPlusDirection: case XPlusDirection:
gegl_buffer_sample ((GeglBuffer *) buffer, n->x + 1, n->y + 1, NULL, &has_stroke, NULL, if (pixels[8])
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
if ((n->x != lx) && (n->y != ly) && has_stroke)
{ {
++(n->y); ++(n->y);
++(n->x); ++(n->x);
n->direction = YMinusDirection; n->direction = YMinusDirection;
} }
else else if (pixels[7])
{
gegl_buffer_sample ((GeglBuffer *) buffer, n->x, n->y + 1, NULL, &has_stroke, NULL,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
if ((n->y != ly) && has_stroke)
{ {
++(n->y); ++(n->y);
} }
@ -1834,22 +1816,15 @@ gimp_edgelset_next8 (const GeglBuffer *buffer,
{ {
n->direction = YPlusDirection; n->direction = YPlusDirection;
} }
}
break; break;
case YMinusDirection: case YMinusDirection:
gegl_buffer_sample ((GeglBuffer *) buffer, n->x + 1, n->y - 1, NULL, &has_stroke, NULL, if (pixels[2])
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
if ((n->x != lx) && n->y && has_stroke)
{ {
++(n->x); ++(n->x);
--(n->y); --(n->y);
n->direction = XMinusDirection; n->direction = XMinusDirection;
} }
else else if (pixels[5])
{
gegl_buffer_sample ((GeglBuffer *) buffer, n->x + 1, n->y, NULL, &has_stroke, NULL,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
if ((n->x != lx) && has_stroke)
{ {
++(n->x); ++(n->x);
} }
@ -1857,22 +1832,15 @@ gimp_edgelset_next8 (const GeglBuffer *buffer,
{ {
n->direction = XPlusDirection; n->direction = XPlusDirection;
} }
}
break; break;
case XMinusDirection: case XMinusDirection:
gegl_buffer_sample ((GeglBuffer *) buffer, n->x - 1, n->y - 1, NULL, &has_stroke, NULL, if (pixels[0])
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
if (n->x && n->y && has_stroke)
{ {
--(n->x); --(n->x);
--(n->y); --(n->y);
n->direction = YPlusDirection; n->direction = YPlusDirection;
} }
else else if (pixels[1])
{
gegl_buffer_sample ((GeglBuffer *) buffer, n->x, n->y - 1, NULL, &has_stroke, NULL,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
if (n->y && has_stroke)
{ {
--(n->y); --(n->y);
} }
@ -1880,22 +1848,15 @@ gimp_edgelset_next8 (const GeglBuffer *buffer,
{ {
n->direction = YMinusDirection; n->direction = YMinusDirection;
} }
}
break; break;
case YPlusDirection: case YPlusDirection:
gegl_buffer_sample ((GeglBuffer *) buffer, n->x - 1, n->y + 1, NULL, &has_stroke, NULL, if (pixels[6])
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
if (n->x && (n->y != ly) && has_stroke)
{ {
--(n->x); --(n->x);
++(n->y); ++(n->y);
n->direction = XPlusDirection; n->direction = XPlusDirection;
} }
else else if (pixels[3])
{
gegl_buffer_sample ((GeglBuffer *) buffer, n->x - 1, n->y, NULL, &has_stroke, NULL,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
if (n->x && has_stroke)
{ {
--(n->x); --(n->x);
} }
@ -1903,10 +1864,9 @@ gimp_edgelset_next8 (const GeglBuffer *buffer,
{ {
n->direction = XMinusDirection; n->direction = XMinusDirection;
} }
}
break; break;
default: default:
gimp_assert (FALSE); g_return_if_reached ();
break; break;
} }
} }