2006-12-09 13:33:38 -08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-24 14:05:25 -08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
2006-07-31 04:42:51 -07:00
|
|
|
* gimpfuzzyselecttool.c
|
|
|
|
|
*
|
1997-11-24 14:05:25 -08:00
|
|
|
* 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-12 22:44:11 -07:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-24 14:05:25 -08:00
|
|
|
*/
|
2001-03-09 09:39:18 -08:00
|
|
|
|
1999-07-26 17:14:14 -07:00
|
|
|
#include "config.h"
|
2000-03-25 10:17:01 -08:00
|
|
|
|
2000-12-16 13:37:03 -08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
2001-08-05 09:08:19 -07:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
2002-05-03 05:45:22 -07:00
|
|
|
#include "tools-types.h"
|
2000-12-16 13:37:03 -08:00
|
|
|
|
2001-05-08 19:32:03 -07:00
|
|
|
#include "core/gimpimage.h"
|
2001-10-22 05:13:44 -07:00
|
|
|
#include "core/gimpimage-contiguous-region.h"
|
2006-07-31 04:42:51 -07:00
|
|
|
#include "core/gimpitem.h"
|
2001-05-08 19:32:03 -07:00
|
|
|
|
2003-08-21 18:42:57 -07:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
|
2001-09-25 16:23:09 -07:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
|
2001-03-07 17:07:03 -08:00
|
|
|
#include "gimpfuzzyselecttool.h"
|
2008-03-09 08:05:54 -07:00
|
|
|
#include "gimpregionselectoptions.h"
|
2003-04-15 09:05:52 -07:00
|
|
|
#include "gimptoolcontrol.h"
|
1998-07-07 23:41:58 -07:00
|
|
|
|
2003-03-25 08:38:19 -08:00
|
|
|
#include "gimp-intl.h"
|
1999-07-06 11:13:59 -07:00
|
|
|
|
2000-12-29 07:22:01 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
static GimpChannel * gimp_fuzzy_select_tool_get_mask (GimpRegionSelectTool *region_select,
|
|
|
|
|
GimpDisplay *display);
|
1999-04-12 10:55:06 -07:00
|
|
|
|
2000-12-30 20:07:42 -08:00
|
|
|
|
2005-12-13 01:13:50 -08:00
|
|
|
G_DEFINE_TYPE (GimpFuzzySelectTool, gimp_fuzzy_select_tool,
|
2006-07-31 04:42:51 -07:00
|
|
|
GIMP_TYPE_REGION_SELECT_TOOL)
|
2005-12-13 01:13:50 -08:00
|
|
|
|
|
|
|
|
#define parent_class gimp_fuzzy_select_tool_parent_class
|
2001-11-20 15:00:47 -08:00
|
|
|
|
2001-03-09 09:39:18 -08:00
|
|
|
|
|
|
|
|
void
|
2002-03-28 19:50:29 -08:00
|
|
|
gimp_fuzzy_select_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 04:31:08 -07:00
|
|
|
gpointer data)
|
2001-03-09 09:39:18 -08:00
|
|
|
{
|
2002-03-28 19:50:29 -08:00
|
|
|
(* callback) (GIMP_TYPE_FUZZY_SELECT_TOOL,
|
2008-03-09 08:05:54 -07:00
|
|
|
GIMP_TYPE_REGION_SELECT_OPTIONS,
|
|
|
|
|
gimp_region_select_options_gui,
|
2003-06-28 04:20:37 -07:00
|
|
|
0,
|
2002-03-21 04:17:17 -08:00
|
|
|
"gimp-fuzzy-select-tool",
|
2001-11-20 15:00:47 -08:00
|
|
|
_("Fuzzy Select"),
|
2006-09-18 11:00:22 -07:00
|
|
|
_("Fuzzy Select Tool: Select a contiguous region on the basis of color"),
|
2006-02-14 03:43:54 -08:00
|
|
|
N_("Fu_zzy Select"), "U",
|
2003-08-21 18:42:57 -07:00
|
|
|
NULL, GIMP_HELP_TOOL_FUZZY_SELECT,
|
2002-03-28 19:50:29 -08:00
|
|
|
GIMP_STOCK_TOOL_FUZZY_SELECT,
|
2002-05-03 04:31:08 -07:00
|
|
|
data);
|
2001-03-09 09:39:18 -08:00
|
|
|
}
|
|
|
|
|
|
1997-11-24 14:05:25 -08:00
|
|
|
static void
|
2001-03-09 09:39:18 -08:00
|
|
|
gimp_fuzzy_select_tool_class_init (GimpFuzzySelectToolClass *klass)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
2006-07-31 04:42:51 -07:00
|
|
|
GimpRegionSelectToolClass *region_class;
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
region_class = GIMP_REGION_SELECT_TOOL_CLASS (klass);
|
2001-10-22 05:13:44 -07:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
region_class->undo_desc = Q_("command|Fuzzy Select");
|
|
|
|
|
region_class->get_mask = gimp_fuzzy_select_tool_get_mask;
|
2001-03-09 09:39:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_fuzzy_select_tool_init (GimpFuzzySelectTool *fuzzy_select)
|
|
|
|
|
{
|
2004-06-04 16:08:29 -07:00
|
|
|
GimpTool *tool = GIMP_TOOL (fuzzy_select);
|
2001-03-09 09:39:18 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
|
GIMP_TOOL_CURSOR_FUZZY_SELECT);
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|
|
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
static GimpChannel *
|
|
|
|
|
gimp_fuzzy_select_tool_get_mask (GimpRegionSelectTool *region_select,
|
|
|
|
|
GimpDisplay *display)
|
2006-06-03 08:41:40 -07:00
|
|
|
{
|
2008-03-09 08:05:54 -07:00
|
|
|
GimpTool *tool = GIMP_TOOL (region_select);
|
|
|
|
|
GimpSelectionOptions *sel_options = GIMP_SELECTION_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
gint x, y;
|
2003-02-05 06:39:40 -08:00
|
|
|
|
2007-07-19 07:59:51 -07:00
|
|
|
drawable = gimp_image_get_active_drawable (display->image);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
x = region_select->x;
|
|
|
|
|
y = region_select->y;
|
2001-11-08 11:14:51 -08:00
|
|
|
|
2003-02-05 06:39:40 -08:00
|
|
|
if (! options->sample_merged)
|
2001-11-08 11:14:51 -08:00
|
|
|
{
|
|
|
|
|
gint off_x, off_y;
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2003-05-08 07:06:03 -07:00
|
|
|
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
|
2001-11-08 11:14:51 -08:00
|
|
|
|
|
|
|
|
x -= off_x;
|
|
|
|
|
y -= off_y;
|
|
|
|
|
}
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
return gimp_image_contiguous_region_by_seed (display->image, drawable,
|
|
|
|
|
options->sample_merged,
|
2008-03-09 08:05:54 -07:00
|
|
|
sel_options->antialias,
|
2006-07-31 04:42:51 -07:00
|
|
|
options->threshold,
|
|
|
|
|
options->select_transparent,
|
Applied (modified and enhanced) patch from Chris Moller which allows tools
2006-08-05 Michael Natterer <mitch@gimp.org>
Applied (modified and enhanced) patch from Chris Moller which allows
tools to distinguish similar colors not only by composite, but also
by R, G, B, H, S and V. Fixes bug #348291.
* app/core/core-enums.[ch]: added new enum GimpSelectCriterion
which can be one of { COMPOSITE, R, G, B, H, S, V }.
* app/core/gimpimage-contiguous-region.[ch]: added
select_criterion params and create the region based on difference
by the selected criterion.
* app/core/gimpchannel-select.[ch]
* app/core/gimpdrawable-bucket-fill.[ch]: take criterion params and
pass them through to the contiguous region functions.
* app/tools/gimpbucketfilloptions.[ch]
* app/tools/gimpselectionoptions.[ch]: added criterion properties
and GUI to select it.
* app/tools/gimpbucketfilltool.c
* app/tools/gimpbycolorselecttool.c
* app/tools/gimpfuzzyselecttool.c: pass the selected criterion to
the resp. core functions.
* app/widgets/gimpdrawabletreeview.c
* app/widgets/gimpselectioneditor.c
* app/display/gimpdisplayshell-dnd.c
* tools/pdbgen/pdb/edit.pdb
* tools/pdbgen/pdb/selection_tools.pdb: changed accordingly
(simply pass GIMP_SELECT_CRITERION_COMPOSITE in most cases).
* app/pdb/edit_cmds.c
* app/pdb/selection_tools_cmds.c: regenerated.
2006-08-05 06:02:47 -07:00
|
|
|
options->select_criterion,
|
2006-07-31 04:42:51 -07:00
|
|
|
x, y);
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|