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"
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
#include "gui-types.h"
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "core/gimp.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"
|
|
|
|
|
2002-03-29 11:50:29 +08:00
|
|
|
#include "libgimptool/gimptool.h"
|
2001-04-19 01:57:10 +08:00
|
|
|
#include "tools/tool_manager.h"
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
#include "widgets/gimpenummenu.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"
|
2002-03-20 22:10:45 +08:00
|
|
|
|
2001-04-19 01:57:10 +08:00
|
|
|
#include "palette-select.h"
|
|
|
|
|
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2002-03-20 22:10:45 +08:00
|
|
|
GtkWidget *shell;
|
|
|
|
GtkWidget *custom_palette_button;
|
|
|
|
GimpImage *gimage;
|
|
|
|
PaletteSelect *palette_select;
|
|
|
|
GimpConvertDitherType dither_type;
|
|
|
|
gboolean alpha_dither;
|
|
|
|
gboolean remove_dups;
|
|
|
|
gint num_colors;
|
|
|
|
gint palette;
|
|
|
|
GimpConvertPaletteType palette_type;
|
2001-04-19 01:57:10 +08:00
|
|
|
} IndexedDialog;
|
|
|
|
|
|
|
|
|
|
|
|
static void indexed_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void indexed_cancel_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void indexed_custom_palette_button_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void indexed_palette_select_destroy_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
static GtkWidget * build_palette_button (Gimp *gimp);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
static gboolean UserHasWebPal = FALSE;
|
|
|
|
static GimpPalette *theCustomPalette = NULL;
|
|
|
|
|
|
|
|
/* Defaults */
|
2002-03-20 22:10:45 +08:00
|
|
|
static GimpConvertDitherType sdither_type = GIMP_FS_DITHER;
|
|
|
|
static gboolean salpha_dither = FALSE;
|
|
|
|
static gboolean sremove_dups = TRUE;
|
|
|
|
static gint snum_colors = 256;
|
|
|
|
static GimpConvertPaletteType spalette_type = GIMP_MAKE_PALETTE;
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
convert_to_rgb (GimpImage *gimage)
|
|
|
|
{
|
2002-08-31 05:00:42 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
|
2001-12-11 23:58:07 +08:00
|
|
|
gimp_image_convert (gimage, GIMP_RGB, 0, 0, 0, 0, 0, NULL);
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_image_flush (gimage);
|
2001-04-19 01:57:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
convert_to_grayscale (GimpImage* gimage)
|
|
|
|
{
|
2002-08-31 05:00:42 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
|
2001-12-11 23:58:07 +08:00
|
|
|
gimp_image_convert (gimage, GIMP_GRAY, 0, 0, 0, 0, 0, NULL);
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_image_flush (gimage);
|
2001-04-19 01:57:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
convert_to_indexed (GimpImage *gimage)
|
|
|
|
{
|
|
|
|
IndexedDialog *dialog;
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkObject *adjustment;
|
|
|
|
GtkWidget *spinbutton;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *toggle;
|
|
|
|
GSList *group = NULL;
|
|
|
|
|
2002-08-31 05:00:42 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (gimage));
|
|
|
|
|
2001-04-19 01:57:10 +08:00
|
|
|
dialog = g_new0 (IndexedDialog, 1);
|
|
|
|
|
|
|
|
dialog->gimage = gimage;
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
dialog->custom_palette_button = build_palette_button (gimage->gimp);
|
|
|
|
dialog->dither_type = sdither_type;
|
|
|
|
dialog->alpha_dither = salpha_dither;
|
|
|
|
dialog->remove_dups = sremove_dups;
|
|
|
|
dialog->num_colors = snum_colors;
|
|
|
|
dialog->palette_type = spalette_type;
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
dialog->shell =
|
2002-08-31 05:00:42 +08:00
|
|
|
gimp_viewable_dialog_new (GIMP_VIEWABLE (gimage),
|
|
|
|
_("Indexed Color Conversion"),
|
|
|
|
"indexed_color_conversion",
|
|
|
|
GIMP_STOCK_CONVERT_INDEXED,
|
|
|
|
_("Convert Image to Indexed Colors"),
|
|
|
|
gimp_standard_help_func,
|
|
|
|
"dialogs/convert_to_indexed.html",
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2002-08-31 05:00:42 +08:00
|
|
|
GTK_STOCK_CANCEL, indexed_cancel_callback,
|
|
|
|
dialog, NULL, NULL, FALSE, TRUE,
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2002-08-31 05:00:42 +08:00
|
|
|
GTK_STOCK_OK, indexed_ok_callback,
|
|
|
|
dialog, NULL, NULL, TRUE, FALSE,
|
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
|
|
|
|
|
|
|
main_vbox = gtk_vbox_new (FALSE, 2);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog->shell)->vbox),
|
|
|
|
main_vbox);
|
|
|
|
gtk_widget_show (main_vbox);
|
|
|
|
|
|
|
|
frame = gtk_frame_new (_("General Palette Options"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 1);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
/* 'generate palette' */
|
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
toggle = gtk_radio_button_new_with_label (NULL,
|
|
|
|
_("Generate Optimum Palette:"));
|
2001-12-29 21:26:29 +08:00
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
g_object_set_data (G_OBJECT (toggle), "gimp-item-data",
|
|
|
|
GINT_TO_POINTER (GIMP_MAKE_PALETTE));
|
|
|
|
g_signal_connect (G_OBJECT (toggle), "toggled",
|
|
|
|
G_CALLBACK (gimp_radio_button_update),
|
|
|
|
&dialog->palette_type);
|
|
|
|
|
|
|
|
if (dialog->num_colors == 256 && gimp_image_has_alpha (gimage))
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
2002-03-20 22:10:45 +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,
|
2001-04-19 01:57:10 +08:00
|
|
|
2, 256, 1, 5, 0, 1, 0);
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (spinbutton);
|
|
|
|
|
2001-08-15 00:33:28 +08:00
|
|
|
g_signal_connect (G_OBJECT (adjustment), "value_changed",
|
|
|
|
G_CALLBACK (gimp_int_adjustment_update),
|
2002-03-20 22:10:45 +08:00
|
|
|
&dialog->num_colors);
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2001-11-27 01:12:29 +08:00
|
|
|
label = gtk_label_new (_("Number of Colors:"));
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (spinbutton), dialog->num_colors);
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (label), dialog->num_colors);
|
2001-08-15 00:33:28 +08:00
|
|
|
g_object_set_data (G_OBJECT (toggle), "set_sensitive", spinbutton);
|
|
|
|
g_object_set_data (G_OBJECT (spinbutton), "set_sensitive", label);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
if (! UserHasWebPal)
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
2002-03-20 22:10:45 +08:00
|
|
|
/* 'web palette'
|
|
|
|
* Only presented as an option to the user if they do not
|
|
|
|
* already have the 'Web' GIMP palette installed on their
|
|
|
|
* system.
|
|
|
|
*/
|
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
toggle = gtk_radio_button_new_with_label (group,
|
|
|
|
_("Use WWW-Optimized Palette"));
|
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
g_object_set_data (G_OBJECT (toggle), "gimp-item-data",
|
|
|
|
GINT_TO_POINTER (GIMP_WEB_PALETTE));
|
2001-08-15 00:33:28 +08:00
|
|
|
g_signal_connect (G_OBJECT (toggle), "toggled",
|
2002-03-20 22:10:45 +08:00
|
|
|
G_CALLBACK (gimp_radio_button_update),
|
|
|
|
&dialog->palette_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 'mono palette' */
|
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
toggle = gtk_radio_button_new_with_label (group,
|
|
|
|
_("Use Black and White (1-Bit) Palette"));
|
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (toggle), "gimp-item-data",
|
|
|
|
GINT_TO_POINTER (GIMP_MONO_PALETTE));
|
|
|
|
g_signal_connect (G_OBJECT (toggle), "toggled",
|
|
|
|
G_CALLBACK (gimp_radio_button_update),
|
|
|
|
&dialog->palette_type);
|
|
|
|
|
|
|
|
/* 'custom' palette from dialog */
|
|
|
|
if (dialog->custom_palette_button)
|
|
|
|
{
|
|
|
|
GtkWidget *remove_toggle;
|
|
|
|
|
|
|
|
remove_toggle = gtk_check_button_new_with_label (_("Remove Unused Colors from Final Palette"));
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (remove_toggle),
|
|
|
|
dialog->remove_dups);
|
|
|
|
g_signal_connect (G_OBJECT (remove_toggle), "toggled",
|
2001-08-15 00:33:28 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
2002-03-20 22:10:45 +08:00
|
|
|
&dialog->remove_dups);
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2001-04-19 01:57:10 +08:00
|
|
|
/* 'custom' palette from dialog */
|
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
2002-03-20 22:10:45 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
toggle = gtk_radio_button_new_with_label (group,
|
|
|
|
_("Use Custom Palette:"));
|
2001-12-29 21:26:29 +08:00
|
|
|
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (toggle);
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
g_object_set_data (G_OBJECT (toggle), "gimp-item-data",
|
|
|
|
GINT_TO_POINTER (GIMP_CUSTOM_PALETTE));
|
|
|
|
g_signal_connect (G_OBJECT (toggle), "toggled",
|
|
|
|
G_CALLBACK (gimp_radio_button_update),
|
|
|
|
&dialog->palette_type);
|
|
|
|
g_object_set_data (G_OBJECT (toggle), "set_sensitive", remove_toggle);
|
|
|
|
|
2001-08-15 00:33:28 +08:00
|
|
|
g_signal_connect (G_OBJECT (dialog->custom_palette_button), "clicked",
|
|
|
|
G_CALLBACK (indexed_custom_palette_button_callback),
|
|
|
|
dialog);
|
2002-03-20 22:10:45 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox),
|
|
|
|
dialog->custom_palette_button, TRUE, TRUE, 0);
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_widget_show (dialog->custom_palette_button);
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
gtk_widget_set_sensitive (remove_toggle,
|
|
|
|
dialog->palette_type == GIMP_CUSTOM_PALETTE);
|
|
|
|
gtk_widget_set_sensitive (dialog->custom_palette_button,
|
|
|
|
dialog->palette_type == GIMP_CUSTOM_PALETTE);
|
|
|
|
g_object_set_data (G_OBJECT (toggle), "set_sensitive", remove_toggle);
|
|
|
|
g_object_set_data (G_OBJECT (remove_toggle), "set_sensitive",
|
2001-08-15 00:33:28 +08:00
|
|
|
dialog->custom_palette_button);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
/* add the remove-duplicates toggle */
|
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
2002-03-20 22:10:45 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), remove_toggle, FALSE, FALSE, 20);
|
|
|
|
gtk_widget_show (remove_toggle);
|
2001-04-19 01:57:10 +08:00
|
|
|
}
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
gimp_radio_group_set_active (GTK_RADIO_BUTTON (toggle),
|
|
|
|
GINT_TO_POINTER (dialog->dither_type));
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
/* the dither type */
|
2001-11-27 01:12:29 +08:00
|
|
|
frame = gtk_frame_new (_("Dithering Options"));
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
vbox = gimp_enum_radio_box_new (GIMP_TYPE_CONVERT_DITHER_TYPE,
|
|
|
|
G_CALLBACK (gimp_radio_button_update),
|
|
|
|
&dialog->dither_type,
|
|
|
|
&toggle);
|
|
|
|
gimp_radio_group_set_active (GTK_RADIO_BUTTON (toggle),
|
|
|
|
GINT_TO_POINTER (dialog->dither_type));
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show(vbox);
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
/* the alpha-dither toggle */
|
2001-04-19 01:57:10 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2002-03-20 22:10:45 +08:00
|
|
|
toggle =
|
|
|
|
gtk_check_button_new_with_label (_("Enable Dithering of Transparency"));
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
|
2002-03-20 22:10:45 +08:00
|
|
|
dialog->alpha_dither);
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (toggle);
|
2001-08-15 00:33:28 +08:00
|
|
|
g_signal_connect (G_OBJECT (toggle), "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
2002-03-20 22:10:45 +08:00
|
|
|
&dialog->alpha_dither);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
/* if the image isn't non-alpha/layered, set the default number of
|
|
|
|
colours to one less than max, to leave room for a transparent index
|
|
|
|
for transparent/animated GIFs */
|
2002-03-20 22:10:45 +08:00
|
|
|
if (gimp_image_has_alpha (gimage))
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
|
|
|
frame = gtk_frame_new (_("[ Warning ]"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 1);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
label = gtk_label_new
|
2001-12-11 23:58:07 +08:00
|
|
|
(_("You are attempting to convert an image with an alpha channel "
|
2002-03-20 22:10:45 +08:00
|
|
|
"to indexed colors.\n"
|
|
|
|
"Do not generate a palette of more than 255 colors if you "
|
|
|
|
"intend to create a transparent or animated GIF file."));
|
2001-04-19 01:57:10 +08:00
|
|
|
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
|
|
|
|
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), label);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_show (dialog->shell);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
2001-10-29 19:47:11 +08:00
|
|
|
build_palette_button (Gimp *gimp)
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GimpPalette *palette;
|
|
|
|
GimpPalette *theWebPalette = NULL;
|
|
|
|
gint i;
|
|
|
|
gint default_palette;
|
|
|
|
|
|
|
|
UserHasWebPal = FALSE;
|
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
list = GIMP_LIST (gimp->palette_factory->container)->list;
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
if (! list)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, default_palette = -1;
|
|
|
|
list;
|
|
|
|
i++, list = g_list_next (list))
|
|
|
|
{
|
|
|
|
palette = (GimpPalette *) list->data;
|
|
|
|
|
|
|
|
/* Preferentially, the initial default is 'Web' if available */
|
|
|
|
if (theWebPalette == NULL &&
|
2001-08-30 01:48:28 +08:00
|
|
|
g_ascii_strcasecmp (GIMP_OBJECT (palette)->name, "Web") == 0)
|
2001-04-19 01:57:10 +08:00
|
|
|
{
|
|
|
|
theWebPalette = palette;
|
|
|
|
UserHasWebPal = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can't dither to > 256 colors */
|
|
|
|
if (palette->n_colors <= 256)
|
|
|
|
{
|
|
|
|
if (theCustomPalette == palette)
|
|
|
|
{
|
|
|
|
default_palette = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default to first one with <= 256 colors
|
|
|
|
* (only used if 'web' palette not available)
|
|
|
|
*/
|
|
|
|
if (default_palette == -1)
|
|
|
|
{
|
|
|
|
if (theWebPalette)
|
|
|
|
{
|
|
|
|
theCustomPalette = theWebPalette;
|
|
|
|
default_palette = 1; /* dummy value */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-10-29 19:47:11 +08:00
|
|
|
for (i = 0, list = GIMP_LIST (gimp->palette_factory->container)->list;
|
2001-04-19 01:57:10 +08:00
|
|
|
list && default_palette == -1;
|
|
|
|
i++, list = g_list_next (list))
|
|
|
|
{
|
|
|
|
palette = (GimpPalette *) list->data;
|
|
|
|
|
|
|
|
if (palette->n_colors <= 256)
|
|
|
|
{
|
|
|
|
theCustomPalette = palette;
|
|
|
|
default_palette = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (default_palette == -1)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return gtk_button_new_with_label (GIMP_OBJECT (theCustomPalette)->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
indexed_ok_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2002-03-20 22:10:45 +08:00
|
|
|
IndexedDialog *dialog;
|
|
|
|
GimpTool *active_tool;
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
dialog = (IndexedDialog *) data;
|
|
|
|
|
|
|
|
/* Close the dialogs when open because they're useless for indexed
|
|
|
|
* images and could crash the GIMP when used nevertheless
|
|
|
|
*/
|
2001-07-08 01:36:00 +08:00
|
|
|
active_tool = tool_manager_get_active (dialog->gimage->gimp);
|
|
|
|
|
2001-04-19 01:57:10 +08:00
|
|
|
if (active_tool)
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_control_active (dialog->gimage->gimp, HALT, active_tool->gdisp);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
/* Convert the image to indexed color */
|
2002-03-20 22:10:45 +08:00
|
|
|
gimp_image_convert (dialog->gimage,
|
|
|
|
GIMP_INDEXED,
|
|
|
|
dialog->num_colors,
|
|
|
|
dialog->dither_type,
|
|
|
|
dialog->alpha_dither,
|
|
|
|
dialog->remove_dups,
|
|
|
|
dialog->palette_type,
|
|
|
|
theCustomPalette);
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_image_flush (dialog->gimage);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
/* Save defaults for next time */
|
2002-03-20 22:10:45 +08:00
|
|
|
sdither_type = dialog->dither_type;
|
|
|
|
salpha_dither = dialog->alpha_dither;
|
|
|
|
sremove_dups = dialog->remove_dups;
|
|
|
|
snum_colors = dialog->num_colors;
|
|
|
|
spalette_type = dialog->palette_type;
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
if (dialog->palette_select)
|
|
|
|
gtk_widget_destroy (dialog->palette_select->shell);
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog->shell);
|
|
|
|
|
|
|
|
g_free (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
indexed_cancel_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
IndexedDialog *dialog;
|
|
|
|
|
|
|
|
dialog = (IndexedDialog *) data;
|
|
|
|
|
|
|
|
if (dialog->palette_select)
|
|
|
|
gtk_widget_destroy (dialog->palette_select->shell);
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog->shell);
|
|
|
|
|
|
|
|
g_free (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
indexed_palette_select_destroy_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
IndexedDialog *dialog = (IndexedDialog *)data;
|
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
dialog->palette_select = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
indexed_palette_select_palette (GimpContext *context,
|
|
|
|
GimpPalette *palette,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
IndexedDialog *dialog;
|
|
|
|
|
|
|
|
dialog = (IndexedDialog *) data;
|
|
|
|
|
|
|
|
if (palette)
|
|
|
|
{
|
|
|
|
if (palette->n_colors <= 256)
|
|
|
|
{
|
|
|
|
theCustomPalette = palette;
|
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (GTK_BIN (dialog->custom_palette_button)->child),
|
|
|
|
GIMP_OBJECT (theCustomPalette)->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
indexed_custom_palette_button_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2001-10-25 21:30:01 +08:00
|
|
|
IndexedDialog *dialog = (IndexedDialog *) data;
|
2001-04-19 01:57:10 +08:00
|
|
|
|
|
|
|
if (dialog->palette_select == NULL)
|
|
|
|
{
|
|
|
|
dialog->palette_select =
|
2001-10-29 19:47:11 +08:00
|
|
|
palette_select_new (dialog->gimage->gimp,
|
2002-03-13 05:02:10 +08:00
|
|
|
NULL,
|
2001-10-25 21:30:01 +08:00
|
|
|
_("Select Custom Palette"),
|
|
|
|
GIMP_OBJECT (theCustomPalette)->name,
|
|
|
|
NULL);
|
2001-04-19 01:57:10 +08:00
|
|
|
|
2001-08-15 00:33:28 +08:00
|
|
|
g_signal_connect (G_OBJECT (dialog->palette_select->shell), "destroy",
|
|
|
|
G_CALLBACK (indexed_palette_select_destroy_callback),
|
|
|
|
dialog);
|
|
|
|
g_signal_connect (G_OBJECT (dialog->palette_select->context),
|
|
|
|
"palette_changed",
|
|
|
|
G_CALLBACK (indexed_palette_select_palette),
|
|
|
|
dialog);
|
2001-04-19 01:57:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_window_raise (dialog->palette_select->shell->window);
|
|
|
|
}
|
|
|
|
}
|