parallelized.

2005-02-16  Sven Neumann  <sven@gimp.org>

	* app/core/gimpdrawable-desaturate.c: parallelized.
This commit is contained in:
Sven Neumann 2005-02-15 23:53:56 +00:00 committed by Sven Neumann
parent ddf6688fc8
commit 637df82c71
2 changed files with 58 additions and 43 deletions

View File

@ -1,3 +1,7 @@
2005-02-16 Sven Neumann <sven@gimp.org>
* app/core/gimpdrawable-desaturate.c: parallelized.
2005-02-16 Sven Neumann <sven@gimp.org>
* app/core/gimplayer.c (gimp_layer_transform_color): code cleanup.

View File

@ -22,6 +22,7 @@
#include "core-types.h"
#include "base/pixel-processor.h"
#include "base/pixel-region.h"
#include "gimpdrawable.h"
@ -31,17 +32,17 @@
#include "gimp-intl.h"
static void desaturate_region (gpointer data,
PixelRegion *srcPR,
PixelRegion *destPR);
void
gimp_drawable_desaturate (GimpDrawable *drawable)
{
PixelRegion srcPR, destPR;
guchar *src, *s;
guchar *dest, *d;
gint h, j;
gint lightness, min, max;
gboolean has_alpha;
gpointer pr;
gint x, y, width, height;
gboolean has_alpha;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (gimp_drawable_is_rgb (drawable));
@ -57,45 +58,55 @@ gimp_drawable_desaturate (GimpDrawable *drawable)
pixel_region_init (&destPR, gimp_drawable_shadow (drawable),
x, y, width, height, TRUE);
for (pr = pixel_regions_register (2, &srcPR, &destPR);
pr != NULL;
pr = pixel_regions_process (pr))
{
src = srcPR.data;
dest = destPR.data;
h = srcPR.h;
while (h--)
{
s = src;
d = dest;
for (j = 0; j < srcPR.w; j++)
{
max = MAX (s[RED_PIX], s[GREEN_PIX]);
max = MAX (max, s[BLUE_PIX]);
min = MIN (s[RED_PIX], s[GREEN_PIX]);
min = MIN (min, s[BLUE_PIX]);
lightness = (max + min) / 2;
d[RED_PIX] = lightness;
d[GREEN_PIX] = lightness;
d[BLUE_PIX] = lightness;
if (has_alpha)
d[ALPHA_PIX] = s[ALPHA_PIX];
d += destPR.bytes;
s += srcPR.bytes;
}
src += srcPR.rowstride;
dest += destPR.rowstride;
}
}
pixel_regions_process_parallel ((PixelProcessorFunc) desaturate_region,
GINT_TO_POINTER (has_alpha),
2, &srcPR, &destPR);
gimp_drawable_merge_shadow (drawable, TRUE, _("Desaturate"));
gimp_drawable_update (drawable, x, y, width, height);
}
static void
desaturate_region (gpointer data,
PixelRegion *srcPR,
PixelRegion *destPR)
{
const guchar *src = srcPR->data;
guchar *dest = destPR->data;
gint h = srcPR->h;
gboolean has_alpha = GPOINTER_TO_INT (data);
while (h--)
{
const guchar *s = src;
guchar *d = dest;
gint j;
for (j = 0; j < srcPR->w; j++)
{
gint min, max;
gint lightness;
max = MAX (s[RED_PIX], s[GREEN_PIX]);
max = MAX (max, s[BLUE_PIX]);
min = MIN (s[RED_PIX], s[GREEN_PIX]);
min = MIN (min, s[BLUE_PIX]);
lightness = (max + min) / 2;
d[RED_PIX] = lightness;
d[GREEN_PIX] = lightness;
d[BLUE_PIX] = lightness;
if (has_alpha)
d[ALPHA_PIX] = s[ALPHA_PIX];
d += destPR->bytes;
s += srcPR->bytes;
}
src += srcPR->rowstride;
dest += destPR->rowstride;
}
}