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
|
|
|
|
*
|
|
|
|
* 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-02-14 06:26:41 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1999-08-27 08:19:25 +08:00
|
|
|
#include <stdio.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-08-27 08:19:25 +08:00
|
|
|
#include <errno.h>
|
2000-02-14 06:26:41 +08:00
|
|
|
|
2007-12-31 01:54:51 +08:00
|
|
|
#include <gegl.h>
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2003-06-06 02:47:23 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2006-08-10 20:04:35 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
#include "base/gimphistogram.h"
|
|
|
|
#include "base/gimplut.h"
|
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
|
|
|
#include "base/levels.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpdrawable-histogram.h"
|
|
|
|
#include "core/gimpimage.h"
|
2002-08-26 19:35:56 +08:00
|
|
|
#include "core/gimpimagemap.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2004-02-20 03:56:04 +08:00
|
|
|
#include "widgets/gimpcolorbar.h"
|
2007-11-21 01:24:37 +08:00
|
|
|
#include "widgets/gimphandlebar.h"
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "widgets/gimphistogramview.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
2003-10-24 16:12:21 +08:00
|
|
|
#include "gimphistogramoptions.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "gimplevelstool.h"
|
2003-04-16 00:05:52 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
1998-12-16 08:37:09 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
#define PICK_LOW_INPUT (1 << 0)
|
|
|
|
#define PICK_GAMMA (1 << 1)
|
|
|
|
#define PICK_HIGH_INPUT (1 << 2)
|
|
|
|
#define PICK_ALL_CHANNELS (1 << 8)
|
|
|
|
|
|
|
|
#define HISTOGRAM_WIDTH 256
|
|
|
|
#define GRADIENT_HEIGHT 12
|
|
|
|
#define CONTROL_HEIGHT 10
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2008-01-08 04:37:25 +08:00
|
|
|
static void gimp_levels_tool_finalize (GObject *object);
|
|
|
|
|
|
|
|
static gboolean gimp_levels_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error);
|
|
|
|
|
|
|
|
static void gimp_levels_tool_color_picked (GimpColorTool *color_tool,
|
|
|
|
GimpColorPickState pick_state,
|
|
|
|
GimpImageType sample_type,
|
|
|
|
GimpRGB *color,
|
|
|
|
gint color_index);
|
|
|
|
|
|
|
|
static GeglNode * gimp_levels_tool_get_operation (GimpImageMapTool *im_tool);
|
|
|
|
static void gimp_levels_tool_map (GimpImageMapTool *im_tool);
|
|
|
|
static void gimp_levels_tool_dialog (GimpImageMapTool *im_tool);
|
|
|
|
static void gimp_levels_tool_dialog_unmap (GtkWidget *dialog,
|
|
|
|
GimpLevelsTool *tool);
|
|
|
|
static void gimp_levels_tool_reset (GimpImageMapTool *im_tool);
|
|
|
|
static gboolean gimp_levels_tool_settings_load (GimpImageMapTool *im_tool,
|
|
|
|
gpointer fp,
|
|
|
|
GError **error);
|
|
|
|
static gboolean gimp_levels_tool_settings_save (GimpImageMapTool *im_tool,
|
|
|
|
gpointer fp);
|
|
|
|
|
|
|
|
static void levels_update_adjustments (GimpLevelsTool *tool);
|
|
|
|
static void levels_update_input_bar (GimpLevelsTool *tool);
|
|
|
|
|
|
|
|
static void levels_channel_callback (GtkWidget *widget,
|
|
|
|
GimpLevelsTool *tool);
|
|
|
|
static void levels_channel_reset_callback (GtkWidget *widget,
|
|
|
|
GimpLevelsTool *tool);
|
|
|
|
|
|
|
|
static gboolean levels_menu_sensitivity (gint value,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void levels_stretch_callback (GtkWidget *widget,
|
|
|
|
GimpLevelsTool *tool);
|
|
|
|
static void levels_low_input_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool);
|
|
|
|
static void levels_gamma_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool);
|
|
|
|
static void levels_linear_gamma_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool);
|
|
|
|
static void levels_high_input_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool);
|
|
|
|
static void levels_low_output_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool);
|
|
|
|
static void levels_high_output_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool);
|
|
|
|
static void levels_input_picker_toggled (GtkWidget *widget,
|
|
|
|
GimpLevelsTool *tool);
|
2004-01-22 00:07:48 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpLevelsTool, gimp_levels_tool, GIMP_TYPE_IMAGE_MAP_TOOL)
|
2001-11-21 07:00:47 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
#define parent_class gimp_levels_tool_parent_class
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_levels_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_LEVELS_TOOL,
|
2003-10-24 16:12:21 +08:00
|
|
|
GIMP_TYPE_HISTOGRAM_OPTIONS,
|
2003-06-06 02:47:23 +08:00
|
|
|
gimp_color_options_gui,
|
2003-06-28 19:20:37 +08:00
|
|
|
0,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-levels-tool",
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Levels"),
|
2006-09-19 02:00:22 +08:00
|
|
|
_("Levels Tool: Adjust color levels"),
|
2004-04-29 21:19:28 +08:00
|
|
|
N_("_Levels..."), NULL,
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_LEVELS,
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_LEVELS,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
static void
|
|
|
|
gimp_levels_tool_class_init (GimpLevelsToolClass *klass)
|
|
|
|
{
|
2005-12-13 17:13:50 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
GimpColorToolClass *color_tool_class = GIMP_COLOR_TOOL_CLASS (klass);
|
|
|
|
GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
|
2004-02-25 18:23:43 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
object_class->finalize = gimp_levels_tool_finalize;
|
2004-02-25 18:23:43 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
tool_class->initialize = gimp_levels_tool_initialize;
|
2003-06-06 02:47:23 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
color_tool_class->picked = gimp_levels_tool_color_picked;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
im_tool_class->shell_desc = _("Adjust Color Levels");
|
|
|
|
im_tool_class->settings_name = "levels";
|
|
|
|
im_tool_class->load_dialog_title = _("Load Levels");
|
|
|
|
im_tool_class->load_button_tip = _("Load levels settings from file");
|
|
|
|
im_tool_class->save_dialog_title = _("Save Levels");
|
|
|
|
im_tool_class->save_button_tip = _("Save levels settings to file");
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2008-01-08 04:37:25 +08:00
|
|
|
im_tool_class->get_operation = gimp_levels_tool_get_operation;
|
2005-12-13 17:13:50 +08:00
|
|
|
im_tool_class->map = gimp_levels_tool_map;
|
|
|
|
im_tool_class->dialog = gimp_levels_tool_dialog;
|
|
|
|
im_tool_class->reset = gimp_levels_tool_reset;
|
|
|
|
im_tool_class->settings_load = gimp_levels_tool_settings_load;
|
|
|
|
im_tool_class->settings_save = gimp_levels_tool_settings_save;
|
2002-08-26 19:35:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_levels_tool_init (GimpLevelsTool *tool)
|
2002-08-26 19:35:56 +08:00
|
|
|
{
|
2008-01-09 09:06:46 +08:00
|
|
|
GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool);
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->lut = gimp_lut_new ();
|
2007-05-23 21:49:06 +08:00
|
|
|
tool->levels = g_slice_new0 (Levels);
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->hist = NULL;
|
|
|
|
tool->channel = GIMP_HISTOGRAM_VALUE;
|
|
|
|
tool->active_picker = NULL;
|
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
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
levels_init (tool->levels);
|
2008-01-09 09:06:46 +08:00
|
|
|
|
|
|
|
im_tool->apply_func = (GimpImageMapApplyFunc) gimp_lut_process;
|
|
|
|
im_tool->apply_data = tool->lut;
|
2000-09-29 09:22:27 +08:00
|
|
|
}
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_levels_tool_finalize (GObject *object)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (object);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2007-05-23 21:49:06 +08:00
|
|
|
gimp_lut_free (tool->lut);
|
|
|
|
g_slice_free (Levels, tool->levels);
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->hist)
|
2002-08-26 19:35:56 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_histogram_free (tool->hist);
|
|
|
|
tool->hist = NULL;
|
2002-08-26 19:35:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2004-01-22 00:07:48 +08:00
|
|
|
static gboolean
|
2006-09-27 04:55:40 +08:00
|
|
|
gimp_levels_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2007-07-19 22:59:51 +08:00
|
|
|
GimpLevelsTool *l_tool = GIMP_LEVELS_TOOL (tool);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (display->image);
|
2003-02-04 07:54:19 +08:00
|
|
|
|
2003-11-13 19:23:01 +08:00
|
|
|
if (! drawable)
|
2004-01-22 00:07:48 +08:00
|
|
|
return FALSE;
|
2003-11-13 19:23:01 +08:00
|
|
|
|
2003-02-04 07:54:19 +08:00
|
|
|
if (gimp_drawable_is_indexed (drawable))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-09-27 04:55:40 +08:00
|
|
|
g_set_error (error, 0, 0,
|
2006-09-27 05:53:43 +08:00
|
|
|
_("Levels does not operate on indexed layers."));
|
2004-01-22 00:07:48 +08:00
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (! l_tool->hist)
|
2005-02-14 09:05:34 +08:00
|
|
|
l_tool->hist = gimp_histogram_new ();
|
2003-01-17 21:34:26 +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
|
|
|
levels_init (l_tool->levels);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
l_tool->channel = GIMP_HISTOGRAM_VALUE;
|
|
|
|
l_tool->color = gimp_drawable_is_rgb (drawable);
|
2004-01-25 02:35:49 +08:00
|
|
|
l_tool->alpha = gimp_drawable_has_alpha (drawable);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2003-03-17 01:00:40 +08:00
|
|
|
if (l_tool->active_picker)
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (l_tool->active_picker),
|
2004-06-28 01:30:55 +08:00
|
|
|
FALSE);
|
2003-03-17 01:00:40 +08:00
|
|
|
|
2006-09-27 04:55:40 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-03-01 07:27:12 +08:00
|
|
|
gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (l_tool->channel_menu),
|
|
|
|
levels_menu_sensitivity, l_tool, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-04-21 03:06:37 +08:00
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (l_tool->channel_menu),
|
|
|
|
l_tool->channel);
|
2004-01-25 02:35:49 +08:00
|
|
|
|
2004-06-28 22:24:56 +08:00
|
|
|
/* FIXME: hack */
|
|
|
|
if (! l_tool->color)
|
|
|
|
l_tool->channel = (l_tool->channel == GIMP_HISTOGRAM_ALPHA) ? 1 : 0;
|
2004-06-28 19:45:14 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_adjustments (l_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_drawable_calculate_histogram (drawable, l_tool->hist);
|
2002-10-15 09:15:43 +08:00
|
|
|
gimp_histogram_view_set_histogram (GIMP_HISTOGRAM_VIEW (l_tool->hist_view),
|
|
|
|
l_tool->hist);
|
2004-01-22 00:07:48 +08:00
|
|
|
|
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2008-01-08 04:37:25 +08:00
|
|
|
static GeglNode *
|
|
|
|
gimp_levels_tool_get_operation (GimpImageMapTool *im_tool)
|
|
|
|
{
|
|
|
|
return g_object_new (GEGL_TYPE_NODE,
|
|
|
|
"operation", "gimp-levels",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_levels_tool_map (GimpImageMapTool *image_map_tool)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2008-01-10 21:12:44 +08:00
|
|
|
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
|
|
|
|
GimpHistogramChannel channel;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2008-01-10 21:12:44 +08:00
|
|
|
for (channel = GIMP_HISTOGRAM_VALUE;
|
|
|
|
channel <= GIMP_HISTOGRAM_ALPHA;
|
|
|
|
channel++)
|
2008-01-08 04:37:25 +08:00
|
|
|
{
|
2008-01-10 21:12:44 +08:00
|
|
|
/* FIXME: hack */
|
|
|
|
if (! tool->color && channel == 1)
|
|
|
|
gegl_node_set (image_map_tool->operation,
|
|
|
|
"channel", GIMP_HISTOGRAM_ALPHA,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
gegl_node_set (image_map_tool->operation,
|
|
|
|
"channel", channel,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gegl_node_set (image_map_tool->operation,
|
|
|
|
"gamma", tool->levels->gamma[channel],
|
|
|
|
"low-input", tool->levels->low_input[channel] / 255.0,
|
|
|
|
"high-input", tool->levels->high_input[channel] / 255.0,
|
|
|
|
"low-output", tool->levels->low_output[channel] / 255.0,
|
|
|
|
"high-output", tool->levels->high_output[channel] / 255.0,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* FIXME: hack */
|
|
|
|
if (! tool->color && channel == 1)
|
|
|
|
break;
|
2008-01-08 04:37:25 +08:00
|
|
|
}
|
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
gimp_lut_setup (tool->lut,
|
|
|
|
(GimpLutFunc) levels_lut_func,
|
|
|
|
tool->levels,
|
|
|
|
gimp_drawable_bytes (image_map_tool->drawable));
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-23 23:24:46 +08:00
|
|
|
/*******************/
|
|
|
|
/* Levels dialog */
|
|
|
|
/*******************/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-17 01:00:40 +08:00
|
|
|
static GtkWidget *
|
|
|
|
gimp_levels_tool_color_picker_new (GimpLevelsTool *tool,
|
2004-06-28 01:30:55 +08:00
|
|
|
guint value)
|
2003-03-17 01:00:40 +08:00
|
|
|
{
|
|
|
|
GtkWidget *button;
|
2006-01-31 23:04:37 +08:00
|
|
|
GtkWidget *image;
|
2003-03-17 01:00:40 +08:00
|
|
|
const gchar *stock_id;
|
|
|
|
const gchar *help;
|
|
|
|
|
|
|
|
switch (value & 0xF)
|
|
|
|
{
|
2007-11-22 17:45:40 +08:00
|
|
|
case PICK_LOW_INPUT:
|
2003-03-17 01:00:40 +08:00
|
|
|
stock_id = GIMP_STOCK_COLOR_PICKER_BLACK;
|
2004-06-24 04:29:46 +08:00
|
|
|
help = _("Pick black point");
|
2003-03-17 01:00:40 +08:00
|
|
|
break;
|
2007-11-22 17:45:40 +08:00
|
|
|
case PICK_GAMMA:
|
2003-03-17 01:00:40 +08:00
|
|
|
stock_id = GIMP_STOCK_COLOR_PICKER_GRAY;
|
2004-06-24 04:29:46 +08:00
|
|
|
help = _("Pick gray point");
|
2003-03-17 01:00:40 +08:00
|
|
|
break;
|
2007-11-22 17:45:40 +08:00
|
|
|
case PICK_HIGH_INPUT:
|
2003-03-17 01:00:40 +08:00
|
|
|
stock_id = GIMP_STOCK_COLOR_PICKER_WHITE;
|
2004-06-24 04:29:46 +08:00
|
|
|
help = _("Pick white point");
|
2003-03-17 01:00:40 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
button = g_object_new (GTK_TYPE_TOGGLE_BUTTON,
|
2005-08-03 17:34:55 +08:00
|
|
|
"draw-indicator", FALSE,
|
2003-03-17 01:00:40 +08:00
|
|
|
NULL);
|
|
|
|
|
2006-01-31 23:04:37 +08:00
|
|
|
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_misc_set_padding (GTK_MISC (image), 2, 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (button), image);
|
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2003-03-17 01:00:40 +08:00
|
|
|
gimp_help_set_help_data (button, help, NULL);
|
|
|
|
|
2004-01-19 07:23:48 +08:00
|
|
|
g_object_set_data (G_OBJECT (button),
|
2007-11-22 17:45:40 +08:00
|
|
|
"pick-value", GUINT_TO_POINTER (value));
|
2003-03-17 01:00:40 +08:00
|
|
|
g_signal_connect (button, "toggled",
|
|
|
|
G_CALLBACK (levels_input_picker_toggled),
|
|
|
|
tool);
|
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static void
|
|
|
|
gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-09-06 02:25:31 +08:00
|
|
|
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
|
|
|
|
GimpToolOptions *tool_options = GIMP_TOOL_GET_OPTIONS (image_map_tool);
|
2005-03-01 07:27:12 +08:00
|
|
|
GtkListStore *store;
|
2003-10-24 16:12:21 +08:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *vbox2;
|
|
|
|
GtkWidget *vbox3;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *hbox2;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *hbbox;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *spinbutton;
|
2004-02-20 03:56:04 +08:00
|
|
|
GtkWidget *bar;
|
2003-10-24 16:12:21 +08:00
|
|
|
GtkObject *data;
|
2004-02-20 03:56:04 +08:00
|
|
|
gint border;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* The option menu for selecting channels */
|
2004-06-03 01:56:02 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), hbox,
|
|
|
|
FALSE, FALSE, 0);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_widget_show (hbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-03-08 20:37:30 +08:00
|
|
|
label = gtk_label_new_with_mnemonic (_("Cha_nnel:"));
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
2000-02-14 06:26:41 +08:00
|
|
|
gtk_widget_show (label);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-03-01 07:27:12 +08:00
|
|
|
store = gimp_enum_store_new_with_range (GIMP_TYPE_HISTOGRAM_CHANNEL,
|
|
|
|
GIMP_HISTOGRAM_VALUE,
|
|
|
|
GIMP_HISTOGRAM_ALPHA);
|
2005-06-27 23:28:44 +08:00
|
|
|
menu = gimp_enum_combo_box_new_with_model (GIMP_ENUM_STORE (store));
|
2005-03-01 07:27:12 +08:00
|
|
|
g_object_unref (store);
|
|
|
|
|
2004-04-18 23:12:42 +08:00
|
|
|
g_signal_connect (menu, "changed",
|
|
|
|
G_CALLBACK (levels_channel_callback),
|
|
|
|
tool);
|
|
|
|
gimp_enum_combo_box_set_stock_prefix (GIMP_ENUM_COMBO_BOX (menu),
|
|
|
|
"gimp-channel");
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), menu, FALSE, FALSE, 0);
|
2003-03-25 02:04:11 +08:00
|
|
|
gtk_widget_show (menu);
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->channel_menu = menu;
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2005-03-08 20:37:30 +08:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), menu);
|
|
|
|
|
2005-06-16 05:38:00 +08:00
|
|
|
button = gtk_button_new_with_mnemonic (_("R_eset Channel"));
|
2004-03-05 09:31:33 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (button);
|
added gimphistogram*, histogramwidget*, removed histogram.[ch]
* app/Makefile.am: added gimphistogram*, histogramwidget*,
removed histogram.[ch]
* app/histogram.[ch]: removed. replaced with histogramwidget.[ch].
* app/{gimphistogramP.h, gimphistogram.h, gimphistogram.c}: new
functions that calculate histograms in parallel and perform
calculations on them.
* app/histogramwidget.[ch]: Same as old histogram.[ch], only it is
now a real widget, and it uses GimpHistograms instead of arrays of
values.
* app/curves.c: #include gimphistogram.h instead of histogram.h.
* app/equalize.c: use GimpHistogram and GimpLut.
* app/gimpbrush.c, app/gimpimage.c, app/gimpset.c: use
GTK_RUN_FIRST in calls to gimp_signal_new.
* app/histogram_tool.c, app/levels.c, app/threshold.c: modified to
use the new HistogramWidget.
* app/paint_funcs.c: removed some unused variables.
* app/preferences_dialog.c: only display the num-processor field
if we are configured --with-mp
* plug-ins/gee/gee.c: removed a couple of c++ style comments.
1999-03-01 13:11:19 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (button, "clicked",
|
2002-08-26 19:35:56 +08:00
|
|
|
G_CALLBACK (levels_channel_reset_callback),
|
2004-02-21 20:25:09 +08:00
|
|
|
tool);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2004-03-05 09:31:33 +08:00
|
|
|
menu = gimp_prop_enum_stock_box_new (G_OBJECT (tool_options),
|
|
|
|
"histogram-scale", "gimp-histogram",
|
|
|
|
0, 0);
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), menu, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (menu);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* Input levels frame */
|
2004-05-05 06:33:52 +08:00
|
|
|
frame = gimp_frame_new (_("Input Levels"));
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), frame,
|
|
|
|
TRUE, TRUE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (frame);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
vbox2 = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox2);
|
|
|
|
gtk_widget_show (vbox2);
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->hist_view = gimp_histogram_view_new (FALSE);
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), tool->hist_view, TRUE, TRUE, 0);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_widget_show (GTK_WIDGET (tool->hist_view));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-10-24 16:12:21 +08:00
|
|
|
gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options),
|
2004-02-21 20:25:09 +08:00
|
|
|
GIMP_HISTOGRAM_VIEW (tool->hist_view));
|
2003-10-24 16:12:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
g_object_get (tool->hist_view, "border-width", &border, NULL);
|
2004-02-20 03:56:04 +08:00
|
|
|
|
|
|
|
vbox3 = gtk_vbox_new (FALSE, 0);
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox3), border);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), vbox3, FALSE, FALSE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (vbox3);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
tool->input_bar = g_object_new (GIMP_TYPE_COLOR_BAR, NULL);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_widget_set_size_request (tool->input_bar, -1, GRADIENT_HEIGHT / 2);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox3), tool->input_bar, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (tool->input_bar);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
bar = g_object_new (GIMP_TYPE_COLOR_BAR, NULL);
|
2004-02-20 03:56:04 +08:00
|
|
|
gtk_widget_set_size_request (bar, -1, GRADIENT_HEIGHT / 2);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox3), bar, FALSE, FALSE, 0);
|
2004-02-20 03:56:04 +08:00
|
|
|
gtk_widget_show (bar);
|
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
tool->input_sliders = g_object_new (GIMP_TYPE_HANDLE_BAR, NULL);
|
|
|
|
gtk_widget_set_size_request (tool->input_sliders, -1, CONTROL_HEIGHT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox3), tool->input_sliders, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (tool->input_sliders);
|
|
|
|
|
2007-11-23 01:07:33 +08:00
|
|
|
g_signal_connect_swapped (tool->input_bar, "button-press-event",
|
|
|
|
G_CALLBACK (GTK_WIDGET_GET_CLASS (tool->input_sliders)->button_press_event),
|
|
|
|
tool->input_sliders);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (tool->input_bar, "button-release-event",
|
|
|
|
G_CALLBACK (GTK_WIDGET_GET_CLASS (tool->input_sliders)->button_release_event),
|
|
|
|
tool->input_sliders);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (tool->input_bar, "motion-notify-event",
|
|
|
|
G_CALLBACK (GTK_WIDGET_GET_CLASS (tool->input_sliders)->motion_notify_event),
|
|
|
|
tool->input_sliders);
|
|
|
|
|
2007-11-23 01:11:05 +08:00
|
|
|
g_signal_connect_swapped (bar, "button-press-event",
|
|
|
|
G_CALLBACK (GTK_WIDGET_GET_CLASS (tool->input_sliders)->button_press_event),
|
|
|
|
tool->input_sliders);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (bar, "button-release-event",
|
|
|
|
G_CALLBACK (GTK_WIDGET_GET_CLASS (tool->input_sliders)->button_release_event),
|
|
|
|
tool->input_sliders);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (bar, "motion-notify-event",
|
|
|
|
G_CALLBACK (GTK_WIDGET_GET_CLASS (tool->input_sliders)->motion_notify_event),
|
|
|
|
tool->input_sliders);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* Horizontal box for input levels spinbuttons */
|
2004-06-03 01:56:02 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (hbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* low input spin */
|
2004-02-25 23:56:50 +08:00
|
|
|
hbox2 = gtk_hbox_new (FALSE, 2);
|
2002-10-14 01:24:29 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), hbox2, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox2);
|
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
button = gimp_levels_tool_color_picker_new (tool, PICK_LOW_INPUT);
|
2002-10-14 01:24:29 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2005-04-17 23:28:28 +08:00
|
|
|
spinbutton = gimp_spin_button_new (&data, 0, 0, 255, 1, 10, 10, 0.5, 0);
|
2002-10-14 01:24:29 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (spinbutton);
|
1999-04-13 12:59:07 +08:00
|
|
|
|
2005-04-17 23:28:28 +08:00
|
|
|
tool->low_input = GTK_ADJUSTMENT (data);
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (tool->low_input, "value-changed",
|
2007-12-30 00:29:31 +08:00
|
|
|
G_CALLBACK (levels_low_input_changed),
|
2004-02-21 20:25:09 +08:00
|
|
|
tool);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
gimp_handle_bar_set_adjustment (GIMP_HANDLE_BAR (tool->input_sliders), 0,
|
|
|
|
tool->low_input);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* input gamma spin */
|
2005-04-17 23:28:28 +08:00
|
|
|
spinbutton = gimp_spin_button_new (&data, 1, 0.1, 10, 0.01, 0.1, 1, 0.5, 2);
|
2004-02-19 07:52:31 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, FALSE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_help_set_help_data (spinbutton, _("Gamma"), NULL);
|
1999-11-22 19:14:29 +08:00
|
|
|
gtk_widget_show (spinbutton);
|
1999-04-13 12:59:07 +08:00
|
|
|
|
2005-04-17 23:28:28 +08:00
|
|
|
tool->gamma = GTK_ADJUSTMENT (data);
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (tool->gamma, "value-changed",
|
2007-12-30 00:29:31 +08:00
|
|
|
G_CALLBACK (levels_gamma_changed),
|
2004-02-21 20:25:09 +08:00
|
|
|
tool);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
tool->gamma_linear = GTK_ADJUSTMENT (gtk_adjustment_new (127, 0, 255,
|
|
|
|
0.1, 1.0, 0.0));
|
|
|
|
g_signal_connect (tool->gamma_linear, "value-changed",
|
2007-12-30 00:29:31 +08:00
|
|
|
G_CALLBACK (levels_linear_gamma_changed),
|
2007-11-22 17:45:40 +08:00
|
|
|
tool);
|
|
|
|
|
|
|
|
gimp_handle_bar_set_adjustment (GIMP_HANDLE_BAR (tool->input_sliders), 1,
|
|
|
|
tool->gamma_linear);
|
|
|
|
g_object_unref (tool->gamma_linear);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* high input spin */
|
2004-02-25 23:56:50 +08:00
|
|
|
hbox2 = gtk_hbox_new (FALSE, 2);
|
2002-10-14 01:24:29 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), hbox2, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox2);
|
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
button = gimp_levels_tool_color_picker_new (tool, PICK_HIGH_INPUT);
|
2004-02-19 08:06:30 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2005-04-17 23:28:28 +08:00
|
|
|
spinbutton = gimp_spin_button_new (&data, 255, 0, 255, 1, 10, 10, 0.5, 0);
|
2002-10-14 01:24:29 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (spinbutton);
|
1999-04-13 12:59:07 +08:00
|
|
|
|
2005-04-17 23:28:28 +08:00
|
|
|
tool->high_input = GTK_ADJUSTMENT (data);
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (tool->high_input, "value-changed",
|
2007-12-30 00:29:31 +08:00
|
|
|
G_CALLBACK (levels_high_input_changed),
|
2004-02-21 20:25:09 +08:00
|
|
|
tool);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
gimp_handle_bar_set_adjustment (GIMP_HANDLE_BAR (tool->input_sliders), 2,
|
|
|
|
tool->high_input);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* Output levels frame */
|
2004-05-05 06:33:52 +08:00
|
|
|
frame = gimp_frame_new (_("Output Levels"));
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), frame,
|
|
|
|
FALSE, FALSE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (frame);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
vbox2 = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox2), border);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox2);
|
|
|
|
gtk_widget_show (vbox2);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-21 01:24:37 +08:00
|
|
|
tool->output_bar = g_object_new (GIMP_TYPE_COLOR_BAR, NULL);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_widget_set_size_request (tool->output_bar, -1, GRADIENT_HEIGHT);
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), tool->output_bar, FALSE, FALSE, 0);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_widget_show (tool->output_bar);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-21 01:24:37 +08:00
|
|
|
tool->output_sliders = g_object_new (GIMP_TYPE_HANDLE_BAR, NULL);
|
|
|
|
gtk_widget_set_size_request (tool->output_sliders, -1, CONTROL_HEIGHT);
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), tool->output_sliders, FALSE, FALSE, 0);
|
2007-11-21 01:24:37 +08:00
|
|
|
gtk_widget_show (tool->output_sliders);
|
|
|
|
|
2007-11-23 01:07:33 +08:00
|
|
|
g_signal_connect_swapped (tool->output_bar, "button-press-event",
|
|
|
|
G_CALLBACK (GTK_WIDGET_GET_CLASS (tool->output_sliders)->button_press_event),
|
|
|
|
tool->output_sliders);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (tool->output_bar, "button-release-event",
|
|
|
|
G_CALLBACK (GTK_WIDGET_GET_CLASS (tool->output_sliders)->button_release_event),
|
|
|
|
tool->output_sliders);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (tool->output_bar, "motion-notify-event",
|
|
|
|
G_CALLBACK (GTK_WIDGET_GET_CLASS (tool->output_sliders)->motion_notify_event),
|
|
|
|
tool->output_sliders);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* Horizontal box for levels spin widgets */
|
2004-06-03 01:56:02 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* low output spin */
|
2005-04-17 23:28:28 +08:00
|
|
|
spinbutton = gimp_spin_button_new (&data, 0, 0, 255, 1, 10, 10, 0.5, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (spinbutton);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2005-04-17 23:28:28 +08:00
|
|
|
tool->low_output = GTK_ADJUSTMENT (data);
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (tool->low_output, "value-changed",
|
2007-12-30 00:29:31 +08:00
|
|
|
G_CALLBACK (levels_low_output_changed),
|
2004-02-21 20:25:09 +08:00
|
|
|
tool);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-21 01:24:37 +08:00
|
|
|
gimp_handle_bar_set_adjustment (GIMP_HANDLE_BAR (tool->output_sliders), 0,
|
|
|
|
tool->low_output);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* high output spin */
|
2005-04-17 23:28:28 +08:00
|
|
|
spinbutton = gimp_spin_button_new (&data, 255, 0, 255, 1, 10, 10, 0.5, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (spinbutton);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2005-04-17 23:28:28 +08:00
|
|
|
tool->high_output = GTK_ADJUSTMENT (data);
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (tool->high_output, "value-changed",
|
2007-12-30 00:29:31 +08:00
|
|
|
G_CALLBACK (levels_high_output_changed),
|
2004-02-21 20:25:09 +08:00
|
|
|
tool);
|
1999-08-27 08:19:25 +08:00
|
|
|
|
2007-11-21 01:24:37 +08:00
|
|
|
gimp_handle_bar_set_adjustment (GIMP_HANDLE_BAR (tool->output_sliders), 2,
|
|
|
|
tool->high_output);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-21 01:24:37 +08:00
|
|
|
|
|
|
|
/* all channels frame */
|
2004-05-05 06:33:52 +08:00
|
|
|
frame = gimp_frame_new (_("All Channels"));
|
2007-11-22 17:45:40 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (image_map_tool->main_vbox), frame,
|
|
|
|
FALSE, FALSE, 0);
|
2002-08-29 03:47:07 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2003-03-17 01:00:40 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), hbox);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
hbbox = gtk_hbutton_box_new ();
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_box_set_spacing (GTK_BOX (hbbox), 4);
|
2003-03-19 20:23:03 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (hbbox);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2004-02-25 21:55:45 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), image_map_tool->load_button,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (image_map_tool->load_button);
|
2003-03-17 01:00:40 +08:00
|
|
|
|
2004-02-25 21:55:45 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), image_map_tool->save_button,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (image_map_tool->save_button);
|
2004-02-19 07:52:31 +08:00
|
|
|
|
2004-06-03 01:56:02 +08:00
|
|
|
hbbox = gtk_hbox_new (FALSE, 6);
|
2004-02-19 07:52:31 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
|
2003-03-17 01:00:40 +08:00
|
|
|
gtk_widget_show (hbbox);
|
|
|
|
|
2003-03-19 20:23:03 +08:00
|
|
|
button = gtk_button_new_with_mnemonic (_("_Auto"));
|
2004-06-03 01:56:02 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
|
2003-03-19 20:23:03 +08:00
|
|
|
gimp_help_set_help_data (button, _("Adjust levels automatically"), NULL);
|
2003-03-17 01:00:40 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2003-03-19 20:23:03 +08:00
|
|
|
g_signal_connect (button, "clicked",
|
2004-11-02 00:05:19 +08:00
|
|
|
G_CALLBACK (levels_stretch_callback),
|
2004-02-21 20:25:09 +08:00
|
|
|
tool);
|
2003-03-19 20:23:03 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
button = gimp_levels_tool_color_picker_new (tool,
|
2007-11-22 17:45:40 +08:00
|
|
|
PICK_LOW_INPUT | PICK_ALL_CHANNELS);
|
2003-03-17 01:00:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
button = gimp_levels_tool_color_picker_new (tool,
|
|
|
|
PICK_GAMMA | PICK_ALL_CHANNELS);
|
2003-03-17 01:00:40 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
button = gimp_levels_tool_color_picker_new (tool,
|
2007-11-22 17:45:40 +08:00
|
|
|
PICK_HIGH_INPUT | PICK_ALL_CHANNELS);
|
2003-03-19 20:23:03 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
|
2003-03-17 01:00:40 +08:00
|
|
|
gtk_widget_show (button);
|
2007-06-27 00:02:14 +08:00
|
|
|
|
|
|
|
g_signal_connect (image_map_tool->shell, "unmap",
|
|
|
|
G_CALLBACK (gimp_levels_tool_dialog_unmap),
|
|
|
|
tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_levels_tool_dialog_unmap (GtkWidget *dialog,
|
|
|
|
GimpLevelsTool *tool)
|
|
|
|
{
|
|
|
|
if (tool->active_picker)
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tool->active_picker),
|
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_levels_tool_reset (GimpImageMapTool *image_map_tool)
|
2001-10-17 19:33:43 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
levels_init (tool->levels);
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_adjustments (tool);
|
2001-10-17 19:33:43 +08:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:23:43 +08:00
|
|
|
static gboolean
|
2006-08-10 20:04:35 +08:00
|
|
|
gimp_levels_tool_settings_load (GimpImageMapTool *image_map_tool,
|
|
|
|
gpointer fp,
|
|
|
|
GError **error)
|
2004-02-25 18:23:43 +08:00
|
|
|
{
|
2004-02-25 21:55:45 +08:00
|
|
|
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
|
|
|
|
FILE *file = fp;
|
|
|
|
gint low_input[5];
|
|
|
|
gint high_input[5];
|
|
|
|
gint low_output[5];
|
|
|
|
gint high_output[5];
|
|
|
|
gdouble gamma[5];
|
|
|
|
gint i, fields;
|
|
|
|
gchar buf[50];
|
|
|
|
gchar *nptr;
|
|
|
|
|
2006-08-10 20:04:35 +08:00
|
|
|
if (! fgets (buf, sizeof (buf), file) ||
|
|
|
|
strcmp (buf, "# GIMP Levels File\n") != 0)
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
|
|
|
|
_("not a GIMP Levels file"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-02-25 21:55:45 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
fields = fscanf (file, "%d %d %d %d ",
|
2004-06-28 01:30:55 +08:00
|
|
|
&low_input[i],
|
|
|
|
&high_input[i],
|
|
|
|
&low_output[i],
|
|
|
|
&high_output[i]);
|
2004-02-25 21:55:45 +08:00
|
|
|
|
|
|
|
if (fields != 4)
|
2006-08-10 20:04:35 +08:00
|
|
|
goto error;
|
2004-02-25 21:55:45 +08:00
|
|
|
|
|
|
|
if (! fgets (buf, 50, file))
|
2006-08-10 20:04:35 +08:00
|
|
|
goto error;
|
2004-02-25 21:55:45 +08:00
|
|
|
|
|
|
|
gamma[i] = g_ascii_strtod (buf, &nptr);
|
|
|
|
|
|
|
|
if (buf == nptr || errno == ERANGE)
|
2006-08-10 20:04:35 +08:00
|
|
|
goto error;
|
2004-02-25 21:55:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
tool->levels->low_input[i] = low_input[i];
|
|
|
|
tool->levels->high_input[i] = high_input[i];
|
|
|
|
tool->levels->low_output[i] = low_output[i];
|
|
|
|
tool->levels->high_output[i] = high_output[i];
|
|
|
|
tool->levels->gamma[i] = gamma[i];
|
|
|
|
}
|
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_adjustments (tool);
|
2004-02-25 21:55:45 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2006-08-10 20:04:35 +08:00
|
|
|
|
|
|
|
error:
|
|
|
|
g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
|
|
|
|
_("parse error"));
|
|
|
|
return FALSE;
|
2004-02-25 18:23:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-02-25 21:55:45 +08:00
|
|
|
gimp_levels_tool_settings_save (GimpImageMapTool *image_map_tool,
|
|
|
|
gpointer fp)
|
2004-02-25 18:23:43 +08:00
|
|
|
{
|
2004-02-25 21:55:45 +08:00
|
|
|
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool);
|
|
|
|
FILE *file = fp;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
fprintf (file, "# GIMP Levels File\n");
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
|
|
|
|
|
|
|
fprintf (file, "%d %d %d %d %s\n",
|
2004-06-28 01:30:55 +08:00
|
|
|
tool->levels->low_input[i],
|
|
|
|
tool->levels->high_input[i],
|
|
|
|
tool->levels->low_output[i],
|
|
|
|
tool->levels->high_output[i],
|
2004-02-25 21:55:45 +08:00
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
tool->levels->gamma[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2004-02-25 18:23:43 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_adjustments (GimpLevelsTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2007-11-22 17:45:40 +08:00
|
|
|
tool->low_input->upper = 255;
|
|
|
|
tool->high_input->lower = 0;
|
|
|
|
tool->gamma_linear->lower = 0;
|
|
|
|
tool->gamma_linear->upper = 255;
|
|
|
|
|
|
|
|
gtk_adjustment_set_value (tool->low_input,
|
|
|
|
tool->levels->low_input[tool->channel]);
|
|
|
|
gtk_adjustment_set_value (tool->gamma,
|
|
|
|
tool->levels->gamma[tool->channel]);
|
|
|
|
gtk_adjustment_set_value (tool->high_input,
|
|
|
|
tool->levels->high_input[tool->channel]);
|
|
|
|
|
|
|
|
tool->low_input->upper = tool->high_input->value;
|
|
|
|
tool->high_input->lower = tool->low_input->value;
|
|
|
|
tool->gamma_linear->lower = tool->low_input->value;
|
|
|
|
tool->gamma_linear->upper = tool->high_input->value;
|
|
|
|
gtk_adjustment_changed (tool->low_input);
|
|
|
|
gtk_adjustment_changed (tool->high_input);
|
|
|
|
gtk_adjustment_changed (tool->gamma_linear);
|
|
|
|
|
|
|
|
gtk_adjustment_set_value (tool->low_output,
|
|
|
|
tool->levels->low_output[tool->channel]);
|
|
|
|
gtk_adjustment_set_value (tool->high_output,
|
|
|
|
tool->levels->high_output[tool->channel]);
|
|
|
|
|
|
|
|
levels_update_input_bar (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_input_bar (GimpLevelsTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-20 03:56:04 +08:00
|
|
|
GimpHistogramChannel channel;
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->color)
|
2001-01-03 10:59:57 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
channel = tool->channel;
|
2001-01-03 10:59:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-28 22:24:56 +08:00
|
|
|
/* FIXME: hack */
|
|
|
|
if (tool->channel == 1)
|
2004-06-28 01:30:55 +08:00
|
|
|
channel = GIMP_HISTOGRAM_ALPHA;
|
2001-01-03 10:59:57 +08:00
|
|
|
else
|
2004-06-28 01:30:55 +08:00
|
|
|
channel = GIMP_HISTOGRAM_VALUE;
|
2001-01-03 10:59:57 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Recalculate the transfer arrays */
|
2004-02-21 20:25:09 +08:00
|
|
|
levels_calculate_transfers (tool->levels);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
switch (channel)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2007-11-22 17:45:40 +08:00
|
|
|
case GIMP_HISTOGRAM_VALUE:
|
|
|
|
case GIMP_HISTOGRAM_ALPHA:
|
|
|
|
case GIMP_HISTOGRAM_RGB:
|
|
|
|
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->input_bar),
|
|
|
|
tool->levels->input[tool->channel],
|
|
|
|
tool->levels->input[tool->channel],
|
|
|
|
tool->levels->input[tool->channel]);
|
|
|
|
break;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
case GIMP_HISTOGRAM_RED:
|
|
|
|
case GIMP_HISTOGRAM_GREEN:
|
|
|
|
case GIMP_HISTOGRAM_BLUE:
|
|
|
|
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->input_bar),
|
|
|
|
tool->levels->input[GIMP_HISTOGRAM_RED],
|
|
|
|
tool->levels->input[GIMP_HISTOGRAM_GREEN],
|
|
|
|
tool->levels->input[GIMP_HISTOGRAM_BLUE]);
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-12-18 23:57:25 +08:00
|
|
|
levels_channel_callback (GtkWidget *widget,
|
2004-06-28 01:30:55 +08:00
|
|
|
GimpLevelsTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2007-04-12 22:48:04 +08:00
|
|
|
gint value;
|
2004-01-13 19:51:45 +08:00
|
|
|
|
2007-04-12 22:48:04 +08:00
|
|
|
if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value))
|
|
|
|
{
|
|
|
|
tool->channel = value;
|
|
|
|
gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->hist_view),
|
|
|
|
tool->channel);
|
2007-11-22 17:45:40 +08:00
|
|
|
gimp_color_bar_set_channel (GIMP_COLOR_BAR (tool->output_bar),
|
|
|
|
tool->channel);
|
2004-04-21 03:06:37 +08:00
|
|
|
|
2007-04-12 22:48:04 +08:00
|
|
|
/* FIXME: hack */
|
|
|
|
if (! tool->color)
|
|
|
|
tool->channel = (tool->channel == GIMP_HISTOGRAM_ALPHA) ? 1 : 0;
|
2004-06-28 19:45:14 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_adjustments (tool);
|
2007-04-12 22:48:04 +08:00
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-12-18 23:57:25 +08:00
|
|
|
levels_channel_reset_callback (GtkWidget *widget,
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpLevelsTool *tool)
|
2002-08-26 19:35:56 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
levels_channel_reset (tool->levels, tool->channel);
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_adjustments (tool);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-03-18 00:35:05 +08:00
|
|
|
static gboolean
|
2005-03-01 07:27:12 +08:00
|
|
|
levels_menu_sensitivity (gint value,
|
|
|
|
gpointer data)
|
2002-03-18 00:35:05 +08:00
|
|
|
{
|
2005-03-01 07:27:12 +08:00
|
|
|
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (data);
|
|
|
|
GimpHistogramChannel channel = value;
|
2004-04-19 06:38:45 +08:00
|
|
|
|
2002-03-18 00:35:05 +08:00
|
|
|
switch (channel)
|
|
|
|
{
|
|
|
|
case GIMP_HISTOGRAM_VALUE:
|
|
|
|
return TRUE;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2002-03-18 00:35:05 +08:00
|
|
|
case GIMP_HISTOGRAM_RED:
|
|
|
|
case GIMP_HISTOGRAM_GREEN:
|
|
|
|
case GIMP_HISTOGRAM_BLUE:
|
2004-02-21 20:25:09 +08:00
|
|
|
return tool->color;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2002-03-18 00:35:05 +08:00
|
|
|
case GIMP_HISTOGRAM_ALPHA:
|
2004-04-19 06:38:45 +08:00
|
|
|
return tool->alpha;
|
2004-07-07 00:33:30 +08:00
|
|
|
|
|
|
|
case GIMP_HISTOGRAM_RGB:
|
|
|
|
return FALSE;
|
2002-03-18 00:35:05 +08:00
|
|
|
}
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2002-03-18 00:35:05 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
static void
|
2004-11-02 00:05:19 +08:00
|
|
|
levels_stretch_callback (GtkWidget *widget,
|
2007-11-21 01:24:37 +08:00
|
|
|
GimpLevelsTool *tool)
|
1999-11-22 19:14:29 +08:00
|
|
|
{
|
2004-11-02 00:05:19 +08:00
|
|
|
levels_stretch (tool->levels, tool->hist, tool->color);
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_adjustments (tool);
|
2000-06-13 17:13:16 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
static void
|
|
|
|
levels_linear_gamma_update (GimpLevelsTool *tool)
|
|
|
|
{
|
|
|
|
gdouble delta, mid, tmp, value;
|
|
|
|
|
|
|
|
delta = (tool->high_input->value - tool->low_input->value) / 2.0;
|
|
|
|
mid = tool->low_input->value + delta;
|
|
|
|
tmp = log10 (1.0 / tool->levels->gamma[tool->channel]);
|
|
|
|
value = mid + delta * tmp;
|
|
|
|
|
|
|
|
gtk_adjustment_set_value (tool->gamma_linear, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-30 00:29:31 +08:00
|
|
|
levels_linear_gamma_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool)
|
2007-11-22 17:45:40 +08:00
|
|
|
{
|
|
|
|
gdouble delta, mid, tmp, value;
|
|
|
|
|
|
|
|
delta = (tool->high_input->value - tool->low_input->value) / 2.0;
|
|
|
|
|
|
|
|
if (delta >= 0.5)
|
|
|
|
{
|
|
|
|
mid = tool->low_input->value + delta;
|
|
|
|
tmp = (adjustment->value - mid) / delta;
|
|
|
|
value = 1.0 / pow (10, tmp);
|
|
|
|
|
|
|
|
/* round the gamma value to the nearest 1/100th */
|
|
|
|
value = floor (value * 100 + 0.5) / 100.0;
|
|
|
|
|
|
|
|
gtk_adjustment_set_value (tool->gamma, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2007-12-30 00:29:31 +08:00
|
|
|
levels_low_input_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-20 03:56:04 +08:00
|
|
|
gint value = ROUND (adjustment->value);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
tool->high_input->lower = value;
|
|
|
|
tool->gamma_linear->lower = value;
|
|
|
|
gtk_adjustment_changed (tool->high_input);
|
|
|
|
gtk_adjustment_changed (tool->gamma_linear);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->levels->low_input[tool->channel] != value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->levels->low_input[tool->channel] = value;
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_input_bar (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2007-11-22 17:45:40 +08:00
|
|
|
|
|
|
|
levels_linear_gamma_update (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-30 00:29:31 +08:00
|
|
|
levels_gamma_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->levels->gamma[tool->channel] != adjustment->value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->levels->gamma[tool->channel] = adjustment->value;
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_input_bar (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2007-11-22 17:45:40 +08:00
|
|
|
|
|
|
|
levels_linear_gamma_update (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-30 00:29:31 +08:00
|
|
|
levels_high_input_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-20 03:56:04 +08:00
|
|
|
gint value = ROUND (adjustment->value);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
tool->low_input->upper = value;
|
|
|
|
tool->gamma_linear->upper = value;
|
|
|
|
gtk_adjustment_changed (tool->low_input);
|
|
|
|
gtk_adjustment_changed (tool->gamma_linear);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->levels->high_input[tool->channel] != value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->levels->high_input[tool->channel] = value;
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_input_bar (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2007-11-22 17:45:40 +08:00
|
|
|
|
|
|
|
levels_linear_gamma_update (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-30 00:29:31 +08:00
|
|
|
levels_low_output_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-20 03:56:04 +08:00
|
|
|
gint value = ROUND (adjustment->value);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->levels->low_output[tool->channel] != value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->levels->low_output[tool->channel] = value;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-30 00:29:31 +08:00
|
|
|
levels_high_output_changed (GtkAdjustment *adjustment,
|
|
|
|
GimpLevelsTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-20 03:56:04 +08:00
|
|
|
gint value = ROUND (adjustment->value);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->levels->high_output[tool->channel] != value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->levels->high_output[tool->channel] = value;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-15 21:36:28 +08:00
|
|
|
static void
|
2002-12-18 23:57:25 +08:00
|
|
|
levels_input_picker_toggled (GtkWidget *widget,
|
2003-03-15 23:02:36 +08:00
|
|
|
GimpLevelsTool *tool)
|
2002-10-15 21:36:28 +08:00
|
|
|
{
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
|
|
|
|
{
|
2003-03-15 23:02:36 +08:00
|
|
|
if (tool->active_picker == widget)
|
2002-10-15 21:36:28 +08:00
|
|
|
return;
|
|
|
|
|
2003-03-15 23:02:36 +08:00
|
|
|
if (tool->active_picker)
|
2003-08-22 09:42:57 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tool->active_picker),
|
2002-10-15 21:36:28 +08:00
|
|
|
FALSE);
|
|
|
|
|
2003-03-15 23:02:36 +08:00
|
|
|
tool->active_picker = widget;
|
2003-06-06 02:47:23 +08:00
|
|
|
|
|
|
|
gimp_color_tool_enable (GIMP_COLOR_TOOL (tool),
|
2006-09-06 02:25:31 +08:00
|
|
|
GIMP_COLOR_TOOL_GET_OPTIONS (tool));
|
2002-10-15 21:36:28 +08:00
|
|
|
}
|
2003-03-15 23:02:36 +08:00
|
|
|
else if (tool->active_picker == widget)
|
2002-10-15 21:36:28 +08:00
|
|
|
{
|
2003-03-15 23:02:36 +08:00
|
|
|
tool->active_picker = NULL;
|
2003-06-06 02:47:23 +08:00
|
|
|
gimp_color_tool_disable (GIMP_COLOR_TOOL (tool));
|
|
|
|
}
|
2002-10-15 21:36:28 +08:00
|
|
|
}
|
|
|
|
|
2003-03-17 01:00:40 +08:00
|
|
|
static void
|
|
|
|
levels_input_adjust_by_color (Levels *levels,
|
2004-06-28 01:30:55 +08:00
|
|
|
guint value,
|
|
|
|
GimpHistogramChannel channel,
|
|
|
|
guchar *color)
|
2003-03-17 01:00:40 +08:00
|
|
|
{
|
|
|
|
switch (value & 0xF)
|
|
|
|
{
|
2007-11-22 17:45:40 +08:00
|
|
|
case PICK_LOW_INPUT:
|
2003-03-17 01:00:40 +08:00
|
|
|
levels_adjust_by_colors (levels, channel, color, NULL, NULL);
|
|
|
|
break;
|
2007-11-22 17:45:40 +08:00
|
|
|
case PICK_GAMMA:
|
2003-03-17 01:00:40 +08:00
|
|
|
levels_adjust_by_colors (levels, channel, NULL, color, NULL);
|
|
|
|
break;
|
2007-11-22 17:45:40 +08:00
|
|
|
case PICK_HIGH_INPUT:
|
2003-03-17 01:00:40 +08:00
|
|
|
levels_adjust_by_colors (levels, channel, NULL, NULL, color);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-15 23:02:36 +08:00
|
|
|
static void
|
2004-06-30 20:10:08 +08:00
|
|
|
gimp_levels_tool_color_picked (GimpColorTool *color_tool,
|
|
|
|
GimpColorPickState pick_state,
|
|
|
|
GimpImageType sample_type,
|
|
|
|
GimpRGB *color,
|
|
|
|
gint color_index)
|
2003-03-15 23:02:36 +08:00
|
|
|
{
|
2004-02-25 21:55:45 +08:00
|
|
|
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (color_tool);
|
2003-06-06 02:47:23 +08:00
|
|
|
guchar col[5];
|
2003-03-15 23:02:36 +08:00
|
|
|
guint value;
|
|
|
|
|
2003-06-06 02:47:23 +08:00
|
|
|
gimp_rgba_get_uchar (color,
|
|
|
|
col + RED_PIX,
|
|
|
|
col + GREEN_PIX,
|
|
|
|
col + BLUE_PIX,
|
|
|
|
col + ALPHA_PIX);
|
2003-03-15 23:02:36 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
value = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (tool->active_picker),
|
2007-11-22 17:45:40 +08:00
|
|
|
"pick-value"));
|
2003-03-15 23:02:36 +08:00
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
if (value & PICK_ALL_CHANNELS && GIMP_IMAGE_TYPE_IS_RGB (sample_type))
|
2003-03-15 23:02:36 +08:00
|
|
|
{
|
2003-03-17 01:00:40 +08:00
|
|
|
GimpHistogramChannel channel;
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2003-03-17 01:00:40 +08:00
|
|
|
/* first reset the value channel */
|
|
|
|
switch (value & 0xF)
|
2004-06-28 01:30:55 +08:00
|
|
|
{
|
2007-11-22 17:45:40 +08:00
|
|
|
case PICK_LOW_INPUT:
|
2004-06-28 01:30:55 +08:00
|
|
|
tool->levels->low_input[GIMP_HISTOGRAM_VALUE] = 0;
|
|
|
|
break;
|
2007-11-22 17:45:40 +08:00
|
|
|
case PICK_GAMMA:
|
2004-06-28 01:30:55 +08:00
|
|
|
tool->levels->gamma[GIMP_HISTOGRAM_VALUE] = 1.0;
|
|
|
|
break;
|
2007-11-22 17:45:40 +08:00
|
|
|
case PICK_HIGH_INPUT:
|
2004-06-28 01:30:55 +08:00
|
|
|
tool->levels->high_input[GIMP_HISTOGRAM_VALUE] = 255;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-03-17 01:00:40 +08:00
|
|
|
|
|
|
|
/* then adjust all color channels */
|
|
|
|
for (channel = GIMP_HISTOGRAM_RED;
|
2004-06-28 01:30:55 +08:00
|
|
|
channel <= GIMP_HISTOGRAM_BLUE;
|
|
|
|
channel++)
|
|
|
|
{
|
|
|
|
levels_input_adjust_by_color (tool->levels,
|
2003-06-06 02:47:23 +08:00
|
|
|
value, channel, col);
|
2004-06-28 01:30:55 +08:00
|
|
|
}
|
2003-03-17 01:00:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
levels_input_adjust_by_color (tool->levels,
|
|
|
|
value, tool->channel, col);
|
2003-03-15 23:02:36 +08:00
|
|
|
}
|
|
|
|
|
2007-11-22 17:45:40 +08:00
|
|
|
levels_update_adjustments (tool);
|
2003-03-15 23:02:36 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
|
2003-03-15 23:02:36 +08:00
|
|
|
}
|