~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/tools/gimpcolorbalancetool.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
20
20
 
21
21
#include <gtk/gtk.h>
22
22
 
23
 
#include "libgimpcolor/gimpcolor.h"
24
 
#include "libgimpmath/gimpmath.h"
25
23
#include "libgimpwidgets/gimpwidgets.h"
26
24
 
27
25
#include "tools-types.h"
33
31
#include "core/gimpimagemap.h"
34
32
 
35
33
#include "widgets/gimphelp-ids.h"
36
 
#include "widgets/gimpenumwidgets.h"
37
34
 
38
35
#include "display/gimpdisplay.h"
39
36
 
52
49
 
53
50
/*  local function prototypes  */
54
51
 
55
 
static void   gimp_color_balance_tool_class_init (GimpColorBalanceToolClass *klass);
56
 
static void   gimp_color_balance_tool_init       (GimpColorBalanceTool      *cb_tool);
57
 
 
58
52
static void     gimp_color_balance_tool_finalize   (GObject          *object);
59
53
 
60
54
static gboolean gimp_color_balance_tool_initialize (GimpTool         *tool,
61
 
                                                    GimpDisplay      *gdisp);
 
55
                                                    GimpDisplay      *display,
 
56
                                                    GError          **error);
62
57
 
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);
 
58
static void     gimp_color_balance_tool_map        (GimpImageMapTool *im_tool);
 
59
static void     gimp_color_balance_tool_dialog     (GimpImageMapTool *im_tool);
 
60
static void     gimp_color_balance_tool_reset      (GimpImageMapTool *im_tool);
66
61
 
67
62
static void     color_balance_update               (GimpColorBalanceTool *cb_tool,
68
63
                                                    gint                  update);
80
75
                                                    GimpColorBalanceTool *cb_tool);
81
76
 
82
77
 
83
 
static GimpImageMapToolClass *parent_class = NULL;
84
 
 
85
 
 
86
 
/*  functions  */
 
78
G_DEFINE_TYPE (GimpColorBalanceTool, gimp_color_balance_tool,
 
79
               GIMP_TYPE_IMAGE_MAP_TOOL)
 
80
 
 
81
#define parent_class gimp_color_balance_tool_parent_class
 
82
 
87
83
 
88
84
void
89
85
gimp_color_balance_tool_register (GimpToolRegisterCallback  callback,
94
90
                0,
95
91
                "gimp-color-balance-tool",
96
92
                _("Color Balance"),
97
 
                _("Adjust color balance"),
 
93
                _("Color Balance Tool: Adjust color distribution"),
98
94
                N_("Color _Balance..."), NULL,
99
95
                NULL, GIMP_HELP_TOOL_COLOR_BALANCE,
100
96
                GIMP_STOCK_TOOL_COLOR_BALANCE,
101
97
                data);
102
98
}
103
99
 
104
 
GType
105
 
gimp_color_balance_tool_get_type (void)
106
 
{
107
 
  static GType tool_type = 0;
108
 
 
109
 
  if (! tool_type)
110
 
    {
111
 
      static const GTypeInfo tool_info =
112
 
      {
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),
120
 
        0,              /* n_preallocs    */
121
 
        (GInstanceInitFunc) gimp_color_balance_tool_init,
122
 
      };
123
 
 
124
 
      tool_type = g_type_register_static (GIMP_TYPE_IMAGE_MAP_TOOL,
125
 
                                          "GimpColorBalanceTool",
126
 
                                          &tool_info, 0);
127
 
    }
128
 
 
129
 
  return tool_type;
130
 
}
131
 
 
132
100
static void
133
101
gimp_color_balance_tool_class_init (GimpColorBalanceToolClass *klass)
134
102
{
135
 
  GObjectClass          *object_class;
136
 
  GimpToolClass         *tool_class;
137
 
  GimpImageMapToolClass *image_map_tool_class;
138
 
 
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);
142
 
 
143
 
  parent_class = g_type_class_peek_parent (klass);
144
 
 
145
 
  object_class->finalize       = gimp_color_balance_tool_finalize;
146
 
 
147
 
  tool_class->initialize       = gimp_color_balance_tool_initialize;
148
 
 
149
 
  image_map_tool_class->shell_desc = _("Adjust Color Balance");
150
 
 
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;
 
103
  GObjectClass          *object_class  = G_OBJECT_CLASS (klass);
 
104
  GimpToolClass         *tool_class    = GIMP_TOOL_CLASS (klass);
 
105
  GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
 
106
 
 
107
  object_class->finalize    = gimp_color_balance_tool_finalize;
 
