1999-04-09 14:00:11 +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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
Win32 portability changes:
* config.h.win32, README.win32: Small changes.
* tools/pdbgen/pdb/*.pdb: Include <string.h>.
* app/*_cmds.c: Autogenerated files reflect above changes.
* libgimp/makefile.msc app/makefile.msc: Various updates,
including new object files. Gtk+ directory now should be called
gtk+ (not gtk-plus). Use win32-specific gdk subdir. Glib directory
now should be called just glib.
* libgimp/gimp.def: Updates.
* libgimp/gimpfeatures.h.win32: Made current with
gimpfeatures.h.in.
* libgimp/gimpfileselection.c: Define S_ISDIR and S_ISREG if
necessary.
* tools/pdbgen/pdb/fileops.pdb: Must have a
statement (even an empty one) after a label.
* app/fileops_cmds.c: Autogenerated file reflects above changes.
* app/crop.c: Include <string.h>.
* app/{app_procs,batch,fileops,datafiles,errorconsole,general,
plug_in,temp_buf,tile_swap}.c: Test NATIVE_WIN32, not
_MSC_VER. (NATIVE_WIN32 means we are using the Microsoft C
runtime, even if we might be compiling with gcc.)
* app/fileops.c: Don't include <process.h> here.
* app/fileops.h: Do include <process.h> here.
* app/gimpparasite.c: Include config.h, guard inclusion of
<unistd.h>. (Is the inclusion of unistd.h in source files all over
the place really necessary?)
* app/ink.c: MSC doesn't handle conversion from unsigned __int64
to double, so cast to signed.
* app/lut_funcs.c: Include config.h, and define rint() if necessary.
* app/pixel_processor.c: Include config.h without "..", like in
all the other places. Include <string.h>
* app/text_tool.c: Guard the "POINTS" identifier that clashes with
<windows.h>, sigh.
1999-05-05 05:32:17 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-12-08 00:10:53 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
#include "base-types.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
|
1999-08-05 07:22:29 +08:00
|
|
|
#include "gimphistogram.h"
|
2001-05-23 07:05:35 +08:00
|
|
|
#include "gimplut.h"
|
|
|
|
#include "lut-funcs.h"
|
Win32 portability changes:
* config.h.win32, README.win32: Small changes.
* tools/pdbgen/pdb/*.pdb: Include <string.h>.
* app/*_cmds.c: Autogenerated files reflect above changes.
* libgimp/makefile.msc app/makefile.msc: Various updates,
including new object files. Gtk+ directory now should be called
gtk+ (not gtk-plus). Use win32-specific gdk subdir. Glib directory
now should be called just glib.
* libgimp/gimp.def: Updates.
* libgimp/gimpfeatures.h.win32: Made current with
gimpfeatures.h.in.
* libgimp/gimpfileselection.c: Define S_ISDIR and S_ISREG if
necessary.
* tools/pdbgen/pdb/fileops.pdb: Must have a
statement (even an empty one) after a label.
* app/fileops_cmds.c: Autogenerated file reflects above changes.
* app/crop.c: Include <string.h>.
* app/{app_procs,batch,fileops,datafiles,errorconsole,general,
plug_in,temp_buf,tile_swap}.c: Test NATIVE_WIN32, not
_MSC_VER. (NATIVE_WIN32 means we are using the Microsoft C
runtime, even if we might be compiling with gcc.)
* app/fileops.c: Don't include <process.h> here.
* app/fileops.h: Do include <process.h> here.
* app/gimpparasite.c: Include config.h, guard inclusion of
<unistd.h>. (Is the inclusion of unistd.h in source files all over
the place really necessary?)
* app/ink.c: MSC doesn't handle conversion from unsigned __int64
to double, so cast to signed.
* app/lut_funcs.c: Include config.h, and define rint() if necessary.
* app/pixel_processor.c: Include config.h without "..", like in
all the other places. Include <string.h>
* app/text_tool.c: Guard the "POINTS" identifier that clashes with
<windows.h>, sigh.
1999-05-05 05:32:17 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
/* ---------- Brightness/Contrast -----------*/
|
|
|
|
|
|
|
|
typedef struct B_C_struct
|
|
|
|
{
|
2001-05-23 07:05:35 +08:00
|
|
|
gdouble brightness;
|
|
|
|
gdouble contrast;
|
1999-04-09 14:00:11 +08:00
|
|
|
} B_C_struct;
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
static gfloat
|
|
|
|
brightness_contrast_lut_func (B_C_struct *data,
|
|
|
|
gint nchannels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
2001-05-23 07:05:35 +08:00
|
|
|
gfloat nvalue;
|
|
|
|
gdouble power;
|
1999-04-09 14:00:11 +08:00
|
|
|
|
|
|
|
/* return the original value for the alpha channel */
|
|
|
|
if ((nchannels == 2 || nchannels == 4) && channel == nchannels -1)
|
|
|
|
return value;
|
|
|
|
|
|
|
|
/* apply brightness */
|
|
|
|
if (data->brightness < 0.0)
|
|
|
|
value = value * (1.0 + data->brightness);
|
|
|
|
else
|
|
|
|
value = value + ((1.0 - value) * data->brightness);
|
|
|
|
|
|
|
|
/* apply contrast */
|
|
|
|
if (data->contrast < 0.0)
|
2001-05-23 07:05:35 +08:00
|
|
|
{
|
|
|
|
if (value > 0.5)
|
|
|
|
nvalue = 1.0 - value;
|
|
|
|
else
|
|
|
|
nvalue = value;
|
|
|
|
|
|
|
|
if (nvalue < 0.0)
|
|
|
|
nvalue = 0.0;
|
|
|
|
|
|
|
|
nvalue = 0.5 * pow (nvalue * 2.0 , (double) (1.0 + data->contrast));
|
|
|
|
|
|
|
|
if (value > 0.5)
|
|
|
|
value = 1.0 - nvalue;
|
|
|
|
else
|
|
|
|
value = nvalue;
|
|
|
|
}
|
1999-04-09 14:00:11 +08:00
|
|
|
else
|
2001-05-23 07:05:35 +08:00
|
|
|
{
|
|
|
|
if (value > 0.5)
|
|
|
|
nvalue = 1.0 - value;
|
|
|
|
else
|
|
|
|
nvalue = value;
|
|
|
|
|
|
|
|
if (nvalue < 0.0)
|
|
|
|
nvalue = 0.0;
|
|
|
|
|
|
|
|
power = (data->contrast == 1.0) ? 127 : 1.0 / (1.0 - data->contrast);
|
|
|
|
nvalue = 0.5 * pow (2.0 * nvalue, power);
|
|
|
|
|
|
|
|
if (value > 0.5)
|
|
|
|
value = 1.0 - nvalue;
|
|
|
|
else
|
|
|
|
value = nvalue;
|
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
GimpLut *
|
|
|
|
brightness_contrast_lut_new (gdouble brightness,
|
|
|
|
gdouble contrast,
|
|
|
|
gint n_channels)
|
|
|
|
{
|
|
|
|
GimpLut *lut;
|
|
|
|
|
|
|
|
lut = gimp_lut_new ();
|
|
|
|
|
|
|
|
brightness_contrast_lut_setup (lut, brightness, contrast, n_channels);
|
|
|
|
|
|
|
|
return lut;
|
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
void
|
2001-05-23 07:05:35 +08:00
|
|
|
brightness_contrast_lut_setup (GimpLut *lut,
|
|
|
|
gdouble brightness,
|
|
|
|
gdouble contrast,
|
|
|
|
gint n_channels)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
B_C_struct data;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
More color correction stuff cleanup:
2002-09-04 Michael Natterer <mitch@gimp.org>
More color correction stuff cleanup:
* app/base/Makefile.am
* app/base/base-types.h
* app/base/levels.[ch]: new files containing levels_lut_func(), a
new "Levels" parameter struct and the "auto levels" stuff.
* app/base/lut-funcs.[ch]: removed the levels stuff here, added
lots of g_return_if_fail().
* app/base/color-balance.[ch]
* app/base/hue-saturation.[ch]: added init() and reset() functions
so we don't need to duplicate this code in the tool and the pdb
wrappers.
* app/base/curves.[ch]: s/gint/GimpHistogramChannel/g, made
curves_channel_reset() initialize the curves array.
* app/tools/gimpcolorbalancetool.[ch]: use the new functions,
moved the "Range" frame to the top, added a per-range "Reset"
button, made the global "Reset" button reset all ranges and
the "Preserve Luminosity" toggle.
* app/tools/gimpcurvestool.[ch]: don't initialize the curves
array manually, as curves_channel_reset() does that,
s/gint/GimpHistogramChannel/g.
* app/tools/gimphuesaturationtool.c: use the new functions, added
a per-channel "Reset" button and made the global "Reset" button
reset all channels, cleaned up the GUI update function.
* app/tools/gimplevelstool.[ch]: changed to use the new Levels
parameter struct and it's utility functions. Removed stuff
which now lives in base/levels.c
* app/tools/gimpimagemaptool.c: align the "Preview" button
bottom-left, not bottom-right.
* tools/pdbgen/pdb/color.pdb: use the new stuff and removed
uglyness because using the "Levels" struct makes the code more
straightforward.
* app/pdb/color_cmds.c: regenerated.
2002-09-04 23:25:15 +08:00
|
|
|
g_return_if_fail (lut != NULL);
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
data.brightness = brightness;
|
2001-05-23 07:05:35 +08:00
|
|
|
data.contrast = contrast;
|
1999-04-09 14:00:11 +08:00
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
gimp_lut_setup (lut, (GimpLutFunc) brightness_contrast_lut_func,
|
|
|
|
(gpointer) &data, n_channels);
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------- invert ------------------ */
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
static gfloat
|
|
|
|
invert_lut_func (gpointer unused,
|
|
|
|
gint n_channels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
/* don't invert the alpha channel */
|
2001-05-23 07:05:35 +08:00
|
|
|
if ((n_channels == 2 || n_channels == 4) && channel == n_channels -1)
|
1999-04-09 14:00:11 +08:00
|
|
|
return value;
|
|
|
|
|
|
|
|
return 1.0 - value;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpLut *
|
2001-05-23 07:05:35 +08:00
|
|
|
invert_lut_new (gint n_channels)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
GimpLut *lut;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
|
|
|
lut = gimp_lut_new ();
|
|
|
|
|
|
|
|
invert_lut_setup (lut, n_channels);
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
return lut;
|
|
|
|
}
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
void
|
|
|
|
invert_lut_setup (GimpLut *lut,
|
|
|
|
gint n_channels)
|
|
|
|
{
|
More color correction stuff cleanup:
2002-09-04 Michael Natterer <mitch@gimp.org>
More color correction stuff cleanup:
* app/base/Makefile.am
* app/base/base-types.h
* app/base/levels.[ch]: new files containing levels_lut_func(), a
new "Levels" parameter struct and the "auto levels" stuff.
* app/base/lut-funcs.[ch]: removed the levels stuff here, added
lots of g_return_if_fail().
* app/base/color-balance.[ch]
* app/base/hue-saturation.[ch]: added init() and reset() functions
so we don't need to duplicate this code in the tool and the pdb
wrappers.
* app/base/curves.[ch]: s/gint/GimpHistogramChannel/g, made
curves_channel_reset() initialize the curves array.
* app/tools/gimpcolorbalancetool.[ch]: use the new functions,
moved the "Range" frame to the top, added a per-range "Reset"
button, made the global "Reset" button reset all ranges and
the "Preserve Luminosity" toggle.
* app/tools/gimpcurvestool.[ch]: don't initialize the curves
array manually, as curves_channel_reset() does that,
s/gint/GimpHistogramChannel/g.
* app/tools/gimphuesaturationtool.c: use the new functions, added
a per-channel "Reset" button and made the global "Reset" button
reset all channels, cleaned up the GUI update function.
* app/tools/gimplevelstool.[ch]: changed to use the new Levels
parameter struct and it's utility functions. Removed stuff
which now lives in base/levels.c
* app/tools/gimpimagemaptool.c: align the "Preview" button
bottom-left, not bottom-right.
* tools/pdbgen/pdb/color.pdb: use the new stuff and removed
uglyness because using the "Levels" struct makes the code more
straightforward.
* app/pdb/color_cmds.c: regenerated.
2002-09-04 23:25:15 +08:00
|
|
|
g_return_if_fail (lut != NULL);
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
gimp_lut_setup_exact (lut, (GimpLutFunc) invert_lut_func,
|
|
|
|
NULL , n_channels);
|
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
/* ---------------- add (or subract)------------------ */
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
static gfloat
|
|
|
|
add_lut_func (gdouble *amount,
|
|
|
|
gint n_channels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
/* don't change the alpha channel */
|
2001-05-23 07:05:35 +08:00
|
|
|
if ((n_channels == 2 || n_channels == 4) && channel == n_channels -1)
|
1999-04-09 14:00:11 +08:00
|
|
|
return value;
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
return (value + *amount);
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpLut *
|
2001-05-23 07:05:35 +08:00
|
|
|
add_lut_new (gdouble amount,
|
|
|
|
gint n_channels)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
GimpLut *lut;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
|
|
|
lut = gimp_lut_new ();
|
|
|
|
|
|
|
|
add_lut_setup (lut, amount, n_channels);
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
return lut;
|
|
|
|
}
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
void
|
|
|
|
add_lut_setup (GimpLut *lut,
|
|
|
|
gdouble amount,
|
|
|
|
gint n_channels)
|
|
|
|
{
|
More color correction stuff cleanup:
2002-09-04 Michael Natterer <mitch@gimp.org>
More color correction stuff cleanup:
* app/base/Makefile.am
* app/base/base-types.h
* app/base/levels.[ch]: new files containing levels_lut_func(), a
new "Levels" parameter struct and the "auto levels" stuff.
* app/base/lut-funcs.[ch]: removed the levels stuff here, added
lots of g_return_if_fail().
* app/base/color-balance.[ch]
* app/base/hue-saturation.[ch]: added init() and reset() functions
so we don't need to duplicate this code in the tool and the pdb
wrappers.
* app/base/curves.[ch]: s/gint/GimpHistogramChannel/g, made
curves_channel_reset() initialize the curves array.
* app/tools/gimpcolorbalancetool.[ch]: use the new functions,
moved the "Range" frame to the top, added a per-range "Reset"
button, made the global "Reset" button reset all ranges and
the "Preserve Luminosity" toggle.
* app/tools/gimpcurvestool.[ch]: don't initialize the curves
array manually, as curves_channel_reset() does that,
s/gint/GimpHistogramChannel/g.
* app/tools/gimphuesaturationtool.c: use the new functions, added
a per-channel "Reset" button and made the global "Reset" button
reset all channels, cleaned up the GUI update function.
* app/tools/gimplevelstool.[ch]: changed to use the new Levels
parameter struct and it's utility functions. Removed stuff
which now lives in base/levels.c
* app/tools/gimpimagemaptool.c: align the "Preview" button
bottom-left, not bottom-right.
* tools/pdbgen/pdb/color.pdb: use the new stuff and removed
uglyness because using the "Levels" struct makes the code more
straightforward.
* app/pdb/color_cmds.c: regenerated.
2002-09-04 23:25:15 +08:00
|
|
|
g_return_if_fail (lut != NULL);
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
gimp_lut_setup (lut, (GimpLutFunc) add_lut_func,
|
|
|
|
(gpointer) &amount, n_channels);
|
|
|
|
}
|
|
|
|
|
2000-01-26 07:06:12 +08:00
|
|
|
/* ---------------- intersect (MIN (pixel, value)) ------------------ */
|
1999-04-09 14:00:11 +08:00
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
static gfloat
|
|
|
|
intersect_lut_func (gdouble *min,
|
|
|
|
gint n_channels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
/* don't change the alpha channel */
|
2001-05-23 07:05:35 +08:00
|
|
|
if ((n_channels == 2 || n_channels == 4) && channel == n_channels -1)
|
1999-04-09 14:00:11 +08:00
|
|
|
return value;
|
|
|
|
|
2000-01-26 07:06:12 +08:00
|
|
|
return MIN (value, *min);
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpLut *
|
2001-05-23 07:05:35 +08:00
|
|
|
intersect_lut_new (gdouble value,
|
|
|
|
gint n_channels)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
GimpLut *lut;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
|
|
|
lut = gimp_lut_new ();
|
|
|
|
|
|
|
|
intersect_lut_setup (lut, value, n_channels);
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
return lut;
|
|
|
|
}
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
void
|
|
|
|
intersect_lut_setup (GimpLut *lut,
|
|
|
|
gdouble value,
|
|
|
|
gint n_channels)
|
|
|
|
{
|
More color correction stuff cleanup:
2002-09-04 Michael Natterer <mitch@gimp.org>
More color correction stuff cleanup:
* app/base/Makefile.am
* app/base/base-types.h
* app/base/levels.[ch]: new files containing levels_lut_func(), a
new "Levels" parameter struct and the "auto levels" stuff.
* app/base/lut-funcs.[ch]: removed the levels stuff here, added
lots of g_return_if_fail().
* app/base/color-balance.[ch]
* app/base/hue-saturation.[ch]: added init() and reset() functions
so we don't need to duplicate this code in the tool and the pdb
wrappers.
* app/base/curves.[ch]: s/gint/GimpHistogramChannel/g, made
curves_channel_reset() initialize the curves array.
* app/tools/gimpcolorbalancetool.[ch]: use the new functions,
moved the "Range" frame to the top, added a per-range "Reset"
button, made the global "Reset" button reset all ranges and
the "Preserve Luminosity" toggle.
* app/tools/gimpcurvestool.[ch]: don't initialize the curves
array manually, as curves_channel_reset() does that,
s/gint/GimpHistogramChannel/g.
* app/tools/gimphuesaturationtool.c: use the new functions, added
a per-channel "Reset" button and made the global "Reset" button
reset all channels, cleaned up the GUI update function.
* app/tools/gimplevelstool.[ch]: changed to use the new Levels
parameter struct and it's utility functions. Removed stuff
which now lives in base/levels.c
* app/tools/gimpimagemaptool.c: align the "Preview" button
bottom-left, not bottom-right.
* tools/pdbgen/pdb/color.pdb: use the new stuff and removed
uglyness because using the "Levels" struct makes the code more
straightforward.
* app/pdb/color_cmds.c: regenerated.
2002-09-04 23:25:15 +08:00
|
|
|
g_return_if_fail (lut != NULL);
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
gimp_lut_setup_exact (lut, (GimpLutFunc) intersect_lut_func,
|
|
|
|
(gpointer) &value , n_channels);
|
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
/* ---------------- Threshold ------------------ */
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
static gfloat
|
|
|
|
threshold_lut_func (gdouble *min,
|
|
|
|
gint n_channels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
/* don't change the alpha channel */
|
2001-05-23 07:05:35 +08:00
|
|
|
if ((n_channels == 2 || n_channels == 4) && channel == n_channels -1)
|
1999-04-09 14:00:11 +08:00
|
|
|
return value;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
if (value < *min)
|
|
|
|
return 0.0;
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
return 1.0;
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpLut *
|
2001-05-23 07:05:35 +08:00
|
|
|
threshold_lut_new (gdouble value,
|
|
|
|
gint n_channels)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
GimpLut *lut;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
|
|
|
lut = gimp_lut_new ();
|
|
|
|
|
|
|
|
threshold_lut_setup (lut, value, n_channels);
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
return lut;
|
|
|
|
}
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
void
|
|
|
|
threshold_lut_setup (GimpLut *lut,
|
|
|
|
gdouble value,
|
|
|
|
gint n_channels)
|
|
|
|
{
|
More color correction stuff cleanup:
2002-09-04 Michael Natterer <mitch@gimp.org>
More color correction stuff cleanup:
* app/base/Makefile.am
* app/base/base-types.h
* app/base/levels.[ch]: new files containing levels_lut_func(), a
new "Levels" parameter struct and the "auto levels" stuff.
* app/base/lut-funcs.[ch]: removed the levels stuff here, added
lots of g_return_if_fail().
* app/base/color-balance.[ch]
* app/base/hue-saturation.[ch]: added init() and reset() functions
so we don't need to duplicate this code in the tool and the pdb
wrappers.
* app/base/curves.[ch]: s/gint/GimpHistogramChannel/g, made
curves_channel_reset() initialize the curves array.
* app/tools/gimpcolorbalancetool.[ch]: use the new functions,
moved the "Range" frame to the top, added a per-range "Reset"
button, made the global "Reset" button reset all ranges and
the "Preserve Luminosity" toggle.
* app/tools/gimpcurvestool.[ch]: don't initialize the curves
array manually, as curves_channel_reset() does that,
s/gint/GimpHistogramChannel/g.
* app/tools/gimphuesaturationtool.c: use the new functions, added
a per-channel "Reset" button and made the global "Reset" button
reset all channels, cleaned up the GUI update function.
* app/tools/gimplevelstool.[ch]: changed to use the new Levels
parameter struct and it's utility functions. Removed stuff
which now lives in base/levels.c
* app/tools/gimpimagemaptool.c: align the "Preview" button
bottom-left, not bottom-right.
* tools/pdbgen/pdb/color.pdb: use the new stuff and removed
uglyness because using the "Levels" struct makes the code more
straightforward.
* app/pdb/color_cmds.c: regenerated.
2002-09-04 23:25:15 +08:00
|
|
|
g_return_if_fail (lut != NULL);
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
gimp_lut_setup_exact (lut, (GimpLutFunc) threshold_lut_func,
|
|
|
|
(gpointer) &value , n_channels);
|
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
/* --------------- posterize ---------------- */
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
static gfloat
|
|
|
|
posterize_lut_func (gint *ilevels,
|
|
|
|
gint n_channels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
2001-05-23 07:05:35 +08:00
|
|
|
gint levels;
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
/* don't posterize the alpha channel */
|
2001-05-23 07:05:35 +08:00
|
|
|
if ((n_channels == 2 || n_channels == 4) && channel == n_channels -1)
|
1999-04-09 14:00:11 +08:00
|
|
|
return value;
|
|
|
|
|
|
|
|
if (*ilevels < 2)
|
|
|
|
levels = 2;
|
|
|
|
else
|
|
|
|
levels = *ilevels;
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
value = RINT (value * (levels - 1.0)) / (levels - 1.0);
|
1999-04-09 14:00:11 +08:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpLut *
|
2001-05-23 07:05:35 +08:00
|
|
|
posterize_lut_new (gint levels,
|
|
|
|
gint n_channels)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
GimpLut *lut;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
|
|
|
lut = gimp_lut_new ();
|
|
|
|
|
|
|
|
posterize_lut_setup (lut, levels, n_channels);
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
return lut;
|
|
|
|
}
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
void
|
|
|
|
posterize_lut_setup (GimpLut *lut,
|
|
|
|
gint levels,
|
|
|
|
gint n_channels)
|
|
|
|
{
|
More color correction stuff cleanup:
2002-09-04 Michael Natterer <mitch@gimp.org>
More color correction stuff cleanup:
* app/base/Makefile.am
* app/base/base-types.h
* app/base/levels.[ch]: new files containing levels_lut_func(), a
new "Levels" parameter struct and the "auto levels" stuff.
* app/base/lut-funcs.[ch]: removed the levels stuff here, added
lots of g_return_if_fail().
* app/base/color-balance.[ch]
* app/base/hue-saturation.[ch]: added init() and reset() functions
so we don't need to duplicate this code in the tool and the pdb
wrappers.
* app/base/curves.[ch]: s/gint/GimpHistogramChannel/g, made
curves_channel_reset() initialize the curves array.
* app/tools/gimpcolorbalancetool.[ch]: use the new functions,
moved the "Range" frame to the top, added a per-range "Reset"
button, made the global "Reset" button reset all ranges and
the "Preserve Luminosity" toggle.
* app/tools/gimpcurvestool.[ch]: don't initialize the curves
array manually, as curves_channel_reset() does that,
s/gint/GimpHistogramChannel/g.
* app/tools/gimphuesaturationtool.c: use the new functions, added
a per-channel "Reset" button and made the global "Reset" button
reset all channels, cleaned up the GUI update function.
* app/tools/gimplevelstool.[ch]: changed to use the new Levels
parameter struct and it's utility functions. Removed stuff
which now lives in base/levels.c
* app/tools/gimpimagemaptool.c: align the "Preview" button
bottom-left, not bottom-right.
* tools/pdbgen/pdb/color.pdb: use the new stuff and removed
uglyness because using the "Levels" struct makes the code more
straightforward.
* app/pdb/color_cmds.c: regenerated.
2002-09-04 23:25:15 +08:00
|
|
|
g_return_if_fail (lut != NULL);
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
gimp_lut_setup_exact (lut, (GimpLutFunc) posterize_lut_func,
|
2004-02-18 21:43:50 +08:00
|
|
|
(gpointer) &levels, n_channels);
|
2001-05-23 07:05:35 +08:00
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
/* --------------- equalize ------------- */
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
typedef struct
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
GimpHistogram *histogram;
|
2001-05-23 07:05:35 +08:00
|
|
|
gint part[5][257];
|
|
|
|
} hist_lut_struct;
|
|
|
|
|
|
|
|
static gfloat
|
2003-10-31 01:48:16 +08:00
|
|
|
equalize_lut_func (hist_lut_struct *hlut,
|
2001-05-23 07:05:35 +08:00
|
|
|
gint n_channels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
2001-05-23 07:05:35 +08:00
|
|
|
gint i = 0;
|
|
|
|
gint j;
|
|
|
|
|
|
|
|
j = (gint) (value * 255.0 + 0.5);
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
while (hlut->part[channel][i + 1] <= j)
|
|
|
|
i++;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
return i / 255.0;
|
|
|
|
}
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
GimpLut *
|
|
|
|
eq_histogram_lut_new (GimpHistogram *histogram,
|
|
|
|
gint n_channels)
|
|
|
|
{
|
|
|
|
GimpLut *lut;
|
|
|
|
|
More color correction stuff cleanup:
2002-09-04 Michael Natterer <mitch@gimp.org>
More color correction stuff cleanup:
* app/base/Makefile.am
* app/base/base-types.h
* app/base/levels.[ch]: new files containing levels_lut_func(), a
new "Levels" parameter struct and the "auto levels" stuff.
* app/base/lut-funcs.[ch]: removed the levels stuff here, added
lots of g_return_if_fail().
* app/base/color-balance.[ch]
* app/base/hue-saturation.[ch]: added init() and reset() functions
so we don't need to duplicate this code in the tool and the pdb
wrappers.
* app/base/curves.[ch]: s/gint/GimpHistogramChannel/g, made
curves_channel_reset() initialize the curves array.
* app/tools/gimpcolorbalancetool.[ch]: use the new functions,
moved the "Range" frame to the top, added a per-range "Reset"
button, made the global "Reset" button reset all ranges and
the "Preserve Luminosity" toggle.
* app/tools/gimpcurvestool.[ch]: don't initialize the curves
array manually, as curves_channel_reset() does that,
s/gint/GimpHistogramChannel/g.
* app/tools/gimphuesaturationtool.c: use the new functions, added
a per-channel "Reset" button and made the global "Reset" button
reset all channels, cleaned up the GUI update function.
* app/tools/gimplevelstool.[ch]: changed to use the new Levels
parameter struct and it's utility functions. Removed stuff
which now lives in base/levels.c
* app/tools/gimpimagemaptool.c: align the "Preview" button
bottom-left, not bottom-right.
* tools/pdbgen/pdb/color.pdb: use the new stuff and removed
uglyness because using the "Levels" struct makes the code more
straightforward.
* app/pdb/color_cmds.c: regenerated.
2002-09-04 23:25:15 +08:00
|
|
|
g_return_val_if_fail (histogram != NULL, NULL);
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
lut = gimp_lut_new ();
|
|
|
|
|
|
|
|
eq_histogram_lut_setup (lut, histogram, n_channels);
|
|
|
|
|
|
|
|
return lut;
|
|
|
|
}
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
void
|
2001-05-23 07:05:35 +08:00
|
|
|
eq_histogram_lut_setup (GimpLut *lut,
|
|
|
|
GimpHistogram *hist,
|
|
|
|
gint n_channels)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
2001-05-23 07:05:35 +08:00
|
|
|
gint i, k, j;
|
|
|
|
hist_lut_struct hlut;
|
|
|
|
gdouble pixels_per_value;
|
|
|
|
gdouble desired;
|
|
|
|
gdouble sum, dif;
|
1999-04-09 14:00:11 +08:00
|
|
|
|
More color correction stuff cleanup:
2002-09-04 Michael Natterer <mitch@gimp.org>
More color correction stuff cleanup:
* app/base/Makefile.am
* app/base/base-types.h
* app/base/levels.[ch]: new files containing levels_lut_func(), a
new "Levels" parameter struct and the "auto levels" stuff.
* app/base/lut-funcs.[ch]: removed the levels stuff here, added
lots of g_return_if_fail().
* app/base/color-balance.[ch]
* app/base/hue-saturation.[ch]: added init() and reset() functions
so we don't need to duplicate this code in the tool and the pdb
wrappers.
* app/base/curves.[ch]: s/gint/GimpHistogramChannel/g, made
curves_channel_reset() initialize the curves array.
* app/tools/gimpcolorbalancetool.[ch]: use the new functions,
moved the "Range" frame to the top, added a per-range "Reset"
button, made the global "Reset" button reset all ranges and
the "Preserve Luminosity" toggle.
* app/tools/gimpcurvestool.[ch]: don't initialize the curves
array manually, as curves_channel_reset() does that,
s/gint/GimpHistogramChannel/g.
* app/tools/gimphuesaturationtool.c: use the new functions, added
a per-channel "Reset" button and made the global "Reset" button
reset all channels, cleaned up the GUI update function.
* app/tools/gimplevelstool.[ch]: changed to use the new Levels
parameter struct and it's utility functions. Removed stuff
which now lives in base/levels.c
* app/tools/gimpimagemaptool.c: align the "Preview" button
bottom-left, not bottom-right.
* tools/pdbgen/pdb/color.pdb: use the new stuff and removed
uglyness because using the "Levels" struct makes the code more
straightforward.
* app/pdb/color_cmds.c: regenerated.
2002-09-04 23:25:15 +08:00
|
|
|
g_return_if_fail (lut != NULL);
|
|
|
|
g_return_if_fail (hist != NULL);
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
/* Find partition points */
|
2003-10-31 01:48:16 +08:00
|
|
|
pixels_per_value = gimp_histogram_get_count (hist,
|
|
|
|
GIMP_HISTOGRAM_VALUE,
|
|
|
|
0, 255) / 256.0;
|
1999-04-09 14:00:11 +08:00
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
for (k = 0; k < n_channels; k++)
|
1999-04-09 14:00:11 +08:00
|
|
|
{
|
|
|
|
/* First and last points in partition */
|
|
|
|
hlut.part[k][0] = 0;
|
|
|
|
hlut.part[k][256] = 256;
|
2003-10-31 01:48:16 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
/* Find intermediate points */
|
2001-05-23 07:05:35 +08:00
|
|
|
j = 0;
|
2003-10-31 01:48:16 +08:00
|
|
|
sum = (gimp_histogram_get_channel (hist, k, 0) +
|
2001-05-23 07:05:35 +08:00
|
|
|
gimp_histogram_get_channel (hist, k, 1));
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
for (i = 1; i < 256; i++)
|
|
|
|
{
|
|
|
|
desired = i * pixels_per_value;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
while (sum <= desired)
|
2001-05-23 07:05:35 +08:00
|
|
|
{
|
|
|
|
j++;
|
|
|
|
sum += gimp_histogram_get_channel (hist, k, j + 1);
|
|
|
|
}
|
1999-04-09 14:00:11 +08:00
|
|
|
|
|
|
|
/* Nearest sum */
|
2001-05-23 07:05:35 +08:00
|
|
|
dif = sum - gimp_histogram_get_channel (hist, k, j);
|
|
|
|
|
1999-04-09 14:00:11 +08:00
|
|
|
if ((sum - desired) > (dif / 2.0))
|
|
|
|
hlut.part[k][i] = j;
|
|
|
|
else
|
|
|
|
hlut.part[k][i] = j + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-23 07:05:35 +08:00
|
|
|
gimp_lut_setup (lut, (GimpLutFunc) equalize_lut_func,
|
|
|
|
(gpointer) &hlut, n_channels);
|
1999-04-09 14:00:11 +08:00
|
|
|
}
|