1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
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
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/pixel-region.h"
|
2004-01-06 22:02:08 +08:00
|
|
|
#include "base/temp-buf.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/tile-manager.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
#include "base/tile-manager-crop.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
|
2001-04-07 23:58:26 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "gimp.h"
|
2003-09-16 01:26:28 +08:00
|
|
|
#include "gimp-edit.h"
|
2004-01-15 22:36:43 +08:00
|
|
|
#include "gimp-utils.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "gimpbuffer.h"
|
|
|
|
#include "gimpchannel.h"
|
|
|
|
#include "gimpcontext.h"
|
|
|
|
#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"
|
2004-12-12 22:01:08 +08:00
|
|
|
#include "gimpprojection.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 */
|
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
static GimpBuffer * gimp_edit_extract (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
gboolean cut_pixels);
|
|
|
|
static GimpBuffer * gimp_edit_extract_visible (GimpImage *gimage,
|
|
|
|
GimpContext *context);
|
|
|
|
static GimpBuffer * gimp_edit_make_buffer (Gimp *gimp,
|
|
|
|
TileManager *tiles,
|
|
|
|
gboolean mask_empty);
|
|
|
|
static gboolean gimp_edit_fill_internal (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpFillType fill_type,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpLayerModeEffects paint_mode,
|
|
|
|
const gchar *undo_desc);
|
2003-10-09 01:20:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2003-09-05 09:40:29 +08:00
|
|
|
const GimpBuffer *
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_edit_cut (GimpImage *gimage,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
GimpBuffer *buffer;
|
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
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);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
buffer = gimp_edit_extract (gimage, drawable, context, TRUE);
|
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
gimp_set_global_buffer (gimage->gimp, buffer);
|
|
|
|
g_object_unref (buffer);
|
|
|
|
|
|
|
|
return gimage->gimp->global_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2003-09-05 09:40:29 +08:00
|
|
|
const GimpBuffer *
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_edit_copy (GimpImage *gimage,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
GimpBuffer *buffer;
|
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
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);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
buffer = gimp_edit_extract (gimage, drawable, context, FALSE);
|
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
gimp_set_global_buffer (gimage->gimp, buffer);
|
|
|
|
g_object_unref (buffer);
|
|
|
|
|
|
|
|
return gimage->gimp->global_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2004-12-12 22:01:08 +08:00
|
|
|
const GimpBuffer *
|
|
|
|
gimp_edit_copy_visible (GimpImage *gimage,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
GimpBuffer *buffer;
|
2004-12-12 22:01:08 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
buffer = gimp_edit_extract_visible (gimage, context);
|
2004-12-12 22:01:08 +08:00
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
gimp_set_global_buffer (gimage->gimp, buffer);
|
|
|
|
g_object_unref (buffer);
|
2004-12-12 22:01:08 +08:00
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
return gimage->gimp->global_buffer;
|
|
|
|
}
|
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 *
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_edit_paste (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
2001-12-13 07:48:18 +08:00
|
|
|
GimpBuffer *paste,
|
2004-01-15 22:36:43 +08:00
|
|
|
gboolean paste_into,
|
|
|
|
gint viewport_x,
|
|
|
|
gint viewport_y,
|
|
|
|
gint viewport_width,
|
|
|
|
gint viewport_height)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-05-21 19:29:20 +08:00
|
|
|
GimpLayer *layer;
|
|
|
|
GimpImageType type;
|
2004-01-15 22:36:43 +08:00
|
|
|
gint center_x;
|
|
|
|
gint center_y;
|
2004-09-17 17:14:02 +08:00
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2000-02-11 05:54:12 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), 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)
|
|
|
|
type = gimp_drawable_type_with_alpha (drawable);
|
2000-01-16 17:34:45 +08:00
|
|
|
else
|
2002-05-21 19:29:20 +08:00
|
|
|
type = gimp_image_base_type_with_alpha (gimage);
|
|
|
|
|
2005-06-10 22:45:11 +08:00
|
|
|
layer = gimp_layer_new_from_tiles (paste->tiles, gimage, type,
|
2002-05-21 19:29:20 +08:00
|
|
|
_("Pasted Layer"),
|
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
|
|
|
|
have_mask = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
center_x = gimage->width / 2;
|
|
|
|
center_y = gimage->height / 2;
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-09-17 17:14:02 +08:00
|
|
|
width = gimp_item_width (GIMP_ITEM (layer));
|
|
|
|
height = gimp_item_height (GIMP_ITEM (layer));
|
|
|
|
|
|
|
|
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).
|
|
|
|
*/
|
|
|
|
offset_x = MIN (offset_x, gimage->width - width);
|
|
|
|
offset_y = MIN (offset_y, gimage->height - height);
|
|
|
|
offset_x = MAX (offset_x, 0);
|
|
|
|
offset_y = MAX (offset_y, 0);
|
|
|
|
|
|
|
|
GIMP_ITEM (layer)->offset_x = offset_x;
|
|
|
|
GIMP_ITEM (layer)->offset_y = offset_y;
|
2001-03-30 19:16:05 +08:00
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
/* Start a group undo */
|
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
|
|
|
|
_("Paste"));
|
|
|
|
|
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.
|
|
|
|
*/
|
2003-09-03 23:13:19 +08:00
|
|
|
if (! gimp_channel_is_empty (gimp_image_get_mask (gimage)) && ! paste_into)
|
removed the feather(), sharpen(), all(), invert(), border(), grow() and
2003-09-03 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-mask.[ch]: removed the feather(), sharpen(),
all(), invert(), border(), grow() and shrink() wrappers.
* app/core/gimpselection.[ch]: changed gimp_selection_invalidate()
and gimp_selection_push_undo() to take GimpChannel parameters, not
GimpSelection ones. They will be made virtual GimpChannel
functions anyway.
* app/core/gimpedit.c
* app/gui/select-commands.c
* app/widgets/gimpselectioneditor.c
* tools/pdbgen/pdb/selection.pdb: changed accordingly.
* app/pdb/selection_cmds.c: regenerated.
2003-09-03 21:37:49 +08:00
|
|
|
gimp_channel_clear (gimp_image_get_mask (gimage), 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
|
2003-12-10 00:20:31 +08:00
|
|
|
gimp_image_add_layer (gimage, layer, 0);
|
2000-02-11 05:54:12 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
/* end the group undo */
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_end (gimage);
|
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
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
GimpImage *
|
2001-12-13 07:48:18 +08:00
|
|
|
gimp_edit_paste_as_new (Gimp *gimp,
|
|
|
|
GimpImage *invoke,
|
|
|
|
GimpBuffer *paste)
|
1999-07-07 04:43:52 +08:00
|
|
|
{
|
2005-06-10 22:45:11 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
GimpLayer *layer;
|
|
|
|
GimpImageType type;
|
1999-07-07 04:43:52 +08:00
|
|
|
|
2003-12-16 20:41:17 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (invoke == NULL || GIMP_IS_IMAGE (invoke), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_BUFFER (paste), NULL);
|
|
|
|
|
2005-06-10 22:45:11 +08:00
|
|
|
switch (tile_manager_bpp (paste->tiles))
|
|
|
|
{
|
|
|
|
case 1: type = GIMP_GRAY_IMAGE; break;
|
|
|
|
case 2: type = GIMP_GRAYA_IMAGE; break;
|
|
|
|
case 3: type = GIMP_RGB_IMAGE; break;
|
|
|
|
case 4: type = GIMP_RGBA_IMAGE; break;
|
|
|
|
default:
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-11 23:58:07 +08:00
|
|
|
/* create a new image (always of type GIMP_RGB) */
|
2001-07-06 00:21:36 +08:00
|
|
|
gimage = gimp_create_image (gimp,
|
2003-09-06 01:44:39 +08:00
|
|
|
gimp_buffer_get_width (paste),
|
|
|
|
gimp_buffer_get_height (paste),
|
2005-06-10 22:45:11 +08:00
|
|
|
GIMP_IMAGE_TYPE_BASE_TYPE (type),
|
2001-07-06 00:21:36 +08:00
|
|
|
TRUE);
|
2000-12-30 08:16:50 +08:00
|
|
|
gimp_image_undo_disable (gimage);
|
2001-07-03 04:57:58 +08:00
|
|
|
|
|
|
|
if (invoke)
|
|
|
|
{
|
|
|
|
gimp_image_set_resolution (gimage,
|
|
|
|
invoke->xresolution, invoke->yresolution);
|
2004-10-13 05:28:53 +08:00
|
|
|
gimp_image_set_unit (gimage,
|
|
|
|
gimp_image_get_unit (invoke));
|
2001-07-03 04:57:58 +08:00
|
|
|
}
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2005-06-10 22:45:11 +08:00
|
|
|
layer = gimp_layer_new_from_tiles (paste->tiles, gimage, type,
|
2001-01-29 07:25:25 +08:00
|
|
|
_("Pasted Layer"),
|
2002-03-04 22:52:54 +08:00
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
|
1999-07-07 04:43:52 +08:00
|
|
|
|
2003-12-16 20:41:17 +08:00
|
|
|
if (! layer)
|
2000-01-16 00:32:02 +08:00
|
|
|
{
|
2003-12-16 20:41:17 +08:00
|
|
|
g_object_unref (gimage);
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-01-02 02:33:40 +08:00
|
|
|
|
2003-12-16 20:41:17 +08:00
|
|
|
gimp_image_add_layer (gimage, layer, 0);
|
2000-01-02 02:33:40 +08:00
|
|
|
|
2003-12-16 20:41:17 +08:00
|
|
|
gimp_image_undo_enable (gimage);
|
1999-07-07 04:43:52 +08:00
|
|
|
|
2003-12-16 20:41:17 +08:00
|
|
|
return gimage;
|
1999-07-07 04:43:52 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-09-03 06:50:06 +08:00
|
|
|
const gchar *
|
|
|
|
gimp_edit_named_cut (GimpImage *gimage,
|
|
|
|
const gchar *name,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
GimpBuffer *buffer;
|
2005-09-03 06:50:06 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
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);
|
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
buffer = gimp_edit_extract (gimage, drawable, context, TRUE);
|
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);
|
|
|
|
gimp_container_add (gimage->gimp->named_buffers, GIMP_OBJECT (buffer));
|
|
|
|
g_object_unref (buffer);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
return gimp_object_get_name (GIMP_OBJECT (buffer));
|
2005-09-03 06:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
gimp_edit_named_copy (GimpImage *gimage,
|
|
|
|
const gchar *name,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
GimpBuffer *buffer;
|
2005-09-03 06:50:06 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
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);
|
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
buffer = gimp_edit_extract (gimage, drawable, context, FALSE);
|
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);
|
|
|
|
gimp_container_add (gimage->gimp->named_buffers, GIMP_OBJECT (buffer));
|
|
|
|
g_object_unref (buffer);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
return gimp_object_get_name (GIMP_OBJECT (buffer));
|
2005-09-03 06:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
gimp_edit_named_copy_visible (GimpImage *gimage,
|
|
|
|
const gchar *name,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
2005-09-06 02:21:51 +08:00
|
|
|
GimpBuffer *buffer;
|
2005-09-03 06:50:06 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
buffer = gimp_edit_extract_visible (gimage, context);
|
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);
|
|
|
|
gimp_container_add (gimage->gimp->named_buffers, GIMP_OBJECT (buffer));
|
|
|
|
g_object_unref (buffer);
|
2005-09-03 06:50:06 +08:00
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
return gimp_object_get_name (GIMP_OBJECT (buffer));
|
2005-09-03 06:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-06-30 09:14:36 +08:00
|
|
|
gboolean
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_edit_clear (GimpImage *gimage,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
|
|
|
|
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
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
return gimp_edit_fill_internal (gimage, drawable, context,
|
2003-10-09 01:20:06 +08:00
|
|
|
GIMP_TRANSPARENT_FILL,
|
2005-07-12 23:11:40 +08:00
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_ERASE_MODE,
|
2003-10-09 01:20:06 +08:00
|
|
|
_("Clear"));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-06-30 09:14:36 +08:00
|
|
|
gboolean
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_edit_fill (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2001-06-30 03:25:03 +08:00
|
|
|
GimpFillType fill_type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-02-17 19:32:02 +08:00
|
|
|
const gchar *undo_desc;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
|
|
|
|
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:
|
2003-02-17 19:32:02 +08:00
|
|
|
undo_desc = _("Fill with FG Color");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_BACKGROUND_FILL:
|
2003-02-17 19:32:02 +08:00
|
|
|
undo_desc = _("Fill with BG Color");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_WHITE_FILL:
|
2003-02-17 19:32:02 +08:00
|
|
|
undo_desc = _("Fill with White");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-18 19:07:34 +08:00
|
|
|
case GIMP_TRANSPARENT_FILL:
|
2003-02-17 19:32:02 +08:00
|
|
|
undo_desc = _("Fill with Transparency");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
|
2004-01-06 22:02:08 +08:00
|
|
|
case GIMP_PATTERN_FILL:
|
|
|
|
undo_desc = _("Fill with Pattern");
|
|
|
|
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);
|
2003-10-09 01:20:06 +08:00
|
|
|
fill_type = GIMP_BACKGROUND_FILL;
|
2003-02-17 19:32:02 +08:00
|
|
|
undo_desc = _("Fill with BG Color");
|
2000-03-24 22:54:59 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
return gimp_edit_fill_internal (gimage, drawable, context,
|
2005-07-12 23:11:40 +08:00
|
|
|
fill_type,
|
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE,
|
|
|
|
undo_desc);
|
2003-10-09 01:20:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
static GimpBuffer *
|
2003-12-10 00:20:31 +08:00
|
|
|
gimp_edit_extract (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-12-10 00:20:31 +08:00
|
|
|
gboolean cut_pixels)
|
|
|
|
{
|
|
|
|
TileManager *tiles;
|
|
|
|
gboolean empty;
|
|
|
|
|
|
|
|
/* See if the gimage mask is empty */
|
|
|
|
empty = gimp_channel_is_empty (gimp_image_get_mask (gimage));
|
|
|
|
|
|
|
|
if (cut_pixels)
|
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_CUT, _("Cut"));
|
|
|
|
|
|
|
|
/* Cut/copy the mask portion from the gimage */
|
|
|
|
tiles = gimp_selection_extract (gimp_image_get_mask (gimage),
|
2005-06-10 22:45:11 +08:00
|
|
|
drawable, context, cut_pixels, FALSE, FALSE);
|
2003-12-10 00:20:31 +08:00
|
|
|
|
|
|
|
if (cut_pixels)
|
|
|
|
gimp_image_undo_group_end (gimage);
|
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
return gimp_edit_make_buffer (gimage->gimp, tiles, empty);
|
2004-12-29 06:42:04 +08:00
|
|
|
}
|
|
|
|
|
2005-09-06 02:21:51 +08:00
|
|
|
static GimpBuffer *
|
|
|
|
gimp_edit_extract_visible (GimpImage *gimage,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
|
|
|
PixelRegion srcPR, destPR;
|
|
|
|
TileManager *tiles;
|
|
|
|
gboolean non_empty;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
|
|
|
|
non_empty = gimp_channel_bounds (gimp_image_get_mask (gimage),
|
|
|
|
&x1, &y1, &x2, &y2);
|
|
|
|
if ((x1 == x2) || (y1 == y2))
|
|
|
|
{
|
|
|
|
g_message (_("Unable to cut or copy because the "
|
|
|
|
"selected region is empty."));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tiles = tile_manager_new (x2 - x1, y2 - y1,
|
|
|
|
gimp_projection_get_bytes (gimage->projection));
|
|
|
|
tile_manager_set_offsets (tiles, x1, y1);
|
|
|
|
|
|
|
|
pixel_region_init (&srcPR, gimp_projection_get_tiles (gimage->projection),
|
|
|
|
x1, y1,
|
|
|
|
x2 - x1, y2 - y1,
|
|
|
|
FALSE);
|
|
|
|
pixel_region_init (&destPR, tiles,
|
|
|
|
0, 0,
|
|
|
|
x2 - x1, y2 - y1,
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
/* use EEKy no-COW copying because sharing tiles with the projection
|
|
|
|
* is buggy as hell, probably because tile_invalidate() doesn't
|
|
|
|
* do what it should --mitch
|
|
|
|
*/
|
|
|
|
copy_region_nocow (&srcPR, &destPR);
|
|
|
|
|
|
|
|
return gimp_edit_make_buffer (gimage->gimp, tiles, ! non_empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpBuffer *
|
|
|
|
gimp_edit_make_buffer (Gimp *gimp,
|
|
|
|
TileManager *tiles,
|
|
|
|
gboolean mask_empty)
|
2004-12-29 06:42:04 +08:00
|
|
|
{
|
2004-03-08 06:28:21 +08:00
|
|
|
/* Only crop if the gimage mask wasn't empty */
|
2004-12-29 06:42:04 +08:00
|
|
|
if (tiles && ! mask_empty)
|
2003-12-10 00:20:31 +08:00
|
|
|
{
|
2004-03-08 06:28:21 +08:00
|
|
|
TileManager *crop = tile_manager_crop (tiles, 0);
|
2004-02-19 20:49:15 +08:00
|
|
|
|
2004-03-08 06:28:21 +08:00
|
|
|
if (crop != tiles)
|
2003-12-10 00:20:31 +08:00
|
|
|
{
|
2004-03-08 06:28:21 +08:00
|
|
|
tile_manager_unref (tiles);
|
|
|
|
tiles = crop;
|
2003-12-10 00:20:31 +08:00
|
|
|
}
|
2004-03-08 06:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tiles)
|
2005-09-06 02:21:51 +08:00
|
|
|
return gimp_buffer_new (tiles, _("Global Buffer"), FALSE);
|
2003-12-10 00:20:31 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-10-09 01:20:06 +08:00
|
|
|
static gboolean
|
2005-07-12 23:11:40 +08:00
|
|
|
gimp_edit_fill_internal (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpFillType fill_type,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpLayerModeEffects paint_mode,
|
|
|
|
const gchar *undo_desc)
|
2003-10-09 01:20:06 +08:00
|
|
|
{
|
|
|
|
TileManager *buf_tiles;
|
|
|
|
PixelRegion bufPR;
|
2004-10-20 06:52:04 +08:00
|
|
|
gint x, y, width, height;
|
2004-01-06 22:02:08 +08:00
|
|
|
gint tiles_bytes;
|
2003-10-09 01:20:06 +08:00
|
|
|
guchar col[MAX_CHANNELS];
|
2004-01-06 22:02:08 +08:00
|
|
|
TempBuf *pat_buf = NULL;
|
|
|
|
gboolean new_buf;
|
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
2004-01-06 22:02:08 +08:00
|
|
|
return TRUE; /* nothing to do, but the fill succeded */
|
|
|
|
|
|
|
|
tiles_bytes = gimp_drawable_bytes (drawable);
|
2003-10-09 01:20:06 +08:00
|
|
|
|
|
|
|
switch (fill_type)
|
|
|
|
{
|
|
|
|
case GIMP_FOREGROUND_FILL:
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_image_get_foreground (gimage, drawable, context, col);
|
2003-10-09 01:20:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_BACKGROUND_FILL:
|
|
|
|
case GIMP_TRANSPARENT_FILL:
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_image_get_background (gimage, drawable, context, col);
|
2003-10-09 01:20:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_WHITE_FILL:
|
2004-01-06 22:02:08 +08:00
|
|
|
{
|
|
|
|
guchar tmp_col[MAX_CHANNELS];
|
|
|
|
|
|
|
|
tmp_col[RED_PIX] = 255;
|
|
|
|
tmp_col[GREEN_PIX] = 255;
|
|
|
|
tmp_col[BLUE_PIX] = 255;
|
|
|
|
gimp_image_transform_color (gimage, drawable, col, GIMP_RGB, tmp_col);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PATTERN_FILL:
|
|
|
|
{
|
|
|
|
GimpPattern *pattern = gimp_context_get_pattern (context);
|
|
|
|
|
|
|
|
pat_buf = gimp_image_transform_temp_buf (gimage, drawable,
|
|
|
|
pattern->mask, &new_buf);
|
|
|
|
|
|
|
|
if (! gimp_drawable_has_alpha (drawable) &&
|
|
|
|
(pat_buf->bytes == 2 || pat_buf->bytes == 4))
|
|
|
|
tiles_bytes++;
|
|
|
|
}
|
2003-10-09 01:20:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_NO_FILL:
|
|
|
|
return TRUE; /* nothing to do, but the fill succeded */
|
|
|
|
}
|
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
buf_tiles = tile_manager_new (width, height, tiles_bytes);
|
2003-10-09 01:20:06 +08:00
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-01-06 22:02:08 +08:00
|
|
|
if (pat_buf)
|
|
|
|
{
|
|
|
|
pattern_region (&bufPR, NULL, pat_buf, 0, 0);
|
2001-03-30 19:16:05 +08:00
|
|
|
|
2004-01-06 22:02:08 +08:00
|
|
|
if (new_buf)
|
|
|
|
temp_buf_free (pat_buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gimp_drawable_has_alpha (drawable))
|
|
|
|
col[gimp_drawable_bytes (drawable) - 1] = OPAQUE_OPACITY;
|
2003-10-09 01:20:06 +08:00
|
|
|
|
2004-01-06 22:02:08 +08:00
|
|
|
color_region (&bufPR, col);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, FALSE);
|
2003-10-06 22:40:12 +08:00
|
|
|
gimp_drawable_apply_region (drawable, &bufPR,
|
|
|
|
TRUE, undo_desc,
|
2005-07-12 23:11:40 +08:00
|
|
|
opacity, paint_mode,
|
2004-10-20 06:52:04 +08:00
|
|
|
NULL, x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-05-27 01:02:06 +08:00
|
|
|
tile_manager_unref (buf_tiles);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-20 06:52:04 +08:00
|
|
|
gimp_drawable_update (drawable, x, y, width, height);
|
2003-10-09 01:20:06 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|