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>
|
2002-06-09 20:53:42 +08:00
|
|
|
#include <errno.h>
|
2000-04-28 01:27:28 +08:00
|
|
|
|
2002-01-30 22:54:27 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning GTK_DISABLE_DEPRECATED
|
|
|
|
#endif
|
|
|
|
#undef GTK_DISABLE_DEPRECATED
|
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-05-22 04:30:16 +08:00
|
|
|
#include "libgimpbase/gimpbase.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
|
|
|
|
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"
|
|
|
|
|
|
|
|
#include "core/gimpdrawable.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
|
|
|
|
|
|
|
#include "widgets/gimpcursor.h"
|
2002-03-18 00:35:05 +08:00
|
|
|
#include "widgets/gimpenummenu.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"
|
|
|
|
#include "tool_manager.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
#define GRAPH 0x1
|
|
|
|
#define XRANGE_TOP 0x2
|
|
|
|
#define XRANGE_BOTTOM 0x4
|
|
|
|
#define YRANGE 0x8
|
|
|
|
#define DRAW 0x10
|
|
|
|
#define ALL 0xFF
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-23 23:24:46 +08:00
|
|
|
/* NB: take care when changing these values: make sure the curve[] array in
|
2002-08-26 19:35:56 +08:00
|
|
|
* base/curves.h is large enough.
|
1999-06-23 23:24:46 +08:00
|
|
|
*/
|
1999-11-22 19:14:29 +08:00
|
|
|
#define GRAPH_WIDTH 256
|
|
|
|
#define GRAPH_HEIGHT 256
|
|
|
|
#define XRANGE_WIDTH 256
|
|
|
|
#define XRANGE_HEIGHT 16
|
|
|
|
#define YRANGE_WIDTH 16
|
|
|
|
#define YRANGE_HEIGHT 256
|
1997-11-25 06:05:25 +08:00
|
|
|
#define RADIUS 3
|
|
|
|
#define MIN_DISTANCE 8
|
|
|
|
|
|
|
|
#define GRAPH_MASK GDK_EXPOSURE_MASK | \
|
|
|
|
GDK_POINTER_MOTION_MASK | \
|
|
|
|
GDK_POINTER_MOTION_HINT_MASK | \
|
|
|
|
GDK_ENTER_NOTIFY_MASK | \
|
|
|
|
GDK_BUTTON_PRESS_MASK | \
|
|
|
|
GDK_BUTTON_RELEASE_MASK | \
|
|
|
|
GDK_BUTTON1_MOTION_MASK
|
|
|
|
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static void gimp_curves_tool_class_init (GimpCurvesToolClass *klass);
|
2002-08-26 19:35:56 +08:00
|
|
|
static void gimp_curves_tool_init (GimpCurvesTool *c_tool);
|
|
|
|
|
|
|
|
static void gimp_curves_tool_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_curves_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_curves_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_curves_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_curves_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
static void curves_color_update (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
|
|
|
static void curves_add_point (GimpCurvesTool *c_tool,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint cchan);
|
|
|
|
|
|
|
|
static void curves_update (GimpCurvesTool *c_tool,
|
|
|
|
gint update);
|
|
|
|
|
|
|
|
static void curves_channel_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void curves_channel_reset_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static gboolean curves_set_sensitive_callback (gpointer item_data,
|
|
|
|
GimpCurvesTool *c_tool);
|
|
|
|
static void curves_smooth_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void curves_free_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void curves_load_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void curves_save_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static gint curves_graph_events (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpCurvesTool *c_tool);
|
|
|
|
|
|
|
|
static void file_dialog_create (GimpCurvesTool *c_tool);
|
|
|
|
static void file_dialog_ok_callback (GimpCurvesTool *c_tool);
|
|
|
|
static gboolean file_dialog_cancel_callback (GimpCurvesTool *c_tool);
|
|
|
|
|
|
|
|
static gboolean curves_read_from_file (GimpCurvesTool *c_tool,
|
|
|
|
FILE *file);
|
|
|
|
static void curves_write_to_file (GimpCurvesTool *c_tool,
|
|
|
|
FILE *file);
|
|
|
|
|
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,
|
2001-11-21 07:00:47 +08:00
|
|
|
NULL,
|
|
|
|
FALSE,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-curves-tool",
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Curves"),
|
|
|
|
_("Adjust color curves"),
|
2001-12-04 01:59:48 +08:00
|
|
|
N_("/Layer/Colors/Curves..."), NULL,
|
2001-11-21 07:00:47 +08:00
|
|
|
NULL, "tools/curves.html",
|
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),
|
2001-08-14 22:53:55 +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,
|
|
|
|
"GimpCurvesTool",
|
|
|
|
&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;
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
object_class->finalize = gimp_curves_tool_finalize;
|
|
|
|
|
|
|
|
tool_class->initialize = gimp_curves_tool_initialize;
|
|
|
|
tool_class->button_press = gimp_curves_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_curves_tool_button_release;
|
|
|
|
tool_class->motion = gimp_curves_tool_motion;
|
|
|
|
|
|
|
|
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;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_curves_tool_init (GimpCurvesTool *c_tool)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpImageMapTool *image_map_tool;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
image_map_tool = GIMP_IMAGE_MAP_TOOL (c_tool);
|
|
|
|
|
2002-08-29 03:47:07 +08:00
|
|
|
image_map_tool->shell_desc = _("Adjust Color Curves");
|
2002-08-26 19:35:56 +08:00
|
|
|
|
GimpViewableDialogs everywhere, cleanup:
2002-09-01 Michael Natterer <mitch@gimp.org>
GimpViewableDialogs everywhere, cleanup:
* libgimpwidgets/gimpstock.c: added texts for the RESIZE, SCALE
and CROP stock items.
* app/widgets/gimpviewabledialog.c: update the title when the
viewable's name changes.
* app/gui/color-notebook.[ch]: added color_notebook_viewable_new()
which creates a GimpViewableDialog.
* app/widgets/gimpgradienteditor.[ch]
* app/gui/colormap-editor-commands.c
* app/gui/file-new-dialog.c
* app/gui/gradient-editor-commands.c
* app/gui/palette-editor-commands.c
* app/undo_history.c: use GimpViewableDialogs and the new
color_notebook constructor.
* app/gui/convert-dialog.c: #include "widgets/gimpviewabledialog.h"
* app/gui/image-commands.c
* app/gui/info-dialog.c
* app/gui/resize-dialog.c: minor cleanups.
* app/gui/info-window.c: cleaned up the whole thing, esp. the
"Extended" page. Added HSV color display to the color picker
frame. Set the icons as frame titles, stuff...
* app/tools/gimpimagemaptool.[ch]: removed "shell_title",
"shell_name" and "stock_id" from the GimpImageMapTool struct
because they can be obtained from the tool's GimpToolInfo object.
* app/tools/gimpbrightnesscontrasttool.c
* app/tools/gimpcolorbalancetool.c
* app/tools/gimpcurvestool.c
* app/tools/gimphuesaturationtool.c
* app/tools/gimplevelstool.c
* app/tools/gimpposterizetool.c
* app/tools/gimpthresholdtool.c: changed accordingly.
* app/tools/gimphistogramtool.c: same here: take values from
tool->tool_info instead of hardcoding them.
* app/tools/gimpcroptool.[ch]: removed the static crop dialog
variables and added them to the GimpCropTool struct. Feels safer
and makes the callback code much simpler. Use stock items for the
dialog's "Resize" and "Crop" buttons.
* app/tools/gimpmeasuretool.c
* app/tools/gimprotatetool.c: for consistency don't name the tools
"Blah Tool", also the dialog titles need to match the menu
entries.
Unrelated:
* libgimpwidgets/gimpwidgets.c: the recently changed, gtk-doc
comment was correct, as gtk-doc takes the parameter names from
the header, not the .c file.
* app/tools/gimptransformtool.c: set the transform tool's state to
TRANSFORM_CREATING after changing displays, so the initial matrix
components are saved correctly for the "Reset" function.
2002-09-01 16:44:57 +08:00
|
|
|
c_tool->curves = g_new0 (Curves, 1);
|
|
|
|
c_tool->lut = gimp_lut_new ();
|
|
|
|
c_tool->channel = GIMP_HISTOGRAM_VALUE;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
curves_init (c_tool->curves);
|
|
|
|
|
|
|
|
for (i = 0;
|
|
|
|
i < (sizeof (c_tool->col_value) /
|
|
|
|
sizeof (c_tool->col_value[0]));
|
|
|
|
i++)
|
|
|
|
c_tool->col_value[i] = 0;
|
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
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (object);
|
|
|
|
|
|
|
|
if (c_tool->curves)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
g_free(c_tool->curves);
|
|
|
|
c_tool->curves = NULL;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->lut)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_lut_free (c_tool->lut);
|
|
|
|
c_tool->lut = NULL;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->pixmap)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
g_object_unref (c_tool->pixmap);
|
|
|
|
c_tool->pixmap = NULL;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
if (c_tool->cursor_layout)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
g_object_unref (c_tool->cursor_layout);
|
|
|
|
c_tool->cursor_layout = NULL;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->xpos_layout)
|
|
|
|
{
|
|
|
|
g_object_unref (c_tool->xpos_layout);
|
|
|
|
c_tool->xpos_layout = NULL;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_curves_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
|
|
|
c_tool = GIMP_CURVES_TOOL (tool);
|
2002-08-29 03:47:07 +08:00
|
|
|
|
|
|
|
if (gimp_drawable_is_indexed (gimp_image_active_drawable (gdisp->gimage)))
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
g_message (_("Curves for indexed drawables cannot be adjusted."));
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
|
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->color = gimp_drawable_is_rgb (drawable);
|
|
|
|
c_tool->channel = GIMP_HISTOGRAM_VALUE;
|
|
|
|
|
|
|
|
c_tool->grab_point = -1;
|
|
|
|
c_tool->last = 0;
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
|
|
|
|
|
|
|
|
/* set the sensitivity of the channel menu based on the drawable type */
|
|
|
|
gimp_option_menu_set_sensitive (GTK_OPTION_MENU (c_tool->channel_menu),
|
|
|
|
(GimpOptionMenuSensitivityCallback) curves_set_sensitive_callback,
|
|
|
|
c_tool);
|
|
|
|
|
|
|
|
/* set the current selection */
|
2002-08-29 03:47:07 +08:00
|
|
|
gimp_option_menu_set_history (GTK_OPTION_MENU (c_tool->channel_menu),
|
|
|
|
GINT_TO_POINTER (c_tool->channel));
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_update (c_tool, ALL);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_curves_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
|
|
|
c_tool = GIMP_CURVES_TOOL (tool);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
drawable = gimp_image_active_drawable (gdisp->gimage);
|
|
|
|
|
|
|
|
tool->gdisp = gdisp;
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
g_assert (drawable == tool->drawable);
|
|
|
|
|
|
|
|
#if 0
|
2001-05-25 07:57:08 +08:00
|
|
|
if (drawable != tool->drawable)
|
|
|
|
{
|
2002-05-03 19:31:08 +08:00
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_image_map_abort (GIMP_IMAGE_MAP_TOOL (tool)->image_map);
|
2002-05-03 19:31:08 +08:00
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
tool->drawable = drawable;
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->color = gimp_drawable_is_rgb (drawable);
|
|
|
|
|
|
|
|
GIMP_IMAGE_MAP_TOOL (tool)->drawable = drawable;
|
|
|
|
GIMP_IMAGE_MAP_TOOL (tool)->image_map = gimp_image_map_new (TRUE, drawable);
|
2002-03-18 00:35:05 +08:00
|
|
|
|
|
|
|
gimp_option_menu_set_sensitive
|
2002-08-26 19:35:56 +08:00
|
|
|
(GTK_OPTION_MENU (c_tool->channel_menu),
|
2002-03-18 00:35:05 +08:00
|
|
|
(GimpOptionMenuSensitivityCallback) curves_set_sensitive_callback,
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
#endif
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-05-03 19:31:08 +08:00
|
|
|
gimp_tool_control_activate (tool->control);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
curves_color_update (tool, gdisp, drawable, coords->x, coords->y);
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_update (c_tool, GRAPH | DRAW);
|
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,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
|
|
|
GimpDrawable *drawable;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (tool);
|
|
|
|
|
|
|
|
drawable = gimp_image_active_drawable (gdisp->gimage);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
curves_color_update (tool, gdisp, drawable, coords->x, coords->y);
|
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
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_tool_control_halt (tool->control);
|
|
|
|
|
|
|
|
curves_update (c_tool, GRAPH | DRAW);
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_curves_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
|
|
|
GimpDrawable *drawable;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
drawable = gimp_image_active_drawable (gdisp->gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_color_update (tool, gdisp, drawable, coords->x, coords->y);
|
|
|
|
curves_update (c_tool, GRAPH | DRAW);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-04-08 06:02:26 +08:00
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
curves_color_update (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
1999-04-08 06:02:26 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
|
|
|
guchar *color;
|
|
|
|
gint offx;
|
|
|
|
gint offy;
|
|
|
|
gint maxval;
|
|
|
|
gboolean has_alpha;
|
|
|
|
gboolean is_indexed;
|
|
|
|
GimpImageType sample_type;
|
|
|
|
|
|
|
|
c_tool = GIMP_CURVES_TOOL (tool);
|
|
|
|
|
|
|
|
if (! (tool && gimp_tool_control_is_active (tool->control)))
|
1999-04-08 06:02:26 +08:00
|
|
|
return;
|
|
|
|
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_offsets (drawable, &offx, &offy);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
|
|
|
x -= offx;
|
|
|
|
y -= offy;
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! (color = gimp_image_map_get_color_at (GIMP_IMAGE_MAP_TOOL (tool)->image_map,
|
|
|
|
x, y)))
|
1999-04-08 06:02:26 +08:00
|
|
|
return;
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
sample_type = gimp_drawable_type (drawable);
|
2000-12-14 02:53:35 +08:00
|
|
|
is_indexed = gimp_drawable_is_indexed (drawable);
|
|
|
|
has_alpha = GIMP_IMAGE_TYPE_HAS_ALPHA (sample_type);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->col_value[GIMP_HISTOGRAM_RED] = color[RED_PIX];
|
|
|
|
c_tool->col_value[GIMP_HISTOGRAM_GREEN] = color[GREEN_PIX];
|
|
|
|
c_tool->col_value[GIMP_HISTOGRAM_BLUE] = color[BLUE_PIX];
|
1999-04-08 06:02:26 +08:00
|
|
|
|
|
|
|
if (has_alpha)
|
2002-08-29 03:47:07 +08:00
|
|
|
c_tool->col_value[GIMP_HISTOGRAM_ALPHA] = color[3];
|
1999-04-08 06:02:26 +08:00
|
|
|
|
|
|
|
if (is_indexed)
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->col_value[GIMP_HISTOGRAM_ALPHA] = color[4];
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2000-01-26 07:06:12 +08:00
|
|
|
maxval = MAX (color[RED_PIX], color[GREEN_PIX]);
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->col_value[GIMP_HISTOGRAM_VALUE] = MAX (maxval, color[BLUE_PIX]);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
g_free (color);
|
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
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_add_point (GimpCurvesTool *c_tool,
|
|
|
|
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
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
switch (c_tool->curves->curve_type[cchan])
|
1999-05-14 06:53:40 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
case CURVES_SMOOTH:
|
|
|
|
curvex = c_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++)
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->curves->points[cchan][i][0] != -1)
|
|
|
|
if (abs (curvex - c_tool->curves->points[cchan][i][0]) < distance)
|
1999-09-04 05:58:41 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
distance = abs (curvex - c_tool->curves->points[cchan][i][0]);
|
1999-09-04 05:58:41 +08:00
|
|
|
closest_point = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (distance > MIN_DISTANCE)
|
|
|
|
closest_point = (curvex + 8) / 16;
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->curves->points[cchan][closest_point][0] = curvex;
|
|
|
|
c_tool->curves->points[cchan][closest_point][1] = c_tool->curves->curve[cchan][curvex];
|
1999-09-04 05:58:41 +08:00
|
|
|
break;
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
case CURVES_FREE:
|
|
|
|
c_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
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
1999-06-23 23:24:46 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (image_map_tool);
|
1999-06-23 23:24:46 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_lut_setup (c_tool->lut,
|
|
|
|
(GimpLutFunc) curves_lut_func,
|
|
|
|
c_tool->curves,
|
|
|
|
gimp_drawable_bytes (image_map_tool->drawable));
|
|
|
|
gimp_image_map_apply (image_map_tool->image_map,
|
|
|
|
(GimpImageMapApplyFunc) gimp_lut_process_2,
|
|
|
|
c_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
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
|
|
|
GtkWidget *hbox;
|
2002-08-29 03:47:07 +08:00
|
|
|
GtkWidget *vbox;
|
2002-08-26 19:35:56 +08:00
|
|
|
GtkWidget *hbbox;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *button;
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (image_map_tool);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2002-08-29 03:47:07 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), hbox,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, FALSE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
table = gtk_table_new (2, 2, FALSE);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
2002-08-29 03:47:07 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (table);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* The option menu for selecting channels */
|
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->channel_menu =
|
|
|
|
gimp_enum_option_menu_new (GIMP_TYPE_HISTOGRAM_CHANNEL,
|
|
|
|
G_CALLBACK (curves_channel_callback),
|
|
|
|
c_tool);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), c_tool->channel_menu, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (c_tool->channel_menu);
|
2001-11-24 07:04:49 +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
|
|
|
button = gtk_button_new_with_mnemonic (_("R_eset Channel"));
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
g_signal_connect (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (curves_channel_reset_callback),
|
|
|
|
c_tool);
|
2001-11-24 07:04:49 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
|
|
|
_("Modify Curves for Channel:"), 1.0, 0.5,
|
|
|
|
hbox, 1, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/* The option menu for selecting the drawing method */
|
|
|
|
c_tool->curve_type_menu =
|
|
|
|
gimp_option_menu_new (FALSE,
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
_("Smooth"), curves_smooth_callback,
|
2002-08-29 03:47:07 +08:00
|
|
|
c_tool, GINT_TO_POINTER (CURVES_SMOOTH), NULL, TRUE,
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
_("Free"), curves_free_callback,
|
2002-08-29 03:47:07 +08:00
|
|
|
c_tool, GINT_TO_POINTER (CURVES_FREE), NULL, FALSE,
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
|
|
|
|
_("Curve Type:"), 1.0, 0.5,
|
|
|
|
c_tool->curve_type_menu, 1, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* The table for the yrange and the graph */
|
|
|
|
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);
|
2002-08-29 03:47:07 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* The range drawing area */
|
|
|
|
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, 0, 1, 0, 1,
|
|
|
|
GTK_EXPAND, GTK_EXPAND, 0, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->yrange = gtk_preview_new (GTK_PREVIEW_COLOR);
|
|
|
|
gtk_preview_size (GTK_PREVIEW (c_tool->yrange), YRANGE_WIDTH, YRANGE_HEIGHT);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), c_tool->yrange);
|
|
|
|
gtk_widget_show (c_tool->yrange);
|
|
|
|
|
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,
|
1999-11-22 19:14:29 +08:00
|
|
|
GTK_SHRINK | GTK_FILL,
|
|
|
|
GTK_SHRINK | GTK_FILL, 0, 0);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (frame);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->graph = gtk_drawing_area_new ();
|
|
|
|
gtk_widget_set_size_request (c_tool->graph,
|
|
|
|
GRAPH_WIDTH + RADIUS * 2,
|
2001-12-29 21:26:29 +08:00
|
|
|
GRAPH_HEIGHT + RADIUS * 2);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_set_events (c_tool->graph, GRAPH_MASK);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), c_tool->graph);
|
|
|
|
gtk_widget_show (c_tool->graph);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
g_signal_connect (G_OBJECT (c_tool->graph), "event",
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
G_CALLBACK (curves_graph_events),
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* The range drawing area */
|
|
|
|
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, 1, 2,
|
|
|
|
GTK_EXPAND, GTK_EXPAND, 0, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->xrange = gtk_preview_new (GTK_PREVIEW_COLOR);
|
|
|
|
gtk_preview_size (GTK_PREVIEW (c_tool->xrange), XRANGE_WIDTH, XRANGE_HEIGHT);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), c_tool->xrange);
|
|
|
|
gtk_widget_show (c_tool->xrange);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (table);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-20 20:22:54 +08:00
|
|
|
/* Horizontal button box for load / save */
|
2002-08-29 03:47:07 +08:00
|
|
|
frame = gtk_frame_new (_("All Channels"));
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2000-01-20 20:22:54 +08:00
|
|
|
hbbox = gtk_hbutton_box_new ();
|
2002-08-29 03:47:07 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbbox), 2);
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_box_set_spacing (GTK_BOX (hbbox), 4);
|
2000-01-20 20:22:54 +08:00
|
|
|
gtk_button_box_set_layout (GTK_BUTTON_BOX (hbbox), GTK_BUTTONBOX_SPREAD);
|
2002-08-29 03:47:07 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), hbbox);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_show (hbbox);
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-29 03:47:07 +08:00
|
|
|
button = gtk_button_new_from_stock (GTK_STOCK_OPEN);
|
2000-01-20 20:22:54 +08:00
|
|
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
|
2002-08-29 03:47:07 +08:00
|
|
|
gimp_help_set_help_data (button, _("Read curves settings from file"), NULL);
|
2000-01-20 20:22:54 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
g_signal_connect (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (curves_load_callback),
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool);
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
2002-08-29 03:47:07 +08:00
|
|
|
button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
|
2000-01-20 20:22:54 +08:00
|
|
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
|
2002-08-29 03:47:07 +08:00
|
|
|
gimp_help_set_help_data (button, _("Save curves settings to file"), NULL);
|
2000-01-20 20:22:54 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
g_signal_connect (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (curves_save_callback),
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool);
|
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
|
|
|
{
|
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
|
|
|
GimpCurvesTool *c_tool;
|
|
|
|
GimpHistogramChannel channel;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
c_tool = GIMP_CURVES_TOOL (image_map_tool);
|
|
|
|
|
|
|
|
c_tool->grab_point = -1;
|
|
|
|
|
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++)
|
|
|
|
curves_channel_reset (c_tool->curves, channel);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
curves_update (c_tool, GRAPH | XRANGE_TOP | DRAW);
|
2001-10-17 19:33:43 +08:00
|
|
|
}
|
|
|
|
|
1999-09-04 05:58:41 +08:00
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
curve_print_loc (GimpCurvesTool *c_tool,
|
|
|
|
gint xpos,
|
|
|
|
gint ypos)
|
1999-09-04 05:58:41 +08:00
|
|
|
{
|
2000-12-14 02:53:35 +08:00
|
|
|
gchar buf[32];
|
1999-09-04 05:58:41 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! c_tool->cursor_layout)
|
1999-09-04 05:58:41 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->cursor_layout = gtk_widget_create_pango_layout (c_tool->graph,
|
|
|
|
"x:888 y:888");
|
|
|
|
pango_layout_get_pixel_extents (c_tool->cursor_layout,
|
|
|
|
NULL, &c_tool->cursor_rect);
|
1999-09-04 05:58:41 +08:00
|
|
|
}
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
if (xpos >= 0 && xpos <= 255 && ypos >=0 && ypos <= 255)
|
1999-09-04 05:58:41 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
gdk_draw_rectangle (c_tool->graph->window,
|
|
|
|
c_tool->graph->style->bg_gc[GTK_STATE_ACTIVE],
|
2001-09-19 22:42:35 +08:00
|
|
|
TRUE,
|
2002-08-26 19:35:56 +08:00
|
|
|
RADIUS * 2 + 2,
|
|
|
|
RADIUS * 2 + 2,
|
|
|
|
c_tool->cursor_rect.width + 4,
|
|
|
|
c_tool->cursor_rect.height + 5);
|
1999-09-04 05:58:41 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gdk_draw_rectangle (c_tool->graph->window,
|
|
|
|
c_tool->graph->style->black_gc,
|
2001-09-19 22:42:35 +08:00
|
|
|
FALSE,
|
2002-08-26 19:35:56 +08:00
|
|
|
RADIUS * 2 + 2,
|
|
|
|
RADIUS * 2 + 2,
|
|
|
|
c_tool->cursor_rect.width + 3,
|
|
|
|
c_tool->cursor_rect.height + 4);
|
2001-09-19 22:42:35 +08:00
|
|
|
|
|
|
|
g_snprintf (buf, sizeof (buf), "x:%3d y:%3d",xpos, ypos);
|
2002-08-26 19:35:56 +08:00
|
|
|
pango_layout_set_text (c_tool->cursor_layout, buf, 11);
|
|
|
|
gdk_draw_layout (c_tool->graph->window,
|
|
|
|
c_tool->graph->style->black_gc,
|
|
|
|
RADIUS * 2 + 4 + c_tool->cursor_rect.x,
|
|
|
|
RADIUS * 2 + 5 + c_tool->cursor_rect.y,
|
|
|
|
c_tool->cursor_layout);
|
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
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_update (GimpCurvesTool *c_tool,
|
|
|
|
gint update)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-29 03:47:07 +08:00
|
|
|
GimpHistogramChannel sel_channel;
|
|
|
|
gint i, j;
|
|
|
|
gchar buf[32];
|
|
|
|
gint offset;
|
|
|
|
gint height;
|
2000-12-01 07:23:59 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->color)
|
2002-05-03 19:31:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
sel_channel = c_tool->channel;
|
2002-08-29 03:47:07 +08:00
|
|
|
}
|
2002-05-03 19:31:08 +08:00
|
|
|
else
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->channel == 2)
|
2002-05-03 19:31:08 +08:00
|
|
|
sel_channel = GIMP_HISTOGRAM_ALPHA;
|
|
|
|
else
|
|
|
|
sel_channel = GIMP_HISTOGRAM_VALUE;
|
|
|
|
}
|
2000-12-01 07:23:59 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (update & XRANGE_TOP)
|
|
|
|
{
|
1999-11-22 19:14:29 +08:00
|
|
|
guchar buf[XRANGE_WIDTH * 3];
|
1999-05-20 23:43:56 +08:00
|
|
|
|
2000-12-01 07:23:59 +08:00
|
|
|
switch (sel_channel)
|
1999-11-22 19:14:29 +08:00
|
|
|
{
|
2000-12-19 22:43:54 +08:00
|
|
|
case GIMP_HISTOGRAM_VALUE:
|
|
|
|
case GIMP_HISTOGRAM_ALPHA:
|
1999-05-20 23:43:56 +08:00
|
|
|
for (i = 0; i < XRANGE_HEIGHT / 2; i++)
|
1999-11-22 19:14:29 +08:00
|
|
|
{
|
1999-05-20 23:43:56 +08:00
|
|
|
for (j = 0; j < XRANGE_WIDTH ; j++)
|
1999-11-22 19:14:29 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
buf[j * 3 + 0] = c_tool->curves->curve[sel_channel][j];
|
|
|
|
buf[j * 3 + 1] = c_tool->curves->curve[sel_channel][j];
|
|
|
|
buf[j * 3 + 2] = c_tool->curves->curve[sel_channel][j];
|
1999-11-22 19:14:29 +08:00
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (c_tool->xrange),
|
1999-05-20 23:43:56 +08:00
|
|
|
buf, 0, i, XRANGE_WIDTH);
|
1999-11-22 19:14:29 +08:00
|
|
|
}
|
1999-05-20 23:43:56 +08:00
|
|
|
break;
|
|
|
|
|
2000-12-19 22:43:54 +08:00
|
|
|
case GIMP_HISTOGRAM_RED:
|
|
|
|
case GIMP_HISTOGRAM_GREEN:
|
|
|
|
case GIMP_HISTOGRAM_BLUE:
|
1999-05-20 23:43:56 +08:00
|
|
|
{
|
1999-11-22 19:14:29 +08:00
|
|
|
for (i = 0; i < XRANGE_HEIGHT / 2; i++)
|
1999-05-20 23:43:56 +08:00
|
|
|
{
|
1999-11-22 19:14:29 +08:00
|
|
|
for (j = 0; j < XRANGE_WIDTH; j++)
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
buf[j * 3 + 0] = c_tool->curves->curve[GIMP_HISTOGRAM_RED][j];
|
|
|
|
buf[j * 3 + 1] = c_tool->curves->curve[GIMP_HISTOGRAM_GREEN][j];
|
|
|
|
buf[j * 3 + 2] = c_tool->curves->curve[GIMP_HISTOGRAM_BLUE][j];
|
1999-11-22 19:14:29 +08:00
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (c_tool->xrange),
|
1999-11-22 19:14:29 +08:00
|
|
|
buf, 0, i, XRANGE_WIDTH);
|
1999-05-20 23:43:56 +08:00
|
|
|
}
|
1999-11-22 19:14:29 +08:00
|
|
|
break;
|
1999-05-20 23:43:56 +08:00
|
|
|
}
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
default:
|
1999-05-20 23:43:56 +08:00
|
|
|
g_warning ("unknown channel type %d, can't happen!?!?",
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->channel);
|
1999-05-20 23:43:56 +08:00
|
|
|
break;
|
1999-11-22 19:14:29 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (update & DRAW)
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_queue_draw_area (c_tool->xrange,
|
|
|
|
0, 0,
|
|
|
|
XRANGE_WIDTH, XRANGE_HEIGHT / 2);
|
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 & XRANGE_BOTTOM)
|
|
|
|
{
|
1999-11-22 19:14:29 +08:00
|
|
|
guchar buf[XRANGE_WIDTH * 3];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0; i < XRANGE_WIDTH; i++)
|
2002-08-26 19:35:56 +08:00
|
|
|
{
|
|
|
|
buf[i * 3 + 0] = i;
|
|
|
|
buf[i * 3 + 1] = i;
|
|
|
|
buf[i * 3 + 2] = i;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = XRANGE_HEIGHT / 2; i < XRANGE_HEIGHT; i++)
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (c_tool->xrange),
|
|
|
|
buf, 0, i, XRANGE_WIDTH);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (update & DRAW)
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_queue_draw_area (c_tool->xrange,
|
|
|
|
0, XRANGE_HEIGHT / 2,
|
|
|
|
XRANGE_WIDTH, XRANGE_HEIGHT / 2);
|
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)
|
|
|
|
{
|
1999-11-22 19:14:29 +08:00
|
|
|
guchar buf[YRANGE_WIDTH * 3];
|
|
|
|
guchar pix[3];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0; i < YRANGE_HEIGHT; i++)
|
|
|
|
{
|
2000-12-01 07:23:59 +08:00
|
|
|
switch (sel_channel)
|
1999-11-22 19:14:29 +08:00
|
|
|
{
|
2000-12-19 22:43:54 +08:00
|
|
|
case GIMP_HISTOGRAM_VALUE:
|
|
|
|
case GIMP_HISTOGRAM_ALPHA:
|
1999-05-20 23:43:56 +08:00
|
|
|
pix[0] = pix[1] = pix[2] = (255 - i);
|
|
|
|
break;
|
|
|
|
|
2000-12-19 22:43:54 +08:00
|
|
|
case GIMP_HISTOGRAM_RED:
|
|
|
|
case GIMP_HISTOGRAM_GREEN:
|
|
|
|
case GIMP_HISTOGRAM_BLUE:
|
1999-05-20 23:43:56 +08:00
|
|
|
pix[0] = pix[1] = pix[2] = 0;
|
2000-12-01 07:23:59 +08:00
|
|
|
pix[sel_channel - 1] = (255 - i);
|
1999-05-20 23:43:56 +08:00
|
|
|
break;
|
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
default:
|
1999-05-20 23:43:56 +08:00
|
|
|
g_warning ("unknown channel type %d, can't happen!?!?",
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->channel);
|
1999-05-20 23:43:56 +08:00
|
|
|
break;
|
1999-11-22 19:14:29 +08:00
|
|
|
}
|
1999-05-20 23:43:56 +08:00
|
|
|
|
|
|
|
for (j = 0; j < YRANGE_WIDTH * 3; j++)
|
1999-11-22 19:14:29 +08:00
|
|
|
buf[j] = pix[j%3];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_preview_draw_row (GTK_PREVIEW (c_tool->yrange),
|
1999-11-22 19:14:29 +08:00
|
|
|
buf, 0, i, YRANGE_WIDTH);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (update & DRAW)
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_widget_queue_draw (c_tool->yrange);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
if ((update & GRAPH) && (update & DRAW) && c_tool->pixmap)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GdkPoint points[256];
|
|
|
|
|
|
|
|
/* Clear the pixmap */
|
2002-08-26 19:35:56 +08:00
|
|
|
gdk_draw_rectangle (c_tool->pixmap,
|
|
|
|
c_tool->graph->style->bg_gc[GTK_STATE_NORMAL],
|
1999-11-22 19:14:29 +08:00
|
|
|
TRUE, 0, 0,
|
|
|
|
GRAPH_WIDTH + RADIUS * 2, GRAPH_HEIGHT + RADIUS * 2);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Draw the grid lines */
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
gdk_draw_line (c_tool->pixmap,
|
|
|
|
c_tool->graph->style->dark_gc[GTK_STATE_NORMAL],
|
1997-11-25 06:05:25 +08:00
|
|
|
RADIUS, i * (GRAPH_HEIGHT / 4) + RADIUS,
|
|
|
|
GRAPH_WIDTH + RADIUS, i * (GRAPH_HEIGHT / 4) + RADIUS);
|
2002-08-26 19:35:56 +08:00
|
|
|
gdk_draw_line (c_tool->pixmap,
|
|
|
|
c_tool->graph->style->dark_gc[GTK_STATE_NORMAL],
|
1997-11-25 06:05:25 +08:00
|
|
|
i * (GRAPH_WIDTH / 4) + RADIUS, RADIUS,
|
|
|
|
i * (GRAPH_WIDTH / 4) + RADIUS, GRAPH_HEIGHT + RADIUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw the curve */
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
points[i].x = i + RADIUS;
|
2002-08-26 19:35:56 +08:00
|
|
|
points[i].y = 255 - c_tool->curves->curve[c_tool->channel][i] + RADIUS;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->curves->curve_type[c_tool->channel] == CURVES_FREE)
|
|
|
|
{
|
|
|
|
gdk_draw_points (c_tool->pixmap,
|
|
|
|
c_tool->graph->style->black_gc,
|
|
|
|
points, 256);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_draw_lines (c_tool->pixmap,
|
|
|
|
c_tool->graph->style->black_gc,
|
|
|
|
points, 256);
|
|
|
|
|
|
|
|
/* Draw the points */
|
|
|
|
for (i = 0; i < 17; i++)
|
|
|
|
{
|
|
|
|
if (c_tool->curves->points[c_tool->channel][i][0] != -1)
|
|
|
|
gdk_draw_arc (c_tool->pixmap,
|
|
|
|
c_tool->graph->style->black_gc,
|
|
|
|
TRUE,
|
|
|
|
c_tool->curves->points[c_tool->channel][i][0],
|
|
|
|
255 - c_tool->curves->points[c_tool->channel][i][1],
|
|
|
|
RADIUS * 2, RADIUS * 2, 0, 23040);
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
/* draw the color line */
|
2002-08-26 19:35:56 +08:00
|
|
|
gdk_draw_line (c_tool->pixmap,
|
|
|
|
c_tool->graph->style->black_gc,
|
|
|
|
c_tool->col_value[sel_channel] + RADIUS,
|
|
|
|
RADIUS,
|
|
|
|
c_tool->col_value[sel_channel] + RADIUS,
|
|
|
|
GRAPH_HEIGHT + RADIUS);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
1999-09-04 05:58:41 +08:00
|
|
|
/* and xpos indicator */
|
2002-08-26 19:35:56 +08:00
|
|
|
g_snprintf (buf, sizeof (buf), "x:%d", c_tool->col_value[sel_channel]);
|
2001-09-19 22:42:35 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! c_tool->xpos_layout)
|
|
|
|
c_tool->xpos_layout = gtk_widget_create_pango_layout (c_tool->graph,
|
|
|
|
buf);
|
2001-09-19 22:42:35 +08:00
|
|
|
else
|
2002-08-26 19:35:56 +08:00
|
|
|
pango_layout_set_text (c_tool->xpos_layout, buf, -1);
|
2001-09-19 22:42:35 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if ((c_tool->col_value[sel_channel] + RADIUS) < 127)
|
1999-09-04 05:58:41 +08:00
|
|
|
{
|
|
|
|
offset = RADIUS + 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
pango_layout_get_pixel_size (c_tool->xpos_layout, &offset, &height);
|
2001-09-19 22:42:35 +08:00
|
|
|
offset = - (offset + 2);
|
1999-09-04 05:58:41 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gdk_draw_layout (c_tool->pixmap,
|
|
|
|
c_tool->graph->style->black_gc,
|
|
|
|
c_tool->col_value[sel_channel] + offset,
|
2001-09-19 22:42:35 +08:00
|
|
|
GRAPH_HEIGHT - height - 2,
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->xpos_layout);
|
2001-09-19 22:42:35 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gdk_draw_drawable (c_tool->graph->window,
|
|
|
|
c_tool->graph->style->black_gc,
|
|
|
|
c_tool->pixmap,
|
2001-09-19 22:42:35 +08:00
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
GRAPH_WIDTH + RADIUS * 2, GRAPH_HEIGHT + RADIUS * 2);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_channel_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_menu_item_update (widget, &c_tool->channel);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! c_tool->color)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->channel > 1)
|
|
|
|
c_tool->channel = 2;
|
|
|
|
else
|
|
|
|
c_tool->channel = 1;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-08-29 03:47:07 +08:00
|
|
|
gimp_option_menu_set_history (GTK_OPTION_MENU (c_tool->curve_type_menu),
|
|
|
|
GINT_TO_POINTER (c_tool->curves->curve_type[c_tool->channel]));
|
1999-02-16 16:53:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_update (c_tool, XRANGE_TOP | YRANGE | GRAPH | DRAW);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_channel_reset_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
1998-03-31 15:23:50 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (data);
|
2001-07-08 01:36:00 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->grab_point = -1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_channel_reset (c_tool->curves, c_tool->channel);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_update (c_tool, GRAPH | XRANGE_TOP | DRAW);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (c_tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-03-18 00:35:05 +08:00
|
|
|
static gboolean
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_set_sensitive_callback (gpointer item_data,
|
|
|
|
GimpCurvesTool *c_tool)
|
2002-03-18 00:35:05 +08:00
|
|
|
{
|
|
|
|
GimpHistogramChannel channel = GPOINTER_TO_INT (item_data);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2002-03-18 00:35:05 +08:00
|
|
|
switch (channel)
|
|
|
|
{
|
|
|
|
case GIMP_HISTOGRAM_VALUE:
|
|
|
|
return TRUE;
|
|
|
|
case GIMP_HISTOGRAM_RED:
|
|
|
|
case GIMP_HISTOGRAM_GREEN:
|
|
|
|
case GIMP_HISTOGRAM_BLUE:
|
2002-08-26 19:35:56 +08:00
|
|
|
return c_tool->color;
|
2002-03-18 00:35:05 +08:00
|
|
|
case GIMP_HISTOGRAM_ALPHA:
|
2002-08-26 19:35:56 +08:00
|
|
|
return gimp_drawable_has_alpha (GIMP_IMAGE_MAP_TOOL (c_tool)->drawable);
|
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
|
1999-11-22 19:14:29 +08:00
|
|
|
curves_smooth_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
|
|
|
gint i;
|
|
|
|
gint32 index;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->curves->curve_type[c_tool->channel] != CURVES_SMOOTH)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->curves->curve_type[c_tool->channel] = CURVES_SMOOTH;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-29 03:47:07 +08:00
|
|
|
/* pick representative points from the curve
|
|
|
|
* and make them control points
|
|
|
|
*/
|
1997-11-25 06:05:25 +08:00
|
|
|
for (i = 0; i <= 8; i++)
|
|
|
|
{
|
1998-07-25 02:52:03 +08:00
|
|
|
index = CLAMP0255 (i * 32);
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->curves->points[c_tool->channel][i * 2][0] = index;
|
|
|
|
c_tool->curves->points[c_tool->channel][i * 2][1] = c_tool->curves->curve[c_tool->channel][index];
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_calculate_curve (c_tool->curves, c_tool->channel);
|
|
|
|
|
|
|
|
curves_update (c_tool, GRAPH | XRANGE_TOP | DRAW);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (c_tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-11-22 19:14:29 +08:00
|
|
|
curves_free_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->curves->curve_type[c_tool->channel] != CURVES_FREE)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->curves->curve_type[c_tool->channel] = CURVES_FREE;
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_calculate_curve (c_tool->curves, c_tool->channel);
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_update (c_tool, GRAPH | DRAW);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (c_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,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpCurvesTool *c_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
static GdkCursorType cursor_type = GDK_TOP_LEFT_ARROW;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
GdkCursorType new_type;
|
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;
|
|
|
|
gint closest_point;
|
|
|
|
gint distance;
|
|
|
|
gint x1, x2, y1, y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
new_type = GDK_X_CURSOR;
|
|
|
|
closest_point = 0;
|
|
|
|
|
|
|
|
/* get the pointer position */
|
2002-08-26 19:35:56 +08:00
|
|
|
gdk_window_get_pointer (c_tool->graph->window, &tx, &ty, NULL);
|
2000-01-26 07:06:12 +08:00
|
|
|
x = CLAMP ((tx - RADIUS), 0, 255);
|
|
|
|
y = CLAMP ((ty - RADIUS), 0, 255);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
distance = G_MAXINT;
|
|
|
|
for (i = 0; i < 17; i++)
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->curves->points[c_tool->channel][i][0] != -1)
|
|
|
|
if (abs (x - c_tool->curves->points[c_tool->channel][i][0]) < distance)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
distance = abs (x - c_tool->curves->points[c_tool->channel][i][0]);
|
1997-11-25 06:05:25 +08:00
|
|
|
closest_point = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (distance > MIN_DISTANCE)
|
|
|
|
closest_point = (x + 8) / 16;
|
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_EXPOSE:
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->pixmap == NULL)
|
|
|
|
c_tool->pixmap = gdk_pixmap_new (c_tool->graph->window,
|
|
|
|
GRAPH_WIDTH + RADIUS * 2,
|
|
|
|
GRAPH_HEIGHT + RADIUS * 2, -1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_update (c_tool, GRAPH | DRAW);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
bevent = (GdkEventButton *) event;
|
|
|
|
new_type = GDK_TCROSS;
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
switch (c_tool->curves->curve_type[c_tool->channel])
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
case CURVES_SMOOTH:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* determine the leftmost and rightmost points */
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->leftmost = -1;
|
1997-11-25 06:05:25 +08:00
|
|
|
for (i = closest_point - 1; i >= 0; i--)
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->curves->points[c_tool->channel][i][0] != -1)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->leftmost = c_tool->curves->points[c_tool->channel][i][0];
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->rightmost = 256;
|
1997-11-25 06:05:25 +08:00
|
|
|
for (i = closest_point + 1; i < 17; i++)
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->curves->points[c_tool->channel][i][0] != -1)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->rightmost = c_tool->curves->points[c_tool->channel][i][0];
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->grab_point = closest_point;
|
|
|
|
c_tool->curves->points[c_tool->channel][c_tool->grab_point][0] = x;
|
|
|
|
c_tool->curves->points[c_tool->channel][c_tool->grab_point][1] = 255 - y;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
case CURVES_FREE:
|
|
|
|
c_tool->curves->curve[c_tool->channel][x] = 255 - y;
|
|
|
|
c_tool->grab_point = x;
|
|
|
|
c_tool->last = y;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-04-08 06:58:44 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_calculate_curve (c_tool->curves, c_tool->channel);
|
1999-04-08 06:02:26 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_update (c_tool, GRAPH | XRANGE_TOP | DRAW);
|
|
|
|
gtk_grab_add (widget);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_BUTTON_RELEASE:
|
|
|
|
new_type = GDK_FLEUR;
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->grab_point = -1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (c_tool));
|
1999-04-08 06:02:26 +08:00
|
|
|
|
1999-11-22 19:14:29 +08:00
|
|
|
gtk_grab_remove (widget);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_MOTION_NOTIFY:
|
|
|
|
mevent = (GdkEventMotion *) event;
|
|
|
|
|
|
|
|
if (mevent->is_hint)
|
|
|
|
{
|
|
|
|
mevent->x = tx;
|
|
|
|
mevent->y = ty;
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
switch (c_tool->curves->curve_type[c_tool->channel])
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
case CURVES_SMOOTH:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* If no point is grabbed... */
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->grab_point == -1)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->curves->points[c_tool->channel][closest_point][0] != -1)
|
1997-11-25 06:05:25 +08:00
|
|
|
new_type = GDK_FLEUR;
|
|
|
|
else
|
|
|
|
new_type = GDK_TCROSS;
|
|
|
|
}
|
|
|
|
/* Else, drag the grabbed point */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_type = GDK_TCROSS;
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->curves->points[c_tool->channel][c_tool->grab_point][0] = -1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (x > c_tool->leftmost && x < c_tool->rightmost)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
closest_point = (x + 8) / 16;
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->curves->points[c_tool->channel][closest_point][0] == -1)
|
|
|
|
c_tool->grab_point = closest_point;
|
|
|
|
|
|
|
|
c_tool->curves->points[c_tool->channel][c_tool->grab_point][0] = x;
|
|
|
|
c_tool->curves->points[c_tool->channel][c_tool->grab_point][1] = 255 - y;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_calculate_curve (c_tool->curves, c_tool->channel);
|
|
|
|
|
|
|
|
curves_update (c_tool, GRAPH | XRANGE_TOP | DRAW);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
case CURVES_FREE:
|
|
|
|
if (c_tool->grab_point != -1)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->grab_point > x)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
x1 = x;
|
2002-08-26 19:35:56 +08:00
|
|
|
x2 = c_tool->grab_point;
|
1997-11-25 06:05:25 +08:00
|
|
|
y1 = y;
|
2002-08-26 19:35:56 +08:00
|
|
|
y2 = c_tool->last;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
x1 = c_tool->grab_point;
|
1997-11-25 06:05:25 +08:00
|
|
|
x2 = x;
|
2002-08-26 19:35:56 +08:00
|
|
|
y1 = c_tool->last;
|
1997-11-25 06:05:25 +08:00
|
|
|
y2 = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x2 != x1)
|
|
|
|
for (i = x1; i <= x2; i++)
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->curves->curve[c_tool->channel][i] = 255 - (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->curves->curve[c_tool->channel][x] = 255 - y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->grab_point = x;
|
|
|
|
c_tool->last = y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_update (c_tool, GRAPH | XRANGE_TOP | DRAW);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mevent->state & GDK_BUTTON1_MASK)
|
|
|
|
new_type = GDK_TCROSS;
|
|
|
|
else
|
|
|
|
new_type = GDK_PENCIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_type != cursor_type)
|
|
|
|
{
|
2001-05-25 07:57:08 +08:00
|
|
|
GdkCursor *cursor;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
cursor_type = new_type;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
cursor = gimp_cursor_new (cursor_type,
|
|
|
|
GIMP_TOOL_CURSOR_NONE,
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
2002-08-26 19:35:56 +08:00
|
|
|
gdk_window_set_cursor (c_tool->graph->window, cursor);
|
2001-08-01 08:35:59 +08:00
|
|
|
gdk_cursor_unref (cursor);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-09-04 05:58:41 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curve_print_loc (c_tool, x, 255 - y);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static void
|
|
|
|
curves_load_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! c_tool->file_dialog)
|
|
|
|
file_dialog_create (c_tool);
|
|
|
|
else if (GTK_WIDGET_VISIBLE (c_tool->file_dialog))
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->is_save = FALSE;
|
|
|
|
|
|
|
|
gtk_window_set_title (GTK_WINDOW (c_tool->file_dialog), _("Load Curves"));
|
|
|
|
gtk_widget_show (c_tool->file_dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static void
|
|
|
|
curves_save_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpCurvesTool *c_tool;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool = GIMP_CURVES_TOOL (data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! c_tool->file_dialog)
|
|
|
|
file_dialog_create (c_tool);
|
|
|
|
else if (GTK_WIDGET_VISIBLE (c_tool->file_dialog))
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->is_save = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_window_set_title (GTK_WINDOW (c_tool->file_dialog), _("Save Curves"));
|
|
|
|
gtk_widget_show (c_tool->file_dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-20 20:22:54 +08:00
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
file_dialog_create (GimpCurvesTool *c_tool)
|
2000-01-20 20:22:54 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GtkFileSelection *file_dlg;
|
|
|
|
gchar *temp;
|
|
|
|
|
|
|
|
c_tool->file_dialog = gtk_file_selection_new ("");
|
|
|
|
|
|
|
|
file_dlg = GTK_FILE_SELECTION (c_tool->file_dialog);
|
2000-01-20 20:22:54 +08:00
|
|
|
|
|
|
|
gtk_window_set_wmclass (GTK_WINDOW (file_dlg), "load_save_curves", "Gimp");
|
|
|
|
gtk_window_set_position (GTK_WINDOW (file_dlg), GTK_WIN_POS_MOUSE);
|
|
|
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (file_dlg), 2);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (file_dlg->button_area), 2);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (G_OBJECT (file_dlg->cancel_button), "clicked",
|
|
|
|
G_CALLBACK (file_dialog_cancel_callback),
|
|
|
|
c_tool);
|
|
|
|
g_signal_connect_swapped (G_OBJECT (file_dlg->ok_button), "clicked",
|
|
|
|
G_CALLBACK (file_dialog_ok_callback),
|
|
|
|
c_tool);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (G_OBJECT (file_dlg), "delete_event",
|
|
|
|
G_CALLBACK (file_dialog_cancel_callback),
|
|
|
|
c_tool);
|
|
|
|
g_signal_connect_swapped (G_OBJECT (GIMP_IMAGE_MAP_TOOL (c_tool)->shell),
|
|
|
|
"unmap",
|
|
|
|
G_CALLBACK (file_dialog_cancel_callback),
|
|
|
|
c_tool);
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2001-10-24 23:56:33 +08:00
|
|
|
temp = g_build_filename (gimp_directory (), "curves", NULL);
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_file_selection_set_filename (file_dlg, temp);
|
2000-01-20 20:22:54 +08:00
|
|
|
g_free (temp);
|
2000-02-14 06:26:41 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_help_connect (c_tool->file_dialog, tool_manager_help_func, NULL);
|
2000-01-20 20:22:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
file_dialog_ok_callback (GimpCurvesTool *c_tool)
|
2000-01-20 20:22:54 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
FILE *file = NULL;
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
const gchar *filename;
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
filename =
|
|
|
|
gtk_file_selection_get_filename (GTK_FILE_SELECTION (c_tool->file_dialog));
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! c_tool->is_save)
|
2000-01-20 20:22:54 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
file = fopen (filename, "rt");
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! file)
|
2000-01-20 20:22:54 +08:00
|
|
|
{
|
2002-06-09 20:53:42 +08:00
|
|
|
g_message (_("Failed to open file: '%s': %s"),
|
|
|
|
filename, g_strerror (errno));
|
2000-01-20 20:22:54 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! curves_read_from_file (c_tool, file))
|
2000-01-20 20:22:54 +08:00
|
|
|
{
|
2002-06-09 20:53:42 +08:00
|
|
|
g_message (("Error in reading file '%s'."), filename);
|
2000-01-20 20:22:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
file = fopen (filename, "wt");
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! file)
|
2000-01-20 20:22:54 +08:00
|
|
|
{
|
2002-06-09 20:53:42 +08:00
|
|
|
g_message (_("Failed to open file: '%s': %s"),
|
|
|
|
filename, g_strerror (errno));
|
2000-01-20 20:22:54 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_write_to_file (c_tool, file);
|
2000-01-20 20:22:54 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (file)
|
|
|
|
fclose (file);
|
|
|
|
|
|
|
|
file_dialog_cancel_callback (c_tool);
|
2000-01-20 20:22:54 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static gboolean
|
|
|
|
file_dialog_cancel_callback (GimpCurvesTool *c_tool)
|
2000-01-20 20:22:54 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->file_dialog)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (c_tool->file_dialog);
|
|
|
|
c_tool->file_dialog = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2000-01-20 20:22:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_read_from_file (GimpCurvesTool *c_tool,
|
|
|
|
FILE *file)
|
2000-01-20 20:22:54 +08:00
|
|
|
{
|
2000-12-14 02:53:35 +08:00
|
|
|
gint i, j;
|
|
|
|
gint fields;
|
2000-01-20 20:22:54 +08:00
|
|
|
gchar buf[50];
|
2000-12-14 02:53:35 +08:00
|
|
|
gint index[5][17];
|
|
|
|
gint value[5][17];
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (! fgets (buf, 50, file))
|
2000-01-20 20:22:54 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (strcmp (buf, "# GIMP Curves File\n") != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < 17; j++)
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
fields = fscanf (file, "%d %d ", &index[i][j], &value[i][j]);
|
2000-01-20 20:22:54 +08:00
|
|
|
if (fields != 2)
|
|
|
|
{
|
|
|
|
g_print ("fields != 2");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->curves->curve_type[i] = CURVES_SMOOTH;
|
|
|
|
|
2000-01-20 20:22:54 +08:00
|
|
|
for (j = 0; j < 17; j++)
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->curves->points[i][j][0] = index[i][j];
|
|
|
|
c_tool->curves->points[i][j][1] = value[i][j];
|
2000-01-20 20:22:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_calculate_curve (c_tool->curves, i);
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_update (c_tool, ALL);
|
2002-08-29 03:47:07 +08:00
|
|
|
|
|
|
|
gimp_option_menu_set_history (GTK_OPTION_MENU (c_tool->curve_type_menu),
|
|
|
|
GINT_TO_POINTER (CURVES_SMOOTH));
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (c_tool));
|
2000-01-20 20:22:54 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
curves_write_to_file (GimpCurvesTool *c_tool,
|
|
|
|
FILE *file)
|
2000-01-20 20:22:54 +08:00
|
|
|
{
|
2000-12-14 02:53:35 +08:00
|
|
|
gint i, j;
|
2000-01-20 20:22:54 +08:00
|
|
|
gint32 index;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
2002-08-26 19:35:56 +08:00
|
|
|
if (c_tool->curves->curve_type[i] == CURVES_FREE)
|
2000-01-20 20:22:54 +08:00
|
|
|
{
|
|
|
|
/* pick representative points from the curve and make them control points */
|
|
|
|
for (j = 0; j <= 8; j++)
|
|
|
|
{
|
|
|
|
index = CLAMP0255 (j * 32);
|
2002-08-26 19:35:56 +08:00
|
|
|
c_tool->curves->points[i][j * 2][0] = index;
|
|
|
|
c_tool->curves->points[i][j * 2][1] = c_tool->curves->curve[i][index];
|
2000-01-20 20:22:54 +08:00
|
|
|
}
|
|
|
|
}
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
fprintf (file, "# GIMP Curves File\n");
|
2000-01-20 20:22:54 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < 17; j++)
|
2002-08-26 19:35:56 +08:00
|
|
|
fprintf (file, "%d %d ",
|
|
|
|
c_tool->curves->points[i][j][0],
|
|
|
|
c_tool->curves->points[i][j][1]);
|
2000-01-20 20:22:54 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
fprintf (file, "\n");
|
2000-01-20 20:22:54 +08:00
|
|
|
}
|
|
|
|
}
|