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
|
|
|
|
*
|
2006-07-31 19:42:51 +08:00
|
|
|
* gimpfuzzyselecttool.c
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2001-03-10 01:39:18 +08:00
|
|
|
|
1999-07-27 08:14:14 +08:00
|
|
|
#include "config.h"
|
2000-03-26 02:17:01 +08:00
|
|
|
|
2008-05-23 22:09:55 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-08-06 00:08:19 +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-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2006-07-31 19:42:51 +08:00
|
|
|
#include "core/gimpitem.h"
|
2014-05-31 15:52:44 +08:00
|
|
|
#include "core/gimppickable.h"
|
|
|
|
#include "core/gimppickable-contiguous-region.h"
|
2001-05-09 10:32:03 +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"
|
|
|
|
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimpfuzzyselecttool.h"
|
2008-03-09 23:05:54 +08:00
|
|
|
#include "gimpregionselectoptions.h"
|
2003-04-16 00:05:52 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
1998-07-08 14:41:58 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
1999-07-07 02:13:59 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2013-04-09 07:38:24 +08:00
|
|
|
static GeglBuffer * gimp_fuzzy_select_tool_get_mask (GimpRegionSelectTool *region_select,
|
|
|
|
GimpDisplay *display);
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
G_DEFINE_TYPE (GimpFuzzySelectTool, gimp_fuzzy_select_tool,
|
2006-07-31 19:42:51 +08:00
|
|
|
GIMP_TYPE_REGION_SELECT_TOOL)
|
2005-12-13 17:13:50 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_fuzzy_select_tool_parent_class
|
2001-11-21 07:00:47 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
|
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_fuzzy_select_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2001-03-10 01:39:18 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_FUZZY_SELECT_TOOL,
|
2008-03-09 23:05:54 +08:00
|
|
|
GIMP_TYPE_REGION_SELECT_OPTIONS,
|
|
|
|
gimp_region_select_options_gui,
|
2003-06-28 19:20:37 +08:00
|
|
|
0,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-fuzzy-select-tool",
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Fuzzy Select"),
|
2006-09-19 02:00:22 +08:00
|
|
|
_("Fuzzy Select Tool: Select a contiguous region on the basis of color"),
|
2006-02-14 19:43:54 +08:00
|
|
|
N_("Fu_zzy Select"), "U",
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_FUZZY_SELECT,
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_FUZZY_SELECT,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2001-03-10 01:39:18 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_fuzzy_select_tool_class_init (GimpFuzzySelectToolClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-07-31 19:42:51 +08:00
|
|
|
GimpRegionSelectToolClass *region_class;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-07-31 19:42:51 +08:00
|
|
|
region_class = GIMP_REGION_SELECT_TOOL_CLASS (klass);
|
2001-10-22 20:13:44 +08:00
|
|
|
|
2008-05-23 22:09:55 +08:00
|
|
|
region_class->undo_desc = C_("command", "Fuzzy Select");
|
2006-07-31 19:42:51 +08:00
|
|
|
region_class->get_mask = gimp_fuzzy_select_tool_get_mask;
|
2001-03-10 01:39:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_fuzzy_select_tool_init (GimpFuzzySelectTool *fuzzy_select)
|
|
|
|
{
|
2004-06-05 07:08:29 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (fuzzy_select);
|
2001-03-10 01:39:18 +08:00
|
|
|
|
2006-07-31 19:42:51 +08:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
GIMP_TOOL_CURSOR_FUZZY_SELECT);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2013-04-09 07:38:24 +08:00
|
|
|
static GeglBuffer *
|
2006-07-31 19:42:51 +08:00
|
|
|
gimp_fuzzy_select_tool_get_mask (GimpRegionSelectTool *region_select,
|
|
|
|
GimpDisplay *display)
|
2006-06-03 23:41:40 +08:00
|
|
|
{
|
2008-03-09 23:05:54 +08: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);
|
2009-10-07 01:20:44 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
2014-05-31 15:52:44 +08:00
|
|
|
GimpPickable *pickable;
|
2008-03-09 23:05:54 +08:00
|
|
|
gint x, y;
|
2003-02-05 22:39:40 +08:00
|
|
|
|
2006-07-31 19:42:51 +08:00
|
|
|
x = region_select->x;
|
|
|
|
y = region_select->y;
|
2001-11-09 03:14:51 +08:00
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
if (! options->sample_merged)
|
2001-11-09 03:14:51 +08:00
|
|
|
{
|
|
|
|
gint off_x, off_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
2014-05-31 15:52:44 +08:00
|
|
|
|
|
|
|
pickable = GIMP_PICKABLE (drawable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pickable = GIMP_PICKABLE (image);
|
2001-11-09 03:14:51 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2014-05-31 15:52:44 +08:00
|
|
|
return gimp_pickable_contiguous_region_by_seed (pickable,
|
|
|
|
sel_options->antialias,
|
|
|
|
options->threshold / 255.0,
|
|
|
|
options->select_transparent,
|
|
|
|
options->select_criterion,
|
2016-01-08 20:53:07 +08:00
|
|
|
FALSE /* no diagonal neighbors */,
|
2014-05-31 15:52:44 +08:00
|
|
|
x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|