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"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2001-02-04 12:51:17 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2003-06-06 04:29:03 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.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
|
|
|
|
2003-12-12 07:35:17 +08:00
|
|
|
#include "config/gimpbaseconfig.h"
|
2004-06-13 10:08:54 +08:00
|
|
|
#include "config/gimpguiconfig.h"
|
2003-12-12 07:35:17 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
#include "base/curves.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "base/gimphistogram.h"
|
|
|
|
#include "base/gimplut.h"
|
|
|
|
|
2003-12-12 07:35:17 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
2003-12-12 07:35:17 +08:00
|
|
|
#include "core/gimpdrawable-histogram.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "core/gimpimage.h"
|
2002-08-26 19:35:56 +08:00
|
|
|
#include "core/gimpimagemap.h"
|
2003-05-26 01:16:59 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2004-02-20 03:56:04 +08:00
|
|
|
#include "widgets/gimpcolorbar.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "widgets/gimpcursor.h"
|
2004-04-18 23:12:42 +08:00
|
|
|
#include "widgets/gimpenumcombobox.h"
|
2004-04-19 06:38:45 +08:00
|
|
|
#include "widgets/gimpenumstore.h"
|
2004-04-18 23:12:42 +08:00
|
|
|
#include "widgets/gimpenumwidgets.h"
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2003-12-12 07:35:17 +08:00
|
|
|
#include "widgets/gimphistogramview.h"
|
2004-03-05 18:03:07 +08:00
|
|
|
#include "widgets/gimppropwidgets.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "gimpcurvestool.h"
|
2003-12-12 08:17:04 +08:00
|
|
|
#include "gimphistogramoptions.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"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2004-02-20 03:56:04 +08:00
|
|
|
#define XRANGE (1 << 0)
|
|
|
|
#define YRANGE (1 << 1)
|
2004-02-21 20:25:09 +08:00
|
|
|
#define GRAPH (1 << 2)
|
|
|
|
#define ALL (XRANGE | YRANGE | GRAPH)
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
#define GRAPH_SIZE 256
|
|
|
|
#define BAR_SIZE 12
|
|
|
|
#define RADIUS 3
|
|
|
|
#define MIN_DISTANCE 8
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2004-01-22 00:07:48 +08:00
|
|
|
static void gimp_curves_tool_class_init (GimpCurvesToolClass *klass);
|
2004-02-21 20:25:09 +08:00
|
|
|
static void gimp_curves_tool_init (GimpCurvesTool *tool);
|
2004-01-22 00:07:48 +08:00
|
|
|
|
|
|
|
static void gimp_curves_tool_finalize (GObject *object);
|
|
|
|
|
|
|
|
static gboolean gimp_curves_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_curves_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
|
|
|
|
static void gimp_curves_tool_color_picked (GimpColorTool *color_tool,
|
|
|
|
GimpImageType sample_type,
|
|
|
|
GimpRGB *color,
|
|
|
|
gint color_index);
|
|
|
|
static void gimp_curves_tool_map (GimpImageMapTool *image_map_tool);
|
|
|
|
static void gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool);
|
|
|
|
static void gimp_curves_tool_reset (GimpImageMapTool *image_map_tool);
|
2004-02-25 21:55:45 +08:00
|
|
|
static gboolean gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
|
|
|
|
gpointer fp);
|
|
|
|
static gboolean gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
|
|
|
|
gpointer fp);
|
2004-01-22 00:07:48 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
static void curves_add_point (GimpCurvesTool *tool,
|
2004-01-22 00:07:48 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint cchan);
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
static void curves_update (GimpCurvesTool *tool,
|
2004-01-22 00:07:48 +08:00
|
|
|
gint update);
|
|
|
|
|
|
|
|
static void curves_channel_callback (GtkWidget *widget,
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool);
|
2004-01-22 00:07:48 +08:00
|
|
|
static void curves_channel_reset_callback (GtkWidget *widget,
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool);
|
2004-01-22 00:07:48 +08:00
|
|
|
|
2004-04-19 06:38:45 +08:00
|
|
|
static gboolean curves_menu_visible_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
2004-01-22 00:07:48 +08:00
|
|
|
static void curves_curve_type_callback (GtkWidget *widget,
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool);
|
2004-01-22 00:07:48 +08:00
|
|
|
static gboolean curves_graph_events (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool);
|
2004-01-22 00:07:48 +08:00
|
|
|
static gboolean curves_graph_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *eevent,
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool);
|
2004-06-23 05:09:26 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
static GimpImageMapToolClass *parent_class = NULL;
|
|
|
|
|
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-03-29 11:50:29 +08:00
|
|
|
gimp_curves_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_CURVES_TOOL,
|
2003-12-12 08:17:04 +08:00
|
|
|
GIMP_TYPE_HISTOGRAM_OPTIONS,
|
2003-12-12 18:53:41 +08:00
|
|
|
gimp_color_options_gui,
|
2003-06-28 19:20:37 +08:00
|
|
|
0,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-curves-tool",
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Curves"),
|
|
|
|
_("Adjust color curves"),
|
2004-04-29 21:19:28 +08:00
|
|
|
N_("_Curves..."), NULL,
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_CURVES,
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_CURVES,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2001-05-25 07:57:08 +08:00
|
|
|
gimp_curves_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static GType tool_type = 0;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpCurvesToolClass),
|
2004-06-23 05:09:26 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_curves_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpCurvesTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_curves_tool_init,
|
2001-05-25 07:57:08 +08:00
|
|
|
};
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_IMAGE_MAP_TOOL,
|
2004-06-23 05:09:26 +08:00
|
|
|
"GimpCurvesTool",
|
2001-08-14 22:53:55 +08:00
|
|
|
&tool_info, 0);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
static void
|
|
|
|
gimp_curves_tool_class_init (GimpCurvesToolClass *klass)
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpToolClass *tool_class;
|
2003-06-06 04:29:03 +08:00
|
|
|
GimpColorToolClass *color_tool_class;
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpImageMapToolClass *image_map_tool_class;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
2003-06-06 04:29:03 +08:00
|
|
|
color_tool_class = GIMP_COLOR_TOOL_CLASS (klass);
|
2002-08-26 19:35:56 +08:00
|
|
|
image_map_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2004-02-25 18:23:43 +08:00
|
|
|
object_class->finalize = gimp_curves_tool_finalize;
|
|
|
|
|
|
|
|
tool_class->initialize = gimp_curves_tool_initialize;
|
|
|
|
tool_class->button_release = gimp_curves_tool_button_release;
|
|
|
|
|
|
|
|
color_tool_class->picked = gimp_curves_tool_color_picked;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-02-25 21:55:45 +08:00
|
|
|
image_map_tool_class->shell_desc = _("Adjust Color Curves");
|
|
|
|
image_map_tool_class->settings_name = "curves";
|
|
|
|
image_map_tool_class->load_dialog_title = _("Load Curves");
|
|
|
|
image_map_tool_class->save_dialog_title = _("Save Curves");
|
2003-06-06 04:29:03 +08:00
|
|
|
|
2004-02-25 21:55:45 +08:00
|
|
|
image_map_tool_class->map = gimp_curves_tool_map;
|
|
|
|
image_map_tool_class->dialog = gimp_curves_tool_dialog;
|
|
|
|
image_map_tool_class->reset = gimp_curves_tool_reset;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-02-25 21:55:45 +08:00
|
|
|
image_map_tool_class->settings_load = gimp_curves_tool_settings_load;
|
|
|
|
image_map_tool_class->settings_save = gimp_curves_tool_settings_save;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_curves_tool_init (GimpCurvesTool *tool)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2004-02-25 21:55:45 +08:00
|
|
|
gint i;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->curves = g_new0 (Curves, 1);
|
|
|
|
tool->lut = gimp_lut_new ();
|
|
|
|
tool->channel = GIMP_HISTOGRAM_VALUE;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_init (tool->curves);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (tool->col_value); i++)
|
|
|
|
tool->col_value[i] = -1;
|
2003-03-14 21:42:39 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->cursor_x = -1;
|
|
|
|
tool->cursor_y = -1;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_curves_tool_finalize (GObject *object)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool = GIMP_CURVES_TOOL (object);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->curves)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
g_free (tool->curves);
|
|
|
|
tool->curves = NULL;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->lut)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_lut_free (tool->lut);
|
|
|
|
tool->lut = NULL;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->hist)
|
2003-12-12 07:35:17 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_histogram_free (tool->hist);
|
|
|
|
tool->hist = NULL;
|
2003-12-12 07:35:17 +08:00
|
|
|
}
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->cursor_layout)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
g_object_unref (tool->cursor_layout);
|
|
|
|
tool->cursor_layout = NULL;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->xpos_layout)
|
2002-08-26 19:35:56 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
g_object_unref (tool->xpos_layout);
|
|
|
|
tool->xpos_layout = NULL;
|
2002-08-26 19:35:56 +08:00
|
|
|
}
|
2001-05-25 07:57:08 +08:00
|
|
|
|
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
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_curves_tool_initialize (GimpTool *tool,
|
2004-06-23 05:09:26 +08:00
|
|
|
GimpDisplay *gdisp)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2003-11-13 19:23:01 +08:00
|
|
|
GimpCurvesTool *c_tool = GIMP_CURVES_TOOL (tool);
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
2003-11-13 19:23:01 +08:00
|
|
|
drawable = gimp_image_active_drawable (gdisp->gimage);
|
|
|
|
|
|
|
|
if (! drawable)
|
2004-01-22 00:07:48 +08:00
|
|
|
return FALSE;
|
2002-08-29 03:47:07 +08:00
|
|
|
|
2003-11-13 19:23:01 +08:00
|
|
|
if (gimp_drawable_is_indexed (drawable))
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2003-11-13 19:23:01 +08:00
|
|
|
g_message (_("Curves for indexed layers cannot be adjusted."));
|
2004-01-22 00:07:48 +08:00
|
|
|
return FALSE;
|
2002-08-26 19:35:56 +08:00
|
|
|
}
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2003-12-12 07:35:17 +08:00
|
|
|
if (! c_tool->hist)
|
|
|
|
{
|
|
|
|
Gimp *gimp = GIMP_TOOL (c_tool)->tool_info->gimp;
|
|
|
|
|
|
|
|
c_tool->hist = gimp_histogram_new (GIMP_BASE_CONFIG (gimp->config));
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_init (c_tool->curves);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->channel = GIMP_HISTOGRAM_VALUE;
|
2004-01-25 02:35:49 +08:00
|
|
|
c_tool->color = gimp_drawable_is_rgb (drawable);
|
|
|
|
c_tool->alpha = gimp_drawable_has_alpha (drawable);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
c_tool->grab_point = -1;
|
|
|
|
c_tool->last = 0;
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
|
|
|
|
|
2003-06-06 04:29:03 +08:00
|
|
|
/* always pick colors */
|
|
|
|
gimp_color_tool_enable (GIMP_COLOR_TOOL (tool),
|
|
|
|
GIMP_COLOR_OPTIONS (tool->tool_info->tool_options));
|
|
|
|
|
2004-04-19 06:38:45 +08:00
|
|
|
gimp_enum_combo_box_set_visible (GIMP_ENUM_COMBO_BOX (c_tool->channel_menu),
|
|
|
|
curves_menu_visible_func, c_tool);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-04-21 03:06:37 +08:00
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (c_tool->channel_menu),
|
|
|
|
c_tool->channel);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2004-06-28 22:24:56 +08:00
|
|
|
/* FIXME: hack */
|
|
|
|
if (! c_tool->color)
|
|
|
|
c_tool->channel = (c_tool->channel == GIMP_HISTOGRAM_ALPHA) ? 1 : 0;
|
2004-01-25 02:35:49 +08:00
|
|
|
|
2003-12-12 07:35:17 +08:00
|
|
|
gimp_drawable_calculate_histogram (drawable, c_tool->hist);
|
|
|
|
gimp_histogram_view_set_histogram (GIMP_HISTOGRAM_VIEW (c_tool->graph),
|
|
|
|
c_tool->hist);
|
2004-01-22 00:07:48 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_update (c_tool, ALL);
|
|
|
|
|
2004-01-22 00:07:48 +08:00
|
|
|
return TRUE;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_curves_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
2004-06-23 05:09:26 +08:00
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2003-11-13 19:23:01 +08:00
|
|
|
GimpCurvesTool *c_tool = GIMP_CURVES_TOOL (tool);
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpDrawable *drawable;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
drawable = gimp_image_active_drawable (gdisp->gimage);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
if (state & GDK_SHIFT_MASK)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-29 03:47:07 +08:00
|
|
|
curves_add_point (c_tool, coords->x, coords->y, c_tool->channel);
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_calculate_curve (c_tool->curves, c_tool->channel);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
2001-11-09 03:14:51 +08:00
|
|
|
else if (state & GDK_CONTROL_MASK)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-29 03:47:07 +08:00
|
|
|
gint i;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2002-08-29 03:47:07 +08:00
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
curves_add_point (c_tool, coords->x, coords->y, i);
|
|
|
|
curves_calculate_curve (c_tool->curves, c_tool->channel);
|
|
|
|
}
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2003-06-06 04:29:03 +08:00
|
|
|
/* chain up to halt the tool */
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->button_release (tool,
|
|
|
|
coords, time, state, gdisp);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-06 04:29:03 +08:00
|
|
|
gimp_curves_tool_color_picked (GimpColorTool *color_tool,
|
2004-06-23 05:09:26 +08:00
|
|
|
GimpImageType sample_type,
|
|
|
|
GimpRGB *color,
|
|
|
|
gint color_index)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2004-06-28 22:24:56 +08:00
|
|
|
GimpCurvesTool *tool = GIMP_CURVES_TOOL (color_tool);
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpDrawable *drawable;
|
2003-06-06 04:29:03 +08:00
|
|
|
guchar r, g, b, a;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
drawable = GIMP_IMAGE_MAP_TOOL (tool)->drawable;
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2003-06-06 04:29:03 +08:00
|
|
|
gimp_rgba_get_uchar (color, &r, &g, &b, &a);
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->col_value[GIMP_HISTOGRAM_RED] = r;
|
|
|
|
tool->col_value[GIMP_HISTOGRAM_GREEN] = g;
|
|
|
|
tool->col_value[GIMP_HISTOGRAM_BLUE] = b;
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2003-06-06 04:29:03 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->col_value[GIMP_HISTOGRAM_ALPHA] = a;
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2003-06-06 04:29:03 +08:00
|
|
|
if (gimp_drawable_is_indexed (drawable))
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->col_value[GIMP_HISTOGRAM_ALPHA] = color_index;
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->col_value[GIMP_HISTOGRAM_VALUE] = MAX (MAX (r, g), b);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_update (tool, GRAPH);
|
1999-05-14 06:53:40 +08:00
|
|
|
}
|
1999-04-08 06:02:26 +08:00
|
|
|
|
1999-05-14 06:53:40 +08:00
|
|
|
static void
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_add_point (GimpCurvesTool *tool,
|
2004-06-23 05:09:26 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint cchan)
|
1999-05-14 06:53:40 +08:00
|
|
|
{
|
|
|
|
/* Add point onto the curve */
|
2000-12-14 02:53:35 +08:00
|
|
|
gint closest_point = 0;
|
|
|
|
gint distance;
|
|
|
|
gint curvex;
|
|
|
|
gint i;
|
1999-05-14 06:53:40 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
switch (tool->curves->curve_type[cchan])
|
1999-05-14 06:53:40 +08:00
|
|
|
{
|
2003-03-15 03:58:59 +08:00
|
|
|
case GIMP_CURVE_SMOOTH:
|
2004-02-21 20:25:09 +08:00
|
|
|
curvex = tool->col_value[cchan];
|
1999-09-04 05:58:41 +08:00
|
|
|
distance = G_MAXINT;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
1999-09-04 05:58:41 +08:00
|
|
|
for (i = 0; i < 17; i++)
|
2004-06-23 05:09:26 +08:00
|
|
|
{
|
|
|
|
if (tool->curves->points[cchan][i][0] != -1)
|
|
|
|
if (abs (curvex - tool->curves->points[cchan][i][0]) < distance)
|
|
|
|
{
|
|
|
|
distance = abs (curvex - tool->curves->points[cchan][i][0]);
|
|
|
|
closest_point = i;
|
|
|
|
}
|
|
|
|
}
|
2003-07-10 20:13:21 +08:00
|
|
|
|
1999-09-04 05:58:41 +08:00
|
|
|
if (distance > MIN_DISTANCE)
|
2004-06-23 05:09:26 +08:00
|
|
|
closest_point = (curvex + 8) / 16;
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->curves->points[cchan][closest_point][0] = curvex;
|
|
|
|
tool->curves->points[cchan][closest_point][1] = tool->curves->curve[cchan][curvex];
|
1999-09-04 05:58:41 +08:00
|
|
|
break;
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2003-03-15 03:58:59 +08:00
|
|
|
case GIMP_CURVE_FREE:
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->curves->curve[cchan][x] = 255 - y;
|
1999-09-04 05:58:41 +08:00
|
|
|
break;
|
1999-05-14 06:53:40 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static void
|
|
|
|
gimp_curves_tool_map (GimpImageMapTool *image_map_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
|
1999-06-23 23:24:46 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_lut_setup (tool->lut,
|
2004-06-23 05:09:26 +08:00
|
|
|
(GimpLutFunc) curves_lut_func,
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->curves,
|
2004-06-23 05:09:26 +08:00
|
|
|
gimp_drawable_bytes (image_map_tool->drawable));
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_image_map_apply (image_map_tool->image_map,
|
|
|
|
(GimpImageMapApplyFunc) gimp_lut_process_2,
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->lut);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
|
1999-07-03 01:40:10 +08:00
|
|
|
/*******************/
|
|
|
|
/* Curves dialog */
|
|
|
|
/*******************/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static void
|
|
|
|
gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
|
2003-12-12 08:17:04 +08:00
|
|
|
GimpToolOptions *tool_options;
|
|
|
|
GtkWidget *vbox;
|
2004-02-21 20:25:09 +08:00
|
|
|
GtkWidget *vbox2;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *hbox2;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *bbox;
|
2003-12-12 08:17:04 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *button;
|
2004-02-20 03:56:04 +08:00
|
|
|
GtkWidget *bar;
|
2004-02-21 20:25:09 +08:00
|
|
|
gint padding;
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2004-03-05 09:31:33 +08:00
|
|
|
tool_options = GIMP_TOOL (tool)->tool_info->tool_options;
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
vbox = image_map_tool->main_vbox;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* The option menu for selecting channels */
|
2004-06-03 01:56:02 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Channel:"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2004-04-18 23:12:42 +08:00
|
|
|
menu = gimp_enum_combo_box_new (GIMP_TYPE_HISTOGRAM_CHANNEL);
|
|
|
|
g_signal_connect (menu, "changed",
|
|
|
|
G_CALLBACK (curves_channel_callback),
|
|
|
|
tool);
|
|
|
|
gimp_enum_combo_box_set_stock_prefix (GIMP_ENUM_COMBO_BOX (menu),
|
|
|
|
"gimp-channel");
|
2003-03-25 02:04:11 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), menu, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (menu);
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->channel_menu = menu;
|
2001-11-24 07:04:49 +08:00
|
|
|
|
2004-06-24 04:29:46 +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);
|
1999-09-28 01:58:10 +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 (curves_channel_reset_callback),
|
2004-02-21 20:25:09 +08:00
|
|
|
tool);
|
1997-11-25 06:05:25 +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);
|
2002-10-14 21:39:35 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
/* The table for the color bars and the graph */
|
1997-11-25 06:05:25 +08:00
|
|
|
table = gtk_table_new (2, 2, FALSE);
|
1999-11-22 19:14:29 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
/* The left color bar */
|
|
|
|
vbox2 = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), vbox2, 0, 1, 0, 1,
|
2004-06-23 05:09:26 +08:00
|
|
|
GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_widget_show (vbox2);
|
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);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), frame, TRUE, TRUE, RADIUS);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->yrange = gimp_color_bar_new (GTK_ORIENTATION_VERTICAL);
|
|
|
|
gtk_widget_set_size_request (tool->yrange, BAR_SIZE, -1);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), tool->yrange);
|
|
|
|
gtk_widget_show (tool->yrange);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* The curves graph */
|
|
|
|
frame = gtk_frame_new (NULL);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_table_attach (GTK_TABLE (table), frame, 1, 2, 0, 1,
|
2004-06-23 05:09:26 +08:00
|
|
|
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (frame);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->graph = gimp_histogram_view_new (FALSE);
|
|
|
|
gtk_widget_set_size_request (tool->graph,
|
|
|
|
GRAPH_SIZE + RADIUS * 2,
|
|
|
|
GRAPH_SIZE + RADIUS * 2);
|
|
|
|
gtk_widget_add_events (tool->graph, (GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK |
|
|
|
|
GDK_LEAVE_NOTIFY_MASK));
|
|
|
|
g_object_set (tool->graph,
|
2003-12-12 07:35:17 +08:00
|
|
|
"border-width", RADIUS,
|
|
|
|
"subdivisions", 1,
|
|
|
|
NULL);
|
2004-02-21 20:25:09 +08:00
|
|
|
GIMP_HISTOGRAM_VIEW (tool->graph)->light_histogram = TRUE;
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), tool->graph);
|
|
|
|
gtk_widget_show (tool->graph);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
g_signal_connect (tool->graph, "event",
|
2004-06-23 05:09:26 +08:00
|
|
|
G_CALLBACK (curves_graph_events),
|
|
|
|
tool);
|
2004-02-21 20:25:09 +08:00
|
|
|
g_signal_connect_after (tool->graph, "expose_event",
|
2003-12-12 07:35:17 +08:00
|
|
|
G_CALLBACK (curves_graph_expose),
|
2004-02-21 20:25:09 +08:00
|
|
|
tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-12-12 08:17:04 +08:00
|
|
|
|
|
|
|
gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options),
|
2004-02-21 20:25:09 +08:00
|
|
|
GIMP_HISTOGRAM_VIEW (tool->graph));
|
|
|
|
|
|
|
|
/* The bottom color bar */
|
|
|
|
hbox2 = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), hbox2, 1, 2, 1, 2,
|
2004-06-23 05:09:26 +08:00
|
|
|
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_widget_show (hbox2);
|
2003-12-12 08:17:04 +08:00
|
|
|
|
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);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox2), frame, TRUE, TRUE, RADIUS);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2004-02-20 03:56:04 +08:00
|
|
|
vbox2 = gtk_vbox_new (TRUE, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox2);
|
|
|
|
gtk_widget_show (vbox2);
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->xrange = gimp_color_bar_new (GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
gtk_widget_set_size_request (tool->xrange, -1, BAR_SIZE / 2);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), tool->xrange, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (tool->xrange);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2004-02-20 03:56:04 +08:00
|
|
|
bar = gimp_color_bar_new (GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox2), bar, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (bar);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (table);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
|
2003-03-15 07:24:37 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2003-03-15 07:24:37 +08:00
|
|
|
/* Horizontal button box for load / save */
|
2004-05-05 06:33:52 +08:00
|
|
|
frame = gimp_frame_new (_("All Channels"));
|
2003-03-15 07:24:37 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
|
2002-08-29 03:47:07 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
bbox = gtk_hbutton_box_new ();
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (bbox), 2);
|
|
|
|
gtk_box_set_spacing (GTK_BOX (bbox), 4);
|
|
|
|
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_SPREAD);
|
2004-06-23 05:09:26 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), bbox);
|
2004-02-21 20:25:09 +08:00
|
|
|
gtk_widget_show (bbox);
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2004-02-25 21:55:45 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (bbox), image_map_tool->load_button,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gimp_help_set_help_data (image_map_tool->load_button,
|
|
|
|
_("Read curves settings from file"), NULL);
|
|
|
|
gtk_widget_show (image_map_tool->load_button);
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2004-02-25 21:55:45 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (bbox), image_map_tool->save_button,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gimp_help_set_help_data (image_map_tool->save_button,
|
|
|
|
_("Save curves settings to file"), NULL);
|
|
|
|
gtk_widget_show (image_map_tool->save_button);
|
2003-03-15 07:24:37 +08:00
|
|
|
|
|
|
|
/* The radio box for selecting the curve type */
|
2004-05-05 06:33:52 +08:00
|
|
|
frame = gimp_frame_new (_("Curve Type"));
|
2003-03-15 07:24:37 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
hbox = gimp_enum_stock_box_new (GIMP_TYPE_CURVE_TYPE,
|
2004-06-23 05:09:26 +08:00
|
|
|
"gimp-curve", GTK_ICON_SIZE_MENU,
|
|
|
|
G_CALLBACK (curves_curve_type_callback),
|
|
|
|
tool,
|
|
|
|
&tool->curve_type);
|
2004-02-21 20:25:09 +08:00
|
|
|
|
|
|
|
gtk_widget_style_get (bbox, "child_internal_pad_x", &padding, NULL);
|
|
|
|
|
|
|
|
gimp_enum_stock_box_set_child_padding (hbox, padding, -1);
|
2003-03-15 07:24:37 +08:00
|
|
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
|
|
|
|
gtk_box_set_spacing (GTK_BOX (hbox), 4);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), hbox);
|
|
|
|
gtk_widget_show (hbox);
|
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_curves_tool_reset (GimpImageMapTool *image_map_tool)
|
2001-10-17 19:33:43 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
|
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;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->grab_point = -1;
|
2002-08-26 19:35:56 +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++)
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_channel_reset (tool->curves, channel);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_update (tool, XRANGE | GRAPH);
|
2001-10-17 19:33:43 +08:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:23:43 +08:00
|
|
|
static gboolean
|
2004-02-25 21:55:45 +08:00
|
|
|
gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
|
|
|
|
gpointer fp)
|
2004-02-25 18:23:43 +08:00
|
|
|
{
|
2004-02-25 21:55:45 +08:00
|
|
|
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
|
|
|
|
FILE *file = fp;
|
|
|
|
gint i, j;
|
|
|
|
gint fields;
|
|
|
|
gchar buf[50];
|
|
|
|
gint index[5][17];
|
|
|
|
gint value[5][17];
|
|
|
|
|
|
|
|
if (! fgets (buf, sizeof (buf), file))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (strcmp (buf, "# GIMP Curves File\n") != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < 17; j++)
|
2004-06-23 05:09:26 +08:00
|
|
|
{
|
|
|
|
fields = fscanf (file, "%d %d ", &index[i][j], &value[i][j]);
|
|
|
|
if (fields != 2)
|
|
|
|
{
|
2004-03-12 21:50:36 +08:00
|
|
|
/* FIXME: should have a helpful error message here */
|
2004-06-23 05:09:26 +08:00
|
|
|
g_printerr ("fields != 2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2004-02-25 21:55:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
tool->curves->curve_type[i] = GIMP_CURVE_SMOOTH;
|
|
|
|
|
|
|
|
for (j = 0; j < 17; j++)
|
2004-06-23 05:09:26 +08:00
|
|
|
{
|
|
|
|
tool->curves->points[i][j][0] = index[i][j];
|
|
|
|
tool->curves->points[i][j][1] = value[i][j];
|
|
|
|
}
|
2004-02-25 21:55:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
curves_calculate_curve (tool->curves, i);
|
|
|
|
|
|
|
|
curves_update (tool, ALL);
|
|
|
|
|
|
|
|
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (tool->curve_type),
|
2004-06-23 05:09:26 +08:00
|
|
|
GIMP_CURVE_SMOOTH);
|
2004-02-25 21:55:45 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2004-02-25 18:23:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-02-25 21:55:45 +08:00
|
|
|
gimp_curves_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
|
|
|
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
|
|
|
|
FILE *file = fp;
|
|
|
|
gint i, j;
|
|
|
|
gint32 index;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
if (tool->curves->curve_type[i] == GIMP_CURVE_FREE)
|
|
|
|
{
|
2004-06-23 05:09:26 +08:00
|
|
|
/* pick representative points from the curve
|
2004-02-25 21:55:45 +08:00
|
|
|
and make them control points */
|
2004-06-23 05:09:26 +08:00
|
|
|
for (j = 0; j <= 8; j++)
|
|
|
|
{
|
|
|
|
index = CLAMP0255 (j * 32);
|
|
|
|
tool->curves->points[i][j * 2][0] = index;
|
|
|
|
tool->curves->points[i][j * 2][1] = tool->curves->curve[i][index];
|
|
|
|
}
|
2004-02-25 21:55:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf (file, "# GIMP Curves File\n");
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < 17; j++)
|
2004-06-23 05:09:26 +08:00
|
|
|
fprintf (file, "%d %d ",
|
2004-02-25 21:55:45 +08:00
|
|
|
tool->curves->points[i][j][0],
|
|
|
|
tool->curves->points[i][j][1]);
|
|
|
|
|
|
|
|
fprintf (file, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2004-02-25 18:23:43 +08:00
|
|
|
}
|
1999-09-04 05:58:41 +08:00
|
|
|
|
1999-05-20 23:43:56 +08:00
|
|
|
/* TODO: preview alpha channel stuff correctly. -- austin, 20/May/99 */
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_update (GimpCurvesTool *tool,
|
2004-06-23 05:09:26 +08:00
|
|
|
gint update)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-20 03:56:04 +08:00
|
|
|
GimpHistogramChannel channel;
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->color)
|
2002-05-03 19:31:08 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
channel = tool->channel;
|
2002-08-29 03:47:07 +08:00
|
|
|
}
|
2003-07-10 20:13:21 +08:00
|
|
|
else
|
2002-05-03 19:31:08 +08:00
|
|
|
{
|
2004-06-28 22:24:56 +08:00
|
|
|
/* FIXME: hack */
|
|
|
|
if (tool->channel == 1)
|
2004-02-20 03:56:04 +08:00
|
|
|
channel = GIMP_HISTOGRAM_ALPHA;
|
2002-05-03 19:31:08 +08:00
|
|
|
else
|
2004-02-20 03:56:04 +08:00
|
|
|
channel = GIMP_HISTOGRAM_VALUE;
|
2002-05-03 19:31:08 +08:00
|
|
|
}
|
2000-12-01 07:23:59 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (update & GRAPH)
|
|
|
|
gtk_widget_queue_draw (tool->graph);
|
|
|
|
|
2004-02-20 03:56:04 +08:00
|
|
|
if (update & XRANGE)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-20 03:56:04 +08:00
|
|
|
switch (channel)
|
2004-06-23 05:09:26 +08:00
|
|
|
{
|
|
|
|
case GIMP_HISTOGRAM_VALUE:
|
|
|
|
case GIMP_HISTOGRAM_ALPHA:
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->xrange),
|
2004-06-28 22:24:56 +08:00
|
|
|
tool->curves->curve[tool->channel],
|
|
|
|
tool->curves->curve[tool->channel],
|
|
|
|
tool->curves->curve[tool->channel]);
|
2004-06-23 05:09:26 +08:00
|
|
|
break;
|
1999-05-20 23:43:56 +08:00
|
|
|
|
2004-06-23 05:09:26 +08:00
|
|
|
case GIMP_HISTOGRAM_RED:
|
|
|
|
case GIMP_HISTOGRAM_GREEN:
|
|
|
|
case GIMP_HISTOGRAM_BLUE:
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->xrange),
|
|
|
|
tool->curves->curve[GIMP_HISTOGRAM_RED],
|
|
|
|
tool->curves->curve[GIMP_HISTOGRAM_GREEN],
|
|
|
|
tool->curves->curve[GIMP_HISTOGRAM_BLUE]);
|
2004-06-23 05:09:26 +08:00
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (update & YRANGE)
|
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_color_bar_set_channel (GIMP_COLOR_BAR (tool->yrange), channel);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-12-18 23:57:25 +08:00
|
|
|
curves_channel_callback (GtkWidget *widget,
|
2004-06-23 05:09:26 +08:00
|
|
|
GimpCurvesTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-04-21 03:06:37 +08:00
|
|
|
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget),
|
|
|
|
(gint *) &tool->channel);
|
|
|
|
gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->graph),
|
|
|
|
tool->channel);
|
2004-01-13 19:51:45 +08:00
|
|
|
|
2004-04-21 03:06:37 +08:00
|
|
|
/* FIXME: hack */
|
2004-06-28 22:24:56 +08:00
|
|
|
if (! tool->color)
|
|
|
|
tool->channel = (tool->channel == GIMP_HISTOGRAM_ALPHA) ? 1 : 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (tool->curve_type),
|
2004-04-18 23:12:42 +08:00
|
|
|
tool->curves->curve_type[tool->channel]);
|
1999-02-16 16:53:54 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_update (tool, ALL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-12-18 23:57:25 +08:00
|
|
|
curves_channel_reset_callback (GtkWidget *widget,
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->grab_point = -1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_channel_reset (tool->curves, tool->channel);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_update (tool, XRANGE | GRAPH);
|
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-03-18 00:35:05 +08:00
|
|
|
static gboolean
|
2004-04-19 06:38:45 +08:00
|
|
|
curves_menu_visible_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
2002-03-18 00:35:05 +08:00
|
|
|
{
|
2004-04-19 06:38:45 +08:00
|
|
|
GimpCurvesTool *tool = GIMP_CURVES_TOOL (data);
|
|
|
|
GimpHistogramChannel channel;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
2004-04-21 03:06:37 +08:00
|
|
|
GIMP_INT_STORE_VALUE, &channel,
|
2004-04-19 06:38:45 +08:00
|
|
|
-1);
|
|
|
|
|
2002-03-18 00:35:05 +08:00
|
|
|
switch (channel)
|
|
|
|
{
|
|
|
|
case GIMP_HISTOGRAM_VALUE:
|
|
|
|
return TRUE;
|
2004-01-25 02:35:49 +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;
|
2004-01-25 02:35:49 +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;
|
2002-03-18 00:35:05 +08:00
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2002-03-18 00:35:05 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2003-03-15 07:24:37 +08:00
|
|
|
curves_curve_type_callback (GtkWidget *widget,
|
2004-06-23 05:09:26 +08:00
|
|
|
GimpCurvesTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-03-15 03:58:59 +08:00
|
|
|
GimpCurveType curve_type;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-15 07:24:37 +08:00
|
|
|
gimp_radio_button_update (widget, &curve_type);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->curves->curve_type[tool->channel] != curve_type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->curves->curve_type[tool->channel] = curve_type;
|
2003-03-15 03:58:59 +08:00
|
|
|
|
|
|
|
if (curve_type == GIMP_CURVE_SMOOTH)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gint32 index;
|
|
|
|
|
|
|
|
/* pick representative points from the curve
|
|
|
|
* and make them control points
|
|
|
|
*/
|
|
|
|
for (i = 0; i <= 8; i++)
|
|
|
|
{
|
|
|
|
index = CLAMP0255 (i * 32);
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->curves->points[tool->channel][i * 2][0] = index;
|
|
|
|
tool->curves->points[tool->channel][i * 2][1] = tool->curves->curve[tool->channel][index];
|
2003-03-15 03:58:59 +08:00
|
|
|
}
|
|
|
|
}
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_calculate_curve (tool->curves, tool->channel);
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_update (tool, XRANGE | GRAPH);
|
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));
|
2000-05-09 13:43:29 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static gboolean
|
|
|
|
curves_graph_events (GtkWidget *widget,
|
2004-06-23 05:09:26 +08:00
|
|
|
GdkEvent *event,
|
|
|
|
GimpCurvesTool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-06-14 18:19:39 +08:00
|
|
|
static GimpCursorType cursor_type = GDK_TOP_LEFT_ARROW;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2004-06-14 18:19:39 +08:00
|
|
|
GimpCursorType new_cursor = GDK_X_CURSOR;
|
1997-11-25 06:05:25 +08:00
|
|
|
GdkEventButton *bevent;
|
|
|
|
GdkEventMotion *mevent;
|
2002-08-26 19:35:56 +08:00
|
|
|
gint i;
|
|
|
|
gint tx, ty;
|
|
|
|
gint x, y;
|
2004-02-21 20:25:09 +08:00
|
|
|
gint width, height;
|
2002-08-26 19:35:56 +08:00
|
|
|
gint closest_point;
|
|
|
|
gint distance;
|
|
|
|
gint x1, x2, y1, y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
width = widget->allocation.width - 2 * RADIUS;
|
|
|
|
height = widget->allocation.height - 2 * RADIUS;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* get the pointer position */
|
2004-02-21 20:25:09 +08:00
|
|
|
gdk_window_get_pointer (tool->graph->window, &tx, &ty, NULL);
|
|
|
|
|
|
|
|
x = ROUND (((gdouble) (tx - RADIUS) / (gdouble) width) * 255.0);
|
|
|
|
y = ROUND (((gdouble) (ty - RADIUS) / (gdouble) height) * 255.0);
|
|
|
|
|
|
|
|
x = CLAMP0255 (x);
|
|
|
|
y = CLAMP0255 (y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
distance = G_MAXINT;
|
2003-03-14 21:42:39 +08:00
|
|
|
for (i = 0, closest_point = 0; i < 17; i++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->curves->points[tool->channel][i][0] != -1)
|
2004-06-23 05:09:26 +08:00
|
|
|
if (abs (x - tool->curves->points[tool->channel][i][0]) < distance)
|
|
|
|
{
|
|
|
|
distance = abs (x - tool->curves->points[tool->channel][i][0]);
|
|
|
|
closest_point = i;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2004-02-21 20:25:09 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (distance > MIN_DISTANCE)
|
|
|
|
closest_point = (x + 8) / 16;
|
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
bevent = (GdkEventButton *) event;
|
2003-03-14 21:42:39 +08:00
|
|
|
|
2004-02-12 21:12:56 +08:00
|
|
|
if (bevent->button != 1)
|
|
|
|
return TRUE;
|
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
new_cursor = GDK_TCROSS;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
switch (tool->curves->curve_type[tool->channel])
|
2004-06-23 05:09:26 +08:00
|
|
|
{
|
|
|
|
case GIMP_CURVE_SMOOTH:
|
|
|
|
/* determine the leftmost and rightmost points */
|
|
|
|
tool->leftmost = -1;
|
|
|
|
for (i = closest_point - 1; i >= 0; i--)
|
|
|
|
if (tool->curves->points[tool->channel][i][0] != -1)
|
|
|
|
{
|
|
|
|
tool->leftmost = tool->curves->points[tool->channel][i][0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tool->rightmost = 256;
|
|
|
|
for (i = closest_point + 1; i < 17; i++)
|
|
|
|
if (tool->curves->points[tool->channel][i][0] != -1)
|
|
|
|
{
|
|
|
|
tool->rightmost = tool->curves->points[tool->channel][i][0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
tool->grab_point = closest_point;
|
|
|
|
tool->curves->points[tool->channel][tool->grab_point][0] = x;
|
|
|
|
tool->curves->points[tool->channel][tool->grab_point][1] = 255 - y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_CURVE_FREE:
|
|
|
|
tool->curves->curve[tool->channel][x] = 255 - y;
|
|
|
|
tool->grab_point = x;
|
|
|
|
tool->last = y;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_calculate_curve (tool->curves, tool->channel);
|
2004-01-29 21:59:14 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_update (tool, XRANGE | GRAPH);
|
2003-03-14 21:42:39 +08:00
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
case GDK_BUTTON_RELEASE:
|
2004-02-12 21:12:56 +08:00
|
|
|
bevent = (GdkEventButton *) event;
|
|
|
|
|
|
|
|
if (bevent->button != 1)
|
|
|
|
return TRUE;
|
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
new_cursor = GDK_FLEUR;
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->grab_point = -1;
|
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));
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
case GDK_MOTION_NOTIFY:
|
|
|
|
mevent = (GdkEventMotion *) event;
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
switch (tool->curves->curve_type[tool->channel])
|
2004-06-23 05:09:26 +08:00
|
|
|
{
|
|
|
|
case GIMP_CURVE_SMOOTH:
|
|
|
|
/* If no point is grabbed... */
|
|
|
|
if (tool->grab_point == -1)
|
|
|
|
{
|
|
|
|
if (tool->curves->points[tool->channel][closest_point][0] != -1)
|
|
|
|
new_cursor = GDK_FLEUR;
|
|
|
|
else
|
|
|
|
new_cursor = GDK_TCROSS;
|
|
|
|
}
|
|
|
|
/* Else, drag the grabbed point */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_cursor = GDK_TCROSS;
|
|
|
|
|
|
|
|
tool->curves->points[tool->channel][tool->grab_point][0] = -1;
|
|
|
|
|
|
|
|
if (x > tool->leftmost && x < tool->rightmost)
|
|
|
|
{
|
|
|
|
closest_point = (x + 8) / 16;
|
|
|
|
if (tool->curves->points[tool->channel][closest_point][0] == -1)
|
|
|
|
tool->grab_point = closest_point;
|
|
|
|
|
|
|
|
tool->curves->points[tool->channel][tool->grab_point][0] = x;
|
|
|
|
tool->curves->points[tool->channel][tool->grab_point][1] = 255 - y;
|
|
|
|
}
|
|
|
|
|
|
|
|
curves_calculate_curve (tool->curves, tool->channel);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_CURVE_FREE:
|
|
|
|
if (tool->grab_point != -1)
|
|
|
|
{
|
|
|
|
if (tool->grab_point > x)
|
|
|
|
{
|
|
|
|
x1 = x;
|
|
|
|
x2 = tool->grab_point;
|
|
|
|
y1 = y;
|
|
|
|
y2 = tool->last;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x1 = tool->grab_point;
|
|
|
|
x2 = x;
|
|
|
|
y1 = tool->last;
|
|
|
|
y2 = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x2 != x1)
|
|
|
|
for (i = x1; i <= x2; i++)
|
|
|
|
tool->curves->curve[tool->channel][i] = 255 - (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
|
|
|
|
else
|
|
|
|
tool->curves->curve[tool->channel][x] = 255 - y;
|
|
|
|
|
|
|
|
tool->grab_point = x;
|
|
|
|
tool->last = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mevent->state & GDK_BUTTON1_MASK)
|
|
|
|
new_cursor = GDK_TCROSS;
|
|
|
|
else
|
|
|
|
new_cursor = GDK_PENCIL;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
if (new_cursor != cursor_type)
|
2004-06-23 05:09:26 +08:00
|
|
|
{
|
|
|
|
cursor_type = new_cursor;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gimp_cursor_set (tool->graph,
|
2004-06-13 10:08:54 +08:00
|
|
|
GIMP_GUI_CONFIG (GIMP_TOOL (tool)->tool_info->gimp->config)->cursor_format,
|
2003-11-02 04:53:18 +08:00
|
|
|
cursor_type,
|
|
|
|
GIMP_TOOL_CURSOR_NONE,
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
2004-06-23 05:09:26 +08:00
|
|
|
}
|
1999-09-04 05:58:41 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->cursor_x = x;
|
|
|
|
tool->cursor_y = y;
|
2003-03-14 21:42:39 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_update (tool, XRANGE | GRAPH);
|
2003-03-14 21:42:39 +08:00
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-10-14 21:39:35 +08:00
|
|
|
case GDK_LEAVE_NOTIFY:
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->cursor_x = -1;
|
|
|
|
tool->cursor_y = -1;
|
2003-03-14 21:42:39 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curves_update (tool, GRAPH);
|
2003-03-14 21:42:39 +08:00
|
|
|
return TRUE;
|
2002-10-14 21:39:35 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
static void
|
2004-02-21 20:25:09 +08:00
|
|
|
curve_print_loc (GimpCurvesTool *tool)
|
2003-03-14 21:42:39 +08:00
|
|
|
{
|
|
|
|
gchar buf[32];
|
|
|
|
gint x, y;
|
|
|
|
gint w, h;
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->cursor_x < 0 || tool->cursor_x > 255 ||
|
|
|
|
tool->cursor_y < 0 || tool->cursor_y > 255)
|
2003-03-14 21:42:39 +08:00
|
|
|
return;
|
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (! tool->cursor_layout)
|
2003-03-14 21:42:39 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->cursor_layout = gtk_widget_create_pango_layout (tool->graph,
|
|
|
|
"x:888 y:888");
|
|
|
|
pango_layout_get_pixel_extents (tool->cursor_layout,
|
|
|
|
NULL, &tool->cursor_rect);
|
2003-03-14 21:42:39 +08:00
|
|
|
}
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
x = RADIUS * 2 + 2;
|
|
|
|
y = RADIUS * 2 + 2;
|
2004-02-21 20:25:09 +08:00
|
|
|
w = tool->cursor_rect.width + 4;
|
|
|
|
h = tool->cursor_rect.height + 4;
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gdk_draw_rectangle (tool->graph->window,
|
|
|
|
tool->graph->style->base_gc[GTK_STATE_ACTIVE],
|
2003-03-14 21:42:39 +08:00
|
|
|
TRUE,
|
|
|
|
x, y, w + 1, h + 1);
|
2004-02-21 20:25:09 +08:00
|
|
|
gdk_draw_rectangle (tool->graph->window,
|
|
|
|
tool->graph->style->text_gc[GTK_STATE_NORMAL],
|
2003-03-14 21:42:39 +08:00
|
|
|
FALSE,
|
|
|
|
x, y, w, h);
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
g_snprintf (buf, sizeof (buf), "x:%3d y:%3d",
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->cursor_x, 255 - tool->cursor_y);
|
|
|
|
pango_layout_set_text (tool->cursor_layout, buf, 11);
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gdk_draw_layout (tool->graph->window,
|
|
|
|
tool->graph->style->text_gc[GTK_STATE_ACTIVE],
|
2003-03-14 21:42:39 +08:00
|
|
|
x + 2, y + 2,
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->cursor_layout);
|
2003-03-14 21:42:39 +08:00
|
|
|
}
|
|
|
|
|
2003-12-12 07:35:17 +08:00
|
|
|
static gboolean
|
2003-03-14 21:42:39 +08:00
|
|
|
curves_graph_expose (GtkWidget *widget,
|
2003-12-12 07:35:17 +08:00
|
|
|
GdkEventExpose *eevent,
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpCurvesTool *tool)
|
2003-03-14 21:42:39 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
GimpHistogramChannel channel;
|
|
|
|
gint width;
|
2003-12-12 07:35:17 +08:00
|
|
|
gint height;
|
2004-02-21 20:25:09 +08:00
|
|
|
gint x, y, i;
|
2003-12-12 07:35:17 +08:00
|
|
|
GdkPoint points[256];
|
|
|
|
GdkGC *graph_gc;
|
2003-03-14 21:42:39 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
width = widget->allocation.width - 2 * RADIUS;
|
|
|
|
height = widget->allocation.height - 2 * RADIUS;
|
|
|
|
|
|
|
|
if (width < 1 || height < 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (tool->color)
|
2003-03-14 21:42:39 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
channel = tool->channel;
|
2003-03-14 21:42:39 +08:00
|
|
|
}
|
2003-07-10 20:13:21 +08:00
|
|
|
else
|
2003-03-14 21:42:39 +08:00
|
|
|
{
|
2004-06-28 22:24:56 +08:00
|
|
|
/* FIXME: hack */
|
|
|
|
if (tool->channel == 1)
|
2004-02-21 20:25:09 +08:00
|
|
|
channel = GIMP_HISTOGRAM_ALPHA;
|
2003-03-14 21:42:39 +08:00
|
|
|
else
|
2004-02-21 20:25:09 +08:00
|
|
|
channel = GIMP_HISTOGRAM_VALUE;
|
2003-03-14 21:42:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw the grid lines */
|
2003-12-12 07:35:17 +08:00
|
|
|
for (i = 1; i < 4; i++)
|
2003-03-14 21:42:39 +08:00
|
|
|
{
|
|
|
|
gdk_draw_line (widget->window,
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->graph->style->dark_gc[GTK_STATE_NORMAL],
|
2003-12-12 07:35:17 +08:00
|
|
|
RADIUS,
|
2004-02-21 20:25:09 +08:00
|
|
|
RADIUS + i * (height / 4),
|
|
|
|
RADIUS + width - 1,
|
|
|
|
RADIUS + i * (height / 4));
|
2003-03-14 21:42:39 +08:00
|
|
|
gdk_draw_line (widget->window,
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->graph->style->dark_gc[GTK_STATE_NORMAL],
|
|
|
|
RADIUS + i * (width / 4),
|
2003-12-12 07:35:17 +08:00
|
|
|
RADIUS,
|
2004-02-21 20:25:09 +08:00
|
|
|
RADIUS + i * (width / 4),
|
|
|
|
RADIUS + height - 1);
|
2003-03-14 21:42:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw the curve */
|
2004-02-21 20:25:09 +08:00
|
|
|
graph_gc = tool->graph->style->text_gc[GTK_STATE_NORMAL];
|
2003-12-12 07:35:17 +08:00
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
x = i;
|
|
|
|
y = 255 - tool->curves->curve[tool->channel][x];
|
2003-03-14 21:42:39 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
points[i].x = RADIUS + ROUND ((gdouble) width * x / 256.0);
|
|
|
|
points[i].y = RADIUS + ROUND ((gdouble) height * y / 256.0);
|
2003-03-14 21:42:39 +08:00
|
|
|
}
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
gdk_draw_lines (widget->window, graph_gc, points, 256);
|
|
|
|
|
|
|
|
if (tool->curves->curve_type[tool->channel] == GIMP_CURVE_SMOOTH)
|
|
|
|
{
|
2003-03-14 21:42:39 +08:00
|
|
|
/* Draw the points */
|
|
|
|
for (i = 0; i < 17; i++)
|
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
x = tool->curves->points[tool->channel][i][0];
|
|
|
|
if (x < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
y = 255 - tool->curves->points[tool->channel][i][1];
|
|
|
|
|
|
|
|
gdk_draw_arc (widget->window,
|
|
|
|
graph_gc,
|
|
|
|
TRUE,
|
|
|
|
ROUND ((gdouble) width * x / 256.0),
|
|
|
|
ROUND ((gdouble) height * y / 256.0),
|
|
|
|
RADIUS * 2, RADIUS * 2, 0, 23040);
|
2003-03-14 21:42:39 +08:00
|
|
|
}
|
|
|
|
}
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (tool->col_value[channel] >= 0)
|
2003-03-14 21:42:39 +08:00
|
|
|
{
|
2004-02-21 20:25:09 +08:00
|
|
|
gchar buf[32];
|
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
/* draw the color line */
|
|
|
|
gdk_draw_line (widget->window,
|
2003-12-12 07:35:17 +08:00
|
|
|
graph_gc,
|
2004-05-15 21:11:07 +08:00
|
|
|
RADIUS +
|
|
|
|
ROUND ((gdouble) width * (tool->col_value[channel]) / 256.0),
|
2003-03-14 21:42:39 +08:00
|
|
|
RADIUS,
|
2004-05-15 21:11:07 +08:00
|
|
|
RADIUS +
|
|
|
|
ROUND ((gdouble) width * (tool->col_value[channel]) / 256.0),
|
2004-02-21 20:25:09 +08:00
|
|
|
height + RADIUS - 1);
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
/* and xpos indicator */
|
|
|
|
g_snprintf (buf, sizeof (buf), "x:%d",
|
2004-02-21 20:25:09 +08:00
|
|
|
tool->col_value[channel]);
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if (! tool->xpos_layout)
|
|
|
|
tool->xpos_layout = gtk_widget_create_pango_layout (tool->graph, buf);
|
2003-03-14 21:42:39 +08:00
|
|
|
else
|
2004-02-21 20:25:09 +08:00
|
|
|
pango_layout_set_text (tool->xpos_layout, buf, -1);
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
pango_layout_get_pixel_size (tool->xpos_layout, &x, &y);
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
if ((tool->col_value[channel] + RADIUS) < 127)
|
|
|
|
x = RADIUS + 4;
|
2003-03-14 21:42:39 +08:00
|
|
|
else
|
2004-02-21 20:25:09 +08:00
|
|
|
x = -(x + 2);
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2003-03-14 21:42:39 +08:00
|
|
|
gdk_draw_layout (widget->window,
|
2003-12-12 07:35:17 +08:00
|
|
|
graph_gc,
|
2004-05-15 21:11:07 +08:00
|
|
|
RADIUS +
|
|
|
|
ROUND (((gdouble) width * (tool->col_value[channel])) / 256.0 + x),
|
2004-02-21 20:25:09 +08:00
|
|
|
height - y - 2,
|
|
|
|
tool->xpos_layout);
|
2003-03-14 21:42:39 +08:00
|
|
|
}
|
2003-07-10 20:13:21 +08:00
|
|
|
|
2004-02-21 20:25:09 +08:00
|
|
|
curve_print_loc (tool);
|
2003-03-14 21:42:39 +08:00
|
|
|
|
2003-12-12 07:35:17 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|