108
 
 
109
  tool_class->initialize    = gimp_color_balance_tool_initialize;
 
110
 
 
111
  im_tool_class->shell_desc = _("Adjust Color Balance");
 
112
 
 
113
  im_tool_class->map        = gimp_color_balance_tool_map;
 
114
  im_tool_class->dialog     = gimp_color_balance_tool_dialog;
 
115
  im_tool_class->reset      = gimp_color_balance_tool_reset;
154
116
}
155
117
 
156
118
static void
177
139
}
178
140
 
179
141
static gboolean
180
 
gimp_color_balance_tool_initialize (GimpTool    *tool,
181
 
                                    GimpDisplay *gdisp)
 
142
gimp_color_balance_tool_initialize (GimpTool     *tool,
 
143
                                    GimpDisplay  *display,
 
144
                                    GError      **error)
182
145
{
183
146
  GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (tool);
184
147
  GimpDrawable         *drawable;
185
148
 
186
 
  drawable = gimp_image_active_drawable (gdisp->gimage);
 
149
  drawable = gimp_image_active_drawable (display->image);
187
150
 
188
151
  if (! drawable)
189
152
    return FALSE;
190
153
 
191
154
  if (! gimp_drawable_is_rgb (drawable))
192
155
    {
193
 
      g_message (_("Color balance operates only on RGB color layers."));
 
156
      g_set_error (error, 0, 0,
 
157
                   _("Color Balance operates only on RGB color layers."));
194
158
      return FALSE;
195
159
    }
196
160
 
198
162
 
199
163
  cb_tool->transfer_mode = GIMP_MIDTONES;
200
164
 
201
 
  GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
 
165
  GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
202
166
 
203
167
  color_balance_update (cb_tool, ALL);
204
168
 
206
170
}
207
171
 
208
172
static void
209
 
gimp_color_balance_tool_map (GimpImageMapTool *image_map_tool)
 
173
gimp_color_balance_tool_map (GimpImageMapTool *im_tool)
210
174
{
211
 
  GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (image_map_tool);
 
175
  GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (im_tool);
212
176
 
213
177
  color_balance_create_lookup_tables (cb_tool->color_balance);
214
 
  gimp_image_map_apply (image_map_tool->image_map,
215
 
                        color_balance,
 
178
  gimp_image_map_apply (im_tool->image_map,
 
179
                        (GimpImageMapApplyFunc) color_balance,
216
180
                        cb_tool->color_balance);
217
181
}
218
182
 
227
191
                     GtkWidget     *table,
228
192
                     gint           col)
229
193
{
230
 
  GtkWidget     *label;
231
 
  GtkWidget     *slider;
232
 
  GtkWidget     *spinbutton;
233
 
  GtkAdjustment *adj;
234
 
 
235
 
  adj = GTK_ADJUSTMENT (gtk_adjustment_new (0, -100.0, 100.0, 1.0, 10.0, 0.0));
 
194
  GtkWidget *label;
 
195
  GtkWidget *slider;
 
196
  GtkWidget *spinbutton;
 
197
  GtkObject *adj;
236
198
 
237
199
  label = gtk_label_new (left);
238
200
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
239
201
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, col, col + 1,
240
 
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
202
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
241
203
  gtk_widget_show (label);
242
204
 
243
 
  slider = gtk_hscale_new (adj);
 
205
  spinbutton = gimp_spin_button_new (&adj,
 
206
                                     0, -100.0, 100.0, 1.0, 10.0, 0.0, 1.0, 0);
 
207
 
 
208
  slider = gtk_hscale_new (GTK_ADJUSTMENT (adj));
244
209
  gtk_scale_set_draw_value (GTK_SCALE (slider), FALSE);
245
 
  gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
 
210
  gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_CONTINUOUS);
246
211
  gtk_widget_set_size_request (slider, 100, -1);
247
212
  gtk_table_attach_defaults (GTK_TABLE (table), slider, 1, 2, col, col + 1);
248
213
  gtk_widget_show (slider);
250
215
  label = gtk_label_new (right);
