2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-24 22:05:25 +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
|
1997-11-24 22:05:25 +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
|
1997-11-24 22:05:25 +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
|
2009-01-17 22:28:01 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
2000-12-16 21:37:03 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
#include <stdlib.h>
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2012-03-16 00:02:27 +01:00
|
|
|
#include <cairo.h>
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2012-05-03 03:36:22 +02:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2001-01-24 22:36:18 +00:00
|
|
|
|
2006-08-29 14:46:32 +00:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2012-03-16 00:02:27 +01:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2006-08-29 14:46:32 +00:00
|
|
|
|
2001-07-04 19:31:35 +00:00
|
|
|
#include "core-types.h"
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2012-03-14 23:09:36 +01:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
2001-07-04 19:31:35 +00:00
|
|
|
#include "gimp.h"
|
2003-09-15 17:26:28 +00:00
|
|
|
#include "gimp-edit.h"
|
2014-06-03 14:00:01 +02:00
|
|
|
#include "gimp-utils.h"
|
2001-07-03 18:38:56 +00:00
|
|
|
#include "gimpbuffer.h"
|
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpcontext.h"
|
2016-03-11 19:52:36 +01:00
|
|
|
#include "gimpfilloptions.h"
|
2006-10-21 18:46:49 +00:00
|
|
|
#include "gimpdrawableundo.h"
|
2001-07-03 18:38:56 +00:00
|
|
|
#include "gimpimage.h"
|
2003-02-13 11:23:50 +00:00
|
|
|
#include "gimpimage-undo.h"
|
2001-07-03 18:38:56 +00:00
|
|
|
#include "gimplayer.h"
|
2002-02-21 22:19:45 +00:00
|
|
|
#include "gimplayer-floating-sel.h"
|
2015-06-17 13:21:01 +02:00
|
|
|
#include "gimplayer-new.h"
|
2001-07-03 18:38:56 +00:00
|
|
|
#include "gimplist.h"
|
2004-01-06 14:02:08 +00:00
|
|
|
#include "gimppattern.h"
|
2006-03-02 19:30:59 +00:00
|
|
|
#include "gimppickable.h"
|
2003-10-06 12:17:11 +00:00
|
|
|
#include "gimpselection.h"
|
2012-04-09 00:59:20 +02:00
|
|
|
#include "gimptempbuf.h"
|
2001-07-03 18:38:56 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
1998-11-23 14:47:09 +00:00
|
|
|
|
1998-01-22 07:02:57 +00:00
|
|
|
|
2003-10-08 17:20:06 +00:00
|
|
|
/* local function protypes */
|
|
|
|
|
2012-03-18 23:05:44 +01:00
|
|
|
static GimpBuffer * gimp_edit_extract (GimpImage *image,
|
|
|
|
GimpPickable *pickable,
|
|
|
|
GimpContext *context,
|
|
|
|
gboolean cut_pixels,
|
|
|
|
GError **error);
|
2003-10-08 17:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2003-09-05 01:40:29 +00:00
|
|
|
const GimpBuffer *
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_edit_cut (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2005-09-05 18:21:51 +00:00
|
|
|
GimpBuffer *buffer;
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2001-06-26 12:09:43 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-11-11 14:05:34 +00:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
2004-04-14 23:37:34 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-14 13:58:10 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2007-04-30 17:26:15 +00:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
|
2007-12-14 13:58:10 +00:00
|
|
|
context, TRUE, error);
|
2005-09-05 18:21:51 +00:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_set_global_buffer (image->gimp, buffer);
|
2005-09-05 18:21:51 +00:00
|
|
|
g_object_unref (buffer);
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
return image->gimp->global_buffer;
|
2005-09-05 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2003-09-05 01:40:29 +00:00
|
|
|
const GimpBuffer *
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_edit_copy (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2005-09-05 18:21:51 +00:00
|
|
|
GimpBuffer *buffer;
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2001-06-26 12:09:43 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-11-11 14:05:34 +00:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
2004-04-14 23:37:34 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-14 13:58:10 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2007-04-30 17:26:15 +00:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
|
2007-12-14 13:58:10 +00:00
|
|
|
context, FALSE, error);
|
2005-09-05 18:21:51 +00:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_set_global_buffer (image->gimp, buffer);
|
2005-09-05 18:21:51 +00:00
|
|
|
g_object_unref (buffer);
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
return image->gimp->global_buffer;
|
2005-09-05 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2004-12-12 14:01:08 +00:00
|
|
|
const GimpBuffer *
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_edit_copy_visible (GimpImage *image,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
2004-12-12 14:01:08 +00:00
|
|
|
{
|
2013-09-13 23:29:06 +02:00
|
|
|
GimpBuffer *buffer;
|
2004-12-12 14:01:08 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2004-12-12 14:01:08 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-14 13:58:10 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2004-12-12 14:01:08 +00:00
|
|
|
|
2013-09-13 23:29:06 +02:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (image),
|
2007-12-14 13:58:10 +00:00
|
|
|
context, FALSE, error);
|
2004-12-12 14:01:08 +00:00
|
|
|
|
2005-09-05 18:21:51 +00:00
|
|
|
if (buffer)
|
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_set_global_buffer (image->gimp, buffer);
|
2005-09-05 18:21:51 +00:00
|
|
|
g_object_unref (buffer);
|
2004-12-12 14:01:08 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
return image->gimp->global_buffer;
|
2005-09-05 18:21:51 +00:00
|
|
|
}
|
2004-12-12 14:01:08 +00:00
|
|
|
|
2005-09-05 18:21:51 +00:00
|
|
|
return NULL;
|
2004-12-12 14:01:08 +00:00
|
|
|
}
|
|
|
|
|
2000-02-10 21:54:12 +00:00
|
|
|
GimpLayer *
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_edit_paste (GimpImage *image,
|
2006-04-12 12:49:29 +00:00
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpBuffer *paste,
|
|
|
|
gboolean paste_into,
|
2004-01-15 14:36:43 +00:00
|
|
|
gint viewport_x,
|
|
|
|
gint viewport_y,
|
|
|
|
gint viewport_width,
|
|
|
|
gint viewport_height)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2012-04-06 23:37:35 +02:00
|
|
|
GimpLayer *layer;
|
|
|
|
const Babl *format;
|
2012-07-30 16:20:11 +02:00
|
|
|
gint image_width;
|
|
|
|
gint image_height;
|
2012-04-06 23:37:35 +02:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2012-07-30 16:20:11 +02:00
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
gboolean clamp_to_image = TRUE;
|
2000-02-10 21:54:12 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2003-12-16 12:41:17 +00:00
|
|
|
g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-01-26 15:34:47 +00:00
|
|
|
g_return_val_if_fail (drawable == NULL ||
|
2004-01-26 16:18:16 +00:00
|
|
|
gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
2003-12-16 12:41:17 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_BUFFER (paste), NULL);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
|
|
|
/* Make a new layer: if drawable == NULL,
|
|
|
|
* user is pasting into an empty image.
|
2000-02-10 21:54:12 +00:00
|
|
|
*/
|
|
|
|
|
2002-05-21 11:29:20 +00:00
|
|
|
if (drawable)
|
2012-04-07 00:46:59 +02:00
|
|
|
format = gimp_drawable_get_format_with_alpha (drawable);
|
2000-01-16 09:34:45 +00:00
|
|
|
else
|
2012-04-07 00:46:59 +02:00
|
|
|
format = gimp_image_get_layer_format (image, TRUE);
|
2002-05-21 11:29:20 +00:00
|
|
|
|
2015-06-20 00:02:11 +02:00
|
|
|
layer = gimp_layer_new_from_buffer (paste, image,
|
2012-04-06 23:37:35 +02:00
|
|
|
format,
|
2012-03-14 23:09:36 +01:00
|
|
|
_("Pasted Layer"),
|
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
|
2002-05-21 11:29:20 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
if (! layer)
|
|
|
|
return NULL;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2012-07-30 16:20:11 +02: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-12 23:48:18 +00:00
|
|
|
if (drawable)
|
2001-06-26 12:09:43 +00:00
|
|
|
{
|
2004-01-15 14:36:43 +00: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-02 23:03:29 +00:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
2010-09-07 21:28:00 +02:00
|
|
|
have_mask = gimp_item_mask_bounds (GIMP_ITEM (drawable),
|
|
|
|
&x1, &y1, &x2, &y2);
|
2004-01-15 14:36:43 +00:00
|
|
|
|
2012-07-30 16:20:11 +02:00
|
|
|
if (! have_mask && /* if we have no mask */
|
|
|
|
viewport_width > 0 && /* and we have a viewport */
|
2004-01-15 14:36:43 +00:00
|
|
|
viewport_height > 0 &&
|
2012-07-30 16:20:11 +02: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 14:36:43 +00: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 16:20:11 +02:00
|
|
|
/* center on the viewport */
|
|
|
|
|
|
|
|
offset_x = paste_x + (paste_width - width) / 2;
|
|
|
|
offset_y = paste_y + (paste_height- height) / 2;
|
2004-01-15 14:36:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-30 16:20:11 +02: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 14:36:43 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 16:20:11 +02: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 14:36:43 +00:00
|
|
|
{
|
2012-07-30 16:20:11 +02:00
|
|
|
/* center on the viewport */
|
2004-01-15 14:36:43 +00:00
|
|
|
|
2012-07-30 16:20:11 +02:00
|
|
|
offset_x = viewport_x + (viewport_width - width) / 2;
|
|
|
|
offset_y = viewport_y + (viewport_height - height) / 2;
|
2001-06-26 12:09:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-30 16:20:11 +02:00
|
|
|
/* otherwise center on the image */
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2012-07-30 16:20:11 +02:00
|
|
|
offset_x = (image_width - width) / 2;
|
|
|
|
offset_y = (image_height - height) / 2;
|
2004-09-17 09:14:02 +00:00
|
|
|
|
2012-07-30 16:20:11 +02:00
|
|
|
/* and keep it that way */
|
|
|
|
clamp_to_image = FALSE;
|
|
|
|
}
|
2004-09-17 09:14:02 +00:00
|
|
|
|
2012-07-30 16:20:11 +02: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 09:14:02 +00:00
|
|
|
|
2008-11-03 21:17:50 +00:00
|
|
|
gimp_item_set_offset (GIMP_ITEM (layer), offset_x, offset_y);
|
2001-03-30 11:16:05 +00:00
|
|
|
|
2004-10-19 22:52:04 +00:00
|
|
|
/* Start a group undo */
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
|
2010-06-08 14:24:11 +03:00
|
|
|
C_("undo-type", "Paste"));
|
2004-10-19 22:52:04 +00:00
|
|
|
|
2001-06-26 12:09:43 +00: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-28 17:08:36 +00: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-24 22:05:25 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
/* if there's a drawable, add a new floating selection */
|
2003-12-09 16:20:31 +00:00
|
|
|
if (drawable)
|
|
|
|
floating_sel_attach (layer, drawable);
|
2001-06-26 12:09:43 +00:00
|
|
|
else
|
2009-08-03 19:21:51 +02:00
|
|
|
gimp_image_add_layer (image, layer, NULL, 0, TRUE);
|
2000-02-10 21:54:12 +00:00
|
|
|
|
2001-06-26 12:09:43 +00:00
|
|
|
/* end the group undo */
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_undo_group_end (image);
|
2001-06-26 12:09:43 +00:00
|
|
|
|
|
|
|
return layer;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2000-01-16 09:34:45 +00:00
|
|
|
|
2005-09-02 22:50:06 +00:00
|
|
|
const gchar *
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_edit_named_cut (GimpImage *image,
|
|
|
|
const gchar *name,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
2005-09-02 22:50:06 +00:00
|
|
|
{
|
2005-09-05 18:21:51 +00:00
|
|
|
GimpBuffer *buffer;
|
2005-09-02 22:50:06 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2005-09-02 22:50:06 +00: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 13:58:10 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2005-09-02 22:50:06 +00:00
|
|
|
|
2007-04-30 17:26:15 +00:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
|
2007-12-14 13:58:10 +00:00
|
|
|
context, TRUE, error);
|
2005-09-02 22:50:06 +00:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2005-09-05 18:21:51 +00:00
|
|
|
gimp_object_set_name (GIMP_OBJECT (buffer), name);
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_container_add (image->gimp->named_buffers, GIMP_OBJECT (buffer));
|
2005-09-05 18:21:51 +00:00
|
|
|
g_object_unref (buffer);
|
2005-09-02 22:50:06 +00:00
|
|
|
|
2009-08-31 22:47:18 +02:00
|
|
|
return gimp_object_get_name (buffer);
|
2005-09-02 22:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_edit_named_copy (GimpImage *image,
|
|
|
|
const gchar *name,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
2005-09-02 22:50:06 +00:00
|
|
|
{
|
2005-09-05 18:21:51 +00:00
|
|
|
GimpBuffer *buffer;
|
2005-09-02 22:50:06 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2005-09-02 22:50:06 +00: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 13:58:10 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2005-09-02 22:50:06 +00:00
|
|
|
|
2007-04-30 17:26:15 +00:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
|
2007-12-14 13:58:10 +00:00
|
|
|
context, FALSE, error);
|
2005-09-02 22:50:06 +00:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2005-09-05 18:21:51 +00:00
|
|
|
gimp_object_set_name (GIMP_OBJECT (buffer), name);
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_container_add (image->gimp->named_buffers, GIMP_OBJECT (buffer));
|
2005-09-05 18:21:51 +00:00
|
|
|
g_object_unref (buffer);
|
2005-09-02 22:50:06 +00:00
|
|
|
|
2009-08-31 22:47:18 +02:00
|
|
|
return gimp_object_get_name (buffer);
|
2005-09-02 22:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_edit_named_copy_visible (GimpImage *image,
|
|
|
|
const gchar *name,
|
|
|
|
GimpContext *context,
|
|
|
|
GError **error)
|
2005-09-02 22:50:06 +00:00
|
|
|
{
|
2013-09-13 23:29:06 +02:00
|
|
|
GimpBuffer *buffer;
|
2005-09-02 22:50:06 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2005-09-02 22:50:06 +00:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2007-12-14 13:58:10 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2005-09-02 22:50:06 +00:00
|
|
|
|
2013-09-13 23:29:06 +02:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (image),
|
2007-12-14 13:58:10 +00:00
|
|
|
context, FALSE, error);
|
2005-09-02 22:50:06 +00:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2005-09-05 18:21:51 +00:00
|
|
|
gimp_object_set_name (GIMP_OBJECT (buffer), name);
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_container_add (image->gimp->named_buffers, GIMP_OBJECT (buffer));
|
2005-09-05 18:21:51 +00:00
|
|
|
g_object_unref (buffer);
|
2005-09-02 22:50:06 +00:00
|
|
|
|
2009-08-31 22:47:18 +02:00
|
|
|
return gimp_object_get_name (buffer);
|
2005-09-02 22:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-11 22:41:25 +01:00
|
|
|
void
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_edit_clear (GimpImage *image,
|
2006-04-12 12:49:29 +00:00
|
|
|
GimpDrawable *drawable,
|
2004-04-14 23:37:34 +00:00
|
|
|
GimpContext *context)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2016-03-11 19:52:36 +01:00
|
|
|
GimpFillOptions *options;
|
2012-03-18 22:17:21 +01:00
|
|
|
|
2016-03-11 22:41:25 +01: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-24 22:05:25 +00:00
|
|
|
|
2016-03-11 19:52:36 +01:00
|
|
|
options = gimp_fill_options_new (context->gimp);
|
2012-03-18 22:17:21 +01:00
|
|
|
|
2012-05-20 17:32:43 +02:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
2016-03-11 19:52:36 +01:00
|
|
|
gimp_fill_options_set_by_fill_type (options, context,
|
|
|
|
GIMP_FILL_TRANSPARENT, NULL);
|
2012-05-20 17:32:43 +02:00
|
|
|
else
|
2016-03-11 19:52:36 +01:00
|
|
|
gimp_fill_options_set_by_fill_type (options, context,
|
|
|
|
GIMP_FILL_BACKGROUND, NULL);
|
2012-05-20 17:32:43 +02:00
|
|
|
|
2016-03-11 22:41:25 +01:00
|
|
|
gimp_edit_fill (image, drawable, options, C_("undo-type", "Clear"));
|
2016-03-11 19:52:36 +01:00
|
|
|
|
|
|
|
g_object_unref (options);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 22:41:25 +01:00
|
|
|
void
|
2016-03-11 19:52:36 +01:00
|
|
|
gimp_edit_fill (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpFillOptions *options,
|
|
|
|
const gchar *undo_desc)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2016-03-11 19:52:36 +01:00
|
|
|
GeglBuffer *dest_buffer;
|
|
|
|
GimpPattern *pattern = NULL;
|
2012-03-18 22:17:21 +01:00
|
|
|
GimpRGB color;
|
2016-03-11 19:52:36 +01:00
|
|
|
const Babl *format;
|
|
|
|
gint x, y, width, height;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2016-03-11 22:41:25 +01: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 14:00:01 +02:00
|
|
|
|
2016-03-11 19:52:36 +01:00
|
|
|
if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
|
2016-03-11 22:41:25 +01:00
|
|
|
return; /* nothing to do, but the fill succeeded */
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2016-03-11 19:52:36 +01:00
|
|
|
switch (gimp_fill_options_get_style (options))
|
2000-03-24 14:54:59 +00:00
|
|
|
{
|
2016-03-11 19:52:36 +01:00
|
|
|
case GIMP_FILL_STYLE_SOLID:
|
|
|
|
gimp_context_get_foreground (GIMP_CONTEXT (options), &color);
|
2000-03-24 14:54:59 +00:00
|
|
|
break;
|
|
|
|
|
2016-03-11 19:52:36 +01:00
|
|
|
case GIMP_FILL_STYLE_PATTERN:
|
|
|
|
pattern = gimp_context_get_pattern (GIMP_CONTEXT (options));
|
2004-01-06 14:02:08 +00:00
|
|
|
break;
|
2000-03-24 14:54:59 +00:00
|
|
|
}
|
|
|
|
|
2012-04-05 20:37:47 +02:00
|
|
|
if (pattern &&
|
2012-04-23 09:40:56 +02:00
|
|
|
babl_format_has_alpha (gimp_temp_buf_get_format (pattern->mask)) &&
|
2012-04-05 20:37:47 +02:00
|
|
|
! gimp_drawable_has_alpha (drawable))
|
2012-03-18 23:05:44 +01:00
|
|
|
{
|
2012-04-05 20:37:47 +02:00
|
|
|
format = gimp_drawable_get_format_with_alpha (drawable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format = gimp_drawable_get_format (drawable);
|
2012-03-18 23:05:44 +01:00
|
|
|
}
|
|
|
|
|
2012-05-20 22:00:27 +02:00
|
|
|
dest_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height),
|
|
|
|
format);
|
2012-03-18 23:05:44 +01:00
|
|
|
|
|
|
|
if (pattern)
|
|
|
|
{
|
|
|
|
GeglBuffer *src_buffer = gimp_pattern_create_buffer (pattern);
|
|
|
|
|
|
|
|
gegl_buffer_set_pattern (dest_buffer, NULL, src_buffer, 0, 0);
|
|
|
|
g_object_unref (src_buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-11 19:52:36 +01:00
|
|
|
GeglColor *gegl_color = gimp_gegl_color_new (&color);
|
2012-03-18 23:05:44 +01:00
|
|
|
|
|
|
|
gegl_buffer_set_color (dest_buffer, NULL, gegl_color);
|
|
|
|
g_object_unref (gegl_color);
|
|
|
|
}
|
|
|
|
|
2016-03-11 19:52:36 +01:00
|
|
|
if (! undo_desc)
|
|
|
|
undo_desc = gimp_fill_options_get_undo_desc (options);
|
|
|
|
|
2012-03-22 18:40:40 +01:00
|
|
|
gimp_drawable_apply_buffer (drawable, dest_buffer,
|
2012-04-02 14:19:47 +01:00
|
|
|
GEGL_RECTANGLE (0, 0, width, height),
|
2012-03-18 23:05:44 +01:00
|
|
|
TRUE, undo_desc,
|
2016-03-11 19:52:36 +01:00
|
|
|
gimp_context_get_opacity (GIMP_CONTEXT (options)),
|
|
|
|
gimp_context_get_paint_mode (GIMP_CONTEXT (options)),
|
2012-03-24 00:57:11 +01:00
|
|
|
NULL, x, y);
|
2012-03-18 23:05:44 +01:00
|
|
|
|
2012-03-22 18:40:40 +01:00
|
|
|
g_object_unref (dest_buffer);
|
2012-03-18 23:05:44 +01:00
|
|
|
|
|
|
|
gimp_drawable_update (drawable, x, y, width, height);
|
2012-03-18 22:31:11 +01:00
|
|
|
}
|
|
|
|
|
2006-10-21 18:46:49 +00: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-22 23:45:11 +01:00
|
|
|
if (undo && undo->applied_buffer)
|
2006-10-21 18:46:49 +00:00
|
|
|
{
|
2012-03-22 23:45:11 +01:00
|
|
|
GimpDrawable *drawable;
|
|
|
|
GeglBuffer *buffer;
|
2006-10-21 18:46:49 +00:00
|
|
|
|
|
|
|
drawable = GIMP_DRAWABLE (GIMP_ITEM_UNDO (undo)->item);
|
|
|
|
|
|
|
|
g_object_ref (undo);
|
2012-03-22 23:45:11 +01:00
|
|
|
buffer = g_object_ref (undo->applied_buffer);
|
2006-10-21 18:46:49 +00:00
|
|
|
|
|
|
|
gimp_image_undo (image);
|
|
|
|
|
2012-03-22 23:45:11 +01:00
|
|
|
gimp_drawable_apply_buffer (drawable, buffer,
|
2012-04-02 14:19:47 +01:00
|
|
|
GEGL_RECTANGLE (0, 0,
|
2012-03-22 23:45:11 +01:00
|
|
|
gegl_buffer_get_width (undo->buffer),
|
|
|
|
gegl_buffer_get_height (undo->buffer)),
|
2006-10-21 18:46:49 +00:00
|
|
|
TRUE,
|
2009-08-31 22:47:18 +02:00
|
|
|
gimp_object_get_name (undo),
|
2006-10-21 18:46:49 +00:00
|
|
|
gimp_context_get_opacity (context),
|
|
|
|
gimp_context_get_paint_mode (context),
|
2012-03-24 00:57:11 +01:00
|
|
|
NULL, undo->x, undo->y);
|
2006-10-21 18:46:49 +00:00
|
|
|
|
2012-03-22 23:45:11 +01:00
|
|
|
g_object_unref (buffer);
|
2006-10-21 18:46:49 +00:00
|
|
|
g_object_unref (undo);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-10-08 17:20:06 +00:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2005-09-05 18:21:51 +00:00
|
|
|
static GimpBuffer *
|
2007-12-14 13:58:10 +00:00
|
|
|
gimp_edit_extract (GimpImage *image,
|
|
|
|
GimpPickable *pickable,
|
|
|
|
GimpContext *context,
|
|
|
|
gboolean cut_pixels,
|
|
|
|
GError **error)
|
2003-12-09 16:20:31 +00:00
|
|
|
{
|
2012-03-21 14:38:19 +01:00
|
|
|
GeglBuffer *buffer;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
2003-12-09 16:20:31 +00:00
|
|
|
|
|
|
|
if (cut_pixels)
|
2015-06-16 23:16:54 +02:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_CUT,
|
|
|
|
C_("undo-type", "Cut"));
|
2003-12-09 16:20:31 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
/* Cut/copy the mask portion from the image */
|
2012-03-21 14:43:38 +01: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-09 16:20:31 +00:00
|
|
|
|
|
|
|
if (cut_pixels)
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_undo_group_end (image);
|
2003-12-09 16:20:31 +00:00
|
|
|
|
2012-03-21 14:38:19 +01:00
|
|
|
if (buffer)
|
2010-03-19 09:52:29 +01:00
|
|
|
{
|
2012-04-07 02:43:18 +02:00
|
|
|
GimpBuffer *gimp_buffer = gimp_buffer_new (buffer, _("Global Buffer"),
|
|
|
|
offset_x, offset_y, FALSE);
|
2012-03-21 14:38:19 +01:00
|
|
|
g_object_unref (buffer);
|
2012-03-14 23:09:36 +01:00
|
|
|
|
2015-09-03 01:36:02 +02:00
|
|
|
if (GIMP_IS_COLOR_MANAGED (pickable))
|
2015-06-16 23:16:54 +02:00
|
|
|
{
|
2015-08-16 13:14:56 +02:00
|
|
|
GimpColorProfile *profile =
|
2015-09-03 01:36:02 +02:00
|
|
|
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (pickable));
|
2015-06-16 23:16:54 +02:00
|
|
|
|
2015-09-03 01:36:02 +02:00
|
|
|
if (profile)
|
|
|
|
gimp_buffer_set_color_profile (gimp_buffer, profile);
|
2015-06-16 23:16:54 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 14:38:19 +01:00
|
|
|
return gimp_buffer;
|
2010-03-19 09:52:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2003-12-09 16:20:31 +00:00
|
|
|
}
|