gimp/app/tools/gimpbrightnesscontrasttool.c

546 lines
15 KiB
C
Raw Normal View History

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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1997-11-25 06:05:25 +08:00
*/
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "appenv.h"
#include "actionarea.h"
#include "brightness_contrast.h"
#include "drawable.h"
#include "gimage_mask.h"
#include "gdisplay.h"
#include "image_map.h"
#include "interface.h"
#include "gimplut.h"
build color_cmds, lut_funcs, and pixel_processor feedback in the splash * app/Makefile.am: build color_cmds, lut_funcs, and pixel_processor * app/app_procs.c: feedback in the splash screen when loading parasites. * app/boundary.c: Optimized find_empty_segs. * app/brightness_contrast.[ch] * app/levels.[ch] * app/posterize.[ch]: moved pdb and lut calculation code. These files now contain only GUI functions. * app/channel.c: Optimized channel_bounds (fewer compares, better use of registers). Use color_region instead of channel_*_segment in channel_combine_rect. Optimized channel_combine_ellipse by skipping pixels inside of the ellipse. Use pixel_region_process_parallel in channel_combine_mask. Use a GimpLut in channel_invert, and channel_sharpen. * app/invert.c * app/equalize.c: moved the lut functions to lut_funcs.c * app/gimpdrawable.c, app/gimpdrawableP.h * app/gimpimage.c, app/gimpimageP.h: removed unused gimpmatrix variables/includes. * app/gimplut.[ch]: added new function gimp_lut_process_inline that operates on a single PixelRegion. * app/gimpparasite.[ch]: new functions to save/load parasiterc * app/parasitelist.[ch]: new functions to save/load ParasiteLists in/from files. * libgimp/parasite.[ch]: new functions to load/save parasites. * app/internal_procs.c: get some procs from new location in color_cmds.h. * app/pixel_region.[ch]: moved pixel_regions_process_parallel related functions to a new file. * app/color_cmds.[ch]: new files for PDB definitions/implementations of color correction functions. * app/lut_funcs.[ch]: new files to hold lut creation functions. * app/pixel_processor.[ch]: new files that contain the pixel_regions_process_parallel routines. Added some new capabilities that are currently unused.
1999-04-09 14:00:11 +08:00
#include "lut_funcs.h"
1997-11-25 06:05:25 +08:00
#include "libgimp/gimpintl.h"
1997-11-25 06:05:25 +08:00
#define TEXT_WIDTH 45
#define TEXT_HEIGHT 25
#define SLIDER_WIDTH 200
#define SLIDER_HEIGHT 35
#define BRIGHTNESS_SLIDER 0x1
#define CONTRAST_SLIDER 0x2
#define BRIGHTNESS_TEXT 0x4
#define CONTRAST_TEXT 0x8
#define ALL 0xF
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
/* the brightness-contrast structures */
1997-11-25 06:05:25 +08:00
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
typedef struct _BrightnessContrast BrightnessContrast;
1997-11-25 06:05:25 +08:00
struct _BrightnessContrast
{
gint x, y; /* coords for last mouse click */
1997-11-25 06:05:25 +08:00
};
typedef struct _BrightnessContrastDialog BrightnessContrastDialog;
struct _BrightnessContrastDialog
{
GtkWidget *shell;
GtkWidget *gimage_name;
GtkWidget *brightness_text;
GtkWidget *contrast_text;
GtkAdjustment *brightness_data;
GtkAdjustment *contrast_data;
GimpDrawable *drawable;
1997-11-25 06:05:25 +08:00
ImageMap image_map;
double brightness;
double contrast;
gint preview;
GimpLut *lut;
1997-11-25 06:05:25 +08:00
};
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
/* the brightness-contrast tool options */
static ToolOptions *brightness_contrast_options = NULL;
/* the brightness-contrast dialog */
static BrightnessContrastDialog *brightness_contrast_dialog = NULL;
1997-11-25 06:05:25 +08:00
/* brightness contrast action functions */
static void brightness_contrast_control (Tool *, ToolAction, gpointer);
1997-11-25 06:05:25 +08:00
static BrightnessContrastDialog * brightness_contrast_new_dialog (void);
1997-11-25 06:05:25 +08:00
static void brightness_contrast_update (BrightnessContrastDialog *, int);
static void brightness_contrast_preview (BrightnessContrastDialog *);
static void brightness_contrast_ok_callback (GtkWidget *, gpointer);
static void brightness_contrast_cancel_callback (GtkWidget *, gpointer);
static gint brightness_contrast_delete_callback (GtkWidget *, GdkEvent *, gpointer);
static void brightness_contrast_preview_update (GtkWidget *, gpointer);
static void brightness_contrast_brightness_scale_update (GtkAdjustment *, gpointer);
static void brightness_contrast_contrast_scale_update (GtkAdjustment *, gpointer);
static void brightness_contrast_brightness_text_update (GtkWidget *, gpointer);
static void brightness_contrast_contrast_text_update (GtkWidget *, gpointer);
/* brightness-contrast select action functions */
1997-11-25 06:05:25 +08:00
static void
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
brightness_contrast_control (Tool *tool,
ToolAction action,
gpointer gdisp_ptr)
1997-11-25 06:05:25 +08:00
{
switch (action)
{
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
case PAUSE:
1997-11-25 06:05:25 +08:00
break;
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
case RESUME:
1997-11-25 06:05:25 +08:00
break;
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
case HALT:
1997-11-25 06:05:25 +08:00
if (brightness_contrast_dialog)
brightness_contrast_cancel_callback (NULL, (gpointer) brightness_contrast_dialog);
1997-11-25 06:05:25 +08:00
break;
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
default:
break;
1997-11-25 06:05:25 +08:00
}
}
Tool *
tools_new_brightness_contrast ()
{
Tool * tool;
BrightnessContrast * private;
/* The tool options */
if (!brightness_contrast_options)
{
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
brightness_contrast_options =
tool_options_new (_("Brightness-Contrast Options"));
tools_register (BRIGHTNESS_CONTRAST, brightness_contrast_options);
}
1997-11-25 06:05:25 +08:00
tool = tools_new_tool (BRIGHTNESS_CONTRAST);
private = g_new (BrightnessContrast, 1);
1997-11-25 06:05:25 +08:00
tool->scroll_lock = TRUE; /* Disallow scrolling */
tool->preserve = FALSE; /* Don't preserve on drawable change */
tool->private = (void *) private;
1997-11-25 06:05:25 +08:00
tool->control_func = brightness_contrast_control;
return tool;
}
void
tools_free_brightness_contrast (Tool *tool)
{
BrightnessContrast * bc;
bc = (BrightnessContrast *) tool->private;
/* Close the color select dialog */
if (brightness_contrast_dialog)
brightness_contrast_cancel_callback (NULL, (gpointer) brightness_contrast_dialog);
1997-11-25 06:05:25 +08:00
g_free (bc);
}
void
brightness_contrast_initialize (GDisplay *gdisp)
1997-11-25 06:05:25 +08:00
{
if (drawable_indexed (gimage_active_drawable (gdisp->gimage)))
{
g_message (_("Brightness-Contrast does not operate on indexed drawables."));
1997-11-25 06:05:25 +08:00
return;
}
/* The brightness-contrast dialog */
if (!brightness_contrast_dialog)
brightness_contrast_dialog = brightness_contrast_new_dialog ();
else
if (!GTK_WIDGET_VISIBLE (brightness_contrast_dialog->shell))
gtk_widget_show (brightness_contrast_dialog->shell);
/* Initialize dialog fields */
brightness_contrast_dialog->image_map = NULL;
brightness_contrast_dialog->brightness = 0.0;
brightness_contrast_dialog->contrast = 0.0;
brightness_contrast_dialog->drawable = gimage_active_drawable (gdisp->gimage);
brightness_contrast_dialog->image_map =
image_map_create (gdisp, brightness_contrast_dialog->drawable);
1997-11-25 06:05:25 +08:00
brightness_contrast_update (brightness_contrast_dialog, ALL);
}
/********************************/
/* Brightness Contrast dialog */
/********************************/
static BrightnessContrastDialog *
1997-11-25 06:05:25 +08:00
brightness_contrast_new_dialog ()
{
BrightnessContrastDialog *bcd;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *table;
GtkWidget *label;
GtkWidget *slider;
GtkWidget *toggle;
GtkObject *data;
static ActionAreaItem action_items[] =
{
{ N_("OK"), brightness_contrast_ok_callback, NULL, NULL },
{ N_("Cancel"), brightness_contrast_cancel_callback, NULL, NULL }
};
bcd = g_new (BrightnessContrastDialog, 1);
1997-11-25 06:05:25 +08:00
bcd->preview = TRUE;
bcd->lut = gimp_lut_new ();
1997-11-25 06:05:25 +08:00
/* The shell and main vbox */
bcd->shell = gtk_dialog_new ();
gtk_window_set_wmclass (GTK_WINDOW (bcd->shell), "brightness_contrast", "Gimp");
gtk_window_set_title (GTK_WINDOW (bcd->shell), _("Brightness-Contrast"));
/* handle wm close signal */
1997-11-25 06:05:25 +08:00
gtk_signal_connect (GTK_OBJECT (bcd->shell), "delete_event",
GTK_SIGNAL_FUNC (brightness_contrast_delete_callback),
bcd);
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (bcd->shell)->vbox), vbox);
1997-11-25 06:05:25 +08:00
/* The table containing sliders */
table = gtk_table_new (2, 3, FALSE);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
/* Create the brightness scale widget */
label = gtk_label_new (_("Brightness"));
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
1997-11-25 06:05:25 +08:00
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 2, 2);
data = gtk_adjustment_new (0, -127, 127.0, 1.0, 1.0, 0.0);
bcd->brightness_data = GTK_ADJUSTMENT (data);
slider = gtk_hscale_new (GTK_ADJUSTMENT (data));
gtk_widget_set_usize (slider, SLIDER_WIDTH, SLIDER_HEIGHT);
gtk_scale_set_digits (GTK_SCALE (slider), 0);
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
gtk_table_attach (GTK_TABLE (table), slider, 1, 2, 0, 1,
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
2, 2);
gtk_signal_connect (GTK_OBJECT (data), "value_changed",
(GtkSignalFunc) brightness_contrast_brightness_scale_update,
bcd);
bcd->brightness_text = gtk_entry_new ();
gtk_widget_set_usize (bcd->brightness_text, TEXT_WIDTH, TEXT_HEIGHT);
gtk_table_attach (GTK_TABLE (table), bcd->brightness_text, 2, 3, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 2, 2);
gtk_signal_connect (GTK_OBJECT (bcd->brightness_text), "changed",
(GtkSignalFunc) brightness_contrast_brightness_text_update,
bcd);
gtk_widget_show (label);
gtk_widget_show (bcd->brightness_text);
gtk_widget_show (slider);
/* Create the contrast scale widget */
label = gtk_label_new (_("Contrast"));
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
1997-11-25 06:05:25 +08:00
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 2, 2);
data = gtk_adjustment_new (0, -127.0, 127.0, 1.0, 1.0, 0.0);
bcd->contrast_data = GTK_ADJUSTMENT (data);
slider = gtk_hscale_new (GTK_ADJUSTMENT (data));
gtk_widget_set_usize (slider, SLIDER_WIDTH, SLIDER_HEIGHT);
gtk_scale_set_digits (GTK_SCALE (slider), 0);
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
gtk_table_attach (GTK_TABLE (table), slider, 1, 2, 1, 2,
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
2, 2);
gtk_signal_connect (GTK_OBJECT (data), "value_changed",
(GtkSignalFunc) brightness_contrast_contrast_scale_update,
bcd);
bcd->contrast_text = gtk_entry_new ();
gtk_widget_set_usize (bcd->contrast_text, TEXT_WIDTH, TEXT_HEIGHT);
gtk_table_attach (GTK_TABLE (table), bcd->contrast_text, 2, 3, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 2, 2);
gtk_signal_connect (GTK_OBJECT (bcd->contrast_text), "changed",
(GtkSignalFunc) brightness_contrast_contrast_text_update,
bcd);
gtk_widget_show (label);
gtk_widget_show (bcd->contrast_text);
gtk_widget_show (slider);
/* Horizontal box for preview and preserve luminosity toggle buttons */
hbox = gtk_hbox_new (TRUE, 2);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
/* The preview toggle */
toggle = gtk_check_button_new_with_label (_("Preview"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), bcd->preview);
1997-11-25 06:05:25 +08:00
gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
(GtkSignalFunc) brightness_contrast_preview_update,
bcd);
gtk_widget_show (label);
gtk_widget_show (toggle);
gtk_widget_show (hbox);
/* The action area */
action_items[0].user_data = bcd;
action_items[1].user_data = bcd;
build_action_area (GTK_DIALOG (bcd->shell), action_items, 2, 0);
gtk_widget_show (table);
gtk_widget_show (vbox);
gtk_widget_show (bcd->shell);
return bcd;
}
static void
brightness_contrast_update (BrightnessContrastDialog *bcd,
gint update)
1997-11-25 06:05:25 +08:00
{
char text[12];
if (update & BRIGHTNESS_SLIDER)
{
bcd->brightness_data->value = bcd->brightness;
gtk_signal_emit_by_name (GTK_OBJECT (bcd->brightness_data), "value_changed");
}
if (update & CONTRAST_SLIDER)
{
bcd->contrast_data->value = bcd->contrast;
gtk_signal_emit_by_name (GTK_OBJECT (bcd->contrast_data), "value_changed");
}
if (update & BRIGHTNESS_TEXT)
{
g_snprintf (text, sizeof (text), "%0.0f", bcd->brightness);
1997-11-25 06:05:25 +08:00
gtk_entry_set_text (GTK_ENTRY (bcd->brightness_text), text);
}
if (update & CONTRAST_TEXT)
{
g_snprintf (text, sizeof (text), "%0.0f", bcd->contrast);
1997-11-25 06:05:25 +08:00
gtk_entry_set_text (GTK_ENTRY (bcd->contrast_text), text);
}
}
static void
brightness_contrast_preview (BrightnessContrastDialog *bcd)
{
if (!bcd->image_map)
{
g_message ("brightness_contrast_preview(): No image map");
return;
}
active_tool->preserve = TRUE;
brightness_contrast_lut_setup (bcd->lut, bcd->brightness / 255.0,
bcd->contrast / 127.0,
gimp_drawable_bytes (bcd->drawable));
image_map_apply (bcd->image_map, (ImageMapApplyFunc) gimp_lut_process_2,
(void *) bcd->lut);
active_tool->preserve = FALSE;
1997-11-25 06:05:25 +08:00
}
static void
brightness_contrast_ok_callback (GtkWidget *widget,
gpointer client_data)
{
BrightnessContrastDialog *bcd;
bcd = (BrightnessContrastDialog *) client_data;
if (GTK_WIDGET_VISIBLE (bcd->shell))
gtk_widget_hide (bcd->shell);
active_tool->preserve = TRUE;
1997-11-25 06:05:25 +08:00
if (!bcd->preview)
{
brightness_contrast_lut_setup (bcd->lut, bcd->brightness / 255.0,
bcd->contrast / 127.0,
gimp_drawable_bytes (bcd->drawable));
image_map_apply (bcd->image_map, (ImageMapApplyFunc) gimp_lut_process_2,
(void *) bcd->lut);
}
1997-11-25 06:05:25 +08:00
if (bcd->image_map)
image_map_commit (bcd->image_map);
active_tool->preserve = FALSE;
1997-11-25 06:05:25 +08:00
bcd->image_map = NULL;
active_tool->gdisp_ptr = NULL;
active_tool->drawable = NULL;
1997-11-25 06:05:25 +08:00
}
static gint
brightness_contrast_delete_callback (GtkWidget *widget,
GdkEvent *event,
gpointer data)
1997-11-25 06:05:25 +08:00
{
brightness_contrast_cancel_callback (widget, data);
1997-11-25 06:05:25 +08:00
return TRUE;
1997-11-25 06:05:25 +08:00
}
static void
brightness_contrast_cancel_callback (GtkWidget *widget,
gpointer data)
1997-11-25 06:05:25 +08:00
{
BrightnessContrastDialog *bcd;
bcd = (BrightnessContrastDialog *) data;
1997-11-25 06:05:25 +08:00
if (GTK_WIDGET_VISIBLE (bcd->shell))
gtk_widget_hide (bcd->shell);
if (bcd->image_map)
{
active_tool->preserve = TRUE;
1997-11-25 06:05:25 +08:00
image_map_abort (bcd->image_map);
active_tool->preserve = FALSE;
bcd->image_map = NULL;
1997-11-25 06:05:25 +08:00
gdisplays_flush ();
}
active_tool->gdisp_ptr = NULL;
active_tool->drawable = NULL;
1997-11-25 06:05:25 +08:00
}
static void
brightness_contrast_preview_update (GtkWidget *widget,
1997-11-25 06:05:25 +08:00
gpointer data)
{
BrightnessContrastDialog *bcd;
bcd = (BrightnessContrastDialog *) data;
if (GTK_TOGGLE_BUTTON (widget)->active)
1997-11-25 06:05:25 +08:00
{
bcd->preview = TRUE;
brightness_contrast_preview (bcd);
}
else
bcd->preview = FALSE;
}
static void
brightness_contrast_brightness_scale_update (GtkAdjustment *adjustment,
gpointer data)
{
BrightnessContrastDialog *bcd;
bcd = (BrightnessContrastDialog *) data;
if (bcd->brightness != adjustment->value)
{
bcd->brightness = adjustment->value;
brightness_contrast_update (bcd, BRIGHTNESS_TEXT);
if (bcd->preview)
brightness_contrast_preview (bcd);
}
}
static void
brightness_contrast_contrast_scale_update (GtkAdjustment *adjustment,
gpointer data)
{
BrightnessContrastDialog *bcd;
bcd = (BrightnessContrastDialog *) data;
if (bcd->contrast != adjustment->value)
{
bcd->contrast = adjustment->value;
brightness_contrast_update (bcd, CONTRAST_TEXT);
if (bcd->preview)
brightness_contrast_preview (bcd);
}
}
static void
brightness_contrast_brightness_text_update (GtkWidget *widget,
1997-11-25 06:05:25 +08:00
gpointer data)
{
BrightnessContrastDialog *bcd;
gchar *str;
gint value;
1997-11-25 06:05:25 +08:00
str = gtk_entry_get_text (GTK_ENTRY (widget));
1997-11-25 06:05:25 +08:00
bcd = (BrightnessContrastDialog *) data;
value = BOUNDS (((int) atof (str)), -127, 127);
if ((int) bcd->brightness != value)
{
bcd->brightness = value;
brightness_contrast_update (bcd, BRIGHTNESS_SLIDER);
if (bcd->preview)
brightness_contrast_preview (bcd);
}
}
static void
brightness_contrast_contrast_text_update (GtkWidget *widget,
1997-11-25 06:05:25 +08:00
gpointer data)
{
BrightnessContrastDialog *bcd;
gchar *str;
gint value;
1997-11-25 06:05:25 +08:00
str = gtk_entry_get_text (GTK_ENTRY (widget));
1997-11-25 06:05:25 +08:00
bcd = (BrightnessContrastDialog *) data;
value = BOUNDS (((int) atof (str)), -127, 127);
if ((int) bcd->contrast != value)
{
bcd->contrast = value;
brightness_contrast_update (bcd, CONTRAST_SLIDER);
if (bcd->preview)
brightness_contrast_preview (bcd);
}
}