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
|
|
|
* gimpbycolorselecttool.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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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"
|
|
|
|
|
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>
|
2000-03-08 04:00:07 +08:00
|
|
|
|
2001-01-24 20:21:50 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 20:21:50 +08:00
|
|
|
|
2001-05-10 16:10:25 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2020-08-02 02:37:48 +08:00
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontainer.h"
|
2001-11-28 11:08:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2020-08-02 02:37:48 +08:00
|
|
|
#include "core/gimpimage-new.h"
|
2006-07-31 19:42:51 +08:00
|
|
|
#include "core/gimpitem.h"
|
2004-07-14 07:04:05 +08:00
|
|
|
#include "core/gimppickable.h"
|
2014-05-31 15:52:44 +08:00
|
|
|
#include "core/gimppickable-contiguous-region.h"
|
2001-05-14 05:51:20 +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-05-10 16:10:25 +08:00
|
|
|
#include "gimpbycolorselecttool.h"
|
2008-03-09 23:05:54 +08:00
|
|
|
#include "gimpregionselectoptions.h"
|
2003-04-16 00:05:52 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2001-05-26 00:04:54 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2013-04-09 07:38:24 +08:00
|
|
|
static GeglBuffer * gimp_by_color_select_tool_get_mask (GimpRegionSelectTool *region_select,
|
|
|
|
GimpDisplay *display);
|
2001-10-22 20:13:44 +08:00
|
|
|
|
2006-07-29 04:04:06 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
G_DEFINE_TYPE (GimpByColorSelectTool, gimp_by_color_select_tool,
|
2006-07-31 19:42:51 +08:00
|
|
|
GIMP_TYPE_REGION_SELECT_TOOL)
|
2001-10-22 20:13:44 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
#define parent_class gimp_by_color_select_tool_parent_class
|
2001-05-10 16:10:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_by_color_select_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2001-05-10 16:10:25 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_BY_COLOR_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-by-color-select-tool",
|
2005-08-23 08:18:08 +08:00
|
|
|
_("Select by Color"),
|
2006-09-19 02:00:22 +08:00
|
|
|
_("Select by Color Tool: Select regions with similar colors"),
|
2004-05-05 09:17:23 +08:00
|
|
|
N_("_By Color Select"), "<shift>O",
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_BY_COLOR_SELECT,
|
2017-03-05 23:01:59 +08:00
|
|
|
GIMP_ICON_TOOL_BY_COLOR_SELECT,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2001-05-10 16:10:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_by_color_select_tool_class_init (GimpByColorSelectToolClass *klass)
|
|
|
|
{
|
2006-07-31 19:42:51 +08:00
|
|
|
GimpRegionSelectToolClass *region_class;
|
2006-06-14 07:47:20 +08:00
|
|
|
|
2006-07-31 19:42:51 +08:00
|
|
|
region_class = GIMP_REGION_SELECT_TOOL_CLASS (klass);
|
2001-05-10 16:10:25 +08:00
|
|
|
|
2008-05-23 22:09:55 +08:00
|
|
|
region_class->undo_desc = C_("command", "Select by Color");
|
2006-07-31 19:42:51 +08:00
|
|
|
region_class->get_mask = gimp_by_color_select_tool_get_mask;
|
2001-05-10 16:10:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_by_color_select_tool_init (GimpByColorSelectTool *by_color_select)
|
|
|
|
{
|
2006-06-02 04:30:52 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (by_color_select);
|
|
|
|
|
2006-06-03 23:41:40 +08:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_HAND);
|
2006-06-14 07:47:20 +08:00
|
|
|
}
|
|
|
|
|
2013-04-09 07:38:24 +08:00
|
|
|
static GeglBuffer *
|
2006-07-31 19:42:51 +08:00
|
|
|
gimp_by_color_select_tool_get_mask (GimpRegionSelectTool *region_select,
|
|
|
|
GimpDisplay *display)
|
2006-06-14 07:47:20 +08:00
|
|
|
{
|
2020-08-02 02:37:48 +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);
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpImage *select_image = NULL;
|
|
|
|
GList *drawables = gimp_image_get_selected_drawables (image);
|
2008-03-09 23:05:54 +08:00
|
|
|
GimpPickable *pickable;
|
2020-08-02 02:37:48 +08:00
|
|
|
GeglBuffer *mask = NULL;
|
2023-11-13 00:56:32 +08:00
|
|
|
GeglColor *color;
|
2008-03-09 23:05:54 +08:00
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +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
|
|
|
{
|
2020-08-02 02:37:48 +08:00
|
|
|
if (g_list_length (drawables) == 1)
|
|
|
|
{
|
|
|
|
gint off_x, off_y;
|
2001-11-09 03:14:51 +08:00
|
|
|
|
2020-08-02 02:37:48 +08:00
|
|
|
gimp_item_get_offset (drawables->data, &off_x, &off_y);
|
2001-11-09 03:14:51 +08:00
|
|
|
|
2020-08-02 02:37:48 +08:00
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2020-08-02 02:37:48 +08:00
|
|
|
pickable = GIMP_PICKABLE (drawables->data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
app: rework and fix the logic for copy-pasting multiple drawables.
There were a lot of incertainty of what should happen when we copy layers being
descendant of each other (i.e. when you select a group layer and some of its
children), then when you paste such data. So we sat down with Aryeom and tried
to come up with some consistent behavior which is somewhat expectable, but also
which would allow the most use-case.
Otherwise it was making very weird result when pasting the data, duplicating
some layers and whatnot, which was obviously a buggy behavior and never the
expected result.
We decided that if you select one leaf item, then even if you also selected a
parent item, it would be as though the parent was not selected. This is very
often what you expect anyway when you select a whole bunch of layers and would
work well if, say, you shift-click over many layers in sub-groups. Then you
wouldn't have to manually ctrl-click to unselect every group.
Then what if you were instead expecting to copy many groups? Then you could
shift-click the group arrow, closing all same-level groups. Once they are all
closed, you can shift-click the groups to only select group layers, not their
contents.
This way, both use cases are still quite doable easily with this default choice.
2022-11-13 01:28:58 +08:00
|
|
|
select_image = gimp_image_new_from_drawables (image->gimp, drawables, FALSE, FALSE);
|
2020-08-02 02:37:48 +08:00
|
|
|
gimp_container_remove (image->gimp->images, GIMP_OBJECT (select_image));
|
|
|
|
|
|
|
|
pickable = GIMP_PICKABLE (select_image);
|
|
|
|
gimp_pickable_flush (pickable);
|
|
|
|
}
|
2001-11-09 03:14:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-14 05:29:06 +08:00
|
|
|
pickable = GIMP_PICKABLE (image);
|
2001-11-09 03:14:51 +08:00
|
|
|
}
|
|
|
|
|
2020-08-02 02:37:48 +08:00
|
|
|
g_list_free (drawables);
|
2006-07-31 19:42:51 +08:00
|
|
|
gimp_pickable_flush (pickable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2023-11-13 00:56:32 +08:00
|
|
|
if ((color = gimp_pickable_get_color_at (pickable, x, y)) != NULL)
|
2016-07-20 00:00:39 +08:00
|
|
|
{
|
2020-08-02 02:37:48 +08:00
|
|
|
mask = gimp_pickable_contiguous_region_by_color (pickable,
|
2016-07-20 00:00:39 +08:00
|
|
|
sel_options->antialias,
|
|
|
|
options->threshold / 255.0,
|
|
|
|
options->select_transparent,
|
|
|
|
options->select_criterion,
|
2023-11-13 00:56:32 +08:00
|
|
|
color);
|
|
|
|
g_object_unref (color);
|
2016-07-20 00:00:39 +08:00
|
|
|
}
|
2011-04-04 06:01:30 +08:00
|
|
|
|
2020-08-02 02:37:48 +08:00
|
|
|
if (select_image)
|
|
|
|
g_object_unref (select_image);
|
|
|
|
|
|
|
|
return mask;
|
2006-06-14 07:47:20 +08:00
|
|
|
}
|