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"
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
static void desaturate (GimpDrawable *);
|
1997-11-25 06:05:25 +08:00
|
|
|
static Argument * desaturate_invoker (Argument *);
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Desaturateer */
|
|
|
|
|
|
|
|
static 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The desaturate procedure definition */
|
|
|
|
ProcArg desaturate_args[] =
|
|
|
|
{
|
|
|
|
{ PDB_DRAWABLE,
|
|
|
|
"drawable",
|
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
|
|
|
N_("the drawable")
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ProcRecord desaturate_proc =
|
|
|
|
{
|
|
|
|
"gimp_desaturate",
|
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
|
|
|
N_("Desaturate the contents of the specified drawable"),
|
|
|
|
N_("This procedure desaturates the contents of the specified drawable. This procedure only works on drawables of type RGB color."),
|
1997-11-25 06:05:25 +08:00
|
|
|
"Spencer Kimball & Peter Mattis",
|
|
|
|
"Spencer Kimball & Peter Mattis",
|
|
|
|
"1995-1996",
|
|
|
|
PDB_INTERNAL,
|
|
|
|
|
|
|
|
/* Input arguments */
|
API-mega-break-it-all patch part one: removed the unnecessary PDB_IMAGE
* airbrush.c, blend.c, brightness_contrast.c, bucket_fill.c
by_color_select.c, channel_ops.c, clone.c, color_balance.c
color_picker.c, convolve.c, curves.c, desaturate.c, edit_cmds.c
equalize.c, eraser.c, flip_tool.c, fuzzy_select.c,
gimage_mask_cmds.c histogram_tool.c, hue_saturation.c, invert.c,
levels.c, pencil.c paintbrush.c, perspective_tool.c, posterize.c,
rotate_tool.c scale_tool.c, shear_tool.c, text_tool.c, threshold.c:
API-mega-break-it-all patch part one: removed the unnecessary
PDB_IMAGE argument from many functions.
Affected functions:
gimp_airbrush gimp_blend gimp_brightness_contrast gimp_bucket_fill
gimp_by_color_select gimp_channel_ops_offset gimp_clone gimp_color_balance
gimp_color_picker gimp_convolve gimp_curves_explicit gimp_curves_spline
gimp_desaturate gimp_edit_clear gimp_edit_copy gimp_edit_cut gimp_edit_fill
gimp_edit_paste gimp_edit_stroke gimp_equalize gimp_eraser
gimp_eraser_extended gimp_flip gimp_fuzzy_select gimp_histogram
gimp_hue_saturation gimp_invert gimp_levels gimp_paintbrush
gimp_paintbrush_extended gimp_pencil gimp_perspective gimp_posterize
gimp_rotate gimp_scale gimp_selection_float gimp_selection_layer_alpha
gimp_selection_load gimp_shear gimp_threshold
1998-11-14 04:40:00 +08:00
|
|
|
1,
|
1997-11-25 06:05:25 +08:00
|
|
|
desaturate_args,
|
|
|
|
|
|
|
|
/* Output arguments */
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
/* Exec method */
|
|
|
|
{ { desaturate_invoker } },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static Argument *
|
|
|
|
desaturate_invoker (args)
|
|
|
|
Argument *args;
|
|
|
|
{
|
|
|
|
int success = TRUE;
|
|
|
|
int int_value;
|
|
|
|
GImage *gimage;
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpDrawable *drawable;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
drawable = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* the drawable */
|
|
|
|
if (success)
|
|
|
|
{
|
API-mega-break-it-all patch part one: removed the unnecessary PDB_IMAGE
* airbrush.c, blend.c, brightness_contrast.c, bucket_fill.c
by_color_select.c, channel_ops.c, clone.c, color_balance.c
color_picker.c, convolve.c, curves.c, desaturate.c, edit_cmds.c
equalize.c, eraser.c, flip_tool.c, fuzzy_select.c,
gimage_mask_cmds.c histogram_tool.c, hue_saturation.c, invert.c,
levels.c, pencil.c paintbrush.c, perspective_tool.c, posterize.c,
rotate_tool.c scale_tool.c, shear_tool.c, text_tool.c, threshold.c:
API-mega-break-it-all patch part one: removed the unnecessary
PDB_IMAGE argument from many functions.
Affected functions:
gimp_airbrush gimp_blend gimp_brightness_contrast gimp_bucket_fill
gimp_by_color_select gimp_channel_ops_offset gimp_clone gimp_color_balance
gimp_color_picker gimp_convolve gimp_curves_explicit gimp_curves_spline
gimp_desaturate gimp_edit_clear gimp_edit_copy gimp_edit_cut gimp_edit_fill
gimp_edit_paste gimp_edit_stroke gimp_equalize gimp_eraser
gimp_eraser_extended gimp_flip gimp_fuzzy_select gimp_histogram
gimp_hue_saturation gimp_invert gimp_levels gimp_paintbrush
gimp_paintbrush_extended gimp_pencil gimp_perspective gimp_posterize
gimp_rotate gimp_scale gimp_selection_float gimp_selection_layer_alpha
gimp_selection_load gimp_shear gimp_threshold
1998-11-14 04:40:00 +08:00
|
|
|
int_value = args[0].value.pdb_int;
|
1998-01-22 15:02:57 +08:00
|
|
|
drawable = drawable_get_ID (int_value);
|
API-mega-break-it-all patch part one: removed the unnecessary PDB_IMAGE
* airbrush.c, blend.c, brightness_contrast.c, bucket_fill.c
by_color_select.c, channel_ops.c, clone.c, color_balance.c
color_picker.c, convolve.c, curves.c, desaturate.c, edit_cmds.c
equalize.c, eraser.c, flip_tool.c, fuzzy_select.c,
gimage_mask_cmds.c histogram_tool.c, hue_saturation.c, invert.c,
levels.c, pencil.c paintbrush.c, perspective_tool.c, posterize.c,
rotate_tool.c scale_tool.c, shear_tool.c, text_tool.c, threshold.c:
API-mega-break-it-all patch part one: removed the unnecessary
PDB_IMAGE argument from many functions.
Affected functions:
gimp_airbrush gimp_blend gimp_brightness_contrast gimp_bucket_fill
gimp_by_color_select gimp_channel_ops_offset gimp_clone gimp_color_balance
gimp_color_picker gimp_convolve gimp_curves_explicit gimp_curves_spline
gimp_desaturate gimp_edit_clear gimp_edit_copy gimp_edit_cut gimp_edit_fill
gimp_edit_paste gimp_edit_stroke gimp_equalize gimp_eraser
gimp_eraser_extended gimp_flip gimp_fuzzy_select gimp_histogram
gimp_hue_saturation gimp_invert gimp_levels gimp_paintbrush
gimp_paintbrush_extended gimp_pencil gimp_perspective gimp_posterize
gimp_rotate gimp_scale gimp_selection_float gimp_selection_layer_alpha
gimp_selection_load gimp_shear gimp_threshold
1998-11-14 04:40:00 +08:00
|
|
|
if (drawable == NULL)
|
|
|
|
success = FALSE;
|
|
|
|
else
|
|
|
|
gimage = drawable_gimage (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check to make sure the drawable is color */
|
|
|
|
if (success)
|
1998-01-22 15:02:57 +08:00
|
|
|
success = drawable_color (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (success)
|
1998-01-22 15:02:57 +08:00
|
|
|
desaturate (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return procedural_db_return_args (&desaturate_proc, success);
|
|
|
|
}
|