1997-11-25 06:05:25 +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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "base/gimplut.h"
|
|
|
|
#include "base/lut-funcs.h"
|
|
|
|
|
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
2002-08-26 19:35:56 +08:00
|
|
|
#include "core/gimpimagemap.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "gimpposterizetool.h"
|
|
|
|
#include "tool_manager.h"
|
|
|
|
|
1998-12-16 08:37:09 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
#define POSTERIZE_DEFAULT_LEVELS 3
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
#define SLIDER_WIDTH 200
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
|
|
|
|
static void gimp_posterize_tool_class_init (GimpPosterizeToolClass *klass);
|
|
|
|
static void gimp_posterize_tool_init (GimpPosterizeTool *bc_tool);
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static void gimp_posterize_tool_finalize (GObject *object);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static void gimp_posterize_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static void gimp_posterize_tool_map (GimpImageMapTool *image_map_tool);
|
|
|
|
static void gimp_posterize_tool_dialog (GimpImageMapTool *image_map_tool);
|
|
|
|
static void gimp_posterize_tool_reset (GimpImageMapTool *image_map_tool);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
static void posterize_levels_adjustment_update (GtkAdjustment *adjustment,
|
|
|
|
GimpPosterizeTool *posterize_tool);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
static GimpImageMapToolClass *parent_class = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
/* functions */
|
1999-06-22 06:12:07 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_posterize_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_POSTERIZE_TOOL,
|
2001-11-21 07:00:47 +08:00
|
|
|
NULL,
|
|
|
|
FALSE,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-posterize-tool",
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Posterize"),
|
2002-08-27 22:57:41 +08:00
|
|
|
_("Reduce image to a fixed number of colors"),
|
2001-12-04 01:59:48 +08:00
|
|
|
N_("/Layer/Colors/Posterize..."), NULL,
|
2001-11-21 07:00:47 +08:00
|
|
|
NULL, "tools/posterize.html",
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_POSTERIZE,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2001-05-25 07:57:08 +08:00
|
|
|
gimp_posterize_tool_get_type (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static GType tool_type = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
if (! tool_type)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpPosterizeToolClass),
|
2001-08-14 22:53:55 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_posterize_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpPosterizeTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_posterize_tool_init,
|
2001-05-25 07:57:08 +08:00
|
|
|
};
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_IMAGE_MAP_TOOL,
|
|
|
|
"GimpPosterizeTool",
|
|
|
|
&tool_info, 0);
|
1999-04-09 06:25:54 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
return tool_type;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
static void
|
|
|
|
gimp_posterize_tool_class_init (GimpPosterizeToolClass *klass)
|
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpToolClass *tool_class;
|
|
|
|
GimpImageMapToolClass *image_map_tool_class;
|
1999-06-26 19:16:47 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
image_map_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
|
1999-06-22 06:12:07 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
object_class->finalize = gimp_posterize_tool_finalize;
|
2000-09-29 09:22:27 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
tool_class->initialize = gimp_posterize_tool_initialize;
|
|
|
|
|
|
|
|
image_map_tool_class->map = gimp_posterize_tool_map;
|
|
|
|
image_map_tool_class->dialog = gimp_posterize_tool_dialog;
|
|
|
|
image_map_tool_class->reset = gimp_posterize_tool_reset;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_posterize_tool_init (GimpPosterizeTool *posterize_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpImageMapTool *image_map_tool;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
image_map_tool = GIMP_IMAGE_MAP_TOOL (posterize_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-29 03:47:07 +08:00
|
|
|
image_map_tool->shell_desc = _("Posterize (Reduce Number of Colors)");
|
1999-06-26 19:16:47 +08:00
|
|
|
|
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
|
|
|
posterize_tool->levels = POSTERIZE_DEFAULT_LEVELS;
|
|
|
|
posterize_tool->lut = gimp_lut_new ();
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-05-25 07:57:08 +08:00
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_posterize_tool_finalize (GObject *object)
|
2001-05-25 07:57:08 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpPosterizeTool *posterize_tool;
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
posterize_tool = GIMP_POSTERIZE_TOOL (object);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
if (posterize_tool->lut)
|
|
|
|
{
|
|
|
|
gimp_lut_free (posterize_tool->lut);
|
|
|
|
posterize_tool->lut = NULL;
|
2001-05-25 07:57:08 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-10-17 19:33:43 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_posterize_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpPosterizeTool *posterize_tool;
|
2001-07-08 01:36:00 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
posterize_tool = GIMP_POSTERIZE_TOOL (tool);
|
2001-07-08 01:36:00 +08:00
|
|
|
|
2002-08-29 03:47:07 +08:00
|
|
|
if (! gdisp)
|
|
|
|
{
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gimp_drawable_is_indexed (gimp_image_active_drawable (gdisp->gimage)))
|
1999-11-22 19:14:29 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
g_message (_("Posterize does not operate on indexed drawables."));
|
1999-11-22 19:14:29 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
posterize_tool->levels = POSTERIZE_DEFAULT_LEVELS;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (posterize_tool->levels_data),
|
|
|
|
posterize_tool->levels);
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (posterize_tool));
|
1999-11-22 19:14:29 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_posterize_tool_map (GimpImageMapTool *image_map_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpPosterizeTool *posterize_tool;
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
|
|
posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
|
|
|
|
tool = GIMP_TOOL (image_map_tool);
|
|
|
|
|
|
|
|
posterize_lut_setup (posterize_tool->lut,
|
|
|
|
posterize_tool->levels,
|
|
|
|
gimp_drawable_bytes (image_map_tool->drawable));
|
|
|
|
gimp_image_map_apply (image_map_tool->image_map,
|
|
|
|
(GimpImageMapApplyFunc) gimp_lut_process_2,
|
|
|
|
posterize_tool->lut);
|
|
|
|
}
|
1998-03-31 15:23:50 +08:00
|
|
|
|
1999-06-26 19:16:47 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
/**********************/
|
|
|
|
/* Posterize dialog */
|
|
|
|
/**********************/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_posterize_tool_dialog (GimpImageMapTool *image_map_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpPosterizeTool *posterize_tool;
|
|
|
|
GtkWidget *table;
|
2002-08-29 03:47:07 +08:00
|
|
|
GtkWidget *slider;
|
2002-08-26 19:35:56 +08:00
|
|
|
GtkObject *data;
|
|
|
|
|
|
|
|
posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
|
|
|
|
|
|
|
|
/* The table containing sliders */
|
|
|
|
table = gtk_table_new (1, 3, FALSE);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), table,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
data = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
2002-08-29 03:47:07 +08:00
|
|
|
_("Posterize _Levels:"),
|
2002-08-26 19:35:56 +08:00
|
|
|
SLIDER_WIDTH, 75,
|
|
|
|
posterize_tool->levels,
|
|
|
|
2.0, 256.0, 1.0, 10.0, 0,
|
|
|
|
TRUE, 0.0, 0.0,
|
|
|
|
NULL, NULL);
|
|
|
|
posterize_tool->levels_data = GTK_ADJUSTMENT (data);
|
2002-08-29 03:47:07 +08:00
|
|
|
slider = GIMP_SCALE_ENTRY_SCALE (data);
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (posterize_tool->levels_data), "value_changed",
|
|
|
|
G_CALLBACK (posterize_levels_adjustment_update),
|
|
|
|
posterize_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_posterize_tool_reset (GimpImageMapTool *image_map_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
GimpPosterizeTool *posterize_tool;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
|
2001-07-08 01:36:00 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
posterize_tool->levels = POSTERIZE_DEFAULT_LEVELS;
|
2002-05-09 01:48:24 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (posterize_tool->levels_data),
|
|
|
|
posterize_tool->levels);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-26 19:35:56 +08:00
|
|
|
posterize_levels_adjustment_update (GtkAdjustment *adjustment,
|
|
|
|
GimpPosterizeTool *posterize_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
if (posterize_tool->levels != adjustment->value)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-08-26 19:35:56 +08:00
|
|
|
posterize_tool->levels = adjustment->value;
|
1999-11-22 19:14:29 +08:00
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (posterize_tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|