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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://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>
|
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));
|
|
|
|
|
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
|
|
|
g_object_unref (drawable->private->shadow);
|
2009-02-04 07:57:11 +08:00
|
|
|
drawable->private->shadow = NULL;
|
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,
|
|
|
|
GIMP_OPACITY_OPAQUE, GIMP_REPLACE_MODE,
|
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
|
|
|
}
|
|
|
|
}
|