2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-09-02 23:07:40 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-09-02 23:07:40 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-09-02 23:07:40 +00: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-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-09-02 23:07:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2016-05-08 18:33:22 +02:00
|
|
|
#include <cairo.h>
|
2013-10-15 01:58:39 +02:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2003-09-02 23:07:40 +00:00
|
|
|
|
2016-05-08 18:33:22 +02:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2003-09-02 23:07:40 +00:00
|
|
|
#include "core-types.h"
|
|
|
|
|
2012-10-13 22:56:32 +02:00
|
|
|
#include "gegl/gimp-babl.h"
|
2012-10-22 16:03:40 +02:00
|
|
|
#include "gegl/gimp-gegl-apply-operation.h"
|
2018-05-24 10:21:21 -04:00
|
|
|
#include "gegl/gimp-gegl-loops.h"
|
2012-03-20 15:02:35 +01:00
|
|
|
|
2006-10-09 18:49:15 +00:00
|
|
|
#include "gimp.h"
|
2004-04-14 23:37:34 +00:00
|
|
|
#include "gimpcontext.h"
|
2018-04-18 23:44:34 +02:00
|
|
|
#include "gimpdrawable-edit.h"
|
2009-02-05 20:27:09 +00:00
|
|
|
#include "gimpdrawable-private.h"
|
2008-11-12 10:56:06 +00:00
|
|
|
#include "gimperror.h"
|
2003-09-02 23:07:40 +00:00
|
|
|
#include "gimpimage.h"
|
2020-05-17 23:00:07 +02:00
|
|
|
#include "gimpimage-new.h"
|
2003-09-02 23:07:40 +00:00
|
|
|
#include "gimpimage-undo.h"
|
|
|
|
#include "gimpimage-undo-push.h"
|
|
|
|
#include "gimplayer.h"
|
2015-06-17 13:21:01 +02:00
|
|
|
#include "gimplayer-new.h"
|
2003-10-06 12:17:11 +00:00
|
|
|
#include "gimplayermask.h"
|
2016-05-20 16:46:26 +02:00
|
|
|
#include "gimplayer-floating-selection.h"
|
2007-04-30 17:26:15 +00:00
|
|
|
#include "gimppickable.h"
|
2003-09-02 23:07:40 +00:00
|
|
|
#include "gimpselection.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2016-05-19 23:51:44 +02:00
|
|
|
static gboolean gimp_selection_is_attached (GimpItem *item);
|
2012-03-19 15:04:20 +01:00
|
|
|
static GimpItemTree * gimp_selection_get_tree (GimpItem *item);
|
|
|
|
static void gimp_selection_translate (GimpItem *item,
|
2018-04-23 01:08:54 +02:00
|
|
|
gdouble offset_x,
|
|
|
|
gdouble offset_y,
|
2012-03-19 15:04:20 +01:00
|
|
|
gboolean push_undo);
|
|
|
|
static void gimp_selection_scale (GimpItem *item,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint new_offset_x,
|
|
|
|
gint new_offset_y,
|
2004-02-09 00:09:20 +00:00
|
|
|
GimpInterpolationType interp_type,
|
2012-03-19 15:04:20 +01:00
|
|
|
GimpProgress *progress);
|
|
|
|
static void gimp_selection_resize (GimpItem *item,
|
|
|
|
GimpContext *context,
|
2016-10-10 00:02:16 +02:00
|
|
|
GimpFillType fill_type,
|
2012-03-19 15:04:20 +01:00
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y);
|
|
|
|
static void gimp_selection_flip (GimpItem *item,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis,
|
|
|
|
gboolean clip_result);
|
|
|
|
static void gimp_selection_rotate (GimpItem *item,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpRotationType rotation_type,
|
|
|
|
gdouble center_x,
|
|
|
|
gdouble center_y,
|
|
|
|
gboolean clip_result);
|
2016-03-14 19:02:18 +01:00
|
|
|
static gboolean gimp_selection_fill (GimpItem *item,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpFillOptions *fill_options,
|
|
|
|
gboolean push_undo,
|
|
|
|
GimpProgress *progress,
|
|
|
|
GError **error);
|
2012-03-19 15:04:20 +01:00
|
|
|
static gboolean gimp_selection_stroke (GimpItem *item,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpStrokeOptions *stroke_options,
|
|
|
|
gboolean push_undo,
|
|
|
|
GimpProgress *progress,
|
|
|
|
GError **error);
|
2012-10-13 22:56:32 +02:00
|
|
|
static void gimp_selection_convert_type (GimpDrawable *drawable,
|
|
|
|
GimpImage *dest_image,
|
|
|
|
const Babl *new_format,
|
2018-08-05 22:19:17 +02:00
|
|
|
GimpColorProfile *src_profile,
|
2016-04-29 00:42:42 +02:00
|
|
|
GimpColorProfile *dest_profile,
|
2016-11-07 20:41:39 +01:00
|
|
|
GeglDitherMethod layer_dither_type,
|
|
|
|
GeglDitherMethod mask_dither_type,
|
2015-10-21 22:22:30 +02:00
|
|
|
gboolean push_undo,
|
|
|
|
GimpProgress *progress);
|
2012-03-19 15:04:20 +01:00
|
|
|
static void gimp_selection_invalidate_boundary (GimpDrawable *drawable);
|
|
|
|
|
|
|
|
static gboolean gimp_selection_boundary (GimpChannel *channel,
|
|
|
|
const GimpBoundSeg **segs_in,
|
|
|
|
const GimpBoundSeg **segs_out,
|
|
|
|
gint *num_segs_in,
|
|
|
|
gint *num_segs_out,
|
|
|
|
gint x1,
|
|
|
|
gint y1,
|
|
|
|
gint x2,
|
|
|
|
gint y2);
|
|
|
|
static gboolean gimp_selection_is_empty (GimpChannel *channel);
|
|
|
|
static void gimp_selection_feather (GimpChannel *channel,
|
|
|
|
gdouble radius_x,
|
|
|
|
gdouble radius_y,
|
2019-06-16 17:06:08 +02:00
|
|
|
gboolean edge_lock,
|
2012-03-19 15:04:20 +01:00
|
|
|
gboolean push_undo);
|
|
|
|
static void gimp_selection_sharpen (GimpChannel *channel,
|
|
|
|
gboolean push_undo);
|
|
|
|
static void gimp_selection_clear (GimpChannel *channel,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
gboolean push_undo);
|
|
|
|
static void gimp_selection_all (GimpChannel *channel,
|
|
|
|
gboolean push_undo);
|
|
|
|
static void gimp_selection_invert (GimpChannel *channel,
|
|
|
|
gboolean push_undo);
|
|
|
|
static void gimp_selection_border (GimpChannel *channel,
|
|
|
|
gint radius_x,
|
|
|
|
gint radius_y,
|
2016-04-04 15:49:12 +00:00
|
|
|
GimpChannelBorderStyle style,
|
2012-03-19 15:04:20 +01:00
|
|
|
gboolean edge_lock,
|
|
|
|
gboolean push_undo);
|
|
|
|
static void gimp_selection_grow (GimpChannel *channel,
|
|
|
|
gint radius_x,
|
|
|
|
gint radius_y,
|
|
|
|
gboolean push_undo);
|
|
|
|
static void gimp_selection_shrink (GimpChannel *channel,
|
|
|
|
gint radius_x,
|
|
|
|
gint radius_y,
|
|
|
|
gboolean edge_lock,
|
|
|
|
gboolean push_undo);
|
2016-01-24 17:43:35 +00:00
|
|
|
static void gimp_selection_flood (GimpChannel *channel,
|
|
|
|
gboolean push_undo);
|
2003-09-02 23:07:40 +00:00
|
|
|
|
|
|
|
|
2006-05-15 09:46:31 +00:00
|
|
|
G_DEFINE_TYPE (GimpSelection, gimp_selection, GIMP_TYPE_CHANNEL)
|
2003-09-02 23:07:40 +00:00
|
|
|
|
2005-12-10 19:24:36 +00:00
|
|
|
#define parent_class gimp_selection_parent_class
|
2003-09-02 23:07:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_class_init (GimpSelectionClass *klass)
|
|
|
|
{
|
2004-03-16 16:23:06 +00:00
|
|
|
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
|
|
|
GimpItemClass *item_class = GIMP_ITEM_CLASS (klass);
|
|
|
|
GimpDrawableClass *drawable_class = GIMP_DRAWABLE_CLASS (klass);
|
|
|
|
GimpChannelClass *channel_class = GIMP_CHANNEL_CLASS (klass);
|
2003-09-02 23:07:40 +00:00
|
|
|
|
2014-05-07 01:01:56 +02:00
|
|
|
viewable_class->default_icon_name = "gimp-selection";
|
2025-07-16 17:22:11 +02:00
|
|
|
viewable_class->default_name = _("Selection Mask");
|
2003-11-18 12:13:46 +00:00
|
|
|
|
2004-01-26 16:18:16 +00:00
|
|
|
item_class->is_attached = gimp_selection_is_attached;
|
2010-02-06 16:17:23 +01:00
|
|
|
item_class->get_tree = gimp_selection_get_tree;
|
2003-09-04 11:33:06 +00:00
|
|
|
item_class->translate = gimp_selection_translate;
|
|
|
|
item_class->scale = gimp_selection_scale;
|
|
|
|
item_class->resize = gimp_selection_resize;
|
|
|
|
item_class->flip = gimp_selection_flip;
|
|
|
|
item_class->rotate = gimp_selection_rotate;
|
2016-03-14 19:02:18 +01:00
|
|
|
item_class->fill = gimp_selection_fill;
|
2003-09-04 11:33:06 +00:00
|
|
|
item_class->stroke = gimp_selection_stroke;
|
2010-06-08 14:24:11 +03:00
|
|
|
item_class->translate_desc = C_("undo-type", "Move Selection");
|
2016-03-14 19:02:18 +01:00
|
|
|
item_class->fill_desc = C_("undo-type", "Fill Selection");
|
2010-06-08 14:24:11 +03:00
|
|
|
item_class->stroke_desc = C_("undo-type", "Stroke Selection");
|
2003-09-04 11:33:06 +00:00
|
|
|
|
2012-10-13 22:56:32 +02:00
|
|
|
drawable_class->convert_type = gimp_selection_convert_type;
|
2003-09-04 11:33:06 +00:00
|
|
|
drawable_class->invalidate_boundary = gimp_selection_invalidate_boundary;
|
|
|
|
|
|
|
|
channel_class->boundary = gimp_selection_boundary;
|
|
|
|
channel_class->is_empty = gimp_selection_is_empty;
|
|
|
|
channel_class->feather = gimp_selection_feather;
|
|
|
|
channel_class->sharpen = gimp_selection_sharpen;
|
|
|
|
channel_class->clear = gimp_selection_clear;
|
|
|
|
channel_class->all = gimp_selection_all;
|
|
|
|
channel_class->invert = gimp_selection_invert;
|
|
|
|
channel_class->border = gimp_selection_border;
|
|
|
|
channel_class->grow = gimp_selection_grow;
|
|
|
|
channel_class->shrink = gimp_selection_shrink;
|
2016-01-24 17:43:35 +00:00
|
|
|
channel_class->flood = gimp_selection_flood;
|
2003-09-04 11:33:06 +00:00
|
|
|
|
2010-06-08 14:24:11 +03:00
|
|
|
channel_class->feather_desc = C_("undo-type", "Feather Selection");
|
|
|
|
channel_class->sharpen_desc = C_("undo-type", "Sharpen Selection");
|
|
|
|
channel_class->clear_desc = C_("undo-type", "Select None");
|
|
|
|
channel_class->all_desc = C_("undo-type", "Select All");
|
|
|
|
channel_class->invert_desc = C_("undo-type", "Invert Selection");
|
|
|
|
channel_class->border_desc = C_("undo-type", "Border Selection");
|
|
|
|
channel_class->grow_desc = C_("undo-type", "Grow Selection");
|
|
|
|
channel_class->shrink_desc = C_("undo-type", "Shrink Selection");
|
2016-02-03 19:25:02 +00:00
|
|
|
channel_class->flood_desc = C_("undo-type", "Remove Holes");
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_init (GimpSelection *selection)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-01-26 16:18:16 +00:00
|
|
|
static gboolean
|
2016-05-19 23:51:44 +02:00
|
|
|
gimp_selection_is_attached (GimpItem *item)
|
2004-01-26 16:18:16 +00:00
|
|
|
{
|
2008-12-28 00:09:33 +00:00
|
|
|
return (GIMP_IS_IMAGE (gimp_item_get_image (item)) &&
|
2009-08-29 19:47:52 +02:00
|
|
|
gimp_image_get_mask (gimp_item_get_image (item)) ==
|
|
|
|
GIMP_CHANNEL (item));
|
2004-01-26 16:18:16 +00:00
|
|
|
}
|
|
|
|
|
2010-02-06 16:17:23 +01:00
|
|
|
static GimpItemTree *
|
|
|
|
gimp_selection_get_tree (GimpItem *item)
|
2009-08-01 20:22:07 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-09-02 23:07:40 +00:00
|
|
|
static void
|
|
|
|
gimp_selection_translate (GimpItem *item,
|
2018-04-23 01:08:54 +02:00
|
|
|
gdouble offset_x,
|
|
|
|
gdouble offset_y,
|
2003-09-02 23:07:40 +00:00
|
|
|
gboolean push_undo)
|
|
|
|
{
|
2003-09-04 11:33:06 +00:00
|
|
|
GIMP_ITEM_CLASS (parent_class)->translate (item, offset_x, offset_y,
|
|
|
|
push_undo);
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
2003-09-03 10:19:47 +00:00
|
|
|
static void
|
|
|
|
gimp_selection_scale (GimpItem *item,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint new_offset_x,
|
|
|
|
gint new_offset_y,
|
2004-02-09 00:09:20 +00:00
|
|
|
GimpInterpolationType interp_type,
|
2004-08-10 18:47:21 +00:00
|
|
|
GimpProgress *progress)
|
2003-09-03 10:19:47 +00:00
|
|
|
{
|
|
|
|
GIMP_ITEM_CLASS (parent_class)->scale (item, new_width, new_height,
|
|
|
|
new_offset_x, new_offset_y,
|
2004-08-10 18:47:21 +00:00
|
|
|
interp_type, progress);
|
2003-09-03 10:19:47 +00:00
|
|
|
|
2008-11-03 21:17:50 +00:00
|
|
|
gimp_item_set_offset (item, 0, 0);
|
2003-09-03 10:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-10-10 00:02:16 +02:00
|
|
|
gimp_selection_resize (GimpItem *item,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpFillType fill_type,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
2003-09-03 10:19:47 +00:00
|
|
|
{
|
2016-10-10 00:02:16 +02:00
|
|
|
GIMP_ITEM_CLASS (parent_class)->resize (item, context, GIMP_FILL_TRANSPARENT,
|
|
|
|
new_width, new_height,
|
2008-11-03 21:17:50 +00:00
|
|
|
offset_x, offset_y);
|
2003-09-03 10:19:47 +00:00
|
|
|
|
2008-11-03 21:17:50 +00:00
|
|
|
gimp_item_set_offset (item, 0, 0);
|
2003-09-03 10:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_flip (GimpItem *item,
|
2004-04-14 23:37:34 +00:00
|
|
|
GimpContext *context,
|
2003-09-03 10:19:47 +00:00
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis,
|
|
|
|
gboolean clip_result)
|
|
|
|
{
|
2004-04-14 23:37:34 +00:00
|
|
|
GIMP_ITEM_CLASS (parent_class)->flip (item, context, flip_type, axis, TRUE);
|
2003-09-03 10:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-04-14 23:37:34 +00:00
|
|
|
gimp_selection_rotate (GimpItem *item,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpRotationType rotation_type,
|
|
|
|
gdouble center_x,
|
|
|
|
gdouble center_y,
|
|
|
|
gboolean clip_result)
|
2003-09-03 10:19:47 +00:00
|
|
|
{
|
2004-04-14 23:37:34 +00:00
|
|
|
GIMP_ITEM_CLASS (parent_class)->rotate (item, context, rotation_type,
|
2003-09-03 10:19:47 +00:00
|
|
|
center_x, center_y,
|
|
|
|
clip_result);
|
|
|
|
}
|
|
|
|
|
2016-03-14 19:02:18 +01:00
|
|
|
static gboolean
|
|
|
|
gimp_selection_fill (GimpItem *item,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpFillOptions *fill_options,
|
|
|
|
gboolean push_undo,
|
|
|
|
GimpProgress *progress,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GimpSelection *selection = GIMP_SELECTION (item);
|
|
|
|
const GimpBoundSeg *dummy_in;
|
|
|
|
const GimpBoundSeg *dummy_out;
|
|
|
|
gint num_dummy_in;
|
|
|
|
gint num_dummy_out;
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
if (! gimp_channel_boundary (GIMP_CHANNEL (selection),
|
|
|
|
&dummy_in, &dummy_out,
|
|
|
|
&num_dummy_in, &num_dummy_out,
|
|
|
|
0, 0, 0, 0))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2016-11-25 05:51:03 +01:00
|
|
|
_("There is no selection to fill."));
|
2016-03-14 19:02:18 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_selection_suspend (selection);
|
|
|
|
|
|
|
|
retval = GIMP_ITEM_CLASS (parent_class)->fill (item, drawable,
|
|
|
|
fill_options,
|
|
|
|
push_undo, progress, error);
|
|
|
|
|
|
|
|
gimp_selection_resume (selection);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2003-09-02 23:07:40 +00:00
|
|
|
static gboolean
|
2008-10-24 07:37:46 +00:00
|
|
|
gimp_selection_stroke (GimpItem *item,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpStrokeOptions *stroke_options,
|
2008-10-25 11:59:03 +00:00
|
|
|
gboolean push_undo,
|
2008-10-24 07:37:46 +00:00
|
|
|
GimpProgress *progress,
|
|
|
|
GError **error)
|
2003-09-02 23:07:40 +00:00
|
|
|
{
|
2012-03-19 15:04:20 +01:00
|
|
|
GimpSelection *selection = GIMP_SELECTION (item);
|
|
|
|
const GimpBoundSeg *dummy_in;
|
|
|
|
const GimpBoundSeg *dummy_out;
|
|
|
|
gint num_dummy_in;
|
|
|
|
gint num_dummy_out;
|
|
|
|
gboolean retval;
|
2003-09-02 23:07:40 +00:00
|
|
|
|
|
|
|
if (! gimp_channel_boundary (GIMP_CHANNEL (selection),
|
|
|
|
&dummy_in, &dummy_out,
|
|
|
|
&num_dummy_in, &num_dummy_out,
|
|
|
|
0, 0, 0, 0))
|
|
|
|
{
|
2008-11-12 10:56:06 +00:00
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2016-11-25 05:51:03 +01:00
|
|
|
_("There is no selection to stroke."));
|
2003-09-02 23:07:40 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-03-07 21:39:41 +01:00
|
|
|
gimp_selection_suspend (selection);
|
2003-09-02 23:07:40 +00:00
|
|
|
|
2008-10-24 07:37:46 +00:00
|
|
|
retval = GIMP_ITEM_CLASS (parent_class)->stroke (item, drawable,
|
|
|
|
stroke_options,
|
2008-10-25 11:59:03 +00:00
|
|
|
push_undo, progress, error);
|
2003-09-02 23:07:40 +00:00
|
|
|
|
2016-03-07 21:39:41 +01:00
|
|
|
gimp_selection_resume (selection);
|
2003-09-02 23:07:40 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2012-10-13 22:56:32 +02:00
|
|
|
static void
|
|
|
|
gimp_selection_convert_type (GimpDrawable *drawable,
|
|
|
|
GimpImage *dest_image,
|
|
|
|
const Babl *new_format,
|
2018-08-05 22:19:17 +02:00
|
|
|
GimpColorProfile *src_profile,
|
2016-04-29 00:42:42 +02:00
|
|
|
GimpColorProfile *dest_profile,
|
2016-11-07 20:41:39 +01:00
|
|
|
GeglDitherMethod layer_dither_type,
|
|
|
|
GeglDitherMethod mask_dither_type,
|
2015-10-21 22:22:30 +02:00
|
|
|
gboolean push_undo,
|
|
|
|
GimpProgress *progress)
|
2012-10-13 22:56:32 +02:00
|
|
|
{
|
2016-10-04 01:39:15 +02:00
|
|
|
new_format =
|
|
|
|
gimp_babl_mask_format (gimp_babl_format_get_precision (new_format));
|
2012-10-13 22:56:32 +02:00
|
|
|
|
|
|
|
GIMP_DRAWABLE_CLASS (parent_class)->convert_type (drawable, dest_image,
|
|
|
|
new_format,
|
2018-08-05 22:19:17 +02:00
|
|
|
src_profile,
|
2016-04-29 00:42:42 +02:00
|
|
|
dest_profile,
|
2012-10-13 22:56:32 +02:00
|
|
|
layer_dither_type,
|
|
|
|
mask_dither_type,
|
2015-10-21 22:22:30 +02:00
|
|
|
push_undo,
|
|
|
|
progress);
|
2012-10-13 22:56:32 +02:00
|
|
|
}
|
|
|
|
|
2003-09-04 11:33:06 +00:00
|
|
|
static void
|
|
|
|
gimp_selection_invalidate_boundary (GimpDrawable *drawable)
|
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
|
2020-05-06 18:37:41 +02:00
|
|
|
GList *layers;
|
2003-09-04 11:33:06 +00:00
|
|
|
|
|
|
|
/* Turn the current selection off */
|
2010-10-09 20:23:05 +02:00
|
|
|
gimp_image_selection_invalidate (image);
|
2003-09-04 11:33:06 +00:00
|
|
|
|
|
|
|
GIMP_DRAWABLE_CLASS (parent_class)->invalidate_boundary (drawable);
|
|
|
|
|
|
|
|
/* If there is a floating selection, update it's area...
|
|
|
|
* we need to do this since this selection mask can act as an additional
|
|
|
|
* mask in the composition of the floating selection
|
|
|
|
*/
|
2020-05-06 18:37:41 +02:00
|
|
|
layers = gimp_image_get_selected_layers (image);
|
2003-09-04 11:33:06 +00:00
|
|
|
|
2020-05-06 18:37:41 +02:00
|
|
|
if (g_list_length (layers) == 1 && gimp_layer_is_floating_sel (layers->data))
|
2017-01-13 02:14:40 +01:00
|
|
|
{
|
2020-05-06 18:37:41 +02:00
|
|
|
gimp_drawable_update (GIMP_DRAWABLE (layers->data), 0, 0, -1, -1);
|
2017-01-13 02:14:40 +01:00
|
|
|
}
|
2003-09-04 11:33:06 +00:00
|
|
|
|
2012-06-20 21:44:09 +02:00
|
|
|
#if 0
|
2003-09-04 11:33:06 +00:00
|
|
|
/* invalidate the preview */
|
2009-02-05 20:27:09 +00:00
|
|
|
drawable->private->preview_valid = FALSE;
|
2012-06-20 21:44:09 +02:00
|
|
|
#endif
|
2003-09-04 11:33:06 +00:00
|
|
|
}
|
|
|
|
|
2003-09-02 23:07:40 +00:00
|
|
|
static gboolean
|
2012-03-19 15:04:20 +01:00
|
|
|
gimp_selection_boundary (GimpChannel *channel,
|
|
|
|
const GimpBoundSeg **segs_in,
|
|
|
|
const GimpBoundSeg **segs_out,
|
|
|
|
gint *num_segs_in,
|
|
|
|
gint *num_segs_out,
|
|
|
|
gint unused1,
|
|
|
|
gint unused2,
|
|
|
|
gint unused3,
|
|
|
|
gint unused4)
|
2003-09-02 23:07:40 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image = gimp_item_get_image (GIMP_ITEM (channel));
|
2020-05-06 18:37:41 +02:00
|
|
|
GimpLayer *floating_selection;
|
|
|
|
GList *drawables;
|
|
|
|
GList *layers;
|
|
|
|
gboolean channel_selected;
|
2003-09-02 23:07:40 +00:00
|
|
|
|
2020-05-06 18:37:41 +02:00
|
|
|
drawables = gimp_image_get_selected_drawables (image);
|
|
|
|
channel_selected = (drawables && GIMP_IS_CHANNEL (drawables->data));
|
|
|
|
g_list_free (drawables);
|
|
|
|
|
|
|
|
if ((floating_selection = gimp_image_get_floating_selection (image)))
|
2003-09-02 23:07:40 +00:00
|
|
|
{
|
|
|
|
/* If there is a floating selection, then
|
|
|
|
* we need to do some slightly different boundaries.
|
|
|
|
* Instead of inside and outside boundaries being defined
|
|
|
|
* by the extents of the layer, the inside boundary (the one
|
|
|
|
* that actually marches and is black/white) is the boundary of
|
|
|
|
* the floating selection. The outside boundary (doesn't move,
|
|
|
|
* is black/gray) is defined as the normal selection mask
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Find the selection mask boundary */
|
|
|
|
GIMP_CHANNEL_CLASS (parent_class)->boundary (channel,
|
|
|
|
segs_in, segs_out,
|
|
|
|
num_segs_in, num_segs_out,
|
|
|
|
0, 0, 0, 0);
|
|
|
|
|
|
|
|
/* Find the floating selection boundary */
|
2020-05-06 18:37:41 +02:00
|
|
|
*segs_in = floating_sel_boundary (floating_selection, num_segs_in);
|
2003-09-02 23:07:40 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-05-06 18:37:41 +02:00
|
|
|
else if (channel_selected)
|
2003-09-02 23:07:40 +00:00
|
|
|
{
|
2020-05-06 18:37:41 +02:00
|
|
|
/* Otherwise, return the boundary...if a channels are selected */
|
2003-09-02 23:07:40 +00:00
|
|
|
|
|
|
|
return GIMP_CHANNEL_CLASS (parent_class)->boundary (channel,
|
|
|
|
segs_in, segs_out,
|
|
|
|
num_segs_in,
|
|
|
|
num_segs_out,
|
|
|
|
0, 0,
|
2007-12-25 16:21:40 +00:00
|
|
|
gimp_image_get_width (image),
|
|
|
|
gimp_image_get_height (image));
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
2020-05-06 18:37:41 +02:00
|
|
|
else if ((layers = gimp_image_get_selected_layers (image)))
|
2003-09-02 23:07:40 +00:00
|
|
|
{
|
2020-05-06 18:37:41 +02:00
|
|
|
/* If layers are selected, we return multiple boundaries based
|
2003-09-02 23:07:40 +00:00
|
|
|
* on the extents
|
|
|
|
*/
|
2020-05-06 18:37:41 +02:00
|
|
|
GList *iter;
|
|
|
|
gint x1, y1;
|
|
|
|
gint x2 = G_MININT;
|
|
|
|
gint y2 = G_MININT;
|
|
|
|
gint offset_x = G_MAXINT;
|
|
|
|
gint offset_y = G_MAXINT;
|
|
|
|
|
|
|
|
for (iter = layers; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
gint item_off_x, item_off_y;
|
|
|
|
gint item_x2, item_y2;
|
|
|
|
|
|
|
|
gimp_item_get_offset (iter->data, &item_off_x, &item_off_y);
|
|
|
|
offset_x = MIN (offset_x, item_off_x);
|
|
|
|
offset_y = MIN (offset_y, item_off_y);
|
|
|
|
|
|
|
|
item_x2 = item_off_x + gimp_item_get_width (GIMP_ITEM (iter->data));
|
|
|
|
item_y2 = item_off_y + gimp_item_get_height (GIMP_ITEM (iter->data));
|
|
|
|
x2 = MAX (x2, item_x2);
|
|
|
|
y2 = MAX (y2, item_y2);
|
|
|
|
}
|
2003-09-02 23:07:40 +00:00
|
|
|
|
2008-11-03 21:17:50 +00:00
|
|
|
x1 = CLAMP (offset_x, 0, gimp_image_get_width (image));
|
|
|
|
y1 = CLAMP (offset_y, 0, gimp_image_get_height (image));
|
2020-05-06 18:37:41 +02:00
|
|
|
x2 = CLAMP (x2, 0, gimp_image_get_width (image));
|
|
|
|
y2 = CLAMP (y2, 0, gimp_image_get_height (image));
|
2003-09-02 23:07:40 +00:00
|
|
|
|
|
|
|
return GIMP_CHANNEL_CLASS (parent_class)->boundary (channel,
|
|
|
|
segs_in, segs_out,
|
|
|
|
num_segs_in,
|
|
|
|
num_segs_out,
|
|
|
|
x1, y1, x2, y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
*segs_in = NULL;
|
|
|
|
*segs_out = NULL;
|
|
|
|
*num_segs_in = 0;
|
|
|
|
*num_segs_out = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_selection_is_empty (GimpChannel *channel)
|
|
|
|
{
|
|
|
|
GimpSelection *selection = GIMP_SELECTION (channel);
|
|
|
|
|
|
|
|
/* in order to allow stroking of selections, we need to pretend here
|
|
|
|
* that the selection mask is empty so that it doesn't mask the paint
|
|
|
|
* during the stroke operation.
|
|
|
|
*/
|
2016-03-07 21:39:41 +01:00
|
|
|
if (selection->suspend_count > 0)
|
2003-09-02 23:07:40 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return GIMP_CHANNEL_CLASS (parent_class)->is_empty (channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_feather (GimpChannel *channel,
|
|
|
|
gdouble radius_x,
|
|
|
|
gdouble radius_y,
|
2019-06-16 17:06:08 +02:00
|
|
|
gboolean edge_lock,
|
2003-09-02 23:07:40 +00:00
|
|
|
gboolean push_undo)
|
|
|
|
{
|
|
|
|
GIMP_CHANNEL_CLASS (parent_class)->feather (channel, radius_x, radius_y,
|
2019-06-16 17:06:08 +02:00
|
|
|
edge_lock, push_undo);
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_sharpen (GimpChannel *channel,
|
|
|
|
gboolean push_undo)
|
|
|
|
{
|
2003-09-04 11:33:06 +00:00
|
|
|
GIMP_CHANNEL_CLASS (parent_class)->sharpen (channel, push_undo);
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_clear (GimpChannel *channel,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
gboolean push_undo)
|
|
|
|
{
|
2003-09-04 11:33:06 +00:00
|
|
|
GIMP_CHANNEL_CLASS (parent_class)->clear (channel, undo_desc, push_undo);
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_all (GimpChannel *channel,
|
|
|
|
gboolean push_undo)
|
|
|
|
{
|
2003-09-04 11:33:06 +00:00
|
|
|
GIMP_CHANNEL_CLASS (parent_class)->all (channel, push_undo);
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_invert (GimpChannel *channel,
|
|
|
|
gboolean push_undo)
|
|
|
|
{
|
2003-09-04 11:33:06 +00:00
|
|
|
GIMP_CHANNEL_CLASS (parent_class)->invert (channel, push_undo);
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-04-04 15:49:12 +00:00
|
|
|
gimp_selection_border (GimpChannel *channel,
|
|
|
|
gint radius_x,
|
|
|
|
gint radius_y,
|
|
|
|
GimpChannelBorderStyle style,
|
|
|
|
gboolean edge_lock,
|
|
|
|
gboolean push_undo)
|
2003-09-02 23:07:40 +00:00
|
|
|
{
|
2006-06-05 20:19:12 +00:00
|
|
|
GIMP_CHANNEL_CLASS (parent_class)->border (channel,
|
2007-03-05 20:21:23 +00:00
|
|
|
radius_x, radius_y,
|
2016-04-04 15:49:12 +00:00
|
|
|
style, edge_lock,
|
2007-03-05 20:21:23 +00:00
|
|
|
push_undo);
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_grow (GimpChannel *channel,
|
|
|
|
gint radius_x,
|
|
|
|
gint radius_y,
|
|
|
|
gboolean push_undo)
|
|
|
|
{
|
2006-06-05 20:19:12 +00:00
|
|
|
GIMP_CHANNEL_CLASS (parent_class)->grow (channel,
|
2016-11-25 05:51:03 +01:00
|
|
|
radius_x, radius_y,
|
2003-09-04 11:33:06 +00:00
|
|
|
push_undo);
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_selection_shrink (GimpChannel *channel,
|
|
|
|
gint radius_x,
|
|
|
|
gint radius_y,
|
|
|
|
gboolean edge_lock,
|
|
|
|
gboolean push_undo)
|
|
|
|
{
|
2006-06-05 20:19:12 +00:00
|
|
|
GIMP_CHANNEL_CLASS (parent_class)->shrink (channel,
|
2016-11-25 05:51:03 +01:00
|
|
|
radius_x, radius_y, edge_lock,
|
|
|
|
push_undo);
|
2003-09-02 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
2016-01-24 17:43:35 +00:00
|
|
|
static void
|
|
|
|
gimp_selection_flood (GimpChannel *channel,
|
|
|
|
gboolean push_undo)
|
|
|
|
{
|
|
|
|
GIMP_CHANNEL_CLASS (parent_class)->flood (channel, push_undo);
|
|
|
|
}
|
|
|
|
|
2003-09-02 23:07:40 +00:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GimpChannel *
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_selection_new (GimpImage *image,
|
2003-09-02 23:07:40 +00:00
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2023-11-20 00:20:03 +01:00
|
|
|
GeglColor *black = gegl_color_new ("black");
|
2003-09-02 23:07:40 +00:00
|
|
|
GimpChannel *channel;
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2011-02-01 12:47:24 +01:00
|
|
|
g_return_val_if_fail (width > 0 && height > 0, NULL);
|
2003-09-02 23:07:40 +00:00
|
|
|
|
2023-11-20 00:20:03 +01:00
|
|
|
gimp_color_set_alpha (black, 0.5);
|
2011-02-01 12:47:24 +01:00
|
|
|
channel = GIMP_CHANNEL (gimp_drawable_new (GIMP_TYPE_SELECTION,
|
|
|
|
image, NULL,
|
|
|
|
0, 0, width, height,
|
2012-04-07 22:45:25 +02:00
|
|
|
gimp_image_get_mask_format (image)));
|
2003-09-02 23:07:40 +00:00
|
|
|
|
2023-11-20 00:20:03 +01:00
|
|
|
gimp_channel_set_color (channel, black, FALSE);
|
2007-12-23 16:58:41 +00:00
|
|
|
gimp_channel_set_show_masked (channel, TRUE);
|
|
|
|
|
|
|
|
channel->x2 = width;
|
|
|
|
channel->y2 = height;
|
2003-09-02 23:07:40 +00:00
|
|
|
|
2023-11-20 00:20:03 +01:00
|
|
|
g_object_unref (black);
|
|
|
|
|
2003-09-02 23:07:40 +00:00
|
|
|
return channel;
|
|
|
|
}
|
2003-09-04 20:18:08 +00:00
|
|
|
|
2008-10-29 19:55:58 +00:00
|
|
|
gint
|
2016-03-07 21:39:41 +01:00
|
|
|
gimp_selection_suspend (GimpSelection *selection)
|
2008-10-29 19:55:58 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SELECTION (selection), 0);
|
|
|
|
|
2016-03-07 21:39:41 +01:00
|
|
|
selection->suspend_count++;
|
2008-10-29 19:55:58 +00:00
|
|
|
|
2016-03-07 21:39:41 +01:00
|
|
|
return selection->suspend_count;
|
2008-10-29 19:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
2016-03-07 21:39:41 +01:00
|
|
|
gimp_selection_resume (GimpSelection *selection)
|
2008-10-29 19:55:58 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SELECTION (selection), 0);
|
2016-03-07 21:39:41 +01:00
|
|
|
g_return_val_if_fail (selection->suspend_count > 0, 0);
|
2008-10-29 19:55:58 +00:00
|
|
|
|
2016-03-07 21:39:41 +01:00
|
|
|
selection->suspend_count--;
|
2008-10-29 19:55:58 +00:00
|
|
|
|
2016-03-07 21:39:41 +01:00
|
|
|
return selection->suspend_count;
|
2008-10-29 19:55:58 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 14:27:07 +01:00
|
|
|
GeglBuffer *
|
2008-11-22 22:07:55 +00:00
|
|
|
gimp_selection_extract (GimpSelection *selection,
|
2020-05-26 16:15:15 +02:00
|
|
|
GList *pickables,
|
2008-11-22 22:07:55 +00:00
|
|
|
GimpContext *context,
|
|
|
|
gboolean cut_image,
|
|
|
|
gboolean keep_indexed,
|
|
|
|
gboolean add_alpha,
|
2011-03-26 08:30:15 +01:00
|
|
|
gint *offset_x,
|
|
|
|
gint *offset_y,
|
2008-11-22 22:07:55 +00:00
|
|
|
GError **error)
|
2003-10-06 12:17:11 +00:00
|
|
|
{
|
2020-05-26 16:15:15 +02:00
|
|
|
GimpImage *image = NULL;
|
|
|
|
GimpImage *temp_image = NULL;
|
|
|
|
GimpPickable *pickable = NULL;
|
|
|
|
GeglBuffer *src_buffer;
|
|
|
|
GeglBuffer *dest_buffer;
|
|
|
|
GList *iter;
|
|
|
|
const Babl *src_format;
|
|
|
|
const Babl *dest_format;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gboolean non_empty;
|
|
|
|
gint off_x, off_y;
|
2003-10-06 12:17:11 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_SELECTION (selection), NULL);
|
2004-04-14 23:37:34 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-07 18:16:28 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2020-05-26 16:15:15 +02:00
|
|
|
g_return_val_if_fail (pickables != NULL, NULL);
|
2003-10-06 12:17:11 +00:00
|
|
|
|
2020-05-26 16:15:15 +02:00
|
|
|
for (iter = pickables; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PICKABLE (iter->data), NULL);
|
|
|
|
|
|
|
|
if (GIMP_IS_ITEM (iter->data))
|
|
|
|
g_return_val_if_fail (gimp_item_is_attached (iter->data), NULL);
|
|
|
|
|
|
|
|
if (! image)
|
|
|
|
image = gimp_pickable_get_image (iter->data);
|
|
|
|
else
|
|
|
|
g_return_val_if_fail (image == gimp_pickable_get_image (iter->data), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_list_length (pickables) == 1)
|
|
|
|
{
|
|
|
|
pickable = pickables->data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (iter = pickables; iter; iter = iter->next)
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (iter->data), NULL);
|
|
|
|
|
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-12 18:28:58 +01:00
|
|
|
temp_image = gimp_image_new_from_drawables (image->gimp, pickables, TRUE, FALSE);
|
2020-05-26 16:15:15 +02:00
|
|
|
selection = GIMP_SELECTION (gimp_image_get_mask (temp_image));
|
|
|
|
|
|
|
|
pickable = GIMP_PICKABLE (temp_image);
|
|
|
|
|
|
|
|
/* Don't cut from the temporary image. */
|
|
|
|
cut_image = FALSE;
|
|
|
|
}
|
2003-10-06 12:17:11 +00:00
|
|
|
|
|
|
|
/* If there are no bounds, then just extract the entire image
|
|
|
|
* This may not be the correct behavior, but after getting rid
|
|
|
|
* of floating selections, it's still tempting to "cut" or "copy"
|
|
|
|
* a small layer and expect it to work, even though there is no
|
|
|
|
* actual selection mask
|
|
|
|
*/
|
2007-04-30 17:26:15 +00:00
|
|
|
if (GIMP_IS_DRAWABLE (pickable))
|
2015-07-02 03:04:39 +02:00
|
|
|
{
|
|
|
|
non_empty = gimp_item_mask_bounds (GIMP_ITEM (pickable),
|
|
|
|
&x1, &y1, &x2, &y2);
|
2016-09-17 15:32:22 +02:00
|
|
|
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (pickable), &off_x, &off_y);
|
2015-07-02 03:04:39 +02:00
|
|
|
}
|
2007-04-30 17:26:15 +00:00
|
|
|
else
|
2015-07-02 03:04:39 +02:00
|
|
|
{
|
|
|
|
non_empty = gimp_item_bounds (GIMP_ITEM (selection),
|
|
|
|
&x1, &y1, &x2, &y2);
|
|
|
|
x2 += x1;
|
|
|
|
y2 += y1;
|
2016-09-17 15:32:22 +02:00
|
|
|
|
|
|
|
off_x = 0;
|
|
|
|
off_y = 0;
|
|
|
|
|
|
|
|
/* can't cut from non-drawables, fall back to copy */
|
|
|
|
cut_image = FALSE;
|
2015-07-02 03:04:39 +02:00
|
|
|
}
|
2007-04-30 17:26:15 +00:00
|
|
|
|
2004-10-19 22:52:04 +00:00
|
|
|
if (non_empty && ((x1 == x2) || (y1 == y2)))
|
2003-10-06 12:17:11 +00:00
|
|
|
{
|
2008-11-12 10:56:06 +00:00
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2016-11-25 05:51:03 +01:00
|
|
|
_("Unable to cut or copy because the "
|
|
|
|
"selected region is empty."));
|
2020-05-26 16:15:15 +02:00
|
|
|
|
|
|
|
if (temp_image)
|
|
|
|
g_object_unref (temp_image);
|
|
|
|
|
2003-10-06 12:17:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-10 14:45:11 +00:00
|
|
|
/* If there is a selection, we must add alpha because the selection
|
|
|
|
* could have any shape.
|
|
|
|
*/
|
|
|
|
if (non_empty)
|
|
|
|
add_alpha = TRUE;
|
|
|
|
|
2012-03-28 22:57:39 +02:00
|
|
|
src_format = gimp_pickable_get_format (pickable);
|
|
|
|
|
2003-10-06 12:17:11 +00:00
|
|
|
/* How many bytes in the temp buffer? */
|
2012-03-28 22:57:39 +02:00
|
|
|
if (babl_format_is_palette (src_format) && ! keep_indexed)
|
2003-10-06 12:17:11 +00:00
|
|
|
{
|
2012-04-21 08:35:52 +02:00
|
|
|
dest_format = gimp_image_get_format (image, GIMP_RGB,
|
2012-05-07 21:46:47 +02:00
|
|
|
gimp_image_get_precision (image),
|
2012-04-21 08:35:52 +02:00
|
|
|
add_alpha ||
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 14:23:01 +02:00
|
|
|
babl_format_has_alpha (src_format),
|
|
|
|
babl_format_get_space (src_format));
|
2012-03-28 22:57:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (add_alpha)
|
|
|
|
dest_format = gimp_pickable_get_format_with_alpha (pickable);
|
2003-10-06 12:17:11 +00:00
|
|
|
else
|
2012-03-28 22:57:39 +02:00
|
|
|
dest_format = src_format;
|
2003-10-06 12:17:11 +00:00
|
|
|
}
|
|
|
|
|
2007-04-30 17:26:15 +00:00
|
|
|
gimp_pickable_flush (pickable);
|
2003-10-06 12:17:11 +00:00
|
|
|
|
2012-03-20 15:02:35 +01:00
|
|
|
src_buffer = gimp_pickable_get_buffer (pickable);
|
|
|
|
|
2003-10-06 12:17:11 +00:00
|
|
|
/* Allocate the temp buffer */
|
2012-06-20 21:44:09 +02:00
|
|
|
dest_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, x2 - x1, y2 - y1),
|
|
|
|
dest_format);
|
2012-03-20 15:02:35 +01:00
|
|
|
|
|
|
|
/* First, copy the pixels, possibly doing INDEXED->RGB and adding alpha */
|
2018-05-24 10:21:21 -04:00
|
|
|
gimp_gegl_buffer_copy (src_buffer, GEGL_RECTANGLE (x1, y1, x2 - x1, y2 - y1),
|
|
|
|
GEGL_ABYSS_NONE,
|
|
|
|
dest_buffer, GEGL_RECTANGLE (0, 0, 0, 0));
|
2012-03-20 15:02:35 +01:00
|
|
|
|
|
|
|
if (non_empty)
|
2003-10-06 12:17:11 +00:00
|
|
|
{
|
2012-03-20 15:02:35 +01:00
|
|
|
/* If there is a selection, mask the dest_buffer with it */
|
2007-04-30 17:26:15 +00:00
|
|
|
|
2012-03-20 15:02:35 +01:00
|
|
|
GeglBuffer *mask_buffer;
|
2003-10-06 12:17:11 +00:00
|
|
|
|
2012-03-21 00:42:44 +01:00
|
|
|
mask_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (selection));
|
2003-10-06 12:17:11 +00:00
|
|
|
|
2012-10-31 23:47:45 +01:00
|
|
|
gimp_gegl_apply_opacity (dest_buffer, NULL, NULL, dest_buffer,
|
|
|
|
mask_buffer,
|
|
|
|
- (off_x + x1),
|
|
|
|
- (off_y + y1),
|
|
|
|
1.0);
|
2012-03-20 15:02:35 +01:00
|
|
|
|
2016-09-17 15:32:22 +02:00
|
|
|
if (cut_image)
|
2006-04-12 12:49:29 +00:00
|
|
|
{
|
2018-04-18 23:44:34 +02:00
|
|
|
gimp_drawable_edit_clear (GIMP_DRAWABLE (pickable), context);
|
2006-04-12 12:49:29 +00:00
|
|
|
}
|
2003-10-06 12:17:11 +00:00
|
|
|
}
|
2016-09-17 15:32:22 +02:00
|
|
|
else if (cut_image)
|
2003-10-06 12:17:11 +00:00
|
|
|
{
|
2012-03-20 15:02:35 +01:00
|
|
|
/* If we're cutting without selection, remove either the layer
|
|
|
|
* (or floating selection), the layer mask, or the channel
|
2003-10-06 12:17:11 +00:00
|
|
|
*/
|
2016-09-17 15:32:22 +02:00
|
|
|
if (GIMP_IS_LAYER (pickable))
|
|
|
|
{
|
|
|
|
gimp_image_remove_layer (image, GIMP_LAYER (pickable),
|
|
|
|
TRUE, NULL);
|
|
|
|
}
|
|
|
|
else if (GIMP_IS_LAYER_MASK (pickable))
|
|
|
|
{
|
|
|
|
gimp_layer_apply_mask (gimp_layer_mask_get_layer (GIMP_LAYER_MASK (pickable)),
|
|
|
|
GIMP_MASK_DISCARD, TRUE);
|
|
|
|
}
|
|
|
|
else if (GIMP_IS_CHANNEL (pickable))
|
2006-04-12 12:49:29 +00:00
|
|
|
{
|
2016-09-17 15:32:22 +02:00
|
|
|
gimp_image_remove_channel (image, GIMP_CHANNEL (pickable),
|
|
|
|
TRUE, NULL);
|
2006-04-12 12:49:29 +00:00
|
|
|
}
|
2003-10-06 12:17:11 +00:00
|
|
|
}
|
|
|
|
|
2011-03-26 08:30:15 +01:00
|
|
|
*offset_x = x1 + off_x;
|
|
|
|
*offset_y = y1 + off_y;
|
|
|
|
|
2020-05-26 16:15:15 +02:00
|
|
|
if (temp_image)
|
|
|
|
g_object_unref (temp_image);
|
|
|
|
|
2012-03-21 14:43:38 +01:00
|
|
|
return dest_buffer;
|
2003-10-06 12:17:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpLayer *
|
2008-11-22 22:07:55 +00:00
|
|
|
gimp_selection_float (GimpSelection *selection,
|
2020-05-17 23:00:07 +02:00
|
|
|
GList *drawables,
|
2007-12-07 18:16:28 +00:00
|
|
|
GimpContext *context,
|
|
|
|
gboolean cut_image,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y,
|
|
|
|
GError **error)
|
2003-10-06 12:17:11 +00:00
|
|
|
{
|
2016-05-08 18:33:22 +02:00
|
|
|
GimpImage *image;
|
|
|
|
GimpLayer *layer;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
GimpColorProfile *profile;
|
2020-05-17 23:00:07 +02:00
|
|
|
GimpImage *temp_image = NULL;
|
|
|
|
const Babl *format = NULL;
|
|
|
|
GList *iter;
|
2016-05-08 18:33:22 +02:00
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
2003-10-06 12:17:11 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_SELECTION (selection), NULL);
|
2004-11-16 13:41:55 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-07 18:16:28 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2003-10-06 12:17:11 +00:00
|
|
|
|
2020-05-17 23:00:07 +02:00
|
|
|
for (iter = drawables; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (iter->data), NULL);
|
|
|
|
g_return_val_if_fail (gimp_item_is_attached (iter->data), NULL);
|
|
|
|
|
|
|
|
if (! format)
|
|
|
|
format = gimp_drawable_get_format_with_alpha (iter->data);
|
|
|
|
else
|
|
|
|
g_return_val_if_fail (format == gimp_drawable_get_format_with_alpha (iter->data),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
image = gimp_item_get_image (GIMP_ITEM (selection));
|
2003-10-06 12:17:11 +00:00
|
|
|
|
|
|
|
/* Make sure there is a region to float... */
|
2020-05-17 23:00:07 +02:00
|
|
|
for (iter = drawables; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
if (gimp_item_mask_bounds (iter->data, &x1, &y1, &x2, &y2) &&
|
|
|
|
x1 != x2 && y1 != y2)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (iter == NULL)
|
2007-12-07 18:16:28 +00:00
|
|
|
{
|
2008-11-12 10:56:06 +00:00
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2016-11-25 05:51:03 +01:00
|
|
|
_("Cannot float selection because the selected "
|
|
|
|
"region is empty."));
|
2007-12-07 18:16:28 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-10-06 12:17:11 +00:00
|
|
|
|
|
|
|
/* Start an undo group */
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_FS_FLOAT,
|
2010-06-08 14:24:11 +03:00
|
|
|
C_("undo-type", "Float Selection"));
|
2003-10-06 12:17:11 +00:00
|
|
|
|
|
|
|
/* Cut or copy the selected region */
|
2020-05-26 16:15:15 +02:00
|
|
|
buffer = gimp_selection_extract (selection, drawables, context,
|
2012-03-21 14:43:38 +01:00
|
|
|
cut_image, FALSE, TRUE,
|
|
|
|
&x1, &y1, NULL);
|
2003-10-06 12:17:11 +00:00
|
|
|
|
2020-05-26 16:15:15 +02:00
|
|
|
profile = gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (drawables->data));
|
2016-05-08 18:33:22 +02:00
|
|
|
|
2008-04-04 14:31:06 +00:00
|
|
|
/* Clear the selection */
|
2008-11-22 22:07:55 +00:00
|
|
|
gimp_channel_clear (GIMP_CHANNEL (selection), NULL, TRUE);
|
2003-10-06 12:17:11 +00:00
|
|
|
|
2020-05-17 23:00:07 +02:00
|
|
|
/* Create a new layer from the buffer, using the drawables' type
|
2003-10-06 12:17:11 +00:00
|
|
|
* because it may be different from the image's type if we cut from
|
|
|
|
* a channel or layer mask
|
|
|
|
*/
|
2020-05-17 23:00:07 +02:00
|
|
|
layer = gimp_layer_new_from_gegl_buffer (buffer, image, format,
|
2015-06-20 00:02:11 +02:00
|
|
|
_("Floated Layer"),
|
|
|
|
GIMP_OPACITY_OPAQUE,
|
2017-08-21 20:04:25 +02:00
|
|
|
gimp_image_get_default_new_layer_mode (image),
|
2016-05-08 18:33:22 +02:00
|
|
|
profile);
|
2003-10-06 12:17:11 +00:00
|
|
|
|
|
|
|
/* Set the offsets */
|
2008-11-03 21:17:50 +00:00
|
|
|
gimp_item_set_offset (GIMP_ITEM (layer), x1 + off_x, y1 + off_y);
|
2003-10-06 12:17:11 +00:00
|
|
|
|
|
|
|
/* Free the temp buffer */
|
2012-03-21 14:38:19 +01:00
|
|
|
g_object_unref (buffer);
|
2003-10-06 12:17:11 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
/* Add the floating layer to the image */
|
2020-05-17 23:00:07 +02:00
|
|
|
floating_sel_attach (layer, drawables->data);
|
2003-10-06 12:17:11 +00:00
|
|
|
|
|
|
|
/* End an undo group */
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_undo_group_end (image);
|
2003-10-06 12:17:11 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
/* invalidate the image's boundary variables */
|
2008-11-22 22:07:55 +00:00
|
|
|
GIMP_CHANNEL (selection)->boundary_known = FALSE;
|
2003-10-06 12:17:11 +00:00
|
|
|
|
2020-05-17 23:00:07 +02:00
|
|
|
if (temp_image)
|
|
|
|
g_object_unref (temp_image);
|
|
|
|
|
2003-10-06 12:17:11 +00:00
|
|
|
return layer;
|
|
|
|
}
|