1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "libgimpcolor/gimpcolor.h"
24
#include "libgimpmath/gimpmath.h"
25
#include "libgimpwidgets/gimpwidgets.h"
27
#include "tools-types.h"
29
#include "base/color-balance.h"
31
#include "core/gimpdrawable.h"
32
#include "core/gimpimage.h"
33
#include "core/gimpimagemap.h"
35
#include "widgets/gimphelp-ids.h"
36
#include "widgets/gimpenumwidgets.h"
38
#include "display/gimpdisplay.h"
40
#include "gimpcolorbalancetool.h"
41
#include "gimpimagemapoptions.h"
43
#include "gimp-intl.h"
46
#define CYAN_RED (1 << 0)
47
#define MAGENTA_GREEN (1 << 1)
48
#define YELLOW_BLUE (1 << 2)
49
#define PRESERVE (1 << 3)
50
#define ALL (CYAN_RED | MAGENTA_GREEN | YELLOW_BLUE | PRESERVE)
53
/* local function prototypes */
55
static void gimp_color_balance_tool_class_init (GimpColorBalanceToolClass *klass);
56
static void gimp_color_balance_tool_init (GimpColorBalanceTool *cb_tool);
58
static void gimp_color_balance_tool_finalize (GObject *object);
60
static gboolean gimp_color_balance_tool_initialize (GimpTool *tool,
63
static void gimp_color_balance_tool_map (GimpImageMapTool *image_map_tool);
64
static void gimp_color_balance_tool_dialog (GimpImageMapTool *image_map_tool);
65
static void gimp_color_balance_tool_reset (GimpImageMapTool *image_map_tool);
67
static void color_balance_update (GimpColorBalanceTool *cb_tool,
69
static void color_balance_range_callback (GtkWidget *widget,
70
GimpColorBalanceTool *cb_tool);
71
static void color_balance_range_reset_callback (GtkWidget *widget,
72
GimpColorBalanceTool *cb_tool);
73
static void color_balance_preserve_update (GtkWidget *widget,
74
GimpColorBalanceTool *cb_tool);
75
static void color_balance_cr_adjustment_update (GtkAdjustment *adj,
76
GimpColorBalanceTool *cb_tool);
77
static void color_balance_mg_adjustment_update (GtkAdjustment *adj,
78
GimpColorBalanceTool *cb_tool);
79
static void color_balance_yb_adjustment_update (GtkAdjustment *adj,
80
GimpColorBalanceTool *cb_tool);
83
static GimpImageMapToolClass *parent_class = NULL;
89
gimp_color_balance_tool_register (GimpToolRegisterCallback callback,
92
(* callback) (GIMP_TYPE_COLOR_BALANCE_TOOL,
93
GIMP_TYPE_IMAGE_MAP_OPTIONS, NULL,
95
"gimp-color-balance-tool",
97
_("Adjust color balance"),
98
N_("Color _Balance..."), NULL,
99
NULL, GIMP_HELP_TOOL_COLOR_BALANCE,
100
GIMP_STOCK_TOOL_COLOR_BALANCE,
105
gimp_color_balance_tool_get_type (void)
107
static GType tool_type = 0;
111
static const GTypeInfo tool_info =
113
sizeof (GimpColorBalanceToolClass),
114
(GBaseInitFunc) NULL,
115
(GBaseFinalizeFunc) NULL,
116
(GClassInitFunc) gimp_color_balance_tool_class_init,
117
NULL, /* class_finalize */
118
NULL, /* class_data */
119
sizeof (GimpColorBalanceTool),
121
(GInstanceInitFunc) gimp_color_balance_tool_init,
124
tool_type = g_type_register_static (GIMP_TYPE_IMAGE_MAP_TOOL,
125
"GimpColorBalanceTool",
133
gimp_color_balance_tool_class_init (GimpColorBalanceToolClass *klass)
135
GObjectClass *object_class;
136
GimpToolClass *tool_class;
137
GimpImageMapToolClass *image_map_tool_class;
139
object_class = G_OBJECT_CLASS (klass);
140
tool_class = GIMP_TOOL_CLASS (klass);
141
image_map_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
143
parent_class = g_type_class_peek_parent (klass);
145
object_class->finalize = gimp_color_balance_tool_finalize;
147
tool_class->initialize = gimp_color_balance_tool_initialize;
149
image_map_tool_class->shell_desc = _("Adjust Color Balance");
151
image_map_tool_class->map = gimp_color_balance_tool_map;
152
image_map_tool_class->dialog = gimp_color_balance_tool_dialog;
153
image_map_tool_class->reset = gimp_color_balance_tool_reset;
157
gimp_color_balance_tool_init (GimpColorBalanceTool *cb_tool)
159
cb_tool->color_balance = g_new0 (ColorBalance, 1);
160
cb_tool->transfer_mode = GIMP_MIDTONES;
162
color_balance_init (cb_tool->color_balance);
166
gimp_color_balance_tool_finalize (GObject *object)
168
GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (object);
170
if (cb_tool->color_balance)
172
g_free (cb_tool->color_balance);
173
cb_tool->color_balance = NULL;
176
G_OBJECT_CLASS (parent_class)->finalize (object);
180
gimp_color_balance_tool_initialize (GimpTool *tool,
183
GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (tool);
184
GimpDrawable *drawable;
186
drawable = gimp_image_active_drawable (gdisp->gimage);
191
if (! gimp_drawable_is_rgb (drawable))
193
g_message (_("Color balance operates only on RGB color layers."));
197
color_balance_init (cb_tool->color_balance);
199
cb_tool->transfer_mode = GIMP_MIDTONES;
201
GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
203
color_balance_update (cb_tool, ALL);
209
gimp_color_balance_tool_map (GimpImageMapTool *image_map_tool)
211
GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (image_map_tool);
213
color_balance_create_lookup_tables (cb_tool->color_balance);
214
gimp_image_map_apply (image_map_tool->image_map,
216
cb_tool->color_balance);
220
/**************************/
221
/* Color Balance dialog */
222
/**************************/
224
static GtkAdjustment *
225
create_levels_scale (const gchar *left,
232
GtkWidget *spinbutton;
235
adj = GTK_ADJUSTMENT (gtk_adjustment_new (0, -100.0, 100.0, 1.0, 10.0, 0.0));
237
label = gtk_label_new (left);
238
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
239
gtk_table_attach (GTK_TABLE (table), label, 0, 1, col, col + 1,
240
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
241
gtk_widget_show (label);
243
slider = gtk_hscale_new (adj);
244
gtk_scale_set_draw_value (GTK_SCALE (slider), FALSE);
245
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
246
gtk_widget_set_size_request (slider, 100, -1);
247
gtk_table_attach_defaults (GTK_TABLE (table), slider, 1, 2, col, col + 1);
248
gtk_widget_show (slider);
250
label = gtk_label_new (right);
251
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
252
gtk_table_attach (GTK_TABLE (table), label, 2, 3, col, col + 1,
253
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
254
gtk_widget_show (label);
256
spinbutton = gtk_spin_button_new (adj, 1.0, 0);
257
gtk_table_attach (GTK_TABLE (table), spinbutton, 3, 4, col, col + 1,
258
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
259
gtk_widget_show (spinbutton);
265
gimp_color_balance_tool_dialog (GimpImageMapTool *image_map_tool)
267
GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (image_map_tool);
275
frame = gimp_enum_radio_frame_new (GIMP_TYPE_TRANSFER_MODE,
276
gtk_label_new (_("Select Range to Modify")),
277
G_CALLBACK (color_balance_range_callback),
280
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), frame,
282
gtk_widget_show (frame);
284
frame = gimp_frame_new (_("Modify Selected Range's Color Levels"));
285
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), frame,
287
gtk_widget_show (frame);
289
vbox = gtk_vbox_new (FALSE, 4);
290
gtk_container_add (GTK_CONTAINER (frame), vbox);
291
gtk_widget_show (vbox);
293
/* The table containing sliders */
294
table = gtk_table_new (3, 4, FALSE);
295
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
296
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
297
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
298
gtk_widget_show (table);
300
cb_tool->cyan_red_adj =
301
create_levels_scale (_("Cyan"), _("Red"), table, 0);
303
g_signal_connect (cb_tool->cyan_red_adj, "value_changed",
304
G_CALLBACK (color_balance_cr_adjustment_update),
307
cb_tool->magenta_green_adj =
308
create_levels_scale (_("Magenta"), _("Green"), table, 1);
310
g_signal_connect (cb_tool->magenta_green_adj, "value_changed",
311
G_CALLBACK (color_balance_mg_adjustment_update),
314
cb_tool->yellow_blue_adj =
315
create_levels_scale (_("Yellow"), _("Blue"), table, 2);
317
g_signal_connect (cb_tool->yellow_blue_adj, "value_changed",
318
G_CALLBACK (color_balance_yb_adjustment_update),
321
hbox = gtk_hbox_new (FALSE, 6);
322
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
323
gtk_widget_show (hbox);
325
button = gtk_button_new_with_mnemonic (_("R_eset range"));
326
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
327
gtk_widget_show (button);
329
g_signal_connect (button, "clicked",
330
G_CALLBACK (color_balance_range_reset_callback),
333
cb_tool->preserve_toggle =
334
gtk_check_button_new_with_mnemonic (_("Preserve _luminosity"));
335
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb_tool->preserve_toggle),
336
cb_tool->color_balance->preserve_luminosity);
337
gtk_box_pack_end (GTK_BOX (image_map_tool->main_vbox),
338
cb_tool->preserve_toggle, FALSE, FALSE, 0);
339
gtk_widget_show (cb_tool->preserve_toggle);
341
g_signal_connect (cb_tool->preserve_toggle, "toggled",
342
G_CALLBACK (color_balance_preserve_update),
345
/* set range after everything is in place */
346
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (toggle),
347
cb_tool->transfer_mode);
351
gimp_color_balance_tool_reset (GimpImageMapTool *image_map_tool)
353
GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (image_map_tool);
355
color_balance_init (cb_tool->color_balance);
356
color_balance_update (cb_tool, ALL);
360
color_balance_update (GimpColorBalanceTool *cb_tool,
365
tm = cb_tool->transfer_mode;
367
if (update & CYAN_RED)
368
gtk_adjustment_set_value (cb_tool->cyan_red_adj,
369
cb_tool->color_balance->cyan_red[tm]);
371
if (update & MAGENTA_GREEN)
372
gtk_adjustment_set_value (cb_tool->magenta_green_adj,
373
cb_tool->color_balance->magenta_green[tm]);
375
if (update & YELLOW_BLUE)
376
gtk_adjustment_set_value (cb_tool->yellow_blue_adj,
377
cb_tool->color_balance->yellow_blue[tm]);
379
if (update & PRESERVE)
380
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb_tool->preserve_toggle),
381
cb_tool->color_balance->preserve_luminosity);
385
color_balance_range_callback (GtkWidget *widget,
386
GimpColorBalanceTool *cb_tool)
388
gimp_radio_button_update (widget, &cb_tool->transfer_mode);
389
color_balance_update (cb_tool, ALL);
393
color_balance_range_reset_callback (GtkWidget *widget,
394
GimpColorBalanceTool *cb_tool)
396
color_balance_range_reset (cb_tool->color_balance,
397
cb_tool->transfer_mode);
398
color_balance_update (cb_tool, ALL);
400
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (cb_tool));
404
color_balance_preserve_update (GtkWidget *widget,
405
GimpColorBalanceTool *cb_tool)
409
active = GTK_TOGGLE_BUTTON (widget)->active;
411
if (cb_tool->color_balance->preserve_luminosity != active)
413
cb_tool->color_balance->preserve_luminosity = active;
415
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (cb_tool));
420
color_balance_cr_adjustment_update (GtkAdjustment *adjustment,
421
GimpColorBalanceTool *cb_tool)
425
tm = cb_tool->transfer_mode;
427
if (cb_tool->color_balance->cyan_red[tm] != adjustment->value)
429
cb_tool->color_balance->cyan_red[tm] = adjustment->value;
431
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (cb_tool));
436
color_balance_mg_adjustment_update (GtkAdjustment *adjustment,
437
GimpColorBalanceTool *cb_tool)
441
tm = cb_tool->transfer_mode;
443
if (cb_tool->color_balance->magenta_green[tm] != adjustment->value)
445
cb_tool->color_balance->magenta_green[tm] = adjustment->value;
447
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (cb_tool));
452
color_balance_yb_adjustment_update (GtkAdjustment *adjustment,
453
GimpColorBalanceTool *cb_tool)
457
tm = cb_tool->transfer_mode;
459
if (cb_tool->color_balance->yellow_blue[tm] != adjustment->value)
461
cb_tool->color_balance->yellow_blue[tm] = adjustment->value;
463
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (cb_tool));