plug-ins: replace calls to GimpRegionIterator functions

by plain pixel region code, copied right out of gimpregioniterator.c.
Makes porting to GEGL easier and GimpRegionIterator unused.

(cherry picked from commit 775abb03f3)
This commit is contained in:
Michael Natterer
2019-07-07 17:09:17 +02:00
parent b15f0ff687
commit f4b836c68d
5 changed files with 332 additions and 9 deletions

View File

@ -231,7 +231,63 @@ colorify (GimpDrawable *drawable,
}
else
{
gimp_rgn_iterate2 (drawable, 0 /* unused */, colorify_func, NULL);
GimpPixelRgn srcPR, destPR;
gint x1, y1, x2, y2;
gpointer pr;
gint total_area;
gint area_so_far;
gint count;
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
total_area = (x2 - x1) * (y2 - y1);
area_so_far = 0;
if (total_area <= 0)
return;
/* Initialize the pixel regions. */
gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (2, &srcPR, &destPR), count = 0;
pr != NULL;
pr = gimp_pixel_rgns_process (pr), count++)
{
const guchar *src = srcPR.data;
guchar *dest = destPR.data;
gint row;
for (row = 0; row < srcPR.h; row++)
{
const guchar *s = src;
guchar *d = dest;
gint pixels = srcPR.w;
while (pixels--)
{
colorify_func (s, d, srcPR.bpp, NULL);
s += srcPR.bpp;
d += destPR.bpp;
}
src += srcPR.rowstride;
dest += destPR.rowstride;
}
area_so_far += srcPR.w * srcPR.h;
if ((count % 16) == 0)
gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
}
/* update the processed region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
}
}

View File

@ -235,15 +235,60 @@ static void
normalize (GimpDrawable *drawable)
{
NormalizeParam_t param;
gint x;
guchar range;
gint x1, y1, x2, y2;
gint x;
guchar range;
gint total_area;
param.min = 255;
param.max = 0;
param.has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
param.alpha = (param.has_alpha) ? drawable->bpp - 1 : drawable->bpp;
gimp_rgn_iterate1 (drawable, 0 /* unused */, find_min_max, &param);
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
total_area = (x2 - x1) * (y2 - y1);
if (total_area <= 0)
return;
{
GimpPixelRgn srcPR;
gpointer pr;
gint area_so_far;
gint count;
area_so_far = 0;
gimp_pixel_rgn_init (&srcPR, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
for (pr = gimp_pixel_rgns_register (1, &srcPR), count = 0;
pr != NULL;
pr = gimp_pixel_rgns_process (pr), count++)
{
const guchar *src = srcPR.data;
gint y;
for (y = 0; y < srcPR.h; y++)
{
const guchar *s = src;
gint x;
for (x = 0; x < srcPR.w; x++)
{
find_min_max (s, srcPR.bpp, &param);
s += srcPR.bpp;
}
src += srcPR.rowstride;
}
area_so_far += srcPR.w * srcPR.h;
if ((count % 16) == 0)
gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
}
}
/* Calculate LUT */
@ -255,5 +300,55 @@ normalize (GimpDrawable *drawable)
else
param.lut[(gint)param.min] = param.min;
gimp_rgn_iterate2 (drawable, 0 /* unused */, normalize_func, &param);
{
GimpPixelRgn srcPR, destPR;
gpointer pr;
gint area_so_far;
gint count;
area_so_far = 0;
/* Initialize the pixel regions. */
gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (2, &srcPR, &destPR), count = 0;
pr != NULL;
pr = gimp_pixel_rgns_process (pr), count++)
{
const guchar *src = srcPR.data;
guchar *dest = destPR.data;
gint row;
for (row = 0; row < srcPR.h; row++)
{
const guchar *s = src;
guchar *d = dest;
gint pixels = srcPR.w;
while (pixels--)
{
normalize_func (s, d, srcPR.bpp, &param);
s += srcPR.bpp;
d += destPR.bpp;
}
src += srcPR.rowstride;
dest += destPR.rowstride;
}
area_so_far += srcPR.w * srcPR.h;
if ((count % 16) == 0)
gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
}
}
/* update the processed region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
}

View File

@ -498,7 +498,65 @@ fp_func (const guchar *src,
static void
fp (GimpDrawable *drawable)
{
gimp_rgn_iterate2 (drawable, 0 /* unused */, fp_func, NULL);
GimpPixelRgn srcPR, destPR;
gint x1, y1, x2, y2;
gpointer pr;
gint total_area;
gint area_so_far;
gint count;
g_return_if_fail (drawable != NULL);
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
total_area = (x2 - x1) * (y2 - y1);
area_so_far = 0;
if (total_area <= 0)
return;
/* Initialize the pixel regions. */
gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (2, &srcPR, &destPR), count = 0;
pr != NULL;
pr = gimp_pixel_rgns_process (pr), count++)
{
const guchar *src = srcPR.data;
guchar *dest = destPR.data;
gint row;
for (row = 0; row < srcPR.h; row++)
{
const guchar *s = src;
guchar *d = dest;
gint pixels = srcPR.w;
while (pixels--)
{
fp_func (s, d, srcPR.bpp, NULL);
s += srcPR.bpp;
d += destPR.bpp;
}
src += srcPR.rowstride;
dest += destPR.rowstride;
}
area_so_far += srcPR.w * srcPR.h;
if ((count % 16) == 0)
gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
}
/* update the processed region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
}
/***********************************************************/

