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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
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
|
|
|
|
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 "gimpcontext.h"
|
2019-01-02 07:14:35 +08:00
|
|
|
#include "gimpgrouplayer.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimpimage.h"
|
2017-05-02 01:10:52 +08:00
|
|
|
#include "gimpimage-duplicate.h"
|
2016-09-20 05:53:40 +08:00
|
|
|
#include "gimpimage-new.h"
|
2003-02-13 19:23:50 +08:00
|
|
|
#include "gimpimage-undo.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"
|
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-09-20 05:53:40 +08:00
|
|
|
GimpObject *
|
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
|
|
|
{
|
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
|
|
|
|
2016-09-20 05:53:40 +08:00
|
|
|
if (GIMP_IS_LAYER (drawable) &&
|
|
|
|
gimp_channel_is_empty (gimp_image_get_mask (image)))
|
|
|
|
{
|
|
|
|
GimpImage *clip_image;
|
2017-11-13 01:41:05 +08:00
|
|
|
gint off_x, off_y;
|
|
|
|
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
2005-09-06 02:21:51 +08:00
|
|
|
|
2016-09-20 05:53:40 +08:00
|
|
|
clip_image = gimp_image_new_from_drawable (image->gimp, drawable);
|
2017-11-13 01:41:05 +08:00
|
|
|
g_object_set_data (G_OBJECT (clip_image), "offset-x",
|
|
|
|
GINT_TO_POINTER (off_x));
|
|
|
|
g_object_set_data (G_OBJECT (clip_image), "offset-y",
|
|
|
|
GINT_TO_POINTER (off_y));
|
2016-09-20 05:53:40 +08:00
|
|
|
gimp_container_remove (image->gimp->images, GIMP_OBJECT (clip_image));
|
|
|
|
gimp_set_clipboard_image (image->gimp, clip_image);
|
|
|
|
g_object_unref (clip_image);
|
|
|
|
|
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_CUT,
|
|
|
|
C_("undo-type", "Cut Layer"));
|
|
|
|
|
|
|
|
gimp_image_remove_layer (image, GIMP_LAYER (drawable),
|
|
|
|
TRUE, NULL);
|
|
|
|
|
|
|
|
gimp_image_undo_group_end (image);
|
|
|
|
|
|
|
|
return GIMP_OBJECT (gimp_get_clipboard_image (image->gimp));
|
|
|
|
}
|
|
|
|
else
|
2005-09-06 02:21:51 +08:00
|
|
|
{
|
2016-09-20 05:53:40 +08:00
|
|
|
GimpBuffer *buffer;
|
2005-09-06 02:21:51 +08:00
|
|
|
|
2016-09-20 05:53:40 +08:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
|
|
|
|
context, TRUE, error);
|
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
gimp_set_clipboard_buffer (image->gimp, buffer);
|
|
|
|
g_object_unref (buffer);
|
|
|
|
|
|
|
|
return GIMP_OBJECT (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-09-20 05:53:40 +08:00
|
|
|
GimpObject *
|
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
|
|
|
{
|
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
|
|
|
|
2016-09-20 05:53:40 +08:00
|
|
|
if (GIMP_IS_LAYER (drawable) &&
|
|
|
|
gimp_channel_is_empty (gimp_image_get_mask (image)))
|
|
|
|
{
|
|
|
|
GimpImage *clip_image;
|
2017-11-13 01:41:05 +08:00
|
|
|
gint off_x, off_y;
|
|
|
|
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
2005-09-06 02:21:51 +08:00
|
|
|
|
2016-09-20 05:53:40 +08:00
|
|
|
clip_image = gimp_image_new_from_drawable (image->gimp, drawable);
|
2017-11-13 01:41:05 +08:00
|
|
|
g_object_set_data (G_OBJECT (clip_image), "offset-x",
|
|
|
|
GINT_TO_POINTER (off_x));
|
|
|
|
g_object_set_data (G_OBJECT (clip_image), "offset-y",
|
|
|
|
GINT_TO_POINTER (off_y));
|
2016-09-20 05:53:40 +08:00
|
|
|
gimp_container_remove (image->gimp->images, GIMP_OBJECT (clip_image));
|
|
|
|
gimp_set_clipboard_image (image->gimp, clip_image);
|
|
|
|
g_object_unref (clip_image);
|
|
|
|
|
|
|
|
return GIMP_OBJECT (gimp_get_clipboard_image (image->gimp));
|
|
|
|
}
|
|
|
|
else
|
2005-09-06 02:21:51 +08:00
|
|
|
{
|
2016-09-20 05:53:40 +08:00
|
|
|
GimpBuffer *buffer;
|
2005-09-06 02:21:51 +08:00
|
|
|
|
2016-09-20 05:53:40 +08:00
|
|
|
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
|
|
|
|
context, FALSE, error);
|
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
gimp_set_clipboard_buffer (image->gimp, buffer);
|
|
|
|
g_object_unref (buffer);
|
|
|
|
|
|
|
|
return GIMP_OBJECT (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
|
|
|
}
|
|
|
|
|
2018-03-25 00:43:30 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_edit_paste_is_in_place (GimpPasteType paste_type)
|
|
|
|
{
|
|
|
|
switch (paste_type)
|
|
|
|
{
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING:
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO:
|
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER:
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
|
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached (FALSE);
|
|
|
|
}
|
|
|
|
|
2019-05-25 23:05:49 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_edit_paste_is_floating (GimpPasteType paste_type)
|
|
|
|
{
|
|
|
|
switch (paste_type)
|
|
|
|
{
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING:
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO:
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER:
|
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached (FALSE);
|
|
|
|
}
|
|
|
|
|
2017-11-13 01:41:05 +08:00
|
|
|
static GimpLayer *
|
|
|
|
gimp_edit_paste_get_layer (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpObject *paste,
|
|
|
|
GimpPasteType *paste_type)
|
|
|
|
{
|
|
|
|
GimpLayer *layer = NULL;
|
|
|
|
const Babl *floating_format;
|
|
|
|
|
|
|
|
/* change paste type to NEW_LAYER for cases where we can't attach a
|
|
|
|
* floating selection
|
|
|
|
*/
|
|
|
|
if (! drawable ||
|
|
|
|
gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) ||
|
|
|
|
gimp_item_is_content_locked (GIMP_ITEM (drawable)))
|
|
|
|
{
|
2018-03-25 00:43:30 +08:00
|
|
|
if (gimp_edit_paste_is_in_place (*paste_type))
|
|
|
|
*paste_type = GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE;
|
|
|
|
else
|
|
|
|
*paste_type = GIMP_PASTE_TYPE_NEW_LAYER;
|
2017-11-13 01:41:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* floating pastes always have the pasted-to drawable's format with
|
|
|
|
* alpha; if drawable == NULL, user is pasting into an empty image
|
|
|
|
*/
|
2019-05-25 23:05:49 +08:00
|
|
|
if (drawable && gimp_edit_paste_is_floating (*paste_type))
|
2017-11-13 01:41:05 +08:00
|
|
|
floating_format = gimp_drawable_get_format_with_alpha (drawable);
|
|
|
|
else
|
|
|
|
floating_format = gimp_image_get_layer_format (image, TRUE);
|
|
|
|
|
|
|
|
if (GIMP_IS_IMAGE (paste))
|
|
|
|
{
|
|
|
|
GType layer_type;
|
|
|
|
|
|
|
|
layer = gimp_image_get_layer_iter (GIMP_IMAGE (paste))->data;
|
|
|
|
|
|
|
|
switch (*paste_type)
|
|
|
|
{
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING:
|
2018-02-11 06:46:58 +08:00
|
|
|
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
|
2017-11-13 01:41:05 +08:00
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO:
|
2018-02-11 06:46:58 +08:00
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
|
2019-01-02 07:14:35 +08:00
|
|
|
/* when pasting as floating make sure gimp_item_convert()
|
|
|
|
* will turn group layers into normal layers, otherwise use
|
|
|
|
* the same layer type so e.g. text information gets
|
|
|
|
* preserved. See issue #2667.
|
2017-11-13 01:41:05 +08:00
|
|
|
*/
|
2019-01-02 07:14:35 +08:00
|
|
|
if (GIMP_IS_GROUP_LAYER (layer))
|
|
|
|
layer_type = GIMP_TYPE_LAYER;
|
|
|
|
else
|
|
|
|
layer_type = G_TYPE_FROM_INSTANCE (layer);
|
2017-11-13 01:41:05 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER:
|
2018-02-11 06:46:58 +08:00
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
|
2017-11-13 01:41:05 +08:00
|
|
|
layer_type = G_TYPE_FROM_INSTANCE (layer);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (layer),
|
|
|
|
image, layer_type));
|
|
|
|
|
|
|
|
switch (*paste_type)
|
|
|
|
{
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING:
|
2018-02-11 06:57:45 +08:00
|
|
|
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
|
2017-11-13 01:41:05 +08:00
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO:
|
2018-02-11 06:57:45 +08:00
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
|
2017-11-13 01:41:05 +08:00
|
|
|
/* when pasting as floating selection, get rid of the layer mask,
|
|
|
|
* and make sure the layer has the right format
|
|
|
|
*/
|
|
|
|
if (gimp_layer_get_mask (layer))
|
|
|
|
gimp_layer_apply_mask (layer, GIMP_MASK_DISCARD, FALSE);
|
|
|
|
|
|
|
|
if (gimp_drawable_get_format (GIMP_DRAWABLE (layer)) !=
|
|
|
|
floating_format)
|
|
|
|
{
|
|
|
|
gimp_drawable_convert_type (GIMP_DRAWABLE (layer), image,
|
|
|
|
gimp_drawable_get_base_type (drawable),
|
|
|
|
gimp_drawable_get_precision (drawable),
|
|
|
|
TRUE,
|
2018-08-06 04:19:17 +08:00
|
|
|
NULL, NULL,
|
2017-11-13 01:41:05 +08:00
|
|
|
GEGL_DITHER_NONE, GEGL_DITHER_NONE,
|
|
|
|
FALSE, NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (GIMP_IS_BUFFER (paste))
|
|
|
|
{
|
|
|
|
layer = gimp_layer_new_from_buffer (GIMP_BUFFER (paste), image,
|
|
|
|
floating_format,
|
|
|
|
_("Pasted Layer"),
|
|
|
|
GIMP_OPACITY_OPAQUE,
|
|
|
|
gimp_image_get_default_new_layer_mode (image));
|
|
|
|
}
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_edit_paste_get_viewport_offset (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpObject *paste,
|
|
|
|
gint viewport_x,
|
|
|
|
gint viewport_y,
|
|
|
|
gint viewport_width,
|
|
|
|
gint viewport_height,
|
|
|
|
gint *offset_x,
|
|
|
|
gint *offset_y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2016-09-19 23:30:41 +08:00
|
|
|
gint image_width;
|
|
|
|
gint image_height;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gboolean clamp_to_image = TRUE;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
|
|
|
g_return_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (drawable == NULL ||
|
|
|
|
gimp_item_is_attached (GIMP_ITEM (drawable)));
|
|
|
|
g_return_if_fail (GIMP_IS_VIEWABLE (paste));
|
|
|
|
g_return_if_fail (offset_x != NULL);
|
|
|
|
g_return_if_fail (offset_y != 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);
|
|
|
|
|
2016-09-19 23:30:41 +08:00
|
|
|
gimp_viewable_get_size (GIMP_VIEWABLE (paste), &width, &height);
|
2012-07-30 22:20:11 +08:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
2016-09-21 15:22:30 +08:00
|
|
|
GimpContainer *children;
|
|
|
|
gint off_x, off_y;
|
|
|
|
gint target_x, target_y;
|
|
|
|
gint target_width, target_height;
|
|
|
|
gint paste_x, paste_y;
|
|
|
|
gint paste_width, paste_height;
|
|
|
|
gboolean have_mask;
|
2004-01-15 22:36:43 +08:00
|
|
|
|
2016-09-21 06:53:42 +08:00
|
|
|
have_mask = ! gimp_channel_is_empty (gimp_image_get_mask (image));
|
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
2016-09-21 15:22:30 +08:00
|
|
|
|
|
|
|
children = gimp_viewable_get_children (GIMP_VIEWABLE (drawable));
|
|
|
|
|
|
|
|
if (children && gimp_container_get_n_children (children) == 0)
|
|
|
|
{
|
|
|
|
/* treat empty layer groups as image-sized, use the selection
|
|
|
|
* as target
|
|
|
|
*/
|
|
|
|
gimp_item_bounds (GIMP_ITEM (gimp_image_get_mask (image)),
|
|
|
|
&target_x, &target_y,
|
|
|
|
&target_width, &target_height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_item_mask_intersect (GIMP_ITEM (drawable),
|
|
|
|
&target_x, &target_y,
|
|
|
|
&target_width, &target_height);
|
|
|
|
}
|
2004-01-15 22:36:43 +08:00
|
|
|
|
2016-09-21 06:53:42 +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 &&
|
2016-09-21 06:53:42 +08:00
|
|
|
(width < target_width || /* and the paste is smaller than the target */
|
|
|
|
height < target_height) &&
|
2012-07-30 22:20:11 +08:00
|
|
|
|
|
|
|
/* 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,
|
2016-09-21 06:53:42 +08:00
|
|
|
off_x, off_y, /* target_x,y are 0 */
|
|
|
|
target_width, target_height,
|
2004-01-15 22:36:43 +08:00
|
|
|
&paste_x, &paste_y,
|
|
|
|
&paste_width, &paste_height))
|
|
|
|
{
|
2012-07-30 22:20:11 +08:00
|
|
|
/* center on the viewport */
|
|
|
|
|
2016-09-19 23:30:41 +08:00
|
|
|
*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 */
|
|
|
|
|
2016-09-21 06:53:42 +08:00
|
|
|
*offset_x = off_x + target_x + (target_width - width) / 2;
|
|
|
|
*offset_y = off_y + target_y + (target_height - height) / 2;
|
2012-07-30 22:20:11 +08:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
2016-09-19 23:30:41 +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
|
|
|
|
2016-09-19 23:30:41 +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).
|
|
|
|
*/
|
2016-09-19 23:30:41 +08:00
|
|
|
*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);
|
2012-07-30 22:20:11 +08:00
|
|
|
}
|
2016-09-19 23:30:41 +08:00
|
|
|
}
|
|
|
|
|
2017-11-13 01:41:05 +08:00
|
|
|
static void
|
|
|
|
gimp_edit_paste_get_paste_offset (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpObject *paste,
|
|
|
|
gint *offset_x,
|
|
|
|
gint *offset_y)
|
2016-09-19 23:30:41 +08:00
|
|
|
{
|
2017-11-13 01:41:05 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
|
|
|
g_return_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (drawable == NULL ||
|
|
|
|
gimp_item_is_attached (GIMP_ITEM (drawable)));
|
|
|
|
g_return_if_fail (GIMP_IS_VIEWABLE (paste));
|
|
|
|
g_return_if_fail (offset_x != NULL);
|
|
|
|
g_return_if_fail (offset_y != NULL);
|
2016-10-05 01:49:57 +08:00
|
|
|
|
2016-09-20 05:53:40 +08:00
|
|
|
if (GIMP_IS_IMAGE (paste))
|
|
|
|
{
|
2017-11-13 01:41:05 +08:00
|
|
|
*offset_x = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (paste),
|
|
|
|
"offset-x"));
|
|
|
|
*offset_y = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (paste),
|
|
|
|
"offset-y"));
|
2016-09-20 05:53:40 +08:00
|
|
|
}
|
2016-10-05 01:49:57 +08:00
|
|
|
else if (GIMP_IS_BUFFER (paste))
|
2016-09-20 05:53:40 +08:00
|
|
|
{
|
2017-11-13 01:41:05 +08:00
|
|
|
GimpBuffer *buffer = GIMP_BUFFER (paste);
|
2016-09-19 23:30:41 +08:00
|
|
|
|
2017-11-13 01:41:05 +08:00
|
|
|
*offset_x = buffer->offset_x;
|
|
|
|
*offset_y = buffer->offset_y;
|
|
|
|
}
|
|
|
|
}
|
2016-09-19 23:30:41 +08:00
|
|
|
|
2017-11-13 01:41:05 +08:00
|
|
|
static GimpLayer *
|
|
|
|
gimp_edit_paste_paste (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpLayer *layer,
|
|
|
|
GimpPasteType paste_type,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
|
|
|
{
|
2017-03-17 17:10:07 +08:00
|
|
|
gimp_item_translate (GIMP_ITEM (layer), offset_x, offset_y, FALSE);
|
2001-03-30 19:16:05 +08:00
|
|
|
|
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
|
|
|
|
2016-09-20 05:53:40 +08:00
|
|
|
switch (paste_type)
|
|
|
|
{
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING:
|
2017-11-13 01:41:05 +08:00
|
|
|
case GIMP_PASTE_TYPE_FLOATING_IN_PLACE:
|
2016-10-05 01:49:57 +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
|
2016-09-20 05:53:40 +08:00
|
|
|
*/
|
|
|
|
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
|
|
|
|
gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-09-20 05:53:40 +08:00
|
|
|
/* fall thru */
|
|
|
|
|
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO:
|
2017-11-13 01:41:05 +08:00
|
|
|
case GIMP_PASTE_TYPE_FLOATING_INTO_IN_PLACE:
|
2016-09-20 05:53:40 +08:00
|
|
|
floating_sel_attach (layer, drawable);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER:
|
2017-11-13 01:41:05 +08:00
|
|
|
case GIMP_PASTE_TYPE_NEW_LAYER_IN_PLACE:
|
2016-09-21 17:15:34 +08:00
|
|
|
{
|
|
|
|
GimpLayer *parent = NULL;
|
|
|
|
gint position = 0;
|
|
|
|
|
2017-11-13 01:41:05 +08:00
|
|
|
/* always add on top of a passed layer, where we would attach
|
|
|
|
* a floating selection
|
2016-09-21 17:15:34 +08:00
|
|
|
*/
|
|
|
|
if (GIMP_IS_LAYER (drawable))
|
|
|
|
{
|
|
|
|
parent = gimp_layer_get_parent (GIMP_LAYER (drawable));
|
|
|
|
position = gimp_item_get_index (GIMP_ITEM (drawable));
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_image_add_layer (image, layer, parent, position, TRUE);
|
|
|
|
}
|
2016-09-20 05:53:40 +08:00
|
|
|
break;
|
|
|
|
}
|
2000-02-11 05:54:12 +08:00
|
|
|
|
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
|
|
|
|
2017-11-13 01:41:05 +08:00
|
|
|
GimpLayer *
|
|
|
|
gimp_edit_paste (GimpImage *image,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpObject *paste,
|
|
|
|
GimpPasteType paste_type,
|
|
|
|
gint viewport_x,
|
|
|
|
gint viewport_y,
|
|
|
|
gint viewport_width,
|
|
|
|
gint viewport_height)
|
|
|
|
{
|
|
|
|
GimpLayer *layer;
|
|
|
|
gint offset_x = 0;
|
|
|
|
gint offset_y = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
g_return_val_if_fail (drawable == NULL ||
|
|
|
|
gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (paste) || GIMP_IS_BUFFER (paste), NULL);
|
|
|
|
|
|
|
|
layer = gimp_edit_paste_get_layer (image, drawable, paste, &paste_type);
|
|
|
|
|
|
|
|
if (! layer)
|
|
|
|
return NULL;
|
|
|
|
|
2018-03-25 00:43:30 +08:00
|
|
|
if (gimp_edit_paste_is_in_place (paste_type))
|
|
|
|
{
|
|
|
|
gimp_edit_paste_get_paste_offset (image, drawable, paste,
|
|
|
|
&offset_x,
|
|
|
|
&offset_y);
|
|
|
|
}
|
|
|
|
else
|
2017-11-13 01:41:05 +08:00
|
|
|
{
|
|
|
|
gimp_edit_paste_get_viewport_offset (image, drawable, GIMP_OBJECT (layer),
|
|
|
|
viewport_x,
|
|
|
|
viewport_y,
|
|
|
|
viewport_width,
|
|
|
|
viewport_height,
|
|
|
|
&offset_x,
|
|
|
|
&offset_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gimp_edit_paste_paste (image, drawable, layer, paste_type,
|
|
|
|
offset_x, offset_y);
|
|
|
|
}
|
|
|
|
|
2017-05-02 01:10:52 +08:00
|
|
|
GimpImage *
|
|
|
|
gimp_edit_paste_as_new_image (Gimp *gimp,
|
|
|
|
GimpObject *paste)
|
|
|
|
{
|
|
|
|
GimpImage *image = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (paste) || GIMP_IS_BUFFER (paste), NULL);
|
|
|
|
|
|
|
|
if (GIMP_IS_IMAGE (paste))
|
|
|
|
{
|
|
|
|
image = gimp_image_duplicate (GIMP_IMAGE (paste));
|
|
|
|
}
|
|
|
|
else if (GIMP_IS_BUFFER (paste))
|
|
|
|
{
|
|
|
|
image = gimp_image_new_from_buffer (gimp, GIMP_BUFFER (paste));
|
|
|
|
}
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-05-02 00:36:33 +08:00
|
|
|
GimpBuffer *gimp_buffer;
|
|
|
|
gdouble res_x;
|
|
|
|
gdouble res_y;
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-05-02 00:36:33 +08:00
|
|
|
gimp_image_get_resolution (image, &res_x, &res_y);
|
|
|
|
gimp_buffer_set_resolution (gimp_buffer, res_x, res_y);
|
|
|
|
gimp_buffer_set_unit (gimp_buffer, gimp_image_get_unit (image));
|
|
|
|
|
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
|
|
|
}
|