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
|
|
|
*/
|
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
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2000-03-26 02:17:01 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-08-06 00:08:19 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/boundary.h"
|
|
|
|
#include "base/pixel-region.h"
|
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpchannel.h"
|
2003-10-06 20:17:11 +08:00
|
|
|
#include "core/gimpchannel-select.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2001-10-22 20:13:44 +08:00
|
|
|
#include "core/gimpimage-contiguous-region.h"
|
2002-03-15 16:01:07 +08:00
|
|
|
#include "core/gimplayer-floating-sel.h"
|
2001-11-20 21:53:21 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
#include "display/gimpcanvas.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2003-01-04 02:01:30 +08:00
|
|
|
#include "display/gimpdisplayshell-cursor.h"
|
|
|
|
#include "display/gimpdisplayshell-transform.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimpfuzzyselecttool.h"
|
2003-02-09 05:12:03 +08:00
|
|
|
#include "gimpselectionoptions.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
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
static void gimp_fuzzy_select_tool_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_fuzzy_select_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display);
|
2001-11-09 03:14:51 +08:00
|
|
|
static void gimp_fuzzy_select_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display);
|
2001-11-09 03:14:51 +08:00
|
|
|
static void gimp_fuzzy_select_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display);
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
|
|
static void gimp_fuzzy_select_tool_draw (GimpDrawTool *draw_tool);
|
2000-03-02 07:22:43 +08:00
|
|
|
|
2002-08-20 18:40:38 +08:00
|
|
|
static GdkSegment *
|
|
|
|
gimp_fuzzy_select_tool_calculate (GimpFuzzySelectTool *fuzzy_sel,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2002-08-20 18:40:38 +08:00
|
|
|
gint *num_segs);
|
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-05-15 17:46:31 +08:00
|
|
|
GIMP_TYPE_SELECTION_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,
|
2003-02-05 22:39:40 +08:00
|
|
|
GIMP_TYPE_SELECTION_OPTIONS,
|
|
|
|
gimp_selection_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"),
|
|
|
|
_("Select contiguous regions"),
|
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
|
|
|
{
|
2004-06-05 07:08:29 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
object_class->finalize = gimp_fuzzy_select_tool_finalize;
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
tool_class->button_press = gimp_fuzzy_select_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_fuzzy_select_tool_button_release;
|
|
|
|
tool_class->motion = gimp_fuzzy_select_tool_motion;
|
|
|
|
|
|
|
|
draw_tool_class->draw = gimp_fuzzy_select_tool_draw;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2002-05-03 05:03:27 +08:00
|
|
|
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
|
|
|
|
gimp_tool_control_set_motion_mode (tool->control, GIMP_MOTION_MODE_COMPRESS);
|
2004-06-05 07:08:29 +08:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_FUZZY_SELECT);
|
2002-03-29 11:50:29 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
fuzzy_select->x = 0;
|
|
|
|
fuzzy_select->y = 0;
|
|
|
|
fuzzy_select->first_x = 0;
|
|
|
|
fuzzy_select->first_y = 0;
|
|
|
|
fuzzy_select->first_threshold = 0.0;
|
2002-06-27 06:16:59 +08:00
|
|
|
|
|
|
|
fuzzy_select->fuzzy_mask = NULL;
|
|
|
|
fuzzy_select->segs = NULL;
|
|
|
|
fuzzy_select->num_segs = 0;
|
2001-03-10 01:39:18 +08:00
|
|
|
}
|
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
static void
|
|
|
|
gimp_fuzzy_select_tool_finalize (GObject *object)
|
|
|
|
{
|
2004-06-05 07:08:29 +08:00
|
|
|
GimpFuzzySelectTool *fuzzy_sel = GIMP_FUZZY_SELECT_TOOL (object);
|
2001-10-22 20:13:44 +08:00
|
|
|
|
|
|
|
if (fuzzy_sel->fuzzy_mask)
|
|
|
|
{
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (fuzzy_sel->fuzzy_mask);
|
2001-10-22 20:13:44 +08:00
|
|
|
fuzzy_sel->fuzzy_mask = NULL;
|
|
|
|
}
|
2002-03-19 21:14:25 +08:00
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
if (fuzzy_sel->segs)
|
|
|
|
{
|
|
|
|
g_free (fuzzy_sel->segs);
|
|
|
|
fuzzy_sel->segs = NULL;
|
|
|
|
fuzzy_sel->num_segs = 0;
|
|
|
|
}
|
|
|
|
|
2002-03-19 21:14:25 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static void
|
2003-07-10 19:59:38 +08:00
|
|
|
gimp_fuzzy_select_tool_button_press (GimpTool *tool,
|
2001-11-09 03:14:51 +08:00
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display)
|
2001-03-10 01:39:18 +08:00
|
|
|
{
|
2004-06-05 07:08:29 +08:00
|
|
|
GimpFuzzySelectTool *fuzzy_sel = GIMP_FUZZY_SELECT_TOOL (tool);
|
2003-02-05 22:39:40 +08:00
|
|
|
GimpSelectionOptions *options;
|
2001-03-10 01:39:18 +08:00
|
|
|
|
2004-07-26 22:50:51 +08:00
|
|
|
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
2001-11-20 21:53:21 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
fuzzy_sel->x = coords->x;
|
|
|
|
fuzzy_sel->y = coords->y;
|
|
|
|
fuzzy_sel->first_x = fuzzy_sel->x;
|
|
|
|
fuzzy_sel->first_y = fuzzy_sel->y;
|
2003-02-05 22:39:40 +08:00
|
|
|
fuzzy_sel->first_threshold = options->threshold;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-05-03 19:31:08 +08:00
|
|
|
gimp_tool_control_activate (tool->control);
|
2006-03-29 01:55:52 +08:00
|
|
|
tool->display = display;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-07-26 22:50:51 +08:00
|
|
|
if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (fuzzy_sel), coords))
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_tool_push_status (tool, display, _("Move the mouse to change threshold."));
|
2005-04-11 20:10:39 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* calculate the region boundary */
|
2006-03-29 01:55:52 +08:00
|
|
|
fuzzy_sel->segs = gimp_fuzzy_select_tool_calculate (fuzzy_sel, display,
|
2002-08-20 18:40:38 +08:00
|
|
|
&fuzzy_sel->num_segs);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-10 19:59:38 +08:00
|
|
|
gimp_fuzzy_select_tool_button_release (GimpTool *tool,
|
2001-11-09 03:14:51 +08:00
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-06-05 07:08:29 +08:00
|
|
|
GimpFuzzySelectTool *fuzzy_sel = GIMP_FUZZY_SELECT_TOOL (tool);
|
2003-02-05 22:39:40 +08:00
|
|
|
GimpSelectionOptions *options;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-04-11 20:10:39 +08:00
|
|
|
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_tool_pop_status (tool, display);
|
2001-11-20 21:53:21 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
|
2002-02-05 19:35:03 +08:00
|
|
|
|
2003-01-03 21:59:23 +08:00
|
|
|
gimp_tool_control_halt (tool->control);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* First take care of the case where the user "cancels" the action */
|
2001-11-09 03:14:51 +08:00
|
|
|
if (! (state & GDK_BUTTON3_MASK))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-03-03 18:38:37 +08:00
|
|
|
gint off_x, off_y;
|
|
|
|
|
2002-03-15 16:01:07 +08:00
|
|
|
if (GIMP_SELECTION_TOOL (tool)->op == SELECTION_ANCHOR)
|
2004-07-26 22:50:51 +08:00
|
|
|
{
|
|
|
|
/* If there is a floating selection, anchor it */
|
2006-03-29 01:55:52 +08:00
|
|
|
if (gimp_image_floating_sel (display->image))
|
|
|
|
floating_sel_anchor (gimp_image_floating_sel (display->image));
|
2004-07-26 22:50:51 +08:00
|
|
|
/* Otherwise, clear the selection mask */
|
|
|
|
else
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_channel_clear (gimp_image_get_mask (display->image), NULL,
|
2003-09-03 22:22:38 +08:00
|
|
|
TRUE);
|
2002-03-15 16:01:07 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_image_flush (display->image);
|
2004-07-26 22:50:51 +08:00
|
|
|
return;
|
|
|
|
}
|
2002-03-15 16:01:07 +08:00
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
if (options->sample_merged)
|
2002-03-03 18:38:37 +08:00
|
|
|
{
|
|
|
|
off_x = 0;
|
|
|
|
off_y = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDrawable *drawable = gimp_image_active_drawable (display->image);
|
2002-03-03 18:38:37 +08:00
|
|
|
|
2003-05-08 22:06:03 +08:00
|
|
|
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
|
2002-03-03 18:38:37 +08:00
|
|
|
}
|
2001-10-22 20:13:44 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_channel_select_channel (gimp_image_get_mask (display->image),
|
2003-10-06 20:17:11 +08:00
|
|
|
tool->tool_info->blurb,
|
|
|
|
fuzzy_sel->fuzzy_mask,
|
|
|
|
off_x,
|
|
|
|
off_y,
|
|
|
|
GIMP_SELECTION_TOOL (tool)->op,
|
|
|
|
options->feather,
|
|
|
|
options->feather_radius,
|
|
|
|
options->feather_radius);
|
1999-06-26 19:16:47 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (fuzzy_sel->fuzzy_mask);
|
2001-10-22 20:13:44 +08:00
|
|
|
fuzzy_sel->fuzzy_mask = NULL;
|
2001-03-10 01:39:18 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_image_flush (display->image);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the segment array is allocated, free it */
|
2002-06-27 06:16:59 +08:00
|
|
|
if (fuzzy_sel->segs)
|
2001-10-22 20:13:44 +08:00
|
|
|
{
|
2002-06-27 06:16:59 +08:00
|
|
|
g_free (fuzzy_sel->segs);
|
|
|
|
fuzzy_sel->segs = NULL;
|
|
|
|
fuzzy_sel->num_segs = 0;
|
2001-10-22 20:13:44 +08:00
|
|
|
}
|
2003-12-17 20:59:06 +08:00
|
|
|
|
|
|
|
/* Restore the original threshold */
|
|
|
|
g_object_set (options,
|
|
|
|
"threshold", fuzzy_sel->first_threshold,
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-10 19:59:38 +08:00
|
|
|
gimp_fuzzy_select_tool_motion (GimpTool *tool,
|
2001-11-09 03:14:51 +08:00
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-06-05 07:08:29 +08:00
|
|
|
GimpFuzzySelectTool *fuzzy_sel = GIMP_FUZZY_SELECT_TOOL (tool);
|
2003-02-05 22:39:40 +08:00
|
|
|
GimpSelectionOptions *options;
|
|
|
|
GdkSegment *new_segs;
|
|
|
|
gint num_new_segs;
|
|
|
|
gint diff_x, diff_y;
|
|
|
|
gdouble diff;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
static guint32 last_time = 0;
|
2000-02-19 21:19:08 +08:00
|
|
|
|
2004-06-05 07:08:29 +08:00
|
|
|
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
2000-03-02 07:22:43 +08:00
|
|
|
|
2000-02-19 21:19:08 +08:00
|
|
|
/* don't let the events come in too fast, ignore below a delay of 100 ms */
|
2003-09-16 21:12:50 +08:00
|
|
|
if (time - last_time < 100)
|
2000-02-19 21:19:08 +08:00
|
|
|
return;
|
2001-03-10 01:39:18 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
last_time = time;
|
2000-02-19 21:19:08 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
diff_x = coords->x - fuzzy_sel->first_x;
|
|
|
|
diff_y = coords->y - fuzzy_sel->first_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-23 06:26:20 +08:00
|
|
|
diff = ((ABS (diff_x) > ABS (diff_y)) ? diff_x : diff_y) / 2.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-02-28 09:14:30 +08:00
|
|
|
g_object_set (options,
|
2003-12-17 20:59:06 +08:00
|
|
|
"threshold", CLAMP (fuzzy_sel->first_threshold + diff, 0, 255),
|
2003-02-08 01:12:21 +08:00
|
|
|
NULL);
|
2001-03-10 01:39:18 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* calculate the new fuzzy boundary */
|
2006-03-29 01:55:52 +08:00
|
|
|
new_segs = gimp_fuzzy_select_tool_calculate (fuzzy_sel, display, &num_new_segs);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* make sure the XSegment array is freed before we assign the new one */
|
2002-06-27 06:16:59 +08:00
|
|
|
if (fuzzy_sel->segs)
|
|
|
|
g_free (fuzzy_sel->segs);
|
|
|
|
|
|
|
|
fuzzy_sel->segs = new_segs;
|
|
|
|
fuzzy_sel->num_segs = num_new_segs;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2002-08-20 18:40:38 +08:00
|
|
|
static void
|
|
|
|
gimp_fuzzy_select_tool_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
GimpFuzzySelectTool *fuzzy_sel = GIMP_FUZZY_SELECT_TOOL (draw_tool);
|
2002-08-20 18:40:38 +08:00
|
|
|
|
|
|
|
if (fuzzy_sel->segs)
|
2003-11-11 03:35:56 +08:00
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (GIMP_TOOL (draw_tool)->display->shell);
|
2003-11-11 03:35:56 +08:00
|
|
|
|
|
|
|
gimp_canvas_draw_segments (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
fuzzy_sel->segs, fuzzy_sel->num_segs);
|
|
|
|
}
|
2002-08-20 18:40:38 +08:00
|
|
|
}
|
1999-07-07 02:13:59 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static GdkSegment *
|
2002-08-20 18:40:38 +08:00
|
|
|
gimp_fuzzy_select_tool_calculate (GimpFuzzySelectTool *fuzzy_sel,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2002-08-20 18:40:38 +08:00
|
|
|
gint *num_segs)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-06-05 07:08:29 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (fuzzy_sel);
|
2003-02-05 22:39:40 +08:00
|
|
|
GimpSelectionOptions *options;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
PixelRegion maskPR;
|
|
|
|
GimpChannel *new;
|
|
|
|
GdkSegment *segs;
|
|
|
|
BoundSeg *bsegs;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
gint i;
|
|
|
|
gint x, y;
|
|
|
|
|
|
|
|
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
2002-02-07 19:33:01 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (display->shell);
|
2002-06-27 06:16:59 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
drawable = gimp_image_active_drawable (display->image);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
gimp_display_shell_set_override_cursor (shell, GDK_WATCH);
|
2000-03-26 02:17:01 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
x = fuzzy_sel->x;
|
|
|
|
y = fuzzy_sel->y;
|
|
|
|
|
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
|
|
|
|
2003-05-08 22:06:03 +08:00
|
|
|
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
new = gimp_image_contiguous_region_by_seed (display->image, drawable,
|
2003-02-05 22:39:40 +08:00
|
|
|
options->sample_merged,
|
|
|
|
options->antialias,
|
|
|
|
options->threshold,
|
|
|
|
options->select_transparent,
|
2001-10-22 20:13:44 +08:00
|
|
|
x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
if (fuzzy_sel->fuzzy_mask)
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (fuzzy_sel->fuzzy_mask);
|
2000-12-29 00:19:55 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
fuzzy_sel->fuzzy_mask = new;
|
2000-12-29 00:19:55 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* calculate and allocate a new XSegment array which represents the boundary
|
|
|
|
* of the color-contiguous region
|
|
|
|
*/
|
2001-10-22 20:13:44 +08:00
|
|
|
pixel_region_init (&maskPR,
|
2006-04-07 17:21:18 +08:00
|
|
|
gimp_drawable_get_tiles (GIMP_DRAWABLE (fuzzy_sel->fuzzy_mask)),
|
2004-07-26 22:50:51 +08:00
|
|
|
0, 0,
|
|
|
|
gimp_item_width (GIMP_ITEM (fuzzy_sel->fuzzy_mask)),
|
|
|
|
gimp_item_height (GIMP_ITEM (fuzzy_sel->fuzzy_mask)),
|
|
|
|
FALSE);
|
2003-05-08 21:12:46 +08:00
|
|
|
|
2005-08-20 23:46:37 +08:00
|
|
|
bsegs = boundary_find (&maskPR, BOUNDARY_WITHIN_BOUNDS,
|
|
|
|
0, 0,
|
|
|
|
gimp_item_width (GIMP_ITEM (fuzzy_sel->fuzzy_mask)),
|
|
|
|
gimp_item_height (GIMP_ITEM (fuzzy_sel->fuzzy_mask)),
|
|
|
|
BOUNDARY_HALF_WAY,
|
|
|
|
num_segs);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
segs = g_new (GdkSegment, *num_segs);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
for (i = 0; i < *num_segs; i++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-06-27 06:16:59 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
bsegs[i].x1, bsegs[i].y1,
|
|
|
|
&x, &y,
|
2003-02-05 22:39:40 +08:00
|
|
|
! options->sample_merged);
|
2001-11-09 03:14:51 +08:00
|
|
|
segs[i].x1 = x;
|
|
|
|
segs[i].y1 = y;
|
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
bsegs[i].x2, bsegs[i].y2,
|
|
|
|
&x, &y,
|
2003-02-05 22:39:40 +08:00
|
|
|
! options->sample_merged);
|
2001-11-09 03:14:51 +08:00
|
|
|
segs[i].x2 = x;
|
|
|
|
segs[i].y2 = y;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (bsegs);
|
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
gimp_display_shell_unset_override_cursor (shell);
|
1999-01-11 07:36:29 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return segs;
|
|
|
|
}
|