1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "appenv.h"
|
|
|
|
#include "drawable.h"
|
|
|
|
#include "desaturate.h"
|
|
|
|
#include "interface.h"
|
|
|
|
#include "paint_funcs.h"
|
1998-01-22 15:02:57 +08:00
|
|
|
#include "gimage.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
image_desaturate (gimage_ptr)
|
|
|
|
void *gimage_ptr;
|
|
|
|
{
|
|
|
|
GImage *gimage;
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpDrawable *drawable;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gimage = (GImage *) gimage_ptr;
|
1998-01-22 15:02:57 +08:00
|
|
|
drawable = gimage_active_drawable (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
if (! drawable_color (drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
g_message (_("Desaturate operates only on RGB color drawables."));
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
}
|
1998-01-22 15:02:57 +08:00
|
|
|
desaturate (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
moved a bunch of PDB stuff here
* app/color_cmds.c: moved a bunch of PDB stuff here
* app/color_balance.[ch]: removed PDB proc, exported TransferMode
enum, ColorBalanceDialog, color_balance_create_lookup_tables, and
color_balance
* app/curves.[ch]: removed PDB procs, exported SMOOTH and GFREE
#defines, CurvesDialog, curves_lut_func and curves_calculate_curve
* app/desaturate.[ch]: removed PDB proc, exported desaturate
* app/equalize.[ch]: removed PDB proc, exported equalize
* app/histogram_tool.[ch]: removed PDB proc, exported HISTOGRAM_WIDTH
and HISTOGRAM_HEIGHT #defines, HistogramToolDialog,
histogram_tool_histogram_range
* app/hue_saturation.[ch]: removed PDB proc, exported HueRange enum,
HueSaturationDialog, hue_saturation_calculate_transfers,
hue_saturation
* app/invert.[ch]: remove PDB proc, export invert
* app/threshold.[ch]: remove PDB proc, export ThresholdDialog and
threshold_2
* internal_procs.c: changes for pdbgen
* app/gimprc.c: removed leftover declaration
* app/image_map.h: add #include "gimpdrawableF.h"
* app/lut_funcs.h: add ALPHA_LUT to ChannelLutType
-Yosh
1999-04-21 13:39:57 +08:00
|
|
|
/* Desaturater */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
moved a bunch of PDB stuff here
* app/color_cmds.c: moved a bunch of PDB stuff here
* app/color_balance.[ch]: removed PDB proc, exported TransferMode
enum, ColorBalanceDialog, color_balance_create_lookup_tables, and
color_balance
* app/curves.[ch]: removed PDB procs, exported SMOOTH and GFREE
#defines, CurvesDialog, curves_lut_func and curves_calculate_curve
* app/desaturate.[ch]: removed PDB proc, exported desaturate
* app/equalize.[ch]: removed PDB proc, exported equalize
* app/histogram_tool.[ch]: removed PDB proc, exported HISTOGRAM_WIDTH
and HISTOGRAM_HEIGHT #defines, HistogramToolDialog,
histogram_tool_histogram_range
* app/hue_saturation.[ch]: removed PDB proc, exported HueRange enum,
HueSaturationDialog, hue_saturation_calculate_transfers,
hue_saturation
* app/invert.[ch]: remove PDB proc, export invert
* app/threshold.[ch]: remove PDB proc, export ThresholdDialog and
threshold_2
* internal_procs.c: changes for pdbgen
* app/gimprc.c: removed leftover declaration
* app/image_map.h: add #include "gimpdrawableF.h"
* app/lut_funcs.h: add ALPHA_LUT to ChannelLutType
-Yosh
1999-04-21 13:39:57 +08:00
|
|
|
void
|
1998-01-22 15:02:57 +08:00
|
|
|
desaturate (GimpDrawable *drawable)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
unsigned char *src, *s;
|
|
|
|
unsigned char *dest, *d;
|
|
|
|
int h, j;
|
|
|
|
int lightness, min, max;
|
|
|
|
int has_alpha;
|
|
|
|
void *pr;
|
|
|
|
int x1, y1, x2, y2;
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
if (!drawable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
has_alpha = drawable_has_alpha (drawable);
|
|
|
|
drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
|
|
|
pixel_region_init (&srcPR, drawable_data (drawable), x1, y1, (x2 - x1), (y2 - y1), FALSE);
|
|
|
|
pixel_region_init (&destPR, drawable_shadow (drawable), x1, y1, (x2 - x1), (y2 - y1), TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
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 = MAXIMUM (s[RED_PIX], s[GREEN_PIX]);
|
|
|
|
max = MAXIMUM (max, s[BLUE_PIX]);
|
|
|
|
min = MINIMUM (s[RED_PIX], s[GREEN_PIX]);
|
|
|
|
min = MINIMUM (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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
drawable_merge_shadow (drawable, TRUE);
|
|
|
|
drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|