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
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
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 "libgimpmath/gimpmath.h"
|
2001-05-22 04:30:16 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
#include "base-types.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
#include "curves.h"
|
|
|
|
#include "gimplut.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2006-04-21 15:02:42 +08:00
|
|
|
static void curves_plot_curve (Curves *curves,
|
|
|
|
gint channel,
|
|
|
|
gint p1,
|
|
|
|
gint p2,
|
|
|
|
gint p3,
|
|
|
|
gint p4);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
/* public functions */
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
void
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_init (Curves *curves)
|
2001-05-25 07:57:08 +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
|
|
|
GimpHistogramChannel channel;
|
2001-05-25 07:57:08 +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 (curves != NULL);
|
2001-05-25 07:57:08 +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
|
|
|
for (channel = GIMP_HISTOGRAM_VALUE;
|
|
|
|
channel <= GIMP_HISTOGRAM_ALPHA;
|
|
|
|
channel++)
|
|
|
|
{
|
2003-03-15 03:58:59 +08:00
|
|
|
curves->curve_type[channel] = GIMP_CURVE_SMOOTH;
|
2001-05-25 07:57:08 +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
|
|
|
curves_channel_reset (curves, channel);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
void
|
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
|
|
|
curves_channel_reset (Curves *curves,
|
|
|
|
GimpHistogramChannel channel)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
gint j;
|
2001-05-25 07:57:08 +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 (curves != NULL);
|
|
|
|
|
|
|
|
for (j = 0; j < 256; j++)
|
|
|
|
curves->curve[channel][j] = j;
|
|
|
|
|
2004-09-24 21:39:57 +08:00
|
|
|
for (j = 0; j < CURVES_NUM_POINTS; j++)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
curves->points[channel][j][0] = -1;
|
|
|
|
curves->points[channel][j][1] = -1;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves->points[channel][0][0] = 0;
|
|
|
|
curves->points[channel][0][1] = 0;
|
2004-09-24 21:39:57 +08:00
|
|
|
curves->points[channel][CURVES_NUM_POINTS - 1][0] = 255;
|
|
|
|
curves->points[channel][CURVES_NUM_POINTS - 1][1] = 255;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
void
|
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
|
|
|
curves_calculate_curve (Curves *curves,
|
|
|
|
GimpHistogramChannel channel)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
gint i;
|
2004-09-24 21:39:57 +08:00
|
|
|
gint points[CURVES_NUM_POINTS];
|
2002-08-26 19:35:56 +08:00
|
|
|
gint num_pts;
|
|
|
|
gint p1, p2, p3, p4;
|
2001-05-25 07:57:08 +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 (curves != NULL);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
switch (curves->curve_type[channel])
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2003-03-15 03:58:59 +08:00
|
|
|
case GIMP_CURVE_FREE:
|
2002-08-26 19:35:56 +08:00
|
|
|
break;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2003-03-15 03:58:59 +08:00
|
|
|
case GIMP_CURVE_SMOOTH:
|
2002-08-26 19:35:56 +08:00
|
|
|
/* cycle through the curves */
|
|
|
|
num_pts = 0;
|
2004-09-24 21:39:57 +08:00
|
|
|
for (i = 0; i < CURVES_NUM_POINTS; i++)
|
2006-04-12 20:49:29 +08:00
|
|
|
if (curves->points[channel][i][0] != -1)
|
|
|
|
points[num_pts++] = i;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* Initialize boundary curve points */
|
|
|
|
if (num_pts != 0)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
for (i = 0; i < curves->points[channel][points[0]][0]; i++)
|
|
|
|
curves->curve[channel][i] = curves->points[channel][points[0]][1];
|
2005-03-03 19:40:37 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
for (i = curves->points[channel][points[num_pts - 1]][0];
|
2005-03-03 19:40:37 +08:00
|
|
|
i < 256;
|
|
|
|
i++)
|
2006-04-12 20:49:29 +08:00
|
|
|
curves->curve[channel][i] =
|
2005-03-03 19:40:37 +08:00
|
|
|
curves->points[channel][points[num_pts - 1]][1];
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
for (i = 0; i < num_pts - 1; i++)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2006-04-21 05:47:16 +08:00
|
|
|
p1 = points[MAX (i - 1, 0)];
|
2006-04-12 20:49:29 +08:00
|
|
|
p2 = points[i];
|
|
|
|
p3 = points[i + 1];
|
2006-04-21 05:47:16 +08:00
|
|
|
p4 = points[MIN (i + 2, num_pts - 1)];
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
curves_plot_curve (curves, channel, p1, p2, p3, p4);
|
|
|
|
}
|
2004-01-08 06:47:25 +08:00
|
|
|
|
|
|
|
/* ensure that the control points are used exactly */
|
|
|
|
for (i = 0; i < num_pts; i++)
|
|
|
|
{
|
2005-03-03 19:40:37 +08:00
|
|
|
gint x = curves->points[channel][points[i]][0];
|
|
|
|
gint y = curves->points[channel][points[i]][1];
|
2004-01-08 06:47:25 +08:00
|
|
|
|
|
|
|
curves->curve[channel][x] = y;
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2000-12-14 02:53:35 +08:00
|
|
|
gfloat
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_lut_func (Curves *curves,
|
2006-04-12 20:49:29 +08:00
|
|
|
gint n_channels,
|
|
|
|
gint channel,
|
|
|
|
gfloat value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-31 12:07:42 +08:00
|
|
|
gfloat f;
|
|
|
|
gint index;
|
2000-12-14 02:53:35 +08:00
|
|
|
gdouble inten;
|
2000-12-31 12:07:42 +08:00
|
|
|
gint j;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-06-28 22:24:56 +08:00
|
|
|
if (n_channels <= 2)
|
|
|
|
j = channel;
|
1999-02-16 16:53:54 +08:00
|
|
|
else
|
|
|
|
j = channel + 1;
|
2000-12-14 02:53:35 +08:00
|
|
|
|
1999-02-16 16:53:54 +08:00
|
|
|
inten = value;
|
2000-12-14 02:53:35 +08:00
|
|
|
|
2004-06-28 22:24:56 +08:00
|
|
|
/* For RGB and RGBA images this runs through the loop with j = channel + 1
|
|
|
|
* the first time and j = 0 the second time
|
|
|
|
*
|
|
|
|
* For GRAY images this runs through the loop with j = 0 the first and
|
|
|
|
* only time
|
|
|
|
*/
|
1999-02-16 16:53:54 +08:00
|
|
|
for (; j >= 0; j -= (channel + 1))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
/* don't apply the overall curve to the alpha channel */
|
2004-06-28 22:24:56 +08:00
|
|
|
if (j == 0 && (n_channels == 2 || n_channels == 4) &&
|
|
|
|
channel == n_channels - 1)
|
2002-08-26 19:35:56 +08:00
|
|
|
return inten;
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (inten < 0.0)
|
2004-06-28 22:24:56 +08:00
|
|
|
{
|
|
|
|
inten = curves->curve[j][0]/255.0;
|
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
else if (inten >= 1.0)
|
2004-06-28 22:24:56 +08:00
|
|
|
{
|
|
|
|
inten = curves->curve[j][255]/255.0;
|
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
else /* interpolate the curve */
|
|
|
|
{
|
2005-03-03 19:40:37 +08:00
|
|
|
index = floor (inten * 255.0);
|
|
|
|
f = inten * 255.0 - index;
|
2004-06-28 22:24:56 +08:00
|
|
|
inten = ((1.0 - f) * curves->curve[j][index ] +
|
2005-03-03 19:40:37 +08:00
|
|
|
f * curves->curve[j][index + 1] ) / 255.0;
|
2002-08-26 19:35:56 +08:00
|
|
|
}
|
1999-04-08 06:02:26 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
return inten;
|
|
|
|
}
|
1999-04-08 06:02:26 +08:00
|
|
|
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* private functions */
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2006-04-21 05:47:16 +08:00
|
|
|
/*
|
|
|
|
* This function calculates the curve values between the control points
|
|
|
|
* p2 and p3, taking the potentially existing neighbors p1 and p4 into
|
|
|
|
* account.
|
|
|
|
*
|
|
|
|
* This function uses a cubic bezier curve for the individual segments and
|
|
|
|
* calculates the necessary intermediate control points depending on the
|
|
|
|
* neighbor curve control points.
|
|
|
|
*/
|
2005-03-03 19:40:37 +08:00
|
|
|
|
1999-05-14 06:53:40 +08:00
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_plot_curve (Curves *curves,
|
|
|
|
gint channel,
|
2006-04-12 20:49:29 +08:00
|
|
|
gint p1,
|
|
|
|
gint p2,
|
|
|
|
gint p3,
|
|
|
|
gint p4)
|
1999-05-14 06:53:40 +08:00
|
|
|
{
|
2006-04-21 05:47:16 +08:00
|
|
|
gint i;
|
|
|
|
gdouble x0, x3;
|
|
|
|
gdouble y0, y1, y2, y3;
|
|
|
|
gdouble dx, dy;
|
|
|
|
gdouble y, t;
|
|
|
|
gdouble slope;
|
|
|
|
|
|
|
|
/* the outer control points for the bezier curve. */
|
|
|
|
x0 = curves->points[channel][p2][0];
|
|
|
|
y0 = curves->points[channel][p2][1];
|
|
|
|
x3 = curves->points[channel][p3][0];
|
|
|
|
y3 = curves->points[channel][p3][1];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the x values of the inner control points are fixed at
|
|
|
|
* x1 = 1/3*x0 + 2/3*x3 and x2 = 2/3*x0 + 1/3*x3
|
|
|
|
* this ensures that the x values increase linearily with the
|
|
|
|
* parameter t and enables us to skip the calculation of the x
|
|
|
|
* values altogehter - just calculate y(t) evenly spaced.
|
2005-03-03 19:40:37 +08:00
|
|
|
*/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-21 05:47:16 +08:00
|
|
|
dx = x3 - x0;
|
|
|
|
dy = y3 - y0;
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2006-04-21 05:47:16 +08:00
|
|
|
g_return_if_fail (dx > 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-21 05:47:16 +08:00
|
|
|
if (p1 == p2 && p3 == p4)
|
|
|
|
{
|
|
|
|
/* No information about the neighbors,
|
|
|
|
* calculate y1 and y2 to get a straight line
|
|
|
|
*/
|
|
|
|
y1 = y0 + dy / 3.0;
|
|
|
|
y2 = y0 + dy * 2.0 / 3.0;
|
|
|
|
}
|
|
|
|
else if (p1 == p2 && p3 != p4)
|
2002-08-26 19:35:56 +08:00
|
|
|
{
|
2006-04-21 05:47:16 +08:00
|
|
|
/* only the right neighbor is available. Make the tangent at the
|
|
|
|
* right endpoint parallel to the line between the left endpoint
|
|
|
|
* and the right neighbor. Then point the tangent at the left towards
|
|
|
|
* the control handle of the right tangent, to ensure that the curve
|
|
|
|
* does not have an inflection point.
|
|
|
|
*/
|
|
|
|
slope = (curves->points[channel][p4][1] - y0) /
|
|
|
|
(curves->points[channel][p4][0] - x0);
|
2006-04-21 15:22:23 +08:00
|
|
|
|
2006-04-21 05:47:16 +08:00
|
|
|
y2 = y3 - slope * dx / 3.0;
|
|
|
|
y1 = y0 + (y2 - y0) / 2.0;
|
|
|
|
}
|
|
|
|
else if (p1 != p2 && p3 == p4)
|
|
|
|
{
|
|
|
|
/* see previous case */
|
|
|
|
slope = (y3 - curves->points[channel][p1][1]) /
|
|
|
|
(x3 - curves->points[channel][p1][0]);
|
2006-04-21 15:22:23 +08:00
|
|
|
|
2006-04-21 05:47:16 +08:00
|
|
|
y1 = y0 + slope * dx / 3.0;
|
|
|
|
y2 = y3 + (y1 - y3) / 2.0;
|
|
|
|
}
|
2006-04-21 15:22:23 +08:00
|
|
|
else /* (p1 != p2 && p3 != p4) */
|
2006-04-21 05:47:16 +08:00
|
|
|
{
|
|
|
|
/* Both neighbors are available. Make the tangents at the endpoints
|
|
|
|
* parallel to the line between the opposite endpoint and the adjacent
|
|
|
|
* neighbor.
|
|
|
|
*/
|
|
|
|
slope = (y3 - curves->points[channel][p1][1]) /
|
|
|
|
(x3 - curves->points[channel][p1][0]);
|
2006-04-21 15:22:23 +08:00
|
|
|
|
2006-04-21 05:47:16 +08:00
|
|
|
y1 = y0 + slope * dx / 3.0;
|
|
|
|
|
|
|
|
slope = (curves->points[channel][p4][1] - y0) /
|
|
|
|
(curves->points[channel][p4][0] - x0);
|
2006-04-21 15:22:23 +08:00
|
|
|
|
2006-04-21 05:47:16 +08:00
|
|
|
y2 = y3 - slope * dx / 3.0;
|
|
|
|
}
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
2006-04-21 05:47:16 +08:00
|
|
|
/*
|
|
|
|
* finally calculate the y(t) values for the given bezier values. We can
|
|
|
|
* use homogenously distributed values for t, since x(t) increases linearily.
|
|
|
|
*/
|
|
|
|
for (i = 0; i <= dx; i++)
|
|
|
|
{
|
|
|
|
t = i / dx;
|
2006-04-21 15:02:42 +08:00
|
|
|
y = y0 * (1-t) * (1-t) * (1-t) +
|
|
|
|
3 * y1 * (1-t) * (1-t) * t +
|
|
|
|
3 * y2 * (1-t) * t * t +
|
|
|
|
y3 * t * t * t;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-21 05:47:16 +08:00
|
|
|
curves->curve[channel][ROUND(x0) + i] = CLAMP0255 (ROUND (y));
|
2002-08-26 19:35:56 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|