View File

@ -229,10 +229,67 @@ main_function (GimpDrawable *drawable,
}
else
{
GimpPixelRgn srcPR, destPR;
gint x1, y1, x2, y2;
gpointer pr;
gint total_area;
gint area_so_far;
gint count;
gimp_progress_init (_("Max RGB"));
gimp_rgn_iterate2 (drawable, 0 /* unused */, max_rgb_func, &param);
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
total_area = (x2 - x1) * (y2 - y1);
area_so_far = 0;
if (total_area <= 0)
goto out;
/* Initialize the pixel regions. */
gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (2, &srcPR, &destPR), count = 0;
pr != NULL;
pr = gimp_pixel_rgns_process (pr), count++)
{
const guchar *src = srcPR.data;
guchar *dest = destPR.data;
gint row;
for (row = 0; row < srcPR.h; row++)
{
const guchar *s = src;
guchar *d = dest;
gint pixels = srcPR.w;
while (pixels--)
{
max_rgb_func (s, d, srcPR.bpp, &param);
s += srcPR.bpp;
d += destPR.bpp;
}
src += srcPR.rowstride;
dest += destPR.rowstride;
}
area_so_far += srcPR.w * srcPR.h;
if ((count % 16) == 0)
gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
}
/* update the processed region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
out:
gimp_drawable_detach (drawable);
}

View File

@ -3043,6 +3043,12 @@ colorize_drawable (gint32 drawable_id)
{
GimpDrawable *drawable;
gboolean has_alpha;
GimpPixelRgn srcPR, destPR;
gint x1, y1, x2, y2;
gpointer pr;
gint total_area;
gint area_so_far;
gint count;
drawable = gimp_drawable_get (drawable_id);
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
@ -3050,8 +3056,59 @@ colorize_drawable (gint32 drawable_id)
if (g_show_progress)
gimp_progress_init (_("Remap colorized"));
gimp_rgn_iterate2 (drawable, 0 /* unused */, colorize_func,
GINT_TO_POINTER (has_alpha));
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
total_area = (x2 - x1) * (y2 - y1);
area_so_far = 0;
if (total_area <= 0)
goto out;
/* Initialize the pixel regions. */
gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
FALSE, FALSE);
gimp_pixel_rgn_init (&destPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (2, &srcPR, &destPR), count = 0;
pr != NULL;
pr = gimp_pixel_rgns_process (pr), count++)
{
const guchar *src = srcPR.data;
guchar *dest = destPR.data;
gint row;
for (row = 0; row < srcPR.h; row++)
{
const guchar *s = src;
guchar *d = dest;
gint pixels = srcPR.w;
while (pixels--)
{
colorize_func (s, d, srcPR.bpp, GINT_TO_POINTER (has_alpha));
s += srcPR.bpp;
d += destPR.bpp;
}
src += srcPR.rowstride;
dest += destPR.rowstride;
}
area_so_far += srcPR.w * srcPR.h;
if ((count % 16) == 0)
gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
}
/* update the processed region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
out:
gimp_drawable_detach (drawable);
if (g_show_progress)
gimp_progress_update (0.0);