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"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimpbuffer.h"
|
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpcontext.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"
|
2002-02-22 06:19:45 +08:00
|
|
|
#include "gimplayer-floating-sel.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimplist.h"
|
2004-01-06 22:02:08 +08:00
|
|
|
#include "gimppattern.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 */
|
|
|
|
|
2003-09-05 09:40:29 +08:00
|
|
|
const 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)
|
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_set_global_buffer (image->gimp, buffer);
|
2005-09-06 02:21:51 +08:00
|
|
|
g_object_unref (buffer);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
return image->gimp->global_buffer;
|
2005-09-06 02:21:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2003-09-05 09:40:29 +08:00
|
|
|
const 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)
|
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_set_global_buffer (image->gimp, buffer);
|
2005-09-06 02:21:51 +08:00
|
|
|
g_object_unref (buffer);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
return image->gimp->global_buffer;
|
2005-09-06 02:21:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-12-12 22:01:08 +08:00
|
|
|
const 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
|
|
|
{
|
2010-02-04 04:46:09 +08:00
|
|
|
GimpProjection *projection;
|
|
|
|
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
|
|
|
|
2010-02-04 04:46:09 +08:00
|
|
|
projection = gimp_image_get_projection (image);
|
|
|
|
|
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (projection),
|
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)
|
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_set_global_buffer (image->gimp, buffer);
|
2005-09-06 02:21:51 +08:00
|
|
|
g_object_unref (buffer);
|
2004-12-12 22:01:08 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
return image->gimp->global_buffer;
|
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;
|
|
|
|
gint center_x;
|
|
|
|
gint center_y;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
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
|
|
|
|
2012-03-15 06:09:36 +08:00
|
|
|
layer = gimp_layer_new_from_buffer (gimp_buffer_get_buffer (paste),
|
2012-03-22 03:21:11 +08:00
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
if (! have_mask &&
|
|
|
|
viewport_width > 0 &&
|
|
|
|
viewport_height > 0 &&
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
center_x = paste_x + paste_width / 2;
|
|
|
|
center_y = paste_y + paste_height / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
center_x = off_x + (x1 + x2) / 2;
|
|
|
|
center_y = off_y + (y1 + y2) / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (viewport_width > 0 && viewport_height > 0)
|
|
|
|
{
|
|
|
|
/* if we got a viewport set the offsets to the center of the viewport */
|
|
|
|
|
|
|
|
center_x = viewport_x + viewport_width / 2;
|
|
|
|
center_y = viewport_y + viewport_height / 2;
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-15 22:36:43 +08:00
|
|
|
/* otherwise the offsets to the center of the image */
|
|
|
|
|
2007-12-26 00:21:40 +08:00
|
|
|
center_x = gimp_image_get_width (image) / 2;
|
|
|
|
center_y = gimp_image_get_height (image) / 2;
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2008-11-03 08:09:01 +08:00
|
|
|
width = gimp_item_get_width (GIMP_ITEM (layer));
|
|
|
|
height = gimp_item_get_height (GIMP_ITEM (layer));
|
2004-09-17 17:14:02 +08:00
|
|
|
|
|
|
|
offset_x = center_x - width / 2;
|
|
|
|
offset_y = center_y - height / 2;
|
|
|
|
|
|
|
|
/* 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).
|
|
|
|
*/
|
2007-12-26 00:21:40 +08:00
|
|
|
offset_x = MIN (offset_x, gimp_image_get_width (image) - width);
|
|
|
|
offset_y = MIN (offset_y, gimp_image_get_height (image) - height);
|
2004-09-17 17:14:02 +08:00
|
|
|
offset_x = MAX (offset_x, 0);
|
|
|
|
offset_y = MAX (offset_y, 0);
|
|
|
|
|
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
|
|
|
{
|
2010-02-04 04:46:09 +08:00
|
|
|
GimpProjection *projection;
|
|
|
|
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
|
|
|
|
2010-02-04 04:46:09 +08:00
|
|
|
projection = gimp_image_get_projection (image);
|
|
|
|
|
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (projection),
|
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;
|
|
|
|
}
|
|
|
|
|
1998-06-30 09:14:36 +08:00
|
|
|
gboolean
|
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
|
|
|
{
|
2012-05-20 23:32:43 +08:00
|
|
|
GimpRGB background;
|
|
|
|
GimpLayerModeEffects paint_mode;
|
2012-03-19 05:17:21 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
2004-11-11 22:05:34 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-03-19 05:17:21 +08:00
|
|
|
gimp_context_get_background (context, &background);
|
|
|
|
|
2012-05-20 23:32:43 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
|
|
|
paint_mode = GIMP_ERASE_MODE;
|
|
|
|
else
|
|
|
|
paint_mode = GIMP_NORMAL_MODE;
|
|
|
|
|
2012-03-19 06:05:44 +08:00
|
|
|
return gimp_edit_fill_full (image, drawable,
|
|
|
|
&background, NULL,
|
2012-05-20 23:32:43 +08:00
|
|
|
GIMP_OPACITY_OPAQUE, paint_mode,
|
2012-03-19 06:05:44 +08:00
|
|
|
C_("undo-type", "Clear"));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-06-30 09:14:36 +08:00
|
|
|
gboolean
|
2012-03-19 06:05:44 +08:00
|
|
|
gimp_edit_fill (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpFillType fill_type,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpLayerModeEffects paint_mode)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-03-19 05:17:21 +08:00
|
|
|
GimpRGB color;
|
|
|
|
GimpPattern *pattern = NULL;
|
2003-02-17 19:32:02 +08:00
|
|
|
const gchar *undo_desc;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
2004-11-11 22:05:34 +08:00
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-03-24 22:54:59 +08:00
|
|
|
switch (fill_type)
|
|
|
|
{
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_FOREGROUND_FILL:
|
2012-03-19 05:17:21 +08:00
|
|
|
gimp_context_get_foreground (context, &color);
|
2010-06-08 19:24:11 +08:00
|
|
|
undo_desc = C_("undo-type", "Fill with Foreground Color");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_BACKGROUND_FILL:
|
2012-03-19 05:17:21 +08:00
|
|
|
gimp_context_get_background (context, &color);
|
2010-06-08 19:24:11 +08:00
|
|
|
undo_desc = C_("undo-type", "Fill with Background Color");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_WHITE_FILL:
|
2012-03-19 05:17:21 +08:00
|
|
|
gimp_rgba_set (&color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
|
2010-06-08 19:24:11 +08:00
|
|
|
undo_desc = C_("undo-type", "Fill with White");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_TRANSPARENT_FILL:
|
2012-03-19 05:17:21 +08:00
|
|
|
gimp_context_get_background (context, &color);
|
2010-06-08 19:24:11 +08:00
|
|
|
undo_desc = C_("undo-type", "Fill with Transparency");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2004-01-06 22:02:08 +08:00
|
|
|
case GIMP_PATTERN_FILL:
|
2012-03-19 05:17:21 +08:00
|
|
|
pattern = gimp_context_get_pattern (context);
|
2010-06-08 19:24:11 +08:00
|
|
|
undo_desc = C_("undo-type", "Fill with Pattern");
|
2004-01-06 22:02:08 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_NO_FILL:
|
2000-03-24 22:54:59 +08:00
|
|
|
return TRUE; /* nothing to do, but the fill succeded */
|
|
|
|
|
|
|
|
default:
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: unknown fill type", G_STRFUNC);
|
2012-03-19 06:05:44 +08:00
|
|
|
return gimp_edit_fill (image, drawable,
|
|
|
|
context, GIMP_BACKGROUND_FILL,
|
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
|
2000-03-24 22:54:59 +08:00
|
|
|
}
|
|
|
|
|
2012-03-19 06:05:44 +08:00
|
|
|
return gimp_edit_fill_full (image, drawable,
|
|
|
|
&color, pattern,
|
|
|
|
opacity, paint_mode,
|
|
|
|
undo_desc);
|
2003-10-09 01:20:06 +08:00
|
|
|
}
|
|
|
|
|
2012-03-19 05:31:11 +08:00
|
|
|
gboolean
|
2012-03-19 06:05:44 +08:00
|
|
|
gimp_edit_fill_full (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpPattern *pattern,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpLayerModeEffects paint_mode,
|
|
|
|
const gchar *undo_desc)
|
2012-03-19 05:31:11 +08:00
|
|
|
{
|
2012-03-23 01:40:40 +08:00
|
|
|
GeglBuffer *dest_buffer;
|
|
|
|
const Babl *format;
|
|
|
|
gint x, y, width, height;
|
2012-03-19 06:05:44 +08:00
|
|
|
|
2012-03-19 05:31:11 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
|
|
|
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
|
|
|
|
g_return_val_if_fail (color != NULL || pattern != NULL, FALSE);
|
|
|
|
|
2012-03-19 06:05:44 +08:00
|
|
|
if (! gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
|
|
|
|
return TRUE; /* nothing to do, but the fill succeded */
|
|
|
|
|
2012-04-06 02:37:47 +08:00
|
|
|
if (pattern &&
|
2012-04-23 15:40:56 +08:00
|
|
|
babl_format_has_alpha (gimp_temp_buf_get_format (pattern->mask)) &&
|
2012-04-06 02:37:47 +08:00
|
|
|
! gimp_drawable_has_alpha (drawable))
|
2012-03-19 06:05:44 +08:00
|
|
|
{
|
2012-04-06 02:37:47 +08:00
|
|
|
format = gimp_drawable_get_format_with_alpha (drawable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format = gimp_drawable_get_format (drawable);
|
2012-03-19 06:05:44 +08:00
|
|
|
}
|
|
|
|
|
2012-04-02 21:19:47 +08:00
|
|
|
dest_buffer = gimp_gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height),
|
2012-03-23 01:40:40 +08:00
|
|
|
format);
|
2012-03-19 06:05:44 +08: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
|
|
|
|
{
|
2012-03-20 17:27:28 +08:00
|
|
|
GeglColor *gegl_color = gimp_gegl_color_new (color);
|
2012-03-19 06:05:44 +08:00
|
|
|
|
|
|
|
gegl_buffer_set_color (dest_buffer, NULL, gegl_color);
|
|
|
|
g_object_unref (gegl_color);
|
|
|
|
}
|
|
|
|
|
2012-03-23 01:40:40 +08:00
|
|
|
gimp_drawable_apply_buffer (drawable, dest_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,
|
|
|
|
opacity, paint_mode,
|
2012-03-24 07:57:11 +08:00
|
|
|
NULL, x, y);
|
2012-03-19 06:05:44 +08:00
|
|
|
|
2012-03-23 01:40:40 +08:00
|
|
|
g_object_unref (dest_buffer);
|
2012-03-19 06:05:44 +08:00
|
|
|
|
|
|
|
gimp_drawable_update (drawable, x, y, width, height);
|
|
|
|
|
|
|
|
return TRUE;
|
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)
|
2010-06-08 19:24:11 +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
|
|
|
|
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
|
|
|
}
|