gimp/plug-ins/common/normalize.c

308 lines
7.9 KiB
C
Raw Normal View History

1997-11-24 22:05:25 +00:00
/* Normalize 1.00 --- image filter plug-in for The GIMP
*
* Copyright (C) 1997 Adam D. Moss (adam@foxbox.org)
* Very largely based on Quartic's "Contrast Autostretch"
*
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1997-11-24 22:05:25 +00:00
*/
1997-11-24 22:05:25 +00:00
/* This plugin performs almost the same operation as the 'contrast
* autostretch' plugin, except that it won't allow the colour channels
* to normalize independently. This is actually what most people probably
* want instead of contrast-autostretch; use c-a only if you wish to remove
* an undesirable colour-tint from a source image which is supposed to
* contain pure-white and pure-black.
*/
#include "config.h"
1997-11-24 22:05:25 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <libgimp/gimp.h>
#include "libgimp/stdplugins-intl.h"
1997-11-24 22:05:25 +00:00
/* Declare local functions.
*/
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
static void query (void);
static void run (gchar *name,
gint nparams,
GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
1997-11-24 22:05:25 +00:00
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
static void normalize (GimpDrawable *drawable);
static void indexed_normalize (gint32 image_ID);
1997-11-24 22:05:25 +00:00
GimpPlugInInfo PLUG_IN_INFO =
1997-11-24 22:05:25 +00:00
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
1997-11-24 22:05:25 +00:00
};
MAIN ()
static void
query (void)
1997-11-24 22:05:25 +00:00
{
static GimpParamDef args[] =
1997-11-24 22:05:25 +00:00
{
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
1997-11-24 22:05:25 +00:00
};
1997-11-24 22:05:25 +00:00
gimp_install_procedure ("plug_in_normalize",
"Normalize the contrast of the specified drawable to "
"cover all possible ranges.",
"This plugin performs almost the same operation as "
"the 'contrast autostretch' plugin, except that it "
"won't allow the color channels to normalize "
"independently. This is actually what most people "
"probably want instead of contrast-autostretch; use "
"c-a only if you wish to remove an undesirable "
"color-tint from a source image which is supposed to "
"contain pure-white and pure-black.",
1997-11-24 22:05:25 +00:00
"Adam D. Moss, Federico Mena Quintero",
"Adam D. Moss, Federico Mena Quintero",
"1997",
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
N_("<Image>/Layer/Colors/Auto/Normalize"),
1997-11-24 22:05:25 +00:00
"RGB*, GRAY*, INDEXED*",
GIMP_PLUGIN,
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
G_N_ELEMENTS (args), 0,
args, NULL);
1997-11-24 22:05:25 +00:00
}
static void
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
run (gchar *name,
gint nparams,
GimpParam *param,
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
gint *nreturn_vals,
GimpParam **return_vals)
1997-11-24 22:05:25 +00:00
{
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
static GimpParam values[1];
GimpDrawable *drawable;
GimpRunMode run_mode;
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
1997-11-24 22:05:25 +00:00
gint32 image_ID;
INIT_I18N();
1997-11-24 22:05:25 +00:00
run_mode = param[0].data.d_int32;
/* Get the specified drawable */
drawable = gimp_drawable_get (param[2].data.d_drawable);
image_ID = param[1].data.d_image;
/* Make sure that the drawable is gray or RGB color */
if (gimp_drawable_is_rgb (drawable->drawable_id) || gimp_drawable_is_gray (drawable->drawable_id))
1997-11-24 22:05:25 +00:00
{
gimp_progress_init (_("Normalizing..."));
1997-11-24 22:05:25 +00:00
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
normalize (drawable);
1997-11-24 22:05:25 +00:00
if (run_mode != GIMP_RUN_NONINTERACTIVE)
1997-11-24 22:05:25 +00:00
gimp_displays_flush ();
}
else if (gimp_drawable_is_indexed (drawable->drawable_id))
1997-11-24 22:05:25 +00:00
{
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
indexed_normalize (image_ID);
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
1997-11-24 22:05:25 +00:00
}
else
{
/* gimp_message ("normalize: cannot operate on indexed color images"); */
status = GIMP_PDB_EXECUTION_ERROR;
1997-11-24 22:05:25 +00:00
}
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
1997-11-24 22:05:25 +00:00
values[0].data.d_status = status;
gimp_drawable_detach (drawable);
}
static void
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
indexed_normalize (gint32 image_ID) /* a.d.m. */
1997-11-24 22:05:25 +00:00
{
guchar *cmap;
gint ncols,i;
gint hi=0,lo=255;
cmap = gimp_image_get_cmap (image_ID, &ncols);
if (cmap==NULL)
{
printf ("normalize: cmap was NULL! Quitting...\n");
return;
1997-11-24 22:05:25 +00:00
}
for (i=0;i<ncols;i++)
{
if (cmap[i*3 +0] > hi) hi=cmap[i*3 +0];
if (cmap[i*3 +1] > hi) hi=cmap[i*3 +1];
if (cmap[i*3 +2] > hi) hi=cmap[i*3 +2];
if (cmap[i*3 +0] < lo) lo=cmap[i*3 +0];
if (cmap[i*3 +1] < lo) lo=cmap[i*3 +1];
if (cmap[i*3 +2] < lo) lo=cmap[i*3 +2];
}
if (hi!=lo)
for (i=0;i<ncols;i++)
{
cmap[i*3 +0] = (255 * (cmap[i*3 +0] - lo)) / (hi-lo);
cmap[i*3 +1] = (255 * (cmap[i*3 +1] - lo)) / (hi-lo);
cmap[i*3 +2] = (255 * (cmap[i*3 +2] - lo)) / (hi-lo);
}
gimp_image_set_cmap (image_ID, cmap, ncols);
}
static void
use the passed Gimp pointer instead of using "the_gimp". 2001-12-03 Michael Natterer <mitch@gimp.org> * app/devices.c: use the passed Gimp pointer instead of using "the_gimp". * app/base/temp-buf.c: indentation. * app/gui/preferences-dialog.c: prefs_toggle_callback(): fixed segfault when trying to find the prefs_dlg widget from a menu item callback (Fixes #65757). * app/gui/offset-dialog.[ch]: fixed public prototype, include the header in the .c file. * app/gui/menus.c: some menu cleanup: moved all functions which operate on the active layer/drawable to <Image>/Layer. Renamed "Layers" to "Layer". * app/display/gimpdisplayshell.c: changed menu update function accordingly. * app/gui/image-commands.[ch] * app/gui/layers-commands.[ch]: moved stuff from image-commands.* to layers-commads.*- * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/transform_options.c * plug-ins/common/align_layers.c * plug-ins/common/autocrop.c * plug-ins/common/autostretch_hsv.c * plug-ins/common/c_astretch.c * plug-ins/common/color_enhance.c * plug-ins/common/guillotine.c * plug-ins/common/normalize.c * plug-ins/common/rotate.c * plug-ins/common/threshold_alpha.c * plug-ins/common/zealouscrop.c * plug-ins/rcm/rcm.c * plug-ins/fp/fp.c: register under <Image>/Layer, some cosmetic fixes.
2001-12-03 17:59:48 +00:00
normalize (GimpDrawable *drawable)
1997-11-24 22:05:25 +00:00
{
GimpPixelRgn src_rgn, dest_rgn;
1997-11-24 22:05:25 +00:00
guchar *src, *s;
guchar *dest, *d;
guchar min, max;
guchar range;
guchar lut[256];
gint progress, max_progress;
gint has_alpha, alpha;
gint x1, y1, x2, y2;
gint x, y, b;
gpointer pr;
/* Get selection area */
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
1997-11-24 22:05:25 +00:00
alpha = (has_alpha) ? drawable->bpp - 1 : drawable->bpp;
/* Initialize progress */
progress = 0;
max_progress = (x2 - x1) * (y2 - y1) * 2;
/* Get minimum and maximum values for each channel */
min = 255;
max = 0;
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
1997-11-24 22:05:25 +00:00
for (pr = gimp_pixel_rgns_register (1, &src_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
1997-11-24 22:05:25 +00:00
{
src = src_rgn.data;
for (y = 0; y < src_rgn.h; y++)
{
s = src;
for (x = 0; x < src_rgn.w; x++)
{
for (b = 0; b < alpha; b++)
{
if (!has_alpha || (has_alpha && s[alpha]))
{
if (s[b] < min)
min = s[b];
if (s[b] > max)
max = s[b];
}
}
s += src_rgn.bpp;
}
src += src_rgn.rowstride;
}
/* Update progress */
progress += src_rgn.w * src_rgn.h;
gimp_progress_update ((double) progress / (double) max_progress);
}
/* Calculate LUT */
range = max - min;
if (range != 0)
for (x = min; x <= max; x++)
lut[x] = 255 * (x - min) / range;
else
lut[min] = min;
/* Now substitute pixel vales */
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
1997-11-24 22:05:25 +00:00
{
src = src_rgn.data;
dest = dest_rgn.data;
for (y = 0; y < src_rgn.h; y++)
{
s = src;
d = dest;
for (x = 0; x < src_rgn.w; x++)
{
for (b = 0; b < alpha; b++)
d[b] = lut[s[b]];
if (has_alpha)
d[alpha] = s[alpha];
s += src_rgn.bpp;
d += dest_rgn.bpp;
}
src += src_rgn.rowstride;
dest += dest_rgn.rowstride;
}
/* Update progress */
progress += src_rgn.w * src_rgn.h;
gimp_progress_update ((double) progress / (double) max_progress);
}
/* update the region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
1997-11-24 22:05:25 +00:00
}