2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-11-08 19:14:51 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-11-08 19:14:51 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-11-08 19:14:51 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-17 22:28:01 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-11-08 19:14:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-05-23 14:09:55 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-04-28 13:50:39 +00:00
|
|
|
#include <cairo.h>
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2001-11-08 19:14:51 +00:00
|
|
|
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/temp-buf.h"
|
|
|
|
#include "base/tile-manager.h"
|
|
|
|
|
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-11-20 13:53:21 +00:00
|
|
|
#include "gimp.h"
|
|
|
|
#include "gimpchannel.h"
|
2003-09-04 12:18:40 +00:00
|
|
|
#include "gimpchannel-combine.h"
|
2001-11-20 13:53:21 +00:00
|
|
|
#include "gimpcontext.h"
|
|
|
|
#include "gimpdrawable.h"
|
|
|
|
#include "gimpdrawable-bucket-fill.h"
|
2008-11-12 10:56:06 +00:00
|
|
|
#include "gimperror.h"
|
2001-11-20 13:53:21 +00:00
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpimage-contiguous-region.h"
|
|
|
|
#include "gimppattern.h"
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2001-11-08 19:14:51 +00:00
|
|
|
|
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
static void gimp_drawable_bucket_fill_internal (GimpDrawable *drawable,
|
|
|
|
GimpBucketFillMode fill_mode,
|
|
|
|
gint paint_mode,
|
|
|
|
gdouble opacity,
|
|
|
|
gboolean fill_transparent,
|
|
|
|
GimpSelectCriterion fill_criterion,
|
|
|
|
gdouble threshold,
|
|
|
|
gboolean sample_merged,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpPattern *pattern);
|
|
|
|
|
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
/* public functions */
|
|
|
|
|
2007-12-06 19:07:11 +00:00
|
|
|
gboolean
|
|
|
|
gimp_drawable_bucket_fill (GimpDrawable *drawable,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpBucketFillMode fill_mode,
|
|
|
|
gint paint_mode,
|
|
|
|
gdouble opacity,
|
|
|
|
gboolean fill_transparent,
|
|
|
|
GimpSelectCriterion fill_criterion,
|
|
|
|
gdouble threshold,
|
|
|
|
gboolean sample_merged,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GError **error)
|
2001-11-08 19:14:51 +00:00
|
|
|
{
|
|
|
|
GimpRGB color;
|
|
|
|
GimpPattern *pattern = NULL;
|
|
|
|
|
2007-12-06 19:07:11 +00:00
|
|
|
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 (GIMP_IS_CONTEXT (context), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2002-03-18 11:07:34 +00:00
|
|
|
if (fill_mode == GIMP_FG_BUCKET_FILL)
|
2001-11-08 19:14:51 +00:00
|
|
|
{
|
2004-04-14 23:37:34 +00:00
|
|
|
gimp_context_get_foreground (context, &color);
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
2002-03-18 11:07:34 +00:00
|
|
|
else if (fill_mode == GIMP_BG_BUCKET_FILL)
|
2001-11-08 19:14:51 +00:00
|
|
|
{
|
2004-04-14 23:37:34 +00:00
|
|
|
gimp_context_get_background (context, &color);
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
2002-03-18 11:07:34 +00:00
|
|
|
else if (fill_mode == GIMP_PATTERN_BUCKET_FILL)
|
2001-11-08 19:14:51 +00:00
|
|
|
{
|
2004-04-14 23:37:34 +00:00
|
|
|
pattern = gimp_context_get_pattern (context);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
|
|
|
if (! pattern)
|
2006-04-12 12:49:29 +00:00
|
|
|
{
|
2008-11-12 10:56:06 +00:00
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2008-11-04 12:33:09 +00:00
|
|
|
_("No patterns available for this operation."));
|
2007-12-06 19:07:11 +00:00
|
|
|
return FALSE;
|
2006-04-12 12:49:29 +00:00
|
|
|
}
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-12 08:13:33 +00:00
|
|
|
g_warning ("%s: invalid fill_mode passed", G_STRFUNC);
|
2007-12-06 19:07:11 +00:00
|
|
|
return FALSE;
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
gimp_drawable_bucket_fill_internal (drawable,
|
|
|
|
fill_mode,
|
|
|
|
paint_mode, opacity,
|
|
|
|
fill_transparent, fill_criterion,
|
|
|
|
threshold, sample_merged,
|
|
|
|
x, y,
|
|
|
|
&color, pattern);
|
2007-12-06 19:07:11 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_bucket_fill_internal (GimpDrawable *drawable,
|
|
|
|
GimpBucketFillMode fill_mode,
|
|
|
|
gint paint_mode,
|
|
|
|
gdouble opacity,
|
|
|
|
gboolean fill_transparent,
|
|
|
|
GimpSelectCriterion fill_criterion,
|
|
|
|
gdouble threshold,
|
|
|
|
gboolean sample_merged,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpPattern *pattern)
|
2001-11-08 19:14:51 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image;
|
2001-11-08 19:14:51 +00:00
|
|
|
TileManager *buf_tiles;
|
|
|
|
PixelRegion bufPR, maskPR;
|
|
|
|
GimpChannel *mask = NULL;
|
|
|
|
gint bytes;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
guchar col[MAX_CHANNELS];
|
|
|
|
TempBuf *pat_buf = NULL;
|
|
|
|
gboolean new_buf = FALSE;
|
2002-09-05 13:36:30 +00:00
|
|
|
gboolean selection;
|
2001-11-08 19:14:51 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
2004-11-11 14:05:34 +00:00
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
2002-03-18 11:07:34 +00:00
|
|
|
g_return_if_fail (fill_mode != GIMP_PATTERN_BUCKET_FILL ||
|
2001-11-08 19:14:51 +00:00
|
|
|
GIMP_IS_PATTERN (pattern));
|
2003-09-27 20:42:31 +00:00
|
|
|
g_return_if_fail (fill_mode == GIMP_PATTERN_BUCKET_FILL ||
|
|
|
|
color != NULL);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
image = gimp_item_get_image (GIMP_ITEM (drawable));
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2004-10-19 22:52:04 +00:00
|
|
|
bytes = gimp_drawable_bytes (drawable);
|
2010-09-07 19:28:00 +00:00
|
|
|
selection = gimp_item_mask_bounds (GIMP_ITEM (drawable), &x1, &y1, &x2, &y2);
|
2004-10-19 22:52:04 +00:00
|
|
|
|
|
|
|
if ((x1 == x2) || (y1 == y2))
|
|
|
|
return;
|
|
|
|
|
2002-03-18 11:07:34 +00:00
|
|
|
if (fill_mode == GIMP_FG_BUCKET_FILL ||
|
|
|
|
fill_mode == GIMP_BG_BUCKET_FILL)
|
2001-11-08 19:14:51 +00:00
|
|
|
{
|
2012-03-15 23:02:27 +00:00
|
|
|
gimp_image_transform_rgb (image, gimp_drawable_type (drawable),
|
|
|
|
color, col);
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
2002-03-18 11:07:34 +00:00
|
|
|
else if (fill_mode == GIMP_PATTERN_BUCKET_FILL)
|
2001-11-08 19:14:51 +00:00
|
|
|
{
|
2006-10-25 22:14:36 +00:00
|
|
|
pat_buf = gimp_image_transform_temp_buf (image,
|
|
|
|
gimp_drawable_type (drawable),
|
2003-09-27 20:04:07 +00:00
|
|
|
pattern->mask, &new_buf);
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-12 08:13:33 +00:00
|
|
|
g_warning ("%s: invalid fill_mode passed", G_STRFUNC);
|
2001-11-08 19:14:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_set_busy (image->gimp);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2003-09-27 20:04:07 +00:00
|
|
|
/* Do a seed bucket fill...To do this, calculate a new
|
|
|
|
* contiguous region. If there is a selection, calculate the
|
2002-09-04 18:32:17 +00:00
|
|
|
* intersection of this region with the existing selection.
|
2001-11-08 19:14:51 +00:00
|
|
|
*/
|
2012-03-18 22:15:02 +00:00
|
|
|
mask = gimp_image_contiguous_region_by_seed (image, drawable,
|
|
|
|
sample_merged,
|
|
|
|
TRUE,
|
|
|
|
(gint) threshold,
|
|
|
|
fill_transparent,
|
|
|
|
fill_criterion,
|
|
|
|
(gint) x,
|
|
|
|
(gint) y);
|
|
|
|
|
|
|
|
if (selection)
|
2001-11-08 19:14:51 +00:00
|
|
|
{
|
2012-03-18 22:15:02 +00:00
|
|
|
gint off_x = 0;
|
|
|
|
gint off_y = 0;
|
2002-09-04 18:32:17 +00:00
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
if (! sample_merged)
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
2002-09-05 13:36:30 +00:00
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
gimp_channel_combine_mask (mask, gimp_image_get_mask (image),
|
|
|
|
GIMP_CHANNEL_OP_INTERSECT,
|
|
|
|
-off_x, -off_y);
|
|
|
|
}
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
gimp_channel_bounds (mask, &x1, &y1, &x2, &y2);
|
2003-05-08 13:12:46 +00:00
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
/* make sure we handle the mask correctly if it was sample-merged */
|
|
|
|
if (sample_merged)
|
|
|
|
{
|
|
|
|
GimpItem *item;
|
|
|
|
gint off_x, off_y;
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
item = GIMP_ITEM (drawable);
|
2003-05-08 13:12:46 +00:00
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
/* Limit the channel bounds to the drawable's extents */
|
|
|
|
gimp_item_get_offset (item, &off_x, &off_y);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
x1 = CLAMP (x1, off_x, (off_x + gimp_item_get_width (item)));
|
|
|
|
y1 = CLAMP (y1, off_y, (off_y + gimp_item_get_height (item)));
|
|
|
|
x2 = CLAMP (x2, off_x, (off_x + gimp_item_get_width (item)));
|
|
|
|
y2 = CLAMP (y2, off_y, (off_y + gimp_item_get_height (item)));
|
2006-04-12 12:49:29 +00:00
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
pixel_region_init (&maskPR,
|
|
|
|
gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)),
|
|
|
|
x1, y1, (x2 - x1), (y2 - y1), TRUE);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
/* translate mask bounds to drawable coords */
|
|
|
|
x1 -= off_x;
|
|
|
|
y1 -= off_y;
|
|
|
|
x2 -= off_x;
|
|
|
|
y2 -= off_y;
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|
2012-03-18 22:15:02 +00:00
|
|
|
else
|
2003-07-03 22:25:58 +00:00
|
|
|
{
|
2012-03-18 22:15:02 +00:00
|
|
|
pixel_region_init (&maskPR,
|
|
|
|
gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)),
|
|
|
|
x1, y1, (x2 - x1), (y2 - y1), TRUE);
|
2003-07-03 22:25:58 +00:00
|
|
|
}
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2012-03-18 22:15:02 +00:00
|
|
|
/* if the image doesn't have an alpha channel, make sure that
|
|
|
|
* the buf_tiles have. We need the alpha channel to fill with
|
|
|
|
* the region calculated above
|
|
|
|
*/
|
|
|
|
if (! gimp_drawable_has_alpha (drawable))
|
|
|
|
bytes++;
|
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
buf_tiles = tile_manager_new ((x2 - x1), (y2 - y1), bytes);
|
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), TRUE);
|
|
|
|
|
2003-09-27 20:04:07 +00:00
|
|
|
switch (fill_mode)
|
|
|
|
{
|
|
|
|
case GIMP_FG_BUCKET_FILL:
|
|
|
|
case GIMP_BG_BUCKET_FILL:
|
2012-03-18 22:15:02 +00:00
|
|
|
color_region_mask (&bufPR, &maskPR, col);
|
2003-09-27 20:04:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PATTERN_BUCKET_FILL:
|
2012-03-18 22:15:02 +00:00
|
|
|
pattern_region (&bufPR, &maskPR, pat_buf, x1, y1);
|
2003-09-27 20:04:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-11-08 19:14:51 +00:00
|
|
|
|
|
|
|
/* Apply it to the image */
|
|
|
|
pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), FALSE);
|
2003-10-06 14:40:12 +00:00
|
|
|
gimp_drawable_apply_region (drawable, &bufPR,
|
2010-06-08 11:24:11 +00:00
|
|
|
TRUE, C_("undo-type", "Bucket Fill"),
|
2003-10-06 14:40:12 +00:00
|
|
|
opacity, paint_mode,
|
2008-11-08 19:52:18 +00:00
|
|
|
NULL, NULL, x1, y1);
|
2003-05-26 17:02:06 +00:00
|
|
|
tile_manager_unref (buf_tiles);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2003-10-06 14:40:12 +00:00
|
|
|
gimp_drawable_update (drawable, x1, y1, x2 - x1, y2 - y1);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
|
|
|
/* free the mask */
|
2012-03-18 22:15:02 +00:00
|
|
|
g_object_unref (mask);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
|
|
|
if (new_buf)
|
|
|
|
temp_buf_free (pat_buf);
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_unset_busy (image->gimp);
|
2001-11-08 19:14:51 +00:00
|
|
|
}
|