mirror of https://github.com/GNOME/gimp.git
fold the three desaturate functions into one
svn path=/trunk/; revision=25729
This commit is contained in:
parent
595d54eddf
commit
9519a1751d
|
@ -28,15 +28,49 @@
|
|||
#include "pixel-region.h"
|
||||
|
||||
|
||||
static void desaturate_region_lightness (PixelRegion *srcPR,
|
||||
PixelRegion *destPR,
|
||||
const gboolean has_alpha);
|
||||
static void desaturate_region_luminosity (PixelRegion *srcPR,
|
||||
PixelRegion *destPR,
|
||||
const gboolean has_alpha);
|
||||
static void desaturate_region_average (PixelRegion *srcPR,
|
||||
PixelRegion *destPR,
|
||||
const gboolean has_alpha);
|
||||
|
||||
|
||||
void
|
||||
desaturate_region_lightness (gpointer data,
|
||||
PixelRegion *srcPR,
|
||||
PixelRegion *destPR)
|
||||
desaturate_region (GimpDesaturateMode mode,
|
||||
PixelRegion *srcPR,
|
||||
PixelRegion *destPR)
|
||||
{
|
||||
const guchar *src = srcPR->data;
|
||||
guchar *dest = destPR->data;
|
||||
gint h = srcPR->h;
|
||||
gboolean has_alpha = GPOINTER_TO_INT (data);
|
||||
g_return_if_fail (srcPR->bytes == destPR->bytes);
|
||||
g_return_if_fail (srcPR->bytes == 3 || srcPR->bytes == 4);
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case GIMP_DESATURATE_LIGHTNESS:
|
||||
desaturate_region_lightness (srcPR, destPR, srcPR->bytes == 4);
|
||||
break;
|
||||
|
||||
case GIMP_DESATURATE_LUMINOSITY:
|
||||
desaturate_region_luminosity (srcPR, destPR, srcPR->bytes == 4);
|
||||
break;
|
||||
|
||||
case GIMP_DESATURATE_AVERAGE:
|
||||
desaturate_region_average (srcPR, destPR, srcPR->bytes == 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
desaturate_region_lightness (PixelRegion *srcPR,
|
||||
PixelRegion *destPR,
|
||||
const gboolean has_alpha)
|
||||
{
|
||||
const guchar *src = srcPR->data;
|
||||
guchar *dest = destPR->data;
|
||||
gint h = srcPR->h;
|
||||
|
||||
while (h--)
|
||||
{
|
||||
|
@ -72,15 +106,14 @@ desaturate_region_lightness (gpointer data,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
desaturate_region_luminosity (gpointer data,
|
||||
PixelRegion *srcPR,
|
||||
PixelRegion *destPR)
|
||||
static void
|
||||
desaturate_region_luminosity (PixelRegion *srcPR,
|
||||
PixelRegion *destPR,
|
||||
const gboolean has_alpha)
|
||||
{
|
||||
const guchar *src = srcPR->data;
|
||||
guchar *dest = destPR->data;
|
||||
gint h = srcPR->h;
|
||||
gboolean has_alpha = GPOINTER_TO_INT (data);
|
||||
const guchar *src = srcPR->data;
|
||||
guchar *dest = destPR->data;
|
||||
gint h = srcPR->h;
|
||||
|
||||
while (h--)
|
||||
{
|
||||
|
@ -110,15 +143,14 @@ desaturate_region_luminosity (gpointer data,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
desaturate_region_average (gpointer data,
|
||||
PixelRegion *srcPR,
|
||||
PixelRegion *destPR)
|
||||
static void
|
||||
desaturate_region_average (PixelRegion *srcPR,
|
||||
PixelRegion *destPR,
|
||||
const gboolean has_alpha)
|
||||
{
|
||||
const guchar *src = srcPR->data;
|
||||
guchar *dest = destPR->data;
|
||||
gint h = srcPR->h;
|
||||
gboolean has_alpha = GPOINTER_TO_INT (data);
|
||||
const guchar *src = srcPR->data;
|
||||
guchar *dest = destPR->data;
|
||||
gint h = srcPR->h;
|
||||
|
||||
while (h--)
|
||||
{
|
||||
|
|
|
@ -20,15 +20,9 @@
|
|||
#define __DESATURATE_H__
|
||||
|
||||
|
||||
void desaturate_region_lightness (gpointer data,
|
||||
PixelRegion *srcPR,
|
||||
PixelRegion *destPR);
|
||||
void desaturate_region_luminosity (gpointer data,
|
||||
PixelRegion *srcPR,
|
||||
PixelRegion *destPR);
|
||||
void desaturate_region_average (gpointer data,
|
||||
PixelRegion *srcPR,
|
||||
PixelRegion *destPR);
|
||||
void desaturate_region (GimpDesaturateMode mode,
|
||||
PixelRegion *srcPR,
|
||||
PixelRegion *destPR);
|
||||
|
||||
|
||||
#endif /* __DESATURATE_H__ */
|
||||
|
|
|
@ -76,43 +76,19 @@ gimp_drawable_desaturate (GimpDrawable *drawable,
|
|||
}
|
||||
else
|
||||
{
|
||||
PixelRegion srcPR, destPR;
|
||||
PixelProcessorFunc function;
|
||||
gint x, y;
|
||||
gint width, height;
|
||||
gboolean has_alpha;
|
||||
PixelRegion srcPR, destPR;
|
||||
gint x, y, width, height;
|
||||
|
||||
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
||||
return;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case GIMP_DESATURATE_LIGHTNESS:
|
||||
function = (PixelProcessorFunc) desaturate_region_lightness;
|
||||
break;
|
||||
|
||||
break;
|
||||
case GIMP_DESATURATE_LUMINOSITY:
|
||||
function = (PixelProcessorFunc) desaturate_region_luminosity;
|
||||
break;
|
||||
|
||||
case GIMP_DESATURATE_AVERAGE:
|
||||
function = (PixelProcessorFunc) desaturate_region_average;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_return_if_reached ();
|
||||
return;
|
||||
}
|
||||
|
||||
has_alpha = gimp_drawable_has_alpha (drawable);
|
||||
|
||||
pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
|
||||
x, y, width, height, FALSE);
|
||||
pixel_region_init (&destPR, gimp_drawable_get_shadow_tiles (drawable),
|
||||
x, y, width, height, TRUE);
|
||||
|
||||
pixel_regions_process_parallel (function, GINT_TO_POINTER (has_alpha),
|
||||
pixel_regions_process_parallel ((PixelProcessorFunc) desaturate_region,
|
||||
GINT_TO_POINTER (mode),
|
||||
2, &srcPR, &destPR);
|
||||
|
||||
gimp_drawable_merge_shadow_tiles (drawable, TRUE, _("Desaturate"));
|
||||
|
|
Loading…
Reference in New Issue