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"
|
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 */
|
|
|
|
|
2003-12-10 00:20:31 +08:00
|
|
|
static const GimpBuffer * 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);
|
|
|
|
static gboolean gimp_edit_fill_internal (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
2004-01-06 22:02:08 +08:00
|
|
|
GimpContext *context,
|
2003-12-10 00:20:31 +08:00
|
|
|
GimpFillType fill_type,
|
|
|
|
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
|
|
|
{
|
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-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
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
return gimp_edit_extract (gimage, drawable, context, TRUE);
|
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
|
|
|
{
|
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-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
|
|
|
|
2004-04-15 07:37:34 +08:00
|
|
|
return gimp_edit_extract (gimage, drawable, context, FALSE);
|
1997-11-25 06:05:25 +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;
|
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);
|
|
|
|
|
|
|
|
layer = gimp_layer_new_from_tiles (paste->tiles,
|
|
|
|
gimage,
|
|
|
|
type,
|
|
|
|
_("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-06-26 20:09:43 +08:00
|
|
|
/* Start a group undo */
|
2003-02-13 19:23:50 +08:00
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE,
|
|
|
|
_("Paste"));
|
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-01-15 22:36:43 +08:00
|
|
|
GIMP_ITEM (layer)->offset_x = center_x - (GIMP_ITEM (layer)->width / 2);
|
|
|
|
GIMP_ITEM (layer)->offset_y = center_y - (GIMP_ITEM (layer)->height / 2);
|
2001-03-30 19:16:05 +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.
|
|
|
|
*/
|
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
|
|
|
{
|
2004-06-02 06:04:20 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
GimpLayer *layer;
|
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);
|
|
|
|
|
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),
|
2001-12-11 23:58:07 +08:00
|
|
|
GIMP_RGB,
|
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);
|
|
|
|
gimp_image_set_unit (gimage, invoke->unit);
|
|
|
|
}
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2002-02-26 01:58:50 +08:00
|
|
|
layer = gimp_layer_new_from_tiles (paste->tiles,
|
|
|
|
gimage,
|
2002-05-21 19:29:20 +08:00
|
|
|
gimp_image_base_type_with_alpha (gimage),
|
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
|
|
|
|
2004-08-09 06:47:23 +08:00
|
|
|
gimp_create_display (gimp, gimage, GIMP_UNIT_PIXEL, 1.0);
|
2003-12-16 20:41:17 +08:00
|
|
|
g_object_unref (gimage);
|
2000-02-11 05:54:12 +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
|
|
|
|
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-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,
|
|
|
|
_("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-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,
|
2004-01-06 22:02:08 +08:00
|
|
|
fill_type, undo_desc);
|
2003-10-09 01:20:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2003-12-10 00:20:31 +08:00
|
|
|
const GimpBuffer *
|
|
|
|
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),
|
2004-04-15 07:37:34 +08:00
|
|
|
drawable, context, cut_pixels, FALSE, TRUE);
|
2003-12-10 00:20:31 +08:00
|
|
|
|
|
|
|
if (cut_pixels)
|
|
|
|
gimp_image_undo_group_end (gimage);
|
|
|
|
|
2004-03-08 06:28:21 +08:00
|
|
|
/* Only crop if the gimage mask wasn't empty */
|
|
|
|
if (tiles && ! 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)
|
|
|
|
{
|
|
|
|
GimpBuffer *buffer = gimp_buffer_new (tiles, "Global Buffer", FALSE);
|
2003-12-10 00:20:31 +08:00
|
|
|
|
2004-02-19 20:49:15 +08:00
|
|
|
gimp_set_global_buffer (gimage->gimp, buffer);
|
|
|
|
g_object_unref (buffer);
|
2003-12-10 00:20:31 +08:00
|
|
|
|
|
|
|
return gimage->gimp->global_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-10-09 01:20:06 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_edit_fill_internal (GimpImage *gimage,
|
|
|
|
GimpDrawable *drawable,
|
2004-01-06 22:02:08 +08:00
|
|
|
GimpContext *context,
|
2003-10-09 01:20:06 +08:00
|
|
|
GimpFillType fill_type,
|
|
|
|
const gchar *undo_desc)
|
|
|
|
{
|
|
|
|
TileManager *buf_tiles;
|
|
|
|
PixelRegion bufPR;
|
|
|
|
gint x1, y1, x2, y2;
|
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;
|
|
|
|
|
|
|
|
gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
|
|
|
|
|
|
|
if (x1 == x2 || y1 == y2)
|
|
|
|
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-01-06 22:02:08 +08:00
|
|
|
buf_tiles = tile_manager_new (x2 - x1, y2 - y1, tiles_bytes);
|
2003-10-09 01:20:06 +08:00
|
|
|
|
2004-01-06 22:02:08 +08:00
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, x2 - x1, y2 - y1, 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
|
|
|
|
2003-10-09 01:20:06 +08:00
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, x2 - x1, y2 - y1, FALSE);
|
2003-10-06 22:40:12 +08:00
|
|
|
gimp_drawable_apply_region (drawable, &bufPR,
|
|
|
|
TRUE, undo_desc,
|
2003-10-09 01:20:06 +08:00
|
|
|
GIMP_OPACITY_OPAQUE,
|
|
|
|
(fill_type == GIMP_TRANSPARENT_FILL) ?
|
|
|
|
GIMP_ERASE_MODE : GIMP_NORMAL_MODE,
|
2003-10-06 22:40:12 +08:00
|
|
|
NULL, x1, y1);
|
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
|
|
|
|
2003-10-09 01:20:06 +08:00
|
|
|
gimp_drawable_update (drawable, x1, y1, x2 - x1, y2 - y1);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|