2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
#include "base-types.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
#include "hue-saturation.h"
|
|
|
|
#include "pixel-region.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
|
1997-11-25 06:05:25 +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
|
|
|
void
|
|
|
|
hue_saturation_init (HueSaturation *hs)
|
|
|
|
{
|
|
|
|
GimpHueRange partition;
|
|
|
|
|
|
|
|
g_return_if_fail (hs != NULL);
|
|
|
|
|
2005-03-12 20:25:57 +08:00
|
|
|
hs->overlap = 0.0;
|
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
|
|
|
|
2008-01-22 17:49:40 +08:00
|
|
|
for (partition = GIMP_ALL_HUES; partition <= GIMP_MAGENTA_HUES; partition++)
|
|
|
|
{
|
|
|
|
hs->hue[partition] = 0.0;
|
|
|
|
hs->lightness[partition] = 0.0;
|
|
|
|
hs->saturation[partition] = 0.0;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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
|
2002-08-26 19:35:56 +08:00
|
|
|
hue_saturation_calculate_transfers (HueSaturation *hs)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-11-22 19:14:29 +08:00
|
|
|
gint value;
|
|
|
|
gint hue;
|
|
|
|
gint i;
|
1997-11-25 06:05:25 +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 (hs != NULL);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Calculate transfers */
|
|
|
|
for (hue = 0; hue < 6; hue++)
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
2008-01-22 17:49:40 +08:00
|
|
|
/* Hue */
|
2006-04-12 20:49:29 +08:00
|
|
|
value = (hs->hue[0] + hs->hue[hue + 1]) * 255.0 / 360.0;
|
|
|
|
if ((i + value) < 0)
|
|
|
|
hs->hue_transfer[hue][i] = 255 + (i + value);
|
|
|
|
else if ((i + value) > 255)
|
|
|
|
hs->hue_transfer[hue][i] = i + value - 255;
|
|
|
|
else
|
|
|
|
hs->hue_transfer[hue][i] = i + value;
|
|
|
|
|
|
|
|
/* Lightness */
|
|
|
|
value = (hs->lightness[0] + hs->lightness[hue + 1]) * 127.0 / 100.0;
|
|
|
|
value = CLAMP (value, -255, 255);
|
|
|
|
|
|
|
|
if (value < 0)
|
|
|
|
hs->lightness_transfer[hue][i] = (guchar) ((i * (255 + value)) / 255);
|
|
|
|
else
|
|
|
|
hs->lightness_transfer[hue][i] = (guchar) (i + ((255 - i) * value) / 255);
|
|
|
|
|
|
|
|
/* Saturation */
|
|
|
|
value = (hs->saturation[0] + hs->saturation[hue + 1]) * 255.0 / 100.0;
|
|
|
|
value = CLAMP (value, -255, 255);
|
|
|
|
|
|
|
|
/* This change affects the way saturation is computed. With the
|
|
|
|
old code (different code for value < 0), increasing the
|
|
|
|
saturation affected muted colors very much, and bright colors
|
|
|
|
less. With the new code, it affects muted colors and bright
|
|
|
|
colors more or less evenly. For enhancing the color in photos,
|
|
|
|
the new behavior is exactly what you want. It's hard for me
|
|
|
|
to imagine a case in which the old behavior is better.
|
|
|
|
*/
|
|
|
|
hs->saturation_transfer[hue][i] = CLAMP ((i * (255 + value)) / 255, 0, 255);
|
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
|
2005-02-15 23:39:27 +08:00
|
|
|
hue_saturation (HueSaturation *hs,
|
|
|
|
PixelRegion *srcPR,
|
2006-04-12 20:49:29 +08:00
|
|
|
PixelRegion *destPR)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-02-15 23:39:27 +08:00
|
|
|
const guchar *src, *s;
|
|
|
|
guchar *dest, *d;
|
2005-03-12 20:25:57 +08:00
|
|
|
const gint hue_thresholds[] = { 21, 64, 106, 149, 192, 234, 255 };
|
|
|
|
gint alpha;
|
2005-02-15 23:39:27 +08:00
|
|
|
gint w, h;
|
|
|
|
gint r, g, b;
|
|
|
|
gint hue;
|
2005-03-12 20:25:57 +08:00
|
|
|
gint hue_counter;
|
|
|
|
gint secondary_hue = 0;
|
|
|
|
gboolean use_secondary_hue = FALSE;
|
|
|
|
gfloat primary_intensity = 0.0;
|
|
|
|
gfloat secondary_intensity = 0.0;
|
|
|
|
gfloat overlap_hue = (hs->overlap / 100.0) * 21;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Set the transfer arrays (for speed) */
|
2002-08-26 19:35:56 +08:00
|
|
|
h = srcPR->h;
|
|
|
|
src = srcPR->data;
|
|
|
|
dest = destPR->data;
|
1997-11-25 06:05:25 +08:00
|
|
|
alpha = (srcPR->bytes == 4) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
while (h--)
|
|
|
|
{
|
|
|
|
w = srcPR->w;
|
|
|
|
s = src;
|
|
|
|
d = dest;
|
2003-03-08 02:08:16 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
while (w--)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2008-10-19 21:47:09 +08:00
|
|
|
r = s[RED];
|
|
|
|
g = s[GREEN];
|
|
|
|
b = s[BLUE];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
gimp_rgb_to_hsl_int (&r, &g, &b);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-08 02:08:16 +08:00
|
|
|
hue = (r + (128 / 6)) / 6;
|
|
|
|
|
2005-03-12 20:25:57 +08:00
|
|
|
for (hue_counter = 0; hue_counter < 7; hue_counter++)
|
|
|
|
if (r < hue_thresholds[hue_counter] + overlap_hue)
|
|
|
|
{
|
|
|
|
gint hue_threshold = hue_thresholds[hue_counter];
|
|
|
|
|
|
|
|
hue = hue_counter;
|
|
|
|
|
|
|
|
if (overlap_hue > 1.0 && r > hue_threshold - overlap_hue)
|
|
|
|
{
|
|
|
|
secondary_hue = hue_counter + 1;
|
|
|
|
use_secondary_hue = TRUE;
|
|
|
|
secondary_intensity =
|
|
|
|
(r - hue_threshold + overlap_hue) / (2.0 * overlap_hue);
|
|
|
|
primary_intensity = 1.0 - secondary_intensity;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
use_secondary_hue = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hue >= 6)
|
|
|
|
{
|
|
|
|
hue = 0;
|
|
|
|
use_secondary_hue = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (secondary_hue >= 6)
|
|
|
|
secondary_hue = 0;
|
|
|
|
|
|
|
|
if (use_secondary_hue)
|
|
|
|
{
|
2008-04-28 22:46:20 +08:00
|
|
|
/* find nearest hue on the circle
|
|
|
|
* between primary and secondary hue
|
|
|
|
*/
|
|
|
|
gint diff;
|
|
|
|
|
|
|
|
diff = hs->hue_transfer[hue][r] - hs->hue_transfer[secondary_hue][r];
|
|
|
|
if (diff < -127 || diff >= 128)
|
|
|
|
r = (gint) (hs->hue_transfer[hue][r] * primary_intensity +
|
|
|
|
(hs->hue_transfer[secondary_hue][r] + 255) * secondary_intensity) % 255;
|
|
|
|
else
|
|
|
|
r = hs->hue_transfer[hue][r] * primary_intensity +
|
|
|
|
hs->hue_transfer[secondary_hue][r] * secondary_intensity;
|
|
|
|
|
2005-03-12 20:25:57 +08:00
|
|
|
g = hs->saturation_transfer[hue][g] * primary_intensity +
|
|
|
|
hs->saturation_transfer[secondary_hue][g] * secondary_intensity;
|
|
|
|
b = hs->lightness_transfer[hue][b] * primary_intensity +
|
|
|
|
hs->lightness_transfer[secondary_hue][b] * secondary_intensity;
|
|
|
|
}
|
2003-03-08 02:08:16 +08:00
|
|
|
else
|
2005-03-12 20:25:57 +08:00
|
|
|
{
|
|
|
|
r = hs->hue_transfer[hue][r];
|
|
|
|
g = hs->saturation_transfer[hue][g];
|
|
|
|
b = hs->lightness_transfer[hue][b];
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
gimp_hsl_to_rgb_int (&r, &g, &b);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2008-10-19 21:47:09 +08:00
|
|
|
d[RED] = r;
|
|
|
|
d[GREEN] = g;
|
|
|
|
d[BLUE] = b;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
if (alpha)
|
2008-10-19 21:47:09 +08:00
|
|
|
d[ALPHA] = s[ALPHA];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
s += srcPR->bytes;
|
|
|
|
d += destPR->bytes;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
src += srcPR->rowstride;
|
1997-11-25 06:05:25 +08:00
|
|
|
dest += destPR->rowstride;
|
|
|
|
}
|
|
|
|
}
|