2008-04-22 01:20:51 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* 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
|
2008-04-22 01:20:51 +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
|
2008-04-22 01:20:51 +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/>.
|
2008-04-22 01:20:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
app: add gimp_drawable_{start,end,flush}_paint()
gimp_drawable_start/end_paint() are used to enter/exit paint mode
for a given drawable. While the drawable is in paint mode,
gimp_drawable_get_buffer() returns a copy of the real drawable's
buffer, referred to as the paint buffer, so that modifications to
the returned buffer don't immediately affect the projection, and
calls to gimp_drawable_update() queue the updated region, instead
of emitting an "update" signal.
gimp_drawable_flush_paint() can be called while the drawable is in
paint mode, in order to copy the updated region of the paint buffer
back to the drawable's real buffer, and to emit "update" signals
for the queued region.
We use these functions in the next commit, to move painting to a
separate thread in the paint tools.
2018-04-08 21:21:46 +08:00
|
|
|
#include <cairo.h>
|
2008-04-22 01:20:51 +08:00
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
2012-03-23 02:10:12 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
2008-04-22 01:20:51 +08:00
|
|
|
|
|
|
|
#include "gimpdrawable.h"
|
2009-02-04 07:57:11 +08:00
|
|
|
#include "gimpdrawable-private.h"
|
2008-04-22 01:20:51 +08:00
|
|
|
#include "gimpdrawable-shadow.h"
|
|
|
|
|
|
|
|
|
2012-03-23 02:10:12 +08:00
|
|
|
GeglBuffer *
|
|
|
|
gimp_drawable_get_shadow_buffer (GimpDrawable *drawable)
|
2008-04-22 01:20:51 +08:00
|
|
|
{
|
2012-03-23 02:10:12 +08:00
|
|
|
GimpItem *item;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
const Babl *format;
|
2008-04-22 01:20:51 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
|
|
|
|
item = GIMP_ITEM (drawable);
|
|
|
|
|
2012-03-23 02:10:12 +08:00
|
|
|
width = gimp_item_get_width (item);
|
|
|
|
height = gimp_item_get_height (item);
|
|
|
|
format = gimp_drawable_get_format (drawable);
|
|
|
|
|
2009-02-04 07:57:11 +08:00
|
|
|
if (drawable->private->shadow)
|
2008-04-22 01:20:51 +08:00
|
|
|
{
|
2012-03-23 02:10:12 +08:00
|
|
|
if ((width != gegl_buffer_get_width (drawable->private->shadow)) ||
|
|
|
|
(height != gegl_buffer_get_height (drawable->private->shadow)) ||
|
|
|
|
(format != gegl_buffer_get_format (drawable->private->shadow)))
|
2008-04-22 01:20:51 +08:00
|
|
|
{
|
2012-03-23 02:10:12 +08:00
|
|
|
gimp_drawable_free_shadow_buffer (drawable);
|
2008-04-22 01:20:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-04 07:57:11 +08:00
|
|
|
return drawable->private->shadow;
|
2008-04-22 01:20:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 04:00:27 +08:00
|
|
|
drawable->private->shadow = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
|
|
|
|
width, height),
|
|
|
|
format);
|
2008-04-22 01:20:51 +08:00
|
|
|
|
2009-02-04 07:57:11 +08:00
|
|
|
return drawable->private->shadow;
|
2008-04-22 01:20:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-23 02:10:12 +08:00
|
|
|
gimp_drawable_free_shadow_buffer (GimpDrawable *drawable)
|
2008-04-22 01:20:51 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_object (&drawable->private->shadow);
|
2008-04-22 01:20:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-23 02:10:12 +08:00
|
|
|
gimp_drawable_merge_shadow_buffer (GimpDrawable *drawable,
|
|
|
|
gboolean push_undo,
|
|
|
|
const gchar *undo_desc)
|
2008-04-22 01:20:51 +08:00
|
|
|
{
|
|
|
|
gint x, y;
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
2012-03-23 02:10:12 +08:00
|
|
|
g_return_if_fail (GEGL_IS_BUFFER (drawable->private->shadow));
|
2008-04-22 01:20:51 +08:00
|
|
|
|
|
|
|
/* A useful optimization here is to limit the update to the
|
|
|
|
* extents of the selection mask, as it cannot extend beyond
|
|
|
|
* them.
|
|
|
|
*/
|
2010-09-08 03:28:00 +08:00
|
|
|
if (gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
|
2008-04-22 01:20:51 +08:00
|
|
|
{
|
2012-03-23 02:10:12 +08:00
|
|
|
GeglBuffer *buffer = g_object_ref (drawable->private->shadow);
|
2008-08-07 03:42:52 +08:00
|
|
|
|
2012-03-23 02:10:12 +08:00
|
|
|
gimp_drawable_apply_buffer (drawable, buffer,
|
2012-04-02 21:19:47 +08:00
|
|
|
GEGL_RECTANGLE (x, y, width, height),
|
2008-04-22 01:20:51 +08:00
|
|
|
push_undo, undo_desc,
|
2017-01-09 06:00:19 +08:00
|
|
|
GIMP_OPACITY_OPAQUE,
|
|
|
|
GIMP_LAYER_MODE_REPLACE,
|
2017-02-13 06:49:26 +08:00
|
|
|
GIMP_LAYER_COLOR_SPACE_AUTO,
|
|
|
|
GIMP_LAYER_COLOR_SPACE_AUTO,
|
2017-02-02 07:38:25 +08:00
|
|
|
GIMP_LAYER_COMPOSITE_AUTO,
|
2012-03-24 07:57:11 +08:00
|
|
|
NULL, x, y);
|
2008-12-27 23:14:48 +08:00
|
|
|
|
2012-03-23 02:10:12 +08:00
|
|
|
g_object_unref (buffer);
|
2008-04-22 01:20:51 +08:00
|
|
|
}
|
|
|
|
}
|