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

« back to all changes in this revision

Viewing changes to app/dialogs/convert-dialog.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
34
34
#include "core/gimppalette.h"
35
35
#include "core/gimpprogress.h"
36
36
 
37
 
#include "widgets/gimpenumwidgets.h"
38
37
#include "widgets/gimphelp-ids.h"
39
 
#include "widgets/gimpenumcombobox.h"
40
38
#include "widgets/gimpviewablebox.h"
41
39
#include "widgets/gimpviewabledialog.h"
42
40
#include "widgets/gimpwidgets-utils.h"
43
41
 
 
42
#include "convert-dialog.h"
 
43
 
44
44
#include "gimp-intl.h"
45
45
 
46
46
 
48
48
{
49
49
  GtkWidget              *dialog;
50
50
 
51
 
  GimpImage              *gimage;
 
51
  GimpImage              *image;
52
52
  GimpProgress           *progress;
53
53
  GimpContext            *context;
54
54
  GimpContainer          *container;
75
75
 
76
76
/*  defaults  */
77
77
 
78
 
static GimpConvertDitherType   saved_dither_type  = GIMP_FS_DITHER;
 
78
static GimpConvertDitherType   saved_dither_type  = GIMP_NO_DITHER;
79
79
static gboolean                saved_alpha_dither = FALSE;
80
80
static gboolean                saved_remove_dups  = TRUE;
81
81
static gint                    saved_num_colors   = 256;
86
86
/*  public functions  */
87
87
 
88
88
GtkWidget *
89
 
convert_dialog_new (GimpImage    *gimage,
 
89
convert_dialog_new (GimpImage    *image,
 
90
                    GimpContext  *context,
90
91
                    GtkWidget    *parent,
91
92
                    GimpProgress *progress)
92
93
{
93
94
  IndexedDialog *dialog;
 
95
  GtkWidget     *button;
94
96
  GtkWidget     *main_vbox;
95
97
  GtkWidget     *vbox;
96
98
  GtkWidget     *hbox;
102
104
  GtkWidget     *palette_box;
103
105
  GtkWidget     *combo;
104
106
 
105
 
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
 
107
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
108
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
106
109
  g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
107
110
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
108
111
 
109
112
  dialog = g_new0 (IndexedDialog, 1);
110
113
 
111
 
  dialog->gimage       = gimage;
 
114
  dialog->image        = image;
112
115
  dialog->progress     = progress;
113
116
  dialog->dither_type  = saved_dither_type;
114
117
  dialog->alpha_dither = saved_alpha_dither;
117
120
  dialog->palette_type = saved_palette_type;
118
121
 
119
122
  dialog->dialog =
120
 
    gimp_viewable_dialog_new (GIMP_VIEWABLE (gimage),
 
123
    gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context,
121
124
                              _("Indexed Color Conversion"),
122
125
                              "gimp-image-convert-indexed",
123
126
                              GIMP_STOCK_CONVERT_INDEXED,
127
130
                              GIMP_HELP_IMAGE_CONVERT_INDEXED,
128
131
 
129
132
                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
130
 
                              GTK_STOCK_OK,     GTK_RESPONSE_OK,
131
133
 
132
134
                              NULL);
133
135
 
 
136
  button = gtk_dialog_add_button (GTK_DIALOG (dialog->dialog),
 
137
                                  _("C_onvert"), GTK_RESPONSE_OK);
 
138
  gtk_button_set_image (GTK_BUTTON (button),
 
139
                        gtk_image_new_from_stock (GIMP_STOCK_CONVERT_INDEXED,
 
140
                                                  GTK_ICON_SIZE_BUTTON));
 
141
 
 
142
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog->dialog),
 
143
                                           GTK_RESPONSE_OK,
 
144
                                           GTK_RESPONSE_CANCEL,
 
145
                                           -1);
 
146
 
134
147
  gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
135
148
 
136
149
  g_object_weak_ref (G_OBJECT (dialog->dialog),
142
155
 
143
156
  palette_box = convert_dialog_palette_box (dialog);
144
157
 
145
 
  if (dialog->context)
146
 
    g_object_weak_ref (G_OBJECT (dialog->dialog),
147
 
                       (GWeakNotify) g_object_unref,
148
 
                       dialog->context);
149
 
 
150
 
  if (dialog->container)
151
 
    g_object_weak_ref (G_OBJECT (dialog->dialog),
152
 
                       (GWeakNotify) g_object_unref,
153
 
                       dialog->container);
154
 
 
155
158
  main_vbox = gtk_vbox_new (FALSE, 12);
156
159
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
157
160
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog->dialog)->vbox),
158
 
                     main_vbox);
 
