2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-10-06 14:40:12 +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
|
2003-10-06 14:40:12 +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
|
2003-10-06 14:40:12 +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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-10-06 14:40:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2019-03-27 12:29:25 -04:00
|
|
|
#include <cairo.h>
|
2013-10-15 01:58:39 +02:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2003-10-06 14:40:12 +00:00
|
|
|
|
2012-03-23 00:32:01 +01:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2003-10-06 14:40:12 +00:00
|
|
|
#include "core-types.h"
|
|
|
|
|
2013-04-17 14:24:33 +02:00
|
|
|
#include "gegl/gimpapplicator.h"
|
2012-03-22 23:45:11 +01:00
|
|
|
|
2012-04-06 21:56:55 +02:00
|
|
|
#include "gimp.h"
|
2003-10-06 14:40:12 +00:00
|
|
|
#include "gimpchannel.h"
|
2019-03-27 12:29:25 -04:00
|
|
|
#include "gimpchunkiterator.h"
|
2003-10-06 14:40:12 +00:00
|
|
|
#include "gimpdrawable-combine.h"
|
|
|
|
#include "gimpimage.h"
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-02-02 00:38:25 +01:00
|
|
|
gimp_drawable_real_apply_buffer (GimpDrawable *drawable,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
const GeglRectangle *buffer_region,
|
|
|
|
gboolean push_undo,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpLayerMode mode,
|
2017-02-12 23:49:26 +01:00
|
|
|
GimpLayerColorSpace blend_space,
|
|
|
|
GimpLayerColorSpace composite_space,
|
|
|
|
GimpLayerCompositeMode composite_mode,
|
2017-02-02 00:38:25 +01:00
|
|
|
GeglBuffer *base_buffer,
|
|
|
|
gint base_x,
|
|
|
|
gint base_y)
|
2003-10-06 14:40:12 +00:00
|
|
|
{
|
2013-04-17 14:24:33 +02:00
|
|
|
GimpItem *item = GIMP_ITEM (drawable);
|
|
|
|
GimpImage *image = gimp_item_get_image (item);
|
|
|
|
GimpChannel *mask = gimp_image_get_mask (image);
|
|
|
|
GimpApplicator *applicator;
|
2019-03-27 12:29:25 -04:00
|
|
|
GimpChunkIterator *iter;
|
2012-05-19 00:14:51 +02:00
|
|
|
gint x, y, width, height;
|
|
|
|
gint offset_x, offset_y;
|
2012-03-23 00:12:13 +01:00
|
|
|
|
2003-10-06 14:40:12 +00:00
|
|
|
/* don't apply the mask to itself and don't apply an empty mask */
|
|
|
|
if (GIMP_DRAWABLE (mask) == drawable || gimp_channel_is_empty (mask))
|
|
|
|
mask = NULL;
|
|
|
|
|
2012-04-06 21:56:55 +02:00
|
|
|
if (! base_buffer)
|
|
|
|
base_buffer = gimp_drawable_get_buffer (drawable);
|
2003-10-06 14:40:12 +00:00
|
|
|
|
|
|
|
/* get the layer offsets */
|
2008-11-02 23:03:29 +00:00
|
|
|
gimp_item_get_offset (item, &offset_x, &offset_y);
|
2003-10-06 14:40:12 +00:00
|
|
|
|
2007-10-23 11:19:08 +00:00
|
|
|
/* make sure the image application coordinates are within drawable bounds */
|
2018-09-29 10:24:53 -04:00
|
|
|
if (! gimp_rectangle_intersect (base_x, base_y,
|
|
|
|
buffer_region->width, buffer_region->height,
|
|
|
|
0, 0,
|
|
|
|
gimp_item_get_width (item),
|
|
|
|
gimp_item_get_height (item),
|
|
|
|
&x, &y, &width, &height))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2003-10-06 14:40:12 +00:00
|
|
|
|
|
|
|
if (mask)
|
|
|
|
{
|
2008-11-08 17:20:34 +00:00
|
|
|
GimpItem *mask_item = GIMP_ITEM (mask);
|
|
|
|
|
2003-10-06 14:40:12 +00:00
|
|
|
/* make sure coordinates are in mask bounds ...
|
|
|
|
* we need to add the layer offset to transform coords
|
|
|
|
* into the mask coordinate system
|
|
|
|
*/
|
2018-09-29 10:24:53 -04:00
|
|
|
if (! gimp_rectangle_intersect (x, y, width, height,
|
|
|
|
-offset_x, -offset_y,
|
|
|
|
gimp_item_get_width (mask_item),
|
|
|
|
gimp_item_get_height (mask_item),
|
|
|
|
&x, &y, &width, &height))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2003-10-06 14:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (push_undo)
|
2006-10-21 18:46:49 +00:00
|
|
|
{
|
2009-06-16 22:59:07 +02:00
|
|
|
gimp_drawable_push_undo (drawable, undo_desc,
|
2012-03-23 00:32:01 +01:00
|
|
|
NULL, x, y, width, height);
|
2006-10-21 18:46:49 +00:00
|
|
|
}
|
2003-10-06 14:40:12 +00:00
|
|
|
|
2018-12-29 14:12:51 -05:00
|
|
|
applicator = gimp_applicator_new (NULL);
|
2013-04-17 14:24:33 +02:00
|
|
|
|
2012-05-06 04:39:23 +02:00
|
|
|
if (mask)
|
2013-04-17 14:24:33 +02:00
|
|
|
{
|
|
|
|
GeglBuffer *mask_buffer;
|
|
|
|
|
|
|
|
mask_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask));
|
|
|
|
|
|
|
|
gimp_applicator_set_mask_buffer (applicator, mask_buffer);
|
|
|
|
gimp_applicator_set_mask_offset (applicator, -offset_x, -offset_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_applicator_set_src_buffer (applicator, base_buffer);
|
|
|
|
gimp_applicator_set_dest_buffer (applicator,
|
|
|
|
gimp_drawable_get_buffer (drawable));
|
|
|
|
|
|
|
|
gimp_applicator_set_apply_buffer (applicator, buffer);
|
|
|
|
gimp_applicator_set_apply_offset (applicator,
|
|
|
|
base_x - buffer_region->x,
|
|
|
|
base_y - buffer_region->y);
|
|
|
|
|
2016-05-18 01:51:09 +02:00
|
|
|
gimp_applicator_set_opacity (applicator, opacity);
|
2017-02-12 23:49:26 +01:00
|
|
|
gimp_applicator_set_mode (applicator, mode,
|
|
|
|
blend_space, composite_space, composite_mode);
|
2013-04-17 14:24:33 +02:00
|
|
|
gimp_applicator_set_affect (applicator,
|
|
|
|
gimp_drawable_get_active_mask (drawable));
|
|
|
|
|
2019-03-27 12:29:25 -04:00
|
|
|
iter = gimp_chunk_iterator_new (cairo_region_create_rectangle (
|
|
|
|
&(cairo_rectangle_int_t) {x, y, width, height}));
|
|
|
|
|
|
|
|
while (gimp_chunk_iterator_next (iter))
|
|
|
|
{
|
|
|
|
GeglRectangle rect;
|
|
|
|
|
|
|
|
while (gimp_chunk_iterator_get_rect (iter, &rect))
|
|
|
|
gimp_applicator_blit (applicator, &rect);
|
|
|
|
}
|
2013-04-17 14:24:33 +02:00
|
|
|
|
|
|
|
g_object_unref (applicator);
|
2003-10-06 14:40:12 +00:00
|
|
|
}
|