34
34
#include "core/gimppalette.h"
35
35
#include "core/gimpprogress.h"
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"
42
#include "convert-dialog.h"
44
44
#include "gimp-intl.h"
102
104
GtkWidget *palette_box;
103
105
GtkWidget *combo;
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);
109
112
dialog = g_new0 (IndexedDialog, 1);
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;
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,
129
132
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
130
GTK_STOCK_OK, GTK_RESPONSE_OK,
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));
142
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog->dialog),
134
147
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
136
149
g_object_weak_ref (G_OBJECT (dialog->dialog),
143
156
palette_box = convert_dialog_palette_box (dialog);
146
g_object_weak_ref (G_OBJECT (dialog->dialog),
147
(GWeakNotify) g_object_unref,
150
if (dialog->container)
151
g_object_weak_ref (G_OBJECT (dialog->dialog),
152
(GWeakNotify) g_object_unref,
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),
159
162
gtk_widget_show (main_vbox);
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,
169
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (toggle),
168
gimp_enum_radio_frame_new_with_range (GIMP_TYPE_CONVERT_PALETTE_TYPE,
171
GIMP_CUSTOM_PALETTE :
173
gtk_label_new (_("Colormap")),
174
G_CALLBACK (gimp_radio_button_update),
175
&dialog->palette_type,
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);
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;
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);
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);
196
205
/* custom palette */
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);
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);
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);
213
g_signal_connect (toggle, "toggled",
214
G_CALLBACK (gimp_toggle_button_update),
215
&dialog->remove_dups);
213
vbox = gtk_bin_get_child (GTK_BIN (frame));
215
toggle = gtk_check_button_new_with_mnemonic (_("_Remove unused colors "
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);
222
g_signal_connect (toggle, "toggled",
223
G_CALLBACK (gimp_toggle_button_update),
224
&dialog->remove_dups);
226
g_object_set_data (G_OBJECT (button), "inverse_sensitive", toggle);
227
gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (button));
271
281
GimpProgress *progress;
273
283
progress = gimp_progress_start (dialog->progress,
274
_("Converting to indexed..."), FALSE);
284
_("Converting to indexed colors"), FALSE);
276
286
/* Convert the image to indexed color */
277
gimp_image_convert (dialog->gimage,
287
gimp_image_convert (dialog->image,
279
289
dialog->num_colors,
280
290
dialog->dither_type,
304
314
static GtkWidget *
305
315
convert_dialog_palette_box (IndexedDialog *dialog)
317
Gimp *gimp = dialog->image->gimp;
309
319
GimpPalette *palette;
310
320
GimpPalette *web_palette = NULL;
311
321
gboolean default_found = FALSE;
313
gimp = dialog->gimage->gimp;
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,
320
if (! gimp_container_num_children (dialog->container))
328
if (gimp_container_is_empty (dialog->container))
322
330
g_object_unref (dialog->container);
331
dialog->container = NULL;
326
335
dialog->context = gimp_context_new (gimp, "convert-dialog", NULL);
337
g_object_weak_ref (G_OBJECT (dialog->dialog),
338
(GWeakNotify) g_object_unref, dialog->context);
340
g_object_weak_ref (G_OBJECT (dialog->dialog),
341
(GWeakNotify) g_object_unref, dialog->container);
328
343
for (list = GIMP_LIST (dialog->container)->list;
330
345
list = g_list_next (list))
332
palette = (GimpPalette *) list->data;
347
palette = list->data;
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)
338
web_palette = palette;
351
g_ascii_strcasecmp (GIMP_OBJECT (palette)->name, "Web") == 0)
353
web_palette = palette;
341
356
if (saved_palette == palette)