161
                     main_vbox);
159
162
  gtk_widget_show (main_vbox);
160
163
 
161
164
 
162
165
  /*  palette  */
163
166
 
164
 
  frame = gimp_enum_radio_frame_new (GIMP_TYPE_CONVERT_PALETTE_TYPE,
165
 
                                     gtk_label_new (_("Colormap")),
166
 
                                     G_CALLBACK (gimp_radio_button_update),
167
 
                                     &dialog->palette_type,
168
 
                                     &toggle);
169
 
  gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (toggle),
 
167
  frame =
 
168
    gimp_enum_radio_frame_new_with_range (GIMP_TYPE_CONVERT_PALETTE_TYPE,
 
169
                                          GIMP_MAKE_PALETTE,
 
170
                                          (palette_box ?
 
171
                                           GIMP_CUSTOM_PALETTE :
 
172
                                           GIMP_MONO_PALETTE),
 
173
                                          gtk_label_new (_("Colormap")),
 
174
                                          G_CALLBACK (gimp_radio_button_update),
 
175
                                          &dialog->palette_type,
 
176
                                          &button);
 
177
 
 
178
  gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button),
170
179
                                   dialog->palette_type);
171
180
  gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
172
181
  gtk_widget_show (frame);
180
189
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
181
190
  gtk_widget_show (label);
182
191
 
183
 
  if (dialog->num_colors == 256 && gimp_image_has_alpha (gimage))
 
192
  if (dialog->num_colors == 256 && gimp_image_has_alpha (image))
184
193
    dialog->num_colors = 255;
185
194
 
186
195
  spinbutton = gimp_spin_button_new (&adjustment, dialog->num_colors,
187
 
                                     2, 256, 1, 8, 0, 1, 0);
 
196
                                     2, 256, 1, 8, 0, 1, 0);
188
197
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
189
198
  gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
190
199
  gtk_widget_show (spinbutton);
191
200
 
192
 
  g_signal_connect (adjustment, "value_changed",
193
 
                    G_CALLBACK (gimp_int_adjustment_update),
194
 
                    &dialog->num_colors);
 
201
  g_signal_connect (adjustment, "value-changed",
 
202
                    G_CALLBACK (gimp_int_adjustment_update),
 
203
                    &dialog->num_colors);
195
204
 
196
205
  /*  custom palette  */
197
206
  if (palette_box)
198
207
    {
199
 
      vbox = gtk_vbox_new (FALSE, 2);
200
 
      gimp_enum_radio_frame_add (GTK_FRAME (frame), vbox, GIMP_CUSTOM_PALETTE);
201
 
      gtk_widget_show (vbox);
202
 
 
203
 
      gtk_box_pack_start (GTK_BOX (vbox), palette_box, FALSE, FALSE, 0);
 
208
      gimp_enum_radio_frame_add (GTK_FRAME (frame),
 
209
                                 palette_box, GIMP_CUSTOM_PALETTE);
204
210
      gtk_widget_show (palette_box);
205
 
 
206
 
      toggle = gtk_check_button_new_with_mnemonic (_("_Remove unused colors "
207
 
                                                     "from final palette"));
208
 
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
209
 
                                    dialog->remove_dups);
210
 
      gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
211
 
      gtk_widget_show (toggle);
212
 
 
213
 
      g_signal_connect (toggle, "toggled",
214
 
                        G_CALLBACK (gimp_toggle_button_update),
215
 
                        &dialog->remove_dups);
216
211
    }
217
212
 
 
213
  vbox = gtk_bin_get_child (GTK_BIN (frame));
 
214
 
 
215
  toggle = gtk_check_button_new_with_mnemonic (_("_Remove unused colors "
 
216
                                                 "from colormap"));
 
217
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
 
218
                                dialog->remove_dups);
 
219
  gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 3);
 
220
  gtk_widget_show (toggle);
 
221
 
 
222
  g_signal_connect (toggle, "toggled",
 
223
                    G_CALLBACK (gimp_toggle_button_update),
 
224
                    &dialog->remove_dups);
 
225
 
 
226
  g_object_set_data (G_OBJECT (button), "inverse_sensitive", toggle);
 
