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
|
|
|
|
*
|
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
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2012-03-16 07:02:27 +08:00
|
|
|
#include <cairo.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2006-08-29 22:46:32 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2012-03-16 07:02:27 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2006-08-29 22:46:32 +08:00
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2012-03-15 06:09:36 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "gimp.h"
|
2003-09-16 01:26:28 +08:00
|
|
|
#include "gimp-edit.h"
|
2014-06-03 20:00:01 +08:00
|
|
|
#include "gimp-utils.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimpbuffer.h"
|
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpcontext.h"
|
2016-03-12 02:52:36 +08:00
|
|
|
#include "gimpfilloptions.h"
|
2006-10-22 02:46:49 +08:00
|
|
|
#include "gimpdrawableundo.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimpimage.h"
|
2003-02-13 19:23:50 +08:00
|
|
|
#include "gimpimage-undo.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimplayer.h"
|
2016-05-20 22:46:26 +08:00
|
|
|
#include "gimplayer-floating-selection.h"
|
2015-06-17 19:21:01 +08:00
|
|
|
#include "gimplayer-new.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimplist.h"
|
2006-03-03 03:30:59 +08:00
|
|
|
#include "gimppickable.h"
|
2003-10-06 20:17:11 +08:00
|
|
|
#include "gimpselection.h"
|
2012-04-09 06:59:20 +08:00
|
|
|
#include "gimptempbuf.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
1998-11-23 22:47:09 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2003-10-09 01:20:06 +08:00
|
|
|
/* local function protypes */
|
|
|
|
|
2012-03-19 06:05:44 +08:00
|
|
|
static GimpBuffer * gimp_edit_extract (GimpImage *image,
|
|
|
|
GimpPickable *pickable,
|
|
|
|
GimpContext *context,
|
|
|
|
gboolean cut_pixels,
|
|
|
|
GError **error);
|
2003-10-09 01:20:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2016-05-20 05:51:44 +08:00
|
|
|
GimpBuffer *
|
2007-12-14 21:58:10 +08:00
|
|
|
gimp_edit_cut (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
GimpBuffer *buffer;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-11-11 22:05:34 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-14 21:58:10 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-05-01 01:26:15 +08:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
|
2007-12-14 21:58:10 +08:00
|
|
|
context, TRUE, error);
|
2005-09-06 02:21:51 +08:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2016-09-17 23:39:54 +08:00
|
|
|
gimp_set_clipboard_buffer (image->gimp, buffer);
|
2005-09-06 02:21:51 +08:00
|
|
|
g_object_unref (buffer);
|
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
return gimp_get_clipboard_buffer (image->gimp);
|
2005-09-06 02:21:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2016-05-20 05:51:44 +08:00
|
|
|
GimpBuffer *
|
2007-12-14 21:58:10 +08:00
|
|
|
gimp_edit_copy (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
GimpBuffer *buffer;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-11-11 22:05:34 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-14 21:58:10 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-05-01 01:26:15 +08:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
|
2007-12-14 21:58:10 +08:00
|
|
|
context, FALSE, error);
|
2005-09-06 02:21:51 +08:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2016-09-17 23:39:54 +08:00
|
|
|
gimp_set_clipboard_buffer (image->gimp, buffer);
|
2005-09-06 02:21:51 +08:00
|
|
|
g_object_unref (buffer);
|
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
return gimp_get_clipboard_buffer (image->gimp);
|
2005-09-06 02:21:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2016-05-20 05:51:44 +08:00
|
|
|
GimpBuffer *
|
2007-12-14 21:58:10 +08:00
|
|
|
gimp_edit_copy_visible (GimpImage *image,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
2004-12-12 22:01:08 +08:00
|
|
|
{
|
2013-09-14 05:29:06 +08:00
|
|
|
GimpBuffer *buffer;
|
2004-12-12 22:01:08 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2004-12-12 22:01:08 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-14 21:58:10 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2004-12-12 22:01:08 +08:00
|
|
|
|
2013-09-14 05:29:06 +08:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (image),
|
2007-12-14 21:58:10 +08:00
|
|
|
context, FALSE, error);
|
2004-12-12 22:01:08 +08:00
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
if (buffer)
|
|
|
|
{
|
2016-09-17 23:39:54 +08:00
|
|
|
gimp_set_clipboard_buffer (image->gimp, buffer);
|
2005-09-06 02:21:51 +08:00
|
|
|
g_object_unref (buffer);
|
2004-12-12 22:01:08 +08:00
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
return gimp_get_clipboard_buffer (image->gimp);
|
2005-09-06 02:21:51 +08:00
|
|
|
}
|
2004-12-12 22:01:08 +08:00
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
return NULL;
|
2004-12-12 22:01:08 +08:00
|
|
|
}
|
|
|
|
|
2000-02-11 05:54:12 +08:00
|
|
|
GimpLayer *
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_edit_paste (GimpImage *image,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpBuffer *paste,
|
|
|
|
gboolean paste_into,
|
2004-01-15 22:36:43 +08:00
|
|
|
gint viewport_x,
|
|
|
|
gint viewport_y,
|
|
|
|
gint viewport_width,
|
|
|
|
gint viewport_height)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-04-07 05:37:35 +08:00
|
|
|
GimpLayer *layer;
|
|
|
|
const Babl *format;
|
2012-07-30 22:20:11 +08:00
|
|
|
gint image_width;
|
|
|
|
gint image_height;
|
2012-04-07 05:37:35 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2012-07-30 22:20:11 +08:00
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
gboolean clamp_to_image = TRUE;
|
2000-02-11 05:54:12 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2003-12-16 20:41:17 +08:00
|
|
|
g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-01-26 23:34:47 +08:00
|
|
|
g_return_val_if_fail (drawable == NULL ||
|
2004-01-27 00:18:16 +08:00
|
|
|
gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
2003-12-16 20:41:17 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BUFFER (paste), NULL);
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
/* Make a new layer: if drawable == NULL,
|
|
|
|
* user is pasting into an empty image.
|
2000-02-11 05:54:12 +08:00
|
|
|
*/
|
|
|
|
|
2002-05-21 19:29:20 +08:00
|
|
|
if (drawable)
|
2012-04-07 06:46:59 +08:00
|
|
|
format = gimp_drawable_get_format_with_alpha (drawable);
|
2000-01-16 17:34:45 +08:00
|
|
|
else
|
2012-04-07 06:46:59 +08:00
|
|
|
format = gimp_image_get_layer_format (image, TRUE);
|
2002-05-21 19:29:20 +08:00
|
|
|
|
2015-06-20 06:02:11 +08:00
|
|
|
layer = gimp_layer_new_from_buffer (paste, image,
|
2012-04-07 05:37:35 +08:00
|
|
|
format,
|
2012-03-15 06:09:36 +08:00
|
|
|
_("Pasted Layer"),
|
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
|
2002-05-21 19:29:20 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
if (! layer)
|
|
|
|
return NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-07-30 22:20:11 +08:00
|
|
|
image_width = gimp_image_get_width (image);
|
|
|
|
image_height = gimp_image_get_height (image);
|
|
|
|
|
|
|
|
width = gimp_item_get_width (GIMP_ITEM (layer));
|
|
|
|
height = gimp_item_get_height (GIMP_ITEM (layer));
|
|
|
|
|
|
|
|
if (viewport_width == image_width &&
|
|
|
|
viewport_height == image_height)
|
|
|
|
{
|
|
|
|
/* if the whole image is visible, act as if there was no viewport */
|
|
|
|
|
|
|
|
viewport_x = 0;
|
|
|
|
viewport_y = 0;
|
|
|
|
viewport_width = 0;
|
|
|
|
viewport_height = 0;
|
|
|
|
}
|
|
|
|
|
2001-12-13 07:48:18 +08:00
|
|
|
if (drawable)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
2004-01-15 22:36:43 +08:00
|
|
|
/* if pasting to a drawable */
|
|
|
|
|
|
|
|
gint off_x, off_y;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint paste_x, paste_y;
|
|
|
|
gint paste_width, paste_height;
|
|
|
|
gboolean have_mask;
|
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
2010-09-08 03:28:00 +08:00
|
|
|
have_mask = gimp_item_mask_bounds (GIMP_ITEM (drawable),
|
|
|
|
&x1, &y1, &x2, &y2);
|
2004-01-15 22:36:43 +08:00
|
|
|
|
2012-07-30 22:20:11 +08:00
|
|
|
if (! have_mask && /* if we have no mask */
|
|
|
|
viewport_width > 0 && /* and we have a viewport */
|
2004-01-15 22:36:43 +08:00
|
|
|
viewport_height > 0 &&
|
2012-07-30 22:20:11 +08:00
|
|
|
(width < (x2 - x1) || /* and the paste is smaller than the target */
|
|
|
|
height < (y2 - y1)) &&
|
|
|
|
|
|
|
|
/* and the viewport intersects with the target */
|
2004-01-15 22:36:43 +08:00
|
|
|
gimp_rectangle_intersect (viewport_x, viewport_y,
|
|
|
|
viewport_width, viewport_height,
|
|
|
|
off_x, off_y,
|
|
|
|
x2 - x1, y2 - y1,
|
|
|
|
&paste_x, &paste_y,
|
|
|
|
&paste_width, &paste_height))
|
|
|
|
{
|
2012-07-30 22:20:11 +08:00
|
|
|
/* center on the viewport */
|
|
|
|
|
|
|
|
offset_x = paste_x + (paste_width - width) / 2;
|
|
|
|
offset_y = paste_y + (paste_height- height) / 2;
|
2004-01-15 22:36:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-30 22:20:11 +08:00
|
|
|
/* otherwise center on the target */
|
|
|
|
|
|
|
|
offset_x = off_x + ((x1 + x2) - width) / 2;
|
|
|
|
offset_y = off_y + ((y1 + y2) - height) / 2;
|
|
|
|
|
|
|
|
/* and keep it that way */
|
|
|
|
clamp_to_image = FALSE;
|
2004-01-15 22:36:43 +08:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 22:20:11 +08:00
|
|
|
else if (viewport_width > 0 && /* if we have a viewport */
|
|
|
|
viewport_height > 0 &&
|
|
|
|
(width < image_width || /* and the paste is */
|
|
|
|
height < image_height)) /* smaller than the image */
|
2004-01-15 22:36:43 +08:00
|
|
|
{
|
2012-07-30 22:20:11 +08:00
|
|
|
/* center on the viewport */
|
2004-01-15 22:36:43 +08:00
|
|
|
|
2012-07-30 22:20:11 +08:00
|
|
|
offset_x = viewport_x + (viewport_width - width) / 2;
|
|
|
|
offset_y = viewport_y + (viewport_height - height) / 2;
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-30 22:20:11 +08:00
|
|
|
/* otherwise center on the image */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-07-30 22:20:11 +08:00
|
|
|
offset_x = (image_width - width) / 2;
|
|
|
|
offset_y = (image_height - height) / 2;
|
2004-09-17 17:14:02 +08:00
|
|
|
|
2012-07-30 22:20:11 +08:00
|
|
|
/* and keep it that way */
|
|
|
|
clamp_to_image = FALSE;
|
|
|
|
}
|
2004-09-17 17:14:02 +08:00
|
|
|
|
2012-07-30 22:20:11 +08:00
|
|
|
if (clamp_to_image)
|
|
|
|
{
|
|
|
|
/* Ensure that the pasted layer is always within the image, if it
|
|
|
|
* fits and aligned at top left if it doesn't. (See bug #142944).
|
|
|
|
*/
|
|
|
|
offset_x = MIN (offset_x, image_width - width);
|
|
|
|
offset_y = MIN (offset_y, image_height - height);
|
|
|
|
offset_x = MAX (offset_x, 0);
|
|
|
|
offset_y = MAX (offset_y, 0);
|
|
|
|
}
|
2004-09-17 17:14:02 +08:00
|
|
|
|
2008-11-04 05:17:50 +08:00
|
|
|
gimp_item_set_offset (GIMP_ITEM (layer), offset_x, offset_y);
|
2001-03-30 19:16:05 +08:00
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
/* Start a group undo */
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
|
2010-06-08 19:24:11 +08:00
|
|
|
C_("undo-type", "Paste"));
|
2004-10-20 06:52:04 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* If there is a selection mask clear it--
|
|
|
|
* this might not always be desired, but in general,
|
|
|
|
* it seems like the correct behavior.
|
|
|
|
*/
|
2006-03-29 01:08:36 +08:00
|
|
|
if (! gimp_channel_is_empty (gimp_image_get_mask (image)) && ! paste_into)
|
|
|
|
gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* if there's a drawable, add a new floating selection */
|
2003-12-10 00:20:31 +08:00
|
|
|
if (drawable)
|
|
|
|
floating_sel_attach (layer, drawable);
|
2001-06-26 20:09:43 +08:00
|
|
|
else
|
2009-08-04 01:21:51 +08:00
|
|
|
gimp_image_add_layer (image, layer, NULL, 0, TRUE);
|
2000-02-11 05:54:12 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* end the group undo */
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_end (image);
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
return layer;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-16 17:34:45 +08:00
|
|
|
|
2005-09-03 06:50:06 +08:00
|
|
|
const gchar *
|
2007-12-14 21:58:10 +08:00
|
|
|
gimp_edit_named_cut (GimpImage *image,
|
|
|
|
const gchar *name,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
2005-09-03 06:50:06 +08:00
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
GimpBuffer *buffer;
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2005-09-03 06:50:06 +08:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-14 21:58:10 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2007-05-01 01:26:15 +08:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
|
2007-12-14 21:58:10 +08:00
|
|
|
context, TRUE, error);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
gimp_object_set_name (GIMP_OBJECT (buffer), name);
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_container_add (image->gimp->named_buffers, GIMP_OBJECT (buffer));
|
2005-09-06 02:21:51 +08:00
|
|
|
g_object_unref (buffer);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
return gimp_object_get_name (buffer);
|
2005-09-03 06:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2007-12-14 21:58:10 +08:00
|
|
|
gimp_edit_named_copy (GimpImage *image,
|
|
|
|
const gchar *name,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
2005-09-03 06:50:06 +08:00
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
GimpBuffer *buffer;
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2005-09-03 06:50:06 +08:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-14 21:58:10 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2007-05-01 01:26:15 +08:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
|
2007-12-14 21:58:10 +08:00
|
|
|
context, FALSE, error);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
gimp_object_set_name (GIMP_OBJECT (buffer), name);
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_container_add (image->gimp->named_buffers, GIMP_OBJECT (buffer));
|
2005-09-06 02:21:51 +08:00
|
|
|
g_object_unref (buffer);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
return gimp_object_get_name (buffer);
|
2005-09-03 06:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2007-12-14 21:58:10 +08:00
|
|
|
gimp_edit_named_copy_visible (GimpImage *image,
|
|
|
|
const gchar *name,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
2005-09-03 06:50:06 +08:00
|
|
|
{
|
2013-09-14 05:29:06 +08:00
|
|
|
GimpBuffer *buffer;
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2005-09-03 06:50:06 +08:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-14 21:58:10 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2013-09-14 05:29:06 +08:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (image),
|
2007-12-14 21:58:10 +08:00
|
|
|
context, FALSE, error);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
gimp_object_set_name (GIMP_OBJECT (buffer), name);
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_container_add (image->gimp->named_buffers, GIMP_OBJECT (buffer));
|
2005-09-06 02:21:51 +08:00
|
|
|
g_object_unref (buffer);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
return gimp_object_get_name (buffer);
|
2005-09-03 06:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-12 05:41:25 +08:00
|
|
|
void
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_edit_clear (GimpImage *image,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2016-03-12 02:52:36 +08:00
|
|
|
GimpFillOptions *options;
|
2012-03-19 05:17:21 +08:00
|
|
|
|
2016-03-12 05:41:25 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
|
|
|
g_return_if_fail (GIMP_IS_CONTEXT (context));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-03-16 03:10:16 +08:00
|
|
|
options = gimp_fill_options_new (context->gimp, NULL, FALSE);
|
2012-03-19 05:17:21 +08:00
|
|
|
|
2012-05-20 23:32:43 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2016-03-12 02:52:36 +08:00
|
|
|
gimp_fill_options_set_by_fill_type (options, context,
|
|
|
|
GIMP_FILL_TRANSPARENT, NULL);
|
2012-05-20 23:32:43 +08:00
|
|
|
else
|
2016-03-12 02:52:36 +08:00
|
|
|
gimp_fill_options_set_by_fill_type (options, context,
|
|
|
|
GIMP_FILL_BACKGROUND, NULL);
|
2012-05-20 23:32:43 +08:00
|
|
|
|
2016-03-12 05:41:25 +08:00
|
|
|
gimp_edit_fill (image, drawable, options, C_("undo-type", "Clear"));
|
2016-03-12 02:52:36 +08:00
|
|
|
|
|
|
|
g_object_unref (options);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2016-03-12 05:41:25 +08:00
|
|
|
void
|
2016-03-12 02:52:36 +08:00
|
|
|
gimp_edit_fill (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpFillOptions *options,
|
|
|
|
const gchar *undo_desc)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2016-05-30 00:25:14 +08:00
|
|
|
GeglBuffer *buffer;
|
2016-03-12 02:52:36 +08:00
|
|
|
gint x, y, width, height;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-03-12 05:41:25 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
|
|
|
g_return_if_fail (GIMP_IS_FILL_OPTIONS (options));
|
2014-06-03 20:00:01 +08:00
|
|
|
|
2016-03-12 02:52:36 +08:00
|
|
|
if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
|
2016-03-12 05:41:25 +08:00
|
|
|
return; /* nothing to do, but the fill succeeded */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-05-30 00:25:14 +08:00
|
|
|
buffer = gimp_fill_options_create_buffer (options, drawable,
|
|
|
|
GEGL_RECTANGLE (0, 0,
|
|
|
|
width, height));
|
2012-03-19 06:05:44 +08:00
|
|
|
|
2016-03-12 02:52:36 +08:00
|
|
|
if (! undo_desc)
|
|
|
|
undo_desc = gimp_fill_options_get_undo_desc (options);
|
|
|
|
|
2016-05-30 00:25:14 +08:00
|
|
|
gimp_drawable_apply_buffer (drawable, buffer,
|
2012-04-02 21:19:47 +08:00
|
|
|
GEGL_RECTANGLE (0, 0, width, height),
|
2012-03-19 06:05:44 +08:00
|
|
|
TRUE, undo_desc,
|
2016-03-12 02:52:36 +08:00
|
|
|
gimp_context_get_opacity (GIMP_CONTEXT (options)),
|
|
|
|
gimp_context_get_paint_mode (GIMP_CONTEXT (options)),
|
2012-03-24 07:57:11 +08:00
|
|
|
NULL, x, y);
|
2012-03-19 06:05:44 +08:00
|
|
|
|
2016-05-30 00:25:14 +08:00
|
|
|
g_object_unref (buffer);
|
2012-03-19 06:05:44 +08:00
|
|
|
|
|
|
|
gimp_drawable_update (drawable, x, y, width, height);
|
2012-03-19 05:31:11 +08:00
|
|
|
}
|
|
|
|
|
2006-10-22 02:46:49 +08:00
|
|
|
gboolean
|
|
|
|
gimp_edit_fade (GimpImage *image,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
|
|
|
GimpDrawableUndo *undo;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
|
|
|
|
|
|
|
|
undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image));
|
|
|
|
|
2012-03-23 06:45:11 +08:00
|
|
|
if (undo && undo->applied_buffer)
|
2006-10-22 02:46:49 +08:00
|
|
|
{
|
2012-03-23 06:45:11 +08:00
|
|
|
GimpDrawable *drawable;
|
|
|
|
GeglBuffer *buffer;
|
2006-10-22 02:46:49 +08:00
|
|
|
|
|
|
|
drawable = GIMP_DRAWABLE (GIMP_ITEM_UNDO (undo)->item);
|
|
|
|
|
|
|
|
g_object_ref (undo);
|
2012-03-23 06:45:11 +08:00
|
|
|
buffer = g_object_ref (undo->applied_buffer);
|
2006-10-22 02:46:49 +08:00
|
|
|
|
|
|
|
gimp_image_undo (image);
|
|
|
|
|
2012-03-23 06:45:11 +08:00
|
|
|
gimp_drawable_apply_buffer (drawable, buffer,
|
2012-04-02 21:19:47 +08:00
|
|
|
GEGL_RECTANGLE (0, 0,
|
2012-03-23 06:45:11 +08:00
|
|
|
gegl_buffer_get_width (undo->buffer),
|
|
|
|
gegl_buffer_get_height (undo->buffer)),
|
2006-10-22 02:46:49 +08:00
|
|
|
TRUE,
|
2009-09-01 04:47:18 +08:00
|
|
|
gimp_object_get_name (undo),
|
2006-10-22 02:46:49 +08:00
|
|
|
gimp_context_get_opacity (context),
|
|
|
|
gimp_context_get_paint_mode (context),
|
2012-03-24 07:57:11 +08:00
|
|
|
NULL, undo->x, undo->y);
|
2006-10-22 02:46:49 +08:00
|
|
|
|
2012-03-23 06:45:11 +08:00
|
|
|
g_object_unref (buffer);
|
2006-10-22 02:46:49 +08:00
|
|
|
g_object_unref (undo);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-10-09 01:20:06 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
static GimpBuffer *
|
2007-12-14 21:58:10 +08:00
|
|
|
gimp_edit_extract (GimpImage *image,
|
|
|
|
GimpPickable *pickable,
|
|
|
|
GimpContext *context,
|
|
|
|
gboolean cut_pixels,
|
|
|
|
GError **error)
|
2003-12-10 00:20:31 +08:00
|
|
|
{
|
2012-03-21 21:38:19 +08:00
|
|
|
GeglBuffer *buffer;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
2003-12-10 00:20:31 +08:00
|
|
|
|
|
|
|
if (cut_pixels)
|
2015-06-17 05:16:54 +08:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_CUT,
|
|
|
|
C_("undo-type", "Cut"));
|
2003-12-10 00:20:31 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
/* Cut/copy the mask portion from the image */
|
2012-03-21 21:43:38 +08:00
|
|
|
buffer = gimp_selection_extract (GIMP_SELECTION (gimp_image_get_mask (image)),
|
|
|
|
pickable, context,
|
|
|
|
cut_pixels, FALSE, FALSE,
|
|
|
|
&offset_x, &offset_y, error);
|
2003-12-10 00:20:31 +08:00
|
|
|
|
|
|
|
if (cut_pixels)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_group_end (image);
|
2003-12-10 00:20:31 +08:00
|
|
|
|
2012-03-21 21:38:19 +08:00
|
|
|
if (buffer)
|
2010-03-19 16:52:29 +08:00
|
|
|
{
|
2012-04-07 08:43:18 +08:00
|
|
|
GimpBuffer *gimp_buffer = gimp_buffer_new (buffer, _("Global Buffer"),
|
|
|
|
offset_x, offset_y, FALSE);
|
2012-03-21 21:38:19 +08:00
|
|
|
g_object_unref (buffer);
|
2012-03-15 06:09:36 +08:00
|
|
|
|
2015-09-03 07:36:02 +08:00
|
|
|
if (GIMP_IS_COLOR_MANAGED (pickable))
|
2015-06-17 05:16:54 +08:00
|
|
|
{
|
2015-08-16 19:14:56 +08:00
|
|
|
GimpColorProfile *profile =
|
2015-09-03 07:36:02 +08:00
|
|
|
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (pickable));
|
2015-06-17 05:16:54 +08:00
|
|
|
|
2015-09-03 07:36:02 +08:00
|
|
|
if (profile)
|
|
|
|
gimp_buffer_set_color_profile (gimp_buffer, profile);
|
2015-06-17 05:16:54 +08:00
|
|
|
}
|
|
|
|
|
2012-03-21 21:38:19 +08:00
|
|
|
return gimp_buffer;
|
2010-03-19 16:52:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2003-12-10 00:20:31 +08:00
|
|
|
}
|