gimp/app/tools/gimpdesaturatetool.c

236 lines
7.5 KiB
C
Raw Normal View History

/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "base/desaturate.h"
#include "gegl/gimpdesaturateconfig.h"
#include "core/gimpdrawable.h"
#include "core/gimperror.h"
#include "core/gimpimage.h"
#include "widgets/gimphelp-ids.h"
#include "display/gimpdisplay.h"
#include "gimpimagemapoptions.h"
#include "gimpdesaturatetool.h"
#include "gimp-intl.h"
static gboolean gimp_desaturate_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static GeglNode * gimp_desaturate_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config);
static void gimp_desaturate_tool_map (GimpImageMapTool *im_tool);
static void gimp_desaturate_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_desaturate_tool_config_notify (GObject *object,
GParamSpec *pspec,
GimpDesaturateTool *desaturate_tool);
static void gimp_desaturate_tool_mode_changed (GtkWidget *button,
GimpDesaturateTool *desaturate_tool);
G_DEFINE_TYPE (GimpDesaturateTool, gimp_desaturate_tool,
GIMP_TYPE_IMAGE_MAP_TOOL)
#define parent_class gimp_desaturate_tool_parent_class
void
gimp_desaturate_tool_register (GimpToolRegisterCallback callback,
gpointer data)
{
(* callback) (GIMP_TYPE_DESATURATE_TOOL,
GIMP_TYPE_IMAGE_MAP_OPTIONS, NULL,
0,
"gimp-desaturate-tool",
_("Desaturate"),
_("Desaturate Tool: Turn colors into shades of gray"),
N_("_Desaturate..."), NULL,
NULL, GIMP_HELP_TOOL_DESATURATE,
GIMP_STOCK_TOOL_DESATURATE,
data);
}
static void
gimp_desaturate_tool_class_init (GimpDesaturateToolClass *klass)
{
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
tool_class->initialize = gimp_desaturate_tool_initialize;
im_tool_class->shell_desc = _("Desaturate (Remove Colors)");
im_tool_class->get_operation = gimp_desaturate_tool_get_operation;
im_tool_class->map = gimp_desaturate_tool_map;
im_tool_class->dialog = gimp_desaturate_tool_dialog;
}
static void
gimp_desaturate_tool_init (GimpDesaturateTool *desaturate_tool)
{
GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (desaturate_tool);
im_tool->apply_func = (GimpImageMapApplyFunc) desaturate_region;
im_tool->apply_data = &desaturate_tool->mode;
}
static gboolean
gimp_desaturate_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error)
{
GimpDesaturateTool *desaturate_tool = GIMP_DESATURATE_TOOL (tool);
GimpDrawable *drawable;
drawable = gimp_image_get_active_drawable (display->image);
if (! drawable)
return FALSE;
if (! gimp_drawable_is_rgb (drawable))
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
bumped minimum required version of GLib to 2.18.0. 2008-11-04 Sven Neumann <sven@sven> * configure.in: bumped minimum required version of GLib to 2.18.0. * INSTALL: document the updated dependency. * app/core/gimp.[ch]: introduced gimp_message_literal(), a variant of gimp_message() that takes a literal string. * app/errors.[ch]: removed format arguments from gimp_fatal_error() and gimp_terminate() and let them take a literal string instead. * app/tools/gimptool.[ch]: introduced gimp_tool_message_literal(), a variant of gimp_tool_message() that takes a literal string. * app/actions/documents-commands.c * app/actions/drawable-commands.c * app/actions/edit-commands.c * app/actions/error-console-commands.c * app/actions/file-commands.c * app/actions/gradients-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palettes-commands.c * app/actions/plug-in-commands.c * app/actions/select-commands.c * app/actions/vectors-commands.c * app/config/gimprc.c * app/core/gimp-modules.c * app/core/gimp-parasites.c * app/core/gimp-templates.c * app/core/gimp-units.c * app/core/gimpchannel.c * app/core/gimpcontainer-filter.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpimage-convert.c * app/core/gimpimage-merge.c * app/core/gimpimage.c * app/core/gimpimagefile.c * app/core/gimplayer-floating-sel.c * app/core/gimplayer.c * app/core/gimpselection.c * app/dialogs/convert-dialog.c * app/dialogs/dialogs.c * app/dialogs/palette-import-dialog.c * app/dialogs/preferences-dialog.c * app/dialogs/quit-dialog.c * app/dialogs/stroke-dialog.c * app/display/gimpdisplayshell-dnd.c * app/file/file-open.c * app/file/file-procedure.c * app/file/file-save.c * app/file/file-utils.c * app/gegl/gimpcurvesconfig.c * app/gegl/gimplevelsconfig.c * app/gui/gui-message.c * app/gui/gui.c * app/gui/session.c * app/paint/gimpbrushcore.c * app/paint/gimpclone.c * app/paint/gimpheal.c * app/paint/gimpperspectiveclone.c * app/paint/gimpsourcecore.c * app/pdb/gimppdb-utils.c * app/pdb/gimpprocedure.c * app/plug-in/gimpplugin-message.c * app/plug-in/gimpplugin.c * app/plug-in/gimppluginmanager-restore.c * app/plug-in/gimppluginprocedure.c * app/text/gimptextlayer.c * app/tools/gimp-tools.c * app/tools/gimpaligntool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcurvestool.c * app/tools/gimpdesaturatetool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpforegroundselecttool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpgegltool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpimagemaptool-settings.c * app/tools/gimpiscissorstool.c * app/tools/gimplevelstool.c * app/tools/gimpmeasuretool.c * app/tools/gimppainttool.c * app/tools/gimpposterizetool.c * app/tools/gimpselectiontool.c * app/tools/gimpsourcetool.c * app/tools/gimpthresholdtool.c * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/widgets/gimpactionview.c * app/widgets/gimpcontrollerlist.c * app/widgets/gimpcontrollers.c * app/widgets/gimpdataeditor.c * app/widgets/gimpdevices.c * app/widgets/gimpdnd-xds.c * app/widgets/gimperrordialog.c * app/widgets/gimphelp.c * app/widgets/gimpitemtreeview.c * app/widgets/gimppdbdialog.c * app/widgets/gimpsettingsbox.c * app/widgets/gimpvectorstreeview.c * app/widgets/gimpwidgets-utils.c * app/xcf/xcf-load.c * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/pdb/floating_sel.pdb * tools/pdbgen/pdb/image.pdb: use the _literal variants for g_set_error(), gimp_message() and gimp_tool_message(). * app/pdb/convert-cmds.c * app/pdb/edit-cmds.c * app/pdb/floating-sel-cmds.c * app/pdb/image-cmds.c: regenerated. svn path=/trunk/; revision=27548
2008-11-04 20:33:09 +08:00
_("Desaturate does only operate on RGB layers."));
return FALSE;
}
gimp_config_reset (GIMP_CONFIG (desaturate_tool->config));
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (desaturate_tool->button),
desaturate_tool->config->mode);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (desaturate_tool));
return TRUE;
}
static GeglNode *
gimp_desaturate_tool_get_operation (GimpImageMapTool *image_map_tool,
GObject **config)
{
GimpDesaturateTool *desaturate_tool = GIMP_DESATURATE_TOOL (image_map_tool);
GeglNode *node;
node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:desaturate",
NULL);
desaturate_tool->config = g_object_new (GIMP_TYPE_DESATURATE_CONFIG, NULL);
*config = G_OBJECT (desaturate_tool->config);
g_signal_connect_object (desaturate_tool->config, "notify",
G_CALLBACK (gimp_desaturate_tool_config_notify),
G_OBJECT (desaturate_tool), 0);
gegl_node_set (node,
"config", desaturate_tool->config,
NULL);
return node;
}
static void
gimp_desaturate_tool_map (GimpImageMapTool *image_map_tool)
{
GimpDesaturateTool *desaturate_tool = GIMP_DESATURATE_TOOL (image_map_tool);
desaturate_tool->mode = desaturate_tool->config->mode;
}
/**********************/
/* Desaturate dialog */
/**********************/
static void
gimp_desaturate_tool_dialog (GimpImageMapTool *image_map_tool)
{
GimpDesaturateTool *desaturate_tool = GIMP_DESATURATE_TOOL (image_map_tool);
GtkWidget *main_vbox;
GtkWidget *frame;
main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool);
/* The table containing sliders */
frame = gimp_enum_radio_frame_new (GIMP_TYPE_DESATURATE_MODE,
gtk_label_new (_("Choose shade of gray based on:")),
G_CALLBACK (gimp_desaturate_tool_mode_changed),
desaturate_tool,
&desaturate_tool->button);
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
}
static void
gimp_desaturate_tool_config_notify (GObject *object,
GParamSpec *pspec,
GimpDesaturateTool *desaturate_tool)
{
GimpDesaturateConfig *config = GIMP_DESATURATE_CONFIG (object);
if (! desaturate_tool->button)
return;
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (desaturate_tool->button),
config->mode);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (desaturate_tool));
}
static void
gimp_desaturate_tool_mode_changed (GtkWidget *button,
GimpDesaturateTool *desaturate_tool)
{
GimpDesaturateConfig *config = desaturate_tool->config;
GimpDesaturateMode mode;
mode = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"gimp-item-data"));
if (config->mode != mode)
{
g_object_set (config,
"mode", mode,
NULL);
}
}