227
  gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (button));
218
228
 
219
229
  /*  dithering  */
220
230
 
252
262
  gtk_widget_show (toggle);
253
263
 
254
264
  g_signal_connect (toggle, "toggled",
255
 
                    G_CALLBACK (gimp_toggle_button_update),
256
 
                    &dialog->alpha_dither);
 
265
                    G_CALLBACK (gimp_toggle_button_update),
 
266
                    &dialog->alpha_dither);
257
267
 
258
268
  return dialog->dialog;
259
269
}
271
281
      GimpProgress *progress;
272
282
 
273
283
      progress = gimp_progress_start (dialog->progress,
274
 
                                      _("Converting to indexed..."), FALSE);
 
284
                                      _("Converting to indexed colors"), FALSE);
275
285
 
276
286
      /*  Convert the image to indexed color  */
277
 
      gimp_image_convert (dialog->gimage,
 
287
      gimp_image_convert (dialog->image,
278
288
                          GIMP_INDEXED,
279
289
                          dialog->num_colors,
280
290
                          dialog->dither_type,
287
297
      if (progress)
288
298
        gimp_progress_end (progress);
289
299
 
290
 
      gimp_image_flush (dialog->gimage);
 
300
      gimp_image_flush (dialog->image);
291
301
 
292
302
      /* Save defaults for next time */
293
303
      saved_dither_type  = dialog->dither_type;
304
314
static GtkWidget *
305
315
convert_dialog_palette_box (IndexedDialog *dialog)
306
316
{
307
 
  Gimp        *gimp;
 
317
  Gimp        *gimp = dialog->image->gimp;
308
318
  GList       *list;
309
319
  GimpPalette *palette;
310
320
  GimpPalette *web_palette   = NULL;
311
321
  gboolean     default_found = FALSE;
312
322
 
313
 
  gimp = dialog->gimage->gimp;
314
 
 
315
323
  /* We can't dither to > 256 colors */
316
324
  dialog->container = gimp_container_filter (gimp->palette_factory->container,
317
325
                                             convert_dialog_palette_filter,
318
326
                                             NULL);
319
327
 
320
 
  if (! gimp_container_num_children (dialog->container))
 
328
  if (gimp_container_is_empty (dialog->container))
321
329
    {
322
330
      g_object_unref (dialog->container);
 
331
      dialog->container = NULL;
323
332
      return NULL;
324
333
    }
325
334
 
326
335
  dialog->context = gimp_context_new (gimp, "convert-dialog", NULL);
327
336
 
 
337
  g_object_weak_ref (G_OBJECT (dialog->dialog),
 
338
                     (GWeakNotify) g_object_unref, dialog->context);
 
339
 
 
340
  g_object_weak_ref (G_OBJECT (dialog->dialog),
 
341
                     (GWeakNotify) g_object_unref, dialog->container);
 
342
 
328
343
  for (list = GIMP_LIST (dialog->container)->list;
329
344
       list;
330
345
       list = g_list_next (list))
331
346
    {
332
 
      palette = (GimpPalette *) list->data;
 
347
      palette = list->data;
333
348
 
334
349
      /* Preferentially, the initial default is 'Web' if available */
335
350
      if (web_palette == NULL &&
336
 
          g_ascii_strcasecmp (GIMP_OBJECT (palette)->name, "Web") == 0)
337
 
        {
338
 
          web_palette = palette;
339
 
        }
 
351
          g_ascii_strcasecmp (GIMP_OBJECT (palette)->name, "Web") == 0)
 
352
        {
 
353
          web_palette = palette;
 
354
        }
340
355
 
341
356
      if (saved_palette == palette)
342
357
        {
373
388
 
374
389
static void
375
390
convert_dialog_palette_changed (GimpContext   *context,
376
 
                                GimpPalette   *palette,
 
391
                                GimpPalette   *palette,
377
392
                                IndexedDialog *dialog)
378
393
{
379
394
  if (! palette)
381
396
 
382
397
  if (palette->n_colors > 256)
383
398
    {
384
 
      g_message (_("Cannot convert to a palette with more than 256 colors."));
 
399
      gimp_message (dialog->image->gimp, G_OBJECT (dialog->dialog),
 
400
                    GIMP_MESSAGE_WARNING,
 
401
                    _("Cannot convert to a palette "
 
402
                      "with more than 256 colors."));
385
403
    }
386
404
  else
387
405
    {