251
216
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
252
217
  gtk_table_attach (GTK_TABLE (table), label, 2, 3, col, col + 1,
253
 
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
 
218
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
254
219
  gtk_widget_show (label);
255
220
 
256
 
  spinbutton = gtk_spin_button_new (adj, 1.0, 0);
257
221
  gtk_table_attach (GTK_TABLE (table), spinbutton, 3, 4, col, col + 1,
258
222
                    GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
259
223
  gtk_widget_show (spinbutton);
260
224
 
261
 
  return adj;
 
225
  return GTK_ADJUSTMENT (adj);
262
226
}
263
227
 
264
228
static void
265
 
gimp_color_balance_tool_dialog (GimpImageMapTool *image_map_tool)
 
229
gimp_color_balance_tool_dialog (GimpImageMapTool *im_tool)
266
230
{
267
 
  GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (image_map_tool);
 
231
  GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (im_tool);
268
232
  GtkWidget            *vbox;
269
233
  GtkWidget            *hbox;
270
234
  GtkWidget            *table;
273
237
  GtkWidget            *frame;
274
238
 
275
239
  frame = gimp_enum_radio_frame_new (GIMP_TYPE_TRANSFER_MODE,
276
 
                                     gtk_label_new (_("Select Range to Modify")),
 
240
                                     gtk_label_new (_("Select Range to Adjust")),
277
241
                                     G_CALLBACK (color_balance_range_callback),
278
242
                                     cb_tool,
279
243
                                     &toggle);
280
 
  gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), frame,
281
 
                      FALSE, FALSE, 0);
 
244
  gtk_box_pack_start (GTK_BOX (im_tool->main_vbox), frame, FALSE, FALSE, 0);
282
245
  gtk_widget_show (frame);
283
246
 
284
 
  frame = gimp_frame_new (_("Modify Selected Range's Color Levels"));
285
 
  gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), frame,
286
 
                      FALSE, FALSE, 0);
 
247
  frame = gimp_frame_new (_("Adjust Color Levels"));
 
248
  gtk_box_pack_start (GTK_BOX (im_tool->main_vbox), frame, FALSE, FALSE, 0);
287
249
  gtk_widget_show (frame);
288
250
 
289
251
  vbox = gtk_vbox_new (FALSE, 4);
300
262
  cb_tool->cyan_red_adj =
301
263
    create_levels_scale (_("Cyan"), _("Red"), table, 0);
302
264
 
303
 
  g_signal_connect (cb_tool->cyan_red_adj, "value_changed",
 
265
  g_signal_connect (cb_tool->cyan_red_adj, "value-changed",
304
266
                    G_CALLBACK (color_balance_cr_adjustment_update),
305
267
                    cb_tool);
306
268
 
307
269
  cb_tool->magenta_green_adj =
308
270
    create_levels_scale (_("Magenta"), _("Green"), table, 1);
309
271
 
310
 
  g_signal_connect (cb_tool->magenta_green_adj, "value_changed",
 
272
  g_signal_connect (cb_tool->magenta_green_adj, "value-changed",
311
273
                    G_CALLBACK (color_balance_mg_adjustment_update),
312
274
                    cb_tool);
313
275
 
314
276
  cb_tool->yellow_blue_adj =
315
277
    create_levels_scale (_("Yellow"), _("Blue"), table, 2);
316
278
 
317
 
  g_signal_connect (cb_tool->yellow_blue_adj, "value_changed",
 
279
  g_signal_connect (cb_tool->yellow_blue_adj, "value-changed",
318
280
                    G_CALLBACK (color_balance_yb_adjustment_update),
319
281
                    cb_tool);
320
282
 
322
284
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
323
285
  gtk_widget_show (hbox);
324
286
 
325
 
  button = gtk_button_new_with_mnemonic (_("R_eset range"));
 
287
  button = gtk_button_new_with_mnemonic (_("R_eset Range"));
326
288
  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
327
289
  gtk_widget_show (button);
328
290
 
333
295
  cb_tool->preserve_toggle =
334
296
    gtk_check_button_new_with_mnemonic (_("Preserve _luminosity"));
335
297
  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);
 
298
                                cb_tool->color_balance->preserve_luminosity);
 
299
  gtk_box_pack_end (GTK_BOX (im_tool->main_vbox), cb_tool->preserve_toggle,
 
300
                    FALSE, FALSE, 0);
339
301
  gtk_widget_show (cb_tool->preserve_toggle);
340
302
 
341
303
  g_signal_connect (cb_tool->preserve_toggle, "toggled",
348
310
}
349
311
 
350
312
static void
351
 
gimp_color_balance_tool_reset (GimpImageMapTool *image_map_tool)
 
313
gimp_color_balance_tool_reset (GimpImageMapTool *im_tool)
352
314
{
353
 
  GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (image_map_tool);
 
315
  GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (im_tool);
354
316
 
355
317
  color_balance_init (cb_tool->color_balance);
356
318
  color_balance_update (cb_tool, ALL);
358
320
 
359
321
static void
360
322
color_balance_update (GimpColorBalanceTool *cb_tool,
361
 
                      gint                  update)
 
323
                      gint                  update)
362
324
{
363
325
  GimpTransferMode tm;
364
326