From 637df82c71ef4b268da701f296666eb1908697b3 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Tue, 15 Feb 2005 23:53:56 +0000 Subject: [PATCH] parallelized. 2005-02-16 Sven Neumann * app/core/gimpdrawable-desaturate.c: parallelized. --- ChangeLog | 4 ++ app/core/gimpdrawable-desaturate.c | 97 +++++++++++++++++------------- 2 files changed, 58 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9eb50cc917..3e07a031df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-02-16 Sven Neumann + + * app/core/gimpdrawable-desaturate.c: parallelized. + 2005-02-16 Sven Neumann * app/core/gimplayer.c (gimp_layer_transform_color): code cleanup. diff --git a/app/core/gimpdrawable-desaturate.c b/app/core/gimpdrawable-desaturate.c index 1385afe9bc..5288e63845 100644 --- a/app/core/gimpdrawable-desaturate.c +++ b/app/core/gimpdrawable-desaturate.c @@ -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; + } +}