2001-04-19 01:57:10 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
#include "dialogs-types.h"
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "core/gimp.h"
|
2004-09-09 19:42:39 +08:00
|
|
|
#include "core/gimpcontainer-filter.h"
|
|
|
|
#include "core/gimpcontext.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpdatafactory.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimage-convert.h"
|
|
|
|
#include "core/gimplist.h"
|
|
|
|
#include "core/gimppalette.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "core/gimpprogress.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2004-10-12 20:06:50 +08:00
|
|
|
#include "widgets/gimpviewablebox.h"
|
GimpViewableDialogs everywhere, cleanup:
2002-09-01 Michael Natterer <mitch@gimp.org>
GimpViewableDialogs everywhere, cleanup:
* libgimpwidgets/gimpstock.c: added texts for the RESIZE, SCALE
and CROP stock items.
* app/widgets/gimpviewabledialog.c: update the title when the
viewable's name changes.
* app/gui/color-notebook.[ch]: added color_notebook_viewable_new()
which creates a GimpViewableDialog.
* app/widgets/gimpgradienteditor.[ch]
* app/gui/colormap-editor-commands.c
* app/gui/file-new-dialog.c
* app/gui/gradient-editor-commands.c
* app/gui/palette-editor-commands.c
* app/undo_history.c: use GimpViewableDialogs and the new
color_notebook constructor.
* app/gui/convert-dialog.c: #include "widgets/gimpviewabledialog.h"
* app/gui/image-commands.c
* app/gui/info-dialog.c
* app/gui/resize-dialog.c: minor cleanups.
* app/gui/info-window.c: cleaned up the whole thing, esp. the
"Extended" page. Added HSV color display to the color picker
frame. Set the icons as frame titles, stuff...
* app/tools/gimpimagemaptool.[ch]: removed "shell_title",
"shell_name" and "stock_id" from the GimpImageMapTool struct
because they can be obtained from the tool's GimpToolInfo object.
* app/tools/gimpbrightnesscontrasttool.c
* app/tools/gimpcolorbalancetool.c
* app/tools/gimpcurvestool.c
* app/tools/gimphuesaturationtool.c
* app/tools/gimplevelstool.c
* app/tools/gimpposterizetool.c
* app/tools/gimpthresholdtool.c: changed accordingly.
* app/tools/gimphistogramtool.c: same here: take values from
tool->tool_info instead of hardcoding them.
* app/tools/gimpcroptool.[ch]: removed the static crop dialog
variables and added them to the GimpCropTool struct. Feels safer
and makes the callback code much simpler. Use stock items for the
dialog's "Resize" and "Crop" buttons.
* app/tools/gimpmeasuretool.c
* app/tools/gimprotatetool.c: for consistency don't name the tools
"Blah Tool", also the dialog titles need to match the menu
entries.
Unrelated:
* libgimpwidgets/gimpwidgets.c: the recently changed, gtk-doc
comment was correct, as gtk-doc takes the parameter names from
the header, not the .c file.
* app/tools/gimptransformtool.c: set the transform tool's state to
TRANSFORM_CREATING after changing displays, so the initial matrix
components are saved correctly for the "Reset" function.
2002-09-01 16:44:57 +08:00
|
|
|
#include "widgets/gimpviewabledialog.h"
|
2004-10-14 21:44:06 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2002-03-20 22:10:45 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
|
2001-04-19 01:57:10 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2004-10-24 03:01:26 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image;
|
2004-09-09 19:42:39 +08:00
|
|
|
GimpProgress *progress;
|
|
|
|
GimpContext *context;
|
|
|
|
GimpContainer *container;
|
|
|
|
GimpPalette *custom_palette;
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
GimpConvertDitherType dither_type;
|
|
|
|
gboolean alpha_dither;
|
|
|
|
gboolean remove_dups;
|
|
|
|
gint num_colors;
|
|
|
|
GimpConvertPaletteType palette_type;
|
2001-04-19 01:57:10 +08:00
|
|
|
} IndexedDialog;
|
|
|
|
|
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
static void convert_dialog_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
IndexedDialog *dialog);
|
|
|
|
static GtkWidget * convert_dialog_palette_box (IndexedDialog *dialog);
|
|
|
|
static gboolean convert_dialog_palette_filter (const GimpObject *object,
|
|
|
|
gpointer user_data);
|
|
|
|
static void convert_dialog_palette_changed (GimpContext *context,
|
|
|
|
GimpPalette *palette,
|
|
|
|
IndexedDialog *dialog);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
/* defaults */
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2005-05-21 08:38:19 +08:00
|
|
|
static GimpConvertDitherType saved_dither_type = GIMP_NO_DITHER;
|
2002-09-07 04:44:47 +08:00
|
|
|
static gboolean saved_alpha_dither = FALSE;
|
|
|
|
static gboolean saved_remove_dups = TRUE;
|
|
|
|
static gint saved_num_colors = 256;
|
|
|
|
static GimpConvertPaletteType saved_palette_type = GIMP_MAKE_PALETTE;
|
2004-09-09 19:42:39 +08:00
|
|
|
static GimpPalette *saved_palette = NULL;
|
|
|
|
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
/* public functions */
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-04-20 21:44:19 +08:00
|
|
|
GtkWidget *
|
2006-03-29 01:08:36 +08:00
|
|
|
convert_dialog_new (GimpImage *image,
|
2004-09-09 19:42:39 +08:00
|
|
|
GtkWidget *parent,
|
|
|
|
GimpProgress *progress)
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
|
|
|
IndexedDialog *dialog;
|
2005-09-26 02:53:32 +08:00
|
|
|
GtkWidget *button;
|
2001-04-19 01:57:10 +08:00
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkObject *adjustment;
|
|
|
|
GtkWidget *spinbutton;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *toggle;
|
2004-09-09 19:42:39 +08:00
|
|
|
GtkWidget *palette_box;
|
2004-10-14 21:44:06 +08:00
|
|
|
GtkWidget *combo;
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2004-04-20 21:44:19 +08:00
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
|
2004-09-09 19:42:39 +08:00
|
|
|
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
|
2002-08-31 05:00:42 +08:00
|
|
|
|
2001-04-19 01:57:10 +08:00
|
|
|
dialog = g_new0 (IndexedDialog, 1);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
dialog->image = image;
|
2004-10-14 21:44:06 +08:00
|
|
|
dialog->progress = progress;
|
|
|
|
dialog->dither_type = saved_dither_type;
|
|
|
|
dialog->alpha_dither = saved_alpha_dither;
|
|
|
|
dialog->remove_dups = saved_remove_dups;
|
|
|
|
dialog->num_colors = saved_num_colors;
|
|
|
|
dialog->palette_type = saved_palette_type;
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-10-24 03:01:26 +08:00
|
|
|
dialog->dialog =
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_viewable_dialog_new (GIMP_VIEWABLE (image),
|
2002-08-31 05:00:42 +08:00
|
|
|
_("Indexed Color Conversion"),
|
2003-11-08 01:29:02 +08:00
|
|
|
"gimp-image-convert-indexed",
|
2002-08-31 05:00:42 +08:00
|
|
|
GIMP_STOCK_CONVERT_INDEXED,
|
|
|
|
_("Convert Image to Indexed Colors"),
|
2003-11-08 23:29:47 +08:00
|
|
|
parent,
|
2002-08-31 05:00:42 +08:00
|
|
|
gimp_standard_help_func,
|
2003-08-22 09:42:57 +08:00
|
|
|
GIMP_HELP_IMAGE_CONVERT_INDEXED,
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
2001-11-24 07:04:49 +08:00
|
|
|
|
2002-08-31 05:00:42 +08:00
|
|
|
NULL);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2005-09-26 02:53:32 +08:00
|
|
|
button = gtk_dialog_add_button (GTK_DIALOG (dialog->dialog),
|
|
|
|
_("C_onvert"), GTK_RESPONSE_OK);
|
|
|
|
gtk_button_set_image (GTK_BUTTON (button),
|
|
|
|
gtk_image_new_from_stock (GIMP_STOCK_CONVERT_INDEXED,
|
|
|
|
GTK_ICON_SIZE_BUTTON));
|
|
|
|
|
2005-02-09 04:40:33 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog->dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2004-10-24 03:01:26 +08:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
|
|
|
|
|
|
|
|
g_object_weak_ref (G_OBJECT (dialog->dialog),
|
|
|
|
(GWeakNotify) g_free, dialog);
|
|
|
|
|
|
|
|
g_signal_connect (dialog->dialog, "response",
|
2004-09-09 19:42:39 +08:00
|
|
|
G_CALLBACK (convert_dialog_response),
|
2003-11-06 23:27:05 +08:00
|
|
|
dialog);
|
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
palette_box = convert_dialog_palette_box (dialog);
|
|
|
|
|
2004-05-03 06:33:33 +08:00
|
|
|
main_vbox = gtk_vbox_new (FALSE, 12);
|
2004-05-04 22:21:13 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
2004-10-24 03:01:26 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog->dialog)->vbox),
|
2006-04-12 20:49:29 +08:00
|
|
|
main_vbox);
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_widget_show (main_vbox);
|
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
|
|
|
|
/* palette */
|
|
|
|
|
2005-04-13 07:46:10 +08:00
|
|
|
frame = gimp_enum_radio_frame_new_with_range (GIMP_TYPE_CONVERT_PALETTE_TYPE,
|
|
|
|
GIMP_MAKE_PALETTE,
|
|
|
|
palette_box ?
|
|
|
|
GIMP_CUSTOM_PALETTE : GIMP_MONO_PALETTE,
|
|
|
|
gtk_label_new (_("Colormap")),
|
|
|
|
G_CALLBACK (gimp_radio_button_update),
|
|
|
|
&dialog->palette_type,
|
|
|
|
&toggle);
|
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (toggle),
|
|
|
|
dialog->palette_type);
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
/* max n_colors */
|
2004-05-26 21:39:23 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2004-10-14 21:44:06 +08:00
|
|
|
gimp_enum_radio_frame_add (GTK_FRAME (frame), hbox, GIMP_MAKE_PALETTE);
|
|
|
|
gtk_widget_show (hbox);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
label = gtk_label_new_with_mnemonic (_("_Maximum number of colors:"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
2002-03-20 22:10:45 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (dialog->num_colors == 256 && gimp_image_has_alpha (image))
|
2004-09-09 19:42:39 +08:00
|
|
|
dialog->num_colors = 255;
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
spinbutton = gimp_spin_button_new (&adjustment, dialog->num_colors,
|
2006-04-12 20:49:29 +08:00
|
|
|
2, 256, 1, 8, 0, 1, 0);
|
2004-10-14 21:44:06 +08:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), spinbutton);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_widget_show (spinbutton);
|
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (adjustment, "value-changed",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_CALLBACK (gimp_int_adjustment_update),
|
|
|
|
&dialog->num_colors);
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
/* custom palette */
|
|
|
|
if (palette_box)
|
|
|
|
{
|
|
|
|
vbox = gtk_vbox_new (FALSE, 2);
|
|
|
|
gimp_enum_radio_frame_add (GTK_FRAME (frame), vbox, GIMP_CUSTOM_PALETTE);
|
|
|
|
gtk_widget_show (vbox);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), palette_box, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (palette_box);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
toggle = gtk_check_button_new_with_mnemonic (_("_Remove unused colors "
|
2004-11-06 20:48:38 +08:00
|
|
|
"from final palette"));
|
2004-10-14 21:44:06 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
|
|
|
|
dialog->remove_dups);
|
2004-05-26 21:39:23 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&dialog->remove_dups);
|
2004-10-14 21:44:06 +08:00
|
|
|
}
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
/* dithering */
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
frame = gimp_frame_new (_("Dithering"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
2002-03-20 22:10:45 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 6);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
label = gtk_label_new_with_mnemonic (_("Color _dithering:"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
combo = gimp_enum_combo_box_new (GIMP_TYPE_CONVERT_DITHER_TYPE);
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (combo);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-10-14 21:44:06 +08:00
|
|
|
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
|
|
|
|
dialog->dither_type,
|
|
|
|
G_CALLBACK (gimp_int_combo_box_get_active),
|
|
|
|
&dialog->dither_type);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
toggle =
|
2004-10-14 21:44:06 +08:00
|
|
|
gtk_check_button_new_with_mnemonic (_("Enable dithering of _transparency"));
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
|
2004-10-14 21:44:06 +08:00
|
|
|
dialog->alpha_dither);
|
2004-05-26 21:39:23 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_widget_show (toggle);
|
2004-09-09 19:42:39 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&dialog->alpha_dither);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2004-10-24 03:01:26 +08:00
|
|
|
return dialog->dialog;
|
2001-04-19 01:57:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
/* private functions */
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
static void
|
2004-09-09 19:42:39 +08:00
|
|
|
convert_dialog_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
IndexedDialog *dialog)
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
2003-11-06 23:27:05 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress;
|
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
progress = gimp_progress_start (dialog->progress,
|
2005-10-01 01:50:50 +08:00
|
|
|
_("Converting to indexed"), FALSE);
|
2004-08-11 02:47:21 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
/* Convert the image to indexed color */
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_convert (dialog->image,
|
2003-11-06 23:27:05 +08:00
|
|
|
GIMP_INDEXED,
|
|
|
|
dialog->num_colors,
|
|
|
|
dialog->dither_type,
|
|
|
|
dialog->alpha_dither,
|
|
|
|
dialog->remove_dups,
|
|
|
|
dialog->palette_type,
|
2004-09-09 19:42:39 +08:00
|
|
|
dialog->custom_palette,
|
2004-08-11 02:47:21 +08:00
|
|
|
progress);
|
|
|
|
|
|
|
|
if (progress)
|
|
|
|
gimp_progress_end (progress);
|
2004-08-10 00:08:36 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_flush (dialog->image);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
|
|
/* Save defaults for next time */
|
|
|
|
saved_dither_type = dialog->dither_type;
|
|
|
|
saved_alpha_dither = dialog->alpha_dither;
|
|
|
|
saved_remove_dups = dialog->remove_dups;
|
|
|
|
saved_num_colors = dialog->num_colors;
|
|
|
|
saved_palette_type = dialog->palette_type;
|
2004-09-09 19:42:39 +08:00
|
|
|
saved_palette = dialog->custom_palette;
|
2003-11-06 23:27:05 +08:00
|
|
|
}
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-10-24 03:01:26 +08:00
|
|
|
gtk_widget_destroy (dialog->dialog);
|
2001-04-19 01:57:10 +08:00
|
|
|
}
|
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
static GtkWidget *
|
|
|
|
convert_dialog_palette_box (IndexedDialog *dialog)
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
Gimp *gimp = dialog->image->gimp;
|
2004-09-09 19:42:39 +08:00
|
|
|
GList *list;
|
|
|
|
GimpPalette *palette;
|
|
|
|
GimpPalette *web_palette = NULL;
|
|
|
|
gboolean default_found = FALSE;
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
/* We can't dither to > 256 colors */
|
|
|
|
dialog->container = gimp_container_filter (gimp->palette_factory->container,
|
|
|
|
convert_dialog_palette_filter,
|
|
|
|
NULL);
|
|
|
|
|
2005-04-13 07:46:10 +08:00
|
|
|
if (gimp_container_is_empty (dialog->container))
|
2004-09-09 19:42:39 +08:00
|
|
|
{
|
|
|
|
g_object_unref (dialog->container);
|
2005-04-13 07:46:10 +08:00
|
|
|
dialog->container = NULL;
|
2004-09-09 19:42:39 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog->context = gimp_context_new (gimp, "convert-dialog", NULL);
|
|
|
|
|
2005-04-13 07:46:10 +08:00
|
|
|
g_object_weak_ref (G_OBJECT (dialog->dialog),
|
|
|
|
(GWeakNotify) g_object_unref, dialog->context);
|
|
|
|
|
|
|
|
g_object_weak_ref (G_OBJECT (dialog->dialog),
|
|
|
|
(GWeakNotify) g_object_unref, dialog->container);
|
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
for (list = GIMP_LIST (dialog->container)->list;
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
2005-04-13 07:46:10 +08:00
|
|
|
palette = list->data;
|
2004-09-09 19:42:39 +08:00
|
|
|
|
|
|
|
/* Preferentially, the initial default is 'Web' if available */
|
|
|
|
if (web_palette == NULL &&
|
2006-04-12 20:49:29 +08:00
|
|
|
g_ascii_strcasecmp (GIMP_OBJECT (palette)->name, "Web") == 0)
|
|
|
|
{
|
|
|
|
web_palette = palette;
|
|
|
|
}
|
2004-09-09 19:42:39 +08:00
|
|
|
|
|
|
|
if (saved_palette == palette)
|
|
|
|
{
|
|
|
|
dialog->custom_palette = saved_palette;
|
|
|
|
default_found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! default_found)
|
2004-07-10 03:14:59 +08:00
|
|
|
{
|
2004-09-09 19:42:39 +08:00
|
|
|
if (web_palette)
|
|
|
|
dialog->custom_palette = web_palette;
|
|
|
|
else
|
|
|
|
dialog->custom_palette = GIMP_LIST (dialog->container)->list->data;
|
2004-07-10 03:14:59 +08:00
|
|
|
}
|
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
gimp_context_set_palette (dialog->context, dialog->custom_palette);
|
|
|
|
|
|
|
|
g_signal_connect (dialog->context, "palette-changed",
|
|
|
|
G_CALLBACK (convert_dialog_palette_changed),
|
|
|
|
dialog);
|
|
|
|
|
2004-10-12 20:06:50 +08:00
|
|
|
return gimp_palette_box_new (dialog->container, dialog->context, 4);
|
2004-07-10 03:14:59 +08:00
|
|
|
}
|
|
|
|
|
2004-09-09 19:42:39 +08:00
|
|
|
static gboolean
|
|
|
|
convert_dialog_palette_filter (const GimpObject *object,
|
|
|
|
gpointer user_data)
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
2005-03-21 18:32:27 +08:00
|
|
|
GimpPalette *palette = GIMP_PALETTE (object);
|
|
|
|
|
|
|
|
return palette->n_colors > 0 && palette->n_colors <= 256;
|
2001-04-19 01:57:10 +08:00
|
|
|
}
|
|
|
|
|
2002-09-07 04:44:47 +08:00
|
|
|
static void
|
2004-09-09 19:42:39 +08:00
|
|
|
convert_dialog_palette_changed (GimpContext *context,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpPalette *palette,
|
2003-11-06 23:27:05 +08:00
|
|
|
IndexedDialog *dialog)
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
2004-03-09 03:23:05 +08:00
|
|
|
if (! palette)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (palette->n_colors > 256)
|
|
|
|
{
|
|
|
|
g_message (_("Cannot convert to a palette with more than 256 colors."));
|
|
|
|
}
|
|
|
|
else
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
2004-09-09 19:42:39 +08:00
|
|
|
dialog->custom_palette = palette;
|
2001-04-19 01:57:10 +08:00
|
|
|
}
|
|
|
|
}
|