2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* 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"
|
2003-08-22 09:42:57 +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
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
2004-02-22 22:28:53 +08:00
|
|
|
#include "gimpimagemapoptions.h"
|
2001-05-25 07:57:08 +08:00
|
|
|
#include "gimpposterizetool.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
1998-12-16 08:37:09 +08:00
|
|
|
|
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
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
static void gimp_posterize_tool_finalize (GObject *object);
|
2001-05-25 07:57:08 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
static gboolean gimp_posterize_tool_initialize (GimpTool *tool,
|
2006-09-27 04:55:40 +08:00
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
static void gimp_posterize_tool_map (GimpImageMapTool *im_tool);
|
|
|
|
static void gimp_posterize_tool_dialog (GimpImageMapTool *im_tool);
|
|
|
|
static void gimp_posterize_tool_reset (GimpImageMapTool *im_tool);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2004-01-22 00:07:48 +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
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
G_DEFINE_TYPE (GimpPosterizeTool, gimp_posterize_tool,
|
2006-05-15 17:46:31 +08:00
|
|
|
GIMP_TYPE_IMAGE_MAP_TOOL)
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
#define parent_class gimp_posterize_tool_parent_class
|
1997-11-25 06:05:25 +08:00
|
|
|
|
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,
|
2004-02-22 22:28:53 +08:00
|
|
|
GIMP_TYPE_IMAGE_MAP_OPTIONS, NULL,
|
2003-06-28 19:20:37 +08:00
|
|
|
0,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-posterize-tool",
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Posterize"),
|
2006-09-19 02:00:22 +08:00
|
|
|
_("Posterize Tool: Reduce to a limited set of colors"),
|
2004-04-29 21:19:28 +08:00
|
|
|
N_("_Posterize..."), NULL,
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_POSTERIZE,
|
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-05-25 07:57:08 +08:00
|
|
|
static void
|
|
|
|
gimp_posterize_tool_class_init (GimpPosterizeToolClass *klass)
|
|
|
|
{
|
2005-12-13 17:13:50 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
object_class->finalize = gimp_posterize_tool_finalize;
|
2000-09-29 09:22:27 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
tool_class->initialize = gimp_posterize_tool_initialize;
|
2002-08-26 19:35:56 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
im_tool_class->shell_desc = _("Posterize (Reduce Number of Colors)");
|
2004-02-25 21:55:45 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
im_tool_class->map = gimp_posterize_tool_map;
|
|
|
|
im_tool_class->dialog = gimp_posterize_tool_dialog;
|
|
|
|
im_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
|
|
|
{
|
2003-05-03 02:43:15 +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
|
|
|
{
|
2003-11-13 19:23:01 +08:00
|
|
|
GimpPosterizeTool *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
|
|
|
}
|
|
|
|
|
2004-01-22 00:07:48 +08:00
|
|
|
static gboolean
|
2006-09-27 04:55:40 +08:00
|
|
|
gimp_posterize_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-11-13 19:23:01 +08:00
|
|
|
GimpPosterizeTool *posterize_tool = GIMP_POSTERIZE_TOOL (tool);
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
2007-07-19 22:59:51 +08:00
|
|
|
drawable = gimp_image_get_active_drawable (display->image);
|
2001-07-08 01:36:00 +08:00
|
|
|
|
2003-11-13 19:23:01 +08:00
|
|
|
if (! drawable)
|
2004-01-22 00:07:48 +08:00
|
|
|
return FALSE;
|
2001-07-08 01:36:00 +08:00
|
|
|
|
2003-11-13 19:23:01 +08:00
|
|
|
if (gimp_drawable_is_indexed (drawable))
|
1999-11-22 19:14:29 +08:00
|
|
|
{
|
2006-09-27 04:55:40 +08:00
|
|
|
g_set_error (error, 0, 0,
|
|
|
|
_("Posterize does not operate on indexed layers."));
|
2004-01-22 00:07:48 +08:00
|
|
|
return FALSE;
|
1999-11-22 19:14:29 +08:00
|
|
|
}
|
|
|
|
|
2002-08-26 19:35:56 +08:00
|
|
|
posterize_tool->levels = POSTERIZE_DEFAULT_LEVELS;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-09-27 04:55:40 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
|
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));
|
2004-01-22 00:07:48 +08:00
|
|
|
|
|
|
|
return TRUE;
|
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
|
|
|
{
|
2003-11-13 19:23:01 +08:00
|
|
|
GimpPosterizeTool *posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
|
2002-08-26 19:35:56 +08:00
|
|
|
|
|
|
|
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,
|
2005-02-15 23:39:27 +08:00
|
|
|
(GimpImageMapApplyFunc) gimp_lut_process,
|
2002-08-26 19:35:56 +08:00
|
|
|
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
|
|
|
{
|
2003-11-13 19:23:01 +08:00
|
|
|
GimpPosterizeTool *posterize_tool = GIMP_POSTERIZE_TOOL (image_map_tool);
|
2002-08-26 19:35:56 +08:00
|
|
|
GtkWidget *table;
|
2002-08-29 03:47:07 +08:00
|
|
|
GtkWidget *slider;
|
2002-08-26 19:35:56 +08:00
|
|
|
GtkObject *data;
|
|
|
|
|
|
|
|
/* 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,
|
2004-06-24 04:29:46 +08:00
|
|
|
_("Posterize _levels:"), SLIDER_WIDTH, -1,
|
2002-08-26 19:35:56 +08:00
|
|
|
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
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (posterize_tool->levels_data, "value-changed",
|
2002-08-26 19:35:56 +08:00
|
|
|
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
|
|
|
{
|
2003-11-13 19:23:01 +08:00
|
|
|
GimpPosterizeTool *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,
|
2006-04-12 20:49:29 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|