2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1998-06-30 23:31:32 +08:00
|
|
|
* 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
|
1998-06-30 23:31:32 +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
|
1998-06-30 23:31:32 +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/>.
|
1998-06-30 23:31:32 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2000-05-27 06:28:40 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-04-28 21:50:39 +08:00
|
|
|
#include <cairo.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2006-08-29 22:46:32 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2012-04-22 05:55:40 +08:00
|
|
|
#include "gegl/gimp-babl.h"
|
2012-10-22 22:14:56 +08:00
|
|
|
#include "gegl/gimp-gegl-apply-operation.h"
|
2010-06-07 01:54:44 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
2014-08-12 19:57:57 +08:00
|
|
|
#include "gimp-memsize.h"
|
2012-03-30 19:03:51 +08:00
|
|
|
#include "gimp-utils.h"
|
2001-02-02 02:44:22 +08:00
|
|
|
#include "gimpchannel.h"
|
2001-07-08 06:49:01 +08:00
|
|
|
#include "gimpcontext.h"
|
2003-10-06 22:40:12 +08:00
|
|
|
#include "gimpdrawable-combine.h"
|
2016-05-19 23:38:55 +08:00
|
|
|
#include "gimpdrawable-floating-selection.h"
|
2001-02-07 08:06:58 +08:00
|
|
|
#include "gimpdrawable-preview.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"
|
2003-05-13 21:57:11 +08:00
|
|
|
#include "gimpdrawable-transform.h"
|
2013-04-12 01:06:23 +08:00
|
|
|
#include "gimpfilterstack.h"
|
2000-12-30 08:16:50 +08:00
|
|
|
#include "gimpimage.h"
|
2006-04-07 17:21:18 +08:00
|
|
|
#include "gimpimage-colormap.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
#include "gimpimage-undo-push.h"
|
2001-11-23 07:46:13 +08:00
|
|
|
#include "gimpmarshal.h"
|
2004-07-14 07:04:05 +08:00
|
|
|
#include "gimppickable.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "gimpprogress.h"
|
2001-05-25 01:09:57 +08:00
|
|
|
|
2010-01-03 06:41:52 +08:00
|
|
|
#include "gimp-log.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
1998-06-30 23:31:32 +08:00
|
|
|
|
2000-05-27 06:28:40 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
UPDATE,
|
2003-05-21 19:34:00 +08:00
|
|
|
ALPHA_CHANGED,
|
1998-06-30 23:31:32 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2012-11-12 17:55:41 +08:00
|
|
|
enum
|
|
|
|
{
|
2013-09-05 16:37:09 +08:00
|
|
|
PROP_0,
|
|
|
|
PROP_BUFFER
|
2012-11-12 17:55:41 +08:00
|
|
|
};
|
|
|
|
|
2001-01-20 21:21:49 +08:00
|
|
|
|
2001-07-11 20:39:49 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2016-05-01 05:41:32 +08:00
|
|
|
static void gimp_color_managed_iface_init (GimpColorManagedInterface *iface);
|
|
|
|
static void gimp_pickable_iface_init (GimpPickableInterface *iface);
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2011-09-24 01:55:24 +08:00
|
|
|
static void gimp_drawable_dispose (GObject *object);
|
2003-02-11 21:52:47 +08:00
|
|
|
static void gimp_drawable_finalize (GObject *object);
|
2012-11-12 17:55:41 +08:00
|
|
|
static void gimp_drawable_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_drawable_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
static gint64 gimp_drawable_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2005-05-25 18:05:17 +08:00
|
|
|
static gboolean gimp_drawable_get_size (GimpViewable *viewable,
|
|
|
|
gint *width,
|
|
|
|
gint *height);
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2016-05-01 20:25:37 +08:00
|
|
|
static void gimp_drawable_visibility_changed (GimpFilter *filter);
|
2013-04-11 08:54:42 +08:00
|
|
|
static GeglNode * gimp_drawable_get_node (GimpFilter *filter);
|
|
|
|
|
2008-04-22 01:20:51 +08:00
|
|
|
static void gimp_drawable_removed (GimpItem *item);
|
2003-02-11 21:52:47 +08:00
|
|
|
static GimpItem * gimp_drawable_duplicate (GimpItem *item,
|
2008-01-08 19:46:15 +08:00
|
|
|
GType new_type);
|
2003-05-07 19:09:00 +08:00
|
|
|
static void gimp_drawable_scale (GimpItem *item,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint new_offset_x,
|
|
|
|
gint new_offset_y,
|
2004-02-09 08:09:20 +08:00
|
|
|
GimpInterpolationType interp_type,
|
2007-12-04 19:30:31 +08:00
|
|
|
GimpProgress *progress);
|
2003-05-07 21:01:17 +08:00
|
|
|
static void gimp_drawable_resize (GimpItem *item,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-05-07 21:01:17 +08:00
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y);
|
2003-05-13 21:57:11 +08:00
|
|
|
static void gimp_drawable_flip (GimpItem *item,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-05-13 21:57:11 +08:00
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis,
|
|
|
|
gboolean clip_result);
|
2003-05-20 18:36:29 +08:00
|
|
|
static void gimp_drawable_rotate (GimpItem *item,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-05-20 18:36:29 +08:00
|
|
|
GimpRotationType rotate_type,
|
|
|
|
gdouble center_x,
|
|
|
|
gdouble center_y,
|
|
|
|
gboolean clip_result);
|
2003-05-13 21:57:11 +08:00
|
|
|
static void gimp_drawable_transform (GimpItem *item,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-07-07 21:50:48 +08:00
|
|
|
const GimpMatrix3 *matrix,
|
2007-12-04 19:30:31 +08:00
|
|
|
GimpTransformDirection direction,
|
|
|
|
GimpInterpolationType interpolation_type,
|
|
|
|
GimpTransformResize clip_result,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress);
|
1998-06-30 23:31:32 +08:00
|
|
|
|
2016-05-01 05:41:32 +08:00
|
|
|
static const guint8 *
|
|
|
|
gimp_drawable_get_icc_profile (GimpColorManaged *managed,
|
|
|
|
gsize *len);
|
|
|
|
static GimpColorProfile *
|
|
|
|
gimp_drawable_get_color_profile (GimpColorManaged *managed);
|
|
|
|
static void gimp_drawable_profile_changed (GimpColorManaged *managed);
|
|
|
|
|
2007-04-28 00:07:49 +08:00
|
|
|
static gboolean gimp_drawable_get_pixel_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
2012-04-21 16:03:32 +08:00
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel);
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
static void gimp_drawable_real_update (GimpDrawable *drawable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
|
|
|
|
2016-05-20 05:51:44 +08:00
|
|
|
static gint64 gimp_drawable_real_estimate_memsize (GimpDrawable *drawable,
|
2014-06-15 05:12:22 +08:00
|
|
|
GimpComponentType component_type,
|
2007-12-04 19:30:31 +08:00
|
|
|
gint width,
|
|
|
|
gint height);
|
|
|
|
|
2009-09-12 03:23:35 +08:00
|
|
|
static void gimp_drawable_real_convert_type (GimpDrawable *drawable,
|
|
|
|
GimpImage *dest_image,
|
2012-10-14 04:56:32 +08:00
|
|
|
const Babl *new_format,
|
2009-09-14 01:24:19 +08:00
|
|
|
GimpImageBaseType new_base_type,
|
2012-04-25 18:09:45 +08:00
|
|
|
GimpPrecision new_precision,
|
2016-04-29 06:42:42 +08:00
|
|
|
GimpColorProfile *dest_profile,
|
2012-10-14 03:46:56 +08:00
|
|
|
gint layer_dither_type,
|
|
|
|
gint mask_dither_type,
|
2015-10-22 04:22:30 +08:00
|
|
|
gboolean push_undo,
|
|
|
|
GimpProgress *progress);
|
2009-09-12 03:23:35 +08:00
|
|
|
|
2012-03-22 07:07:48 +08:00
|
|
|
static GeglBuffer * gimp_drawable_real_get_buffer (GimpDrawable *drawable);
|
2012-03-22 06:37:16 +08:00
|
|
|
static void gimp_drawable_real_set_buffer (GimpDrawable *drawable,
|
2004-03-13 21:56:09 +08:00
|
|
|
gboolean push_undo,
|
|
|
|
const gchar *undo_desc,
|
2012-03-22 06:37:16 +08:00
|
|
|
GeglBuffer *buffer,
|
2004-03-16 03:34:35 +08:00
|
|
|
gint offset_x,
|
|
|
|
gint offset_y);
|
2004-03-13 21:56:09 +08:00
|
|
|
|
2004-04-01 22:51:58 +08:00
|
|
|
static void gimp_drawable_real_push_undo (GimpDrawable *drawable,
|
|
|
|
const gchar *undo_desc,
|
2012-03-22 21:13:17 +08:00
|
|
|
GeglBuffer *buffer,
|
2004-04-01 22:51:58 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
2004-03-15 22:10:30 +08:00
|
|
|
static void gimp_drawable_real_swap_pixels (GimpDrawable *drawable,
|
2012-03-22 21:13:17 +08:00
|
|
|
GeglBuffer *buffer,
|
2004-03-15 22:10:30 +08:00
|
|
|
gint x,
|
2012-03-22 21:25:45 +08:00
|
|
|
gint y);
|
2004-03-15 22:10:30 +08:00
|
|
|
|
2001-01-10 08:36:54 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpDrawable, gimp_drawable, GIMP_TYPE_ITEM,
|
2016-05-01 05:41:32 +08:00
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_COLOR_MANAGED,
|
|
|
|
gimp_color_managed_iface_init)
|
2005-12-11 03:24:36 +08:00
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_PICKABLE,
|
2016-05-01 05:41:32 +08:00
|
|
|
gimp_pickable_iface_init))
|
2001-01-20 21:21:49 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
#define parent_class gimp_drawable_parent_class
|
2000-12-29 00:19:55 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static guint gimp_drawable_signals[LAST_SIGNAL] = { 0 };
|
2000-12-29 00:19:55 +08:00
|
|
|
|
1998-06-30 23:31:32 +08:00
|
|
|
|
|
|
|
static void
|
2000-12-29 00:19:55 +08:00
|
|
|
gimp_drawable_class_init (GimpDrawableClass *klass)
|
1998-06-30 23:31:32 +08:00
|
|
|
{
|
2004-07-14 18:31:59 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
2013-04-11 08:54:42 +08:00
|
|
|
GimpFilterClass *filter_class = GIMP_FILTER_CLASS (klass);
|
2004-07-14 18:31:59 +08:00
|
|
|
GimpItemClass *item_class = GIMP_ITEM_CLASS (klass);
|
2001-01-10 08:36:54 +08:00
|
|
|
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
gimp_drawable_signals[UPDATE] =
|
|
|
|
g_signal_new ("update",
|
2004-07-14 18:31:59 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpDrawableClass, update),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__INT_INT_INT_INT,
|
|
|
|
G_TYPE_NONE, 4,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT);
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
|
2003-05-21 19:34:00 +08:00
|
|
|
gimp_drawable_signals[ALPHA_CHANGED] =
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_new ("alpha-changed",
|
2004-07-14 18:31:59 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpDrawableClass, alpha_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2003-05-21 19:34:00 +08:00
|
|
|
|
2011-09-24 01:55:24 +08:00
|
|
|
object_class->dispose = gimp_drawable_dispose;
|
2001-08-11 22:39:19 +08:00
|
|
|
object_class->finalize = gimp_drawable_finalize;
|
2012-11-12 17:55:41 +08:00
|
|
|
object_class->set_property = gimp_drawable_set_property;
|
|
|
|
object_class->get_property = gimp_drawable_get_property;
|
2000-12-29 00:19:55 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
gimp_object_class->get_memsize = gimp_drawable_get_memsize;
|
2001-01-10 11:13:03 +08:00
|
|
|
|
2005-05-25 18:05:17 +08:00
|
|
|
viewable_class->get_size = gimp_drawable_get_size;
|
2012-06-21 03:44:09 +08:00
|
|
|
viewable_class->get_new_preview = gimp_drawable_get_new_preview;
|
2016-04-15 23:52:25 +08:00
|
|
|
viewable_class->get_new_pixbuf = gimp_drawable_get_new_pixbuf;
|
2001-02-05 06:10:54 +08:00
|
|
|
|
2016-05-01 20:25:37 +08:00
|
|
|
filter_class->visibility_changed = gimp_drawable_visibility_changed;
|
2013-04-11 08:54:42 +08:00
|
|
|
filter_class->get_node = gimp_drawable_get_node;
|
|
|
|
|
2008-04-22 01:20:51 +08:00
|
|
|
item_class->removed = gimp_drawable_removed;
|
2003-02-11 21:52:47 +08:00
|
|
|
item_class->duplicate = gimp_drawable_duplicate;
|
2003-05-07 19:09:00 +08:00
|
|
|
item_class->scale = gimp_drawable_scale;
|
2003-05-07 21:01:17 +08:00
|
|
|
item_class->resize = gimp_drawable_resize;
|
2003-05-13 21:57:11 +08:00
|
|
|
item_class->flip = gimp_drawable_flip;
|
2003-05-20 18:36:29 +08:00
|
|
|
item_class->rotate = gimp_drawable_rotate;
|
2003-05-13 21:57:11 +08:00
|
|
|
item_class->transform = gimp_drawable_transform;
|
2003-02-11 21:52:47 +08:00
|
|
|
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
klass->update = gimp_drawable_real_update;
|
2003-05-21 19:34:00 +08:00
|
|
|
klass->alpha_changed = NULL;
|
2007-12-04 19:30:31 +08:00
|
|
|
klass->estimate_memsize = gimp_drawable_real_estimate_memsize;
|
2003-09-04 19:33:06 +08:00
|
|
|
klass->invalidate_boundary = NULL;
|
2003-10-06 22:40:12 +08:00
|
|
|
klass->get_active_components = NULL;
|
2012-04-26 05:23:31 +08:00
|
|
|
klass->get_active_mask = NULL;
|
2009-09-12 03:23:35 +08:00
|
|
|
klass->convert_type = gimp_drawable_real_convert_type;
|
2012-03-23 06:45:11 +08:00
|
|
|
klass->apply_buffer = gimp_drawable_real_apply_buffer;
|
2012-03-23 19:31:21 +08:00
|
|
|
klass->replace_buffer = gimp_drawable_real_replace_buffer;
|
2012-03-22 07:07:48 +08:00
|
|
|
klass->get_buffer = gimp_drawable_real_get_buffer;
|
2012-03-22 06:37:16 +08:00
|
|
|
klass->set_buffer = gimp_drawable_real_set_buffer;
|
2004-04-01 22:51:58 +08:00
|
|
|
klass->push_undo = gimp_drawable_real_push_undo;
|
2004-03-15 22:10:30 +08:00
|
|
|
klass->swap_pixels = gimp_drawable_real_swap_pixels;
|
2009-02-04 07:57:11 +08:00
|
|
|
|
2013-09-05 16:37:09 +08:00
|
|
|
g_object_class_override_property (object_class, PROP_BUFFER, "buffer");
|
|
|
|
|
2009-02-04 07:57:11 +08:00
|
|
|
g_type_class_add_private (klass, sizeof (GimpDrawablePrivate));
|
1998-06-30 23:31:32 +08:00
|
|
|
}
|
|
|
|
|
2001-01-20 21:21:49 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_init (GimpDrawable *drawable)
|
|
|
|
{
|
2010-06-08 16:10:04 +08:00
|
|
|
drawable->private = G_TYPE_INSTANCE_GET_PRIVATE (drawable,
|
|
|
|
GIMP_TYPE_DRAWABLE,
|
|
|
|
GimpDrawablePrivate);
|
2013-04-12 01:06:23 +08:00
|
|
|
|
|
|
|
drawable->private->filter_stack = gimp_filter_stack_new (GIMP_TYPE_FILTER);
|
2001-01-20 21:21:49 +08:00
|
|
|
}
|
|
|
|
|
2006-11-25 06:41:03 +08:00
|
|
|
/* sorry for the evil casts */
|
|
|
|
|
2004-07-14 07:04:05 +08:00
|
|
|
static void
|
2016-05-01 05:41:32 +08:00
|
|
|
gimp_color_managed_iface_init (GimpColorManagedInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_icc_profile = gimp_drawable_get_icc_profile;
|
|
|
|
iface->get_color_profile = gimp_drawable_get_color_profile;
|
|
|
|
iface->profile_changed = gimp_drawable_profile_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pickable_iface_init (GimpPickableInterface *iface)
|
2004-07-14 07:04:05 +08:00
|
|
|
{
|
2012-03-18 23:20:01 +08:00
|
|
|
iface->get_image = (GimpImage * (*) (GimpPickable *pickable)) gimp_item_get_image;
|
|
|
|
iface->get_format = (const Babl * (*) (GimpPickable *pickable)) gimp_drawable_get_format;
|
|
|
|
iface->get_format_with_alpha = (const Babl * (*) (GimpPickable *pickable)) gimp_drawable_get_format_with_alpha;
|
2012-03-21 07:42:44 +08:00
|
|
|
iface->get_buffer = (GeglBuffer * (*) (GimpPickable *pickable)) gimp_drawable_get_buffer;
|
2012-03-18 23:20:01 +08:00
|
|
|
iface->get_pixel_at = gimp_drawable_get_pixel_at;
|
2004-07-14 07:04:05 +08:00
|
|
|
}
|
|
|
|
|
2001-01-20 21:21:49 +08:00
|
|
|
static void
|
2011-09-24 01:55:24 +08:00
|
|
|
gimp_drawable_dispose (GObject *object)
|
2001-01-20 21:21:49 +08:00
|
|
|
{
|
2003-09-02 21:43:26 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (object);
|
2001-01-20 21:21:49 +08:00
|
|
|
|
2011-09-24 01:55:24 +08:00
|
|
|
if (gimp_drawable_get_floating_sel (drawable))
|
|
|
|
gimp_drawable_detach_floating_sel (drawable);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (object);
|
2009-01-27 06:05:07 +08:00
|
|
|
|
2012-03-21 07:42:44 +08:00
|
|
|
if (drawable->private->buffer)
|
2012-03-15 09:42:59 +08:00
|
|
|
{
|
2012-03-21 07:42:44 +08:00
|
|
|
g_object_unref (drawable->private->buffer);
|
|
|
|
drawable->private->buffer = NULL;
|
2012-03-15 09:42:59 +08:00
|
|
|
}
|
|
|
|
|
2012-03-23 02:10:12 +08:00
|
|
|
gimp_drawable_free_shadow_buffer (drawable);
|
2012-03-22 04:26:05 +08:00
|
|
|
|
2009-02-04 07:57:11 +08:00
|
|
|
if (drawable->private->source_node)
|
2008-10-10 04:44:23 +08:00
|
|
|
{
|
2009-02-04 07:57:11 +08:00
|
|
|
g_object_unref (drawable->private->source_node);
|
|
|
|
drawable->private->source_node = NULL;
|
2008-10-10 04:44:23 +08:00
|
|
|
}
|
|
|
|
|
2013-04-12 01:06:23 +08:00
|
|
|
if (drawable->private->filter_stack)
|
|
|
|
{
|
|
|
|
g_object_unref (drawable->private->filter_stack);
|
|
|
|
drawable->private->filter_stack = NULL;
|
|
|
|
}
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-01-20 21:21:49 +08:00
|
|
|
}
|
|
|
|
|
2012-11-12 17:55:41 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2013-09-05 16:37:09 +08:00
|
|
|
case PROP_BUFFER:
|
2012-11-12 17:55:41 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2013-09-05 16:37:09 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (object);
|
|
|
|
|
2012-11-12 17:55:41 +08:00
|
|
|
switch (property_id)
|
|
|
|
{
|
2013-09-05 16:37:09 +08:00
|
|
|
case PROP_BUFFER:
|
|
|
|
g_value_set_object (value, drawable->private->buffer);
|
|
|
|
break;
|
|
|
|
|
2012-11-12 17:55:41 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
static gint64
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_drawable_get_memsize (GimpObject *object,
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 *gui_size)
|
2002-01-31 00:14:26 +08:00
|
|
|
{
|
2004-07-14 18:31:59 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (object);
|
|
|
|
gint64 memsize = 0;
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2012-03-22 07:07:48 +08:00
|
|
|
memsize += gimp_gegl_buffer_get_memsize (gimp_drawable_get_buffer (drawable));
|
2012-03-23 02:10:12 +08:00
|
|
|
memsize += gimp_gegl_buffer_get_memsize (drawable->private->shadow);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2003-08-25 18:49:33 +08:00
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
2002-01-31 00:14:26 +08:00
|
|
|
}
|
|
|
|
|
2005-05-25 18:05:17 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_drawable_get_size (GimpViewable *viewable,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
|
|
|
{
|
|
|
|
GimpItem *item = GIMP_ITEM (viewable);
|
|
|
|
|
2008-11-03 08:09:01 +08:00
|
|
|
*width = gimp_item_get_width (item);
|
|
|
|
*height = gimp_item_get_height (item);
|
2005-05-25 18:05:17 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-05-01 20:25:37 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_visibility_changed (GimpFilter *filter)
|
|
|
|
{
|
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (filter);
|
|
|
|
GeglNode *node;
|
|
|
|
|
|
|
|
/* don't use gimp_filter_get_node() because that would create
|
|
|
|
* the node.
|
|
|
|
*/
|
|
|
|
node = gimp_filter_peek_node (filter);
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
GeglNode *input = gegl_node_get_input_proxy (node, "input");
|
|
|
|
GeglNode *output = gegl_node_get_output_proxy (node, "output");
|
|
|
|
|
|
|
|
if (gimp_filter_get_visible (filter))
|
|
|
|
{
|
|
|
|
gegl_node_connect_to (input, "output",
|
|
|
|
drawable->private->mode_node, "input");
|
|
|
|
gegl_node_connect_to (drawable->private->mode_node, "output",
|
|
|
|
output, "input");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gegl_node_disconnect (drawable->private->mode_node, "input");
|
|
|
|
|
|
|
|
/* The rest handled by GimpFilter */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_FILTER_CLASS (parent_class)->visibility_changed (filter);
|
|
|
|
}
|
|
|
|
|
2013-04-11 08:54:42 +08:00
|
|
|
static GeglNode *
|
|
|
|
gimp_drawable_get_node (GimpFilter *filter)
|
|
|
|
{
|
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (filter);
|
|
|
|
GeglNode *node;
|
|
|
|
GeglNode *input;
|
|
|
|
GeglNode *output;
|
|
|
|
|
|
|
|
node = GIMP_FILTER_CLASS (parent_class)->get_node (filter);
|
|
|
|
|
|
|
|
g_warn_if_fail (drawable->private->mode_node == NULL);
|
|
|
|
|
|
|
|
drawable->private->mode_node =
|
|
|
|
gegl_node_new_child (node,
|
|
|
|
"operation", "gimp:normal-mode",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
input = gegl_node_get_input_proxy (node, "input");
|
|
|
|
output = gegl_node_get_output_proxy (node, "output");
|
|
|
|
|
2016-05-01 20:25:37 +08:00
|
|
|
if (gimp_filter_get_visible (filter))
|
2013-04-11 08:54:42 +08:00
|
|
|
{
|
|
|
|
gegl_node_connect_to (input, "output",
|
|
|
|
drawable->private->mode_node, "input");
|
|
|
|
gegl_node_connect_to (drawable->private->mode_node, "output",
|
|
|
|
output, "input");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-01 20:25:37 +08:00
|
|
|
/* Handled by GimpFilter */
|
2013-04-11 08:54:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2008-04-22 01:20:51 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_removed (GimpItem *item)
|
|
|
|
{
|
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (item);
|
|
|
|
|
2012-03-23 02:10:12 +08:00
|
|
|
gimp_drawable_free_shadow_buffer (drawable);
|
2008-04-22 01:20:51 +08:00
|
|
|
|
|
|
|
if (GIMP_ITEM_CLASS (parent_class)->removed)
|
|
|
|
GIMP_ITEM_CLASS (parent_class)->removed (item);
|
|
|
|
}
|
|
|
|
|
2003-02-11 21:52:47 +08:00
|
|
|
static GimpItem *
|
|
|
|
gimp_drawable_duplicate (GimpItem *item,
|
2008-01-08 19:46:15 +08:00
|
|
|
GType new_type)
|
2001-12-13 07:48:18 +08:00
|
|
|
{
|
2005-12-23 09:15:19 +08:00
|
|
|
GimpItem *new_item;
|
2001-12-13 07:48:18 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_DRAWABLE), NULL);
|
|
|
|
|
2008-01-08 19:46:15 +08:00
|
|
|
new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type);
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2005-12-23 09:15:19 +08:00
|
|
|
if (GIMP_IS_DRAWABLE (new_item))
|
|
|
|
{
|
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (item);
|
|
|
|
GimpDrawable *new_drawable = GIMP_DRAWABLE (new_item);
|
2011-02-01 17:46:53 +08:00
|
|
|
|
2012-03-22 04:26:05 +08:00
|
|
|
if (new_drawable->private->buffer)
|
|
|
|
g_object_unref (new_drawable->private->buffer);
|
2005-12-23 09:15:19 +08:00
|
|
|
|
2012-03-22 04:26:05 +08:00
|
|
|
new_drawable->private->buffer =
|
2012-06-21 03:44:09 +08:00
|
|
|
gegl_buffer_dup (gimp_drawable_get_buffer (drawable));
|
2005-12-23 09:15:19 +08:00
|
|
|
}
|
2001-12-13 07:48:18 +08:00
|
|
|
|
2003-02-11 21:52:47 +08:00
|
|
|
return new_item;
|
|
|
|
}
|
|
|
|
|
2003-05-07 19:09:00 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_scale (GimpItem *item,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint new_offset_x,
|
|
|
|
gint new_offset_y,
|
2004-02-09 08:09:20 +08:00
|
|
|
GimpInterpolationType interpolation_type,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress)
|
2003-05-07 19:09:00 +08:00
|
|
|
{
|
2004-03-16 04:05:31 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (item);
|
2012-03-22 04:46:03 +08:00
|
|
|
GeglBuffer *new_buffer;
|
2003-05-07 19:09:00 +08:00
|
|
|
|
2012-06-21 03:44:09 +08:00
|
|
|
new_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
|
|
|
|
new_width, new_height),
|
|
|
|
gimp_drawable_get_format (drawable));
|
2003-05-07 19:09:00 +08:00
|
|
|
|
2012-11-01 06:47:45 +08:00
|
|
|
gimp_gegl_apply_scale (gimp_drawable_get_buffer (drawable),
|
|
|
|
progress, C_("undo-type", "Scale"),
|
|
|
|
new_buffer,
|
|
|
|
interpolation_type,
|
|
|
|
((gdouble) new_width /
|
|
|
|
gimp_item_get_width (item)),
|
|
|
|
((gdouble) new_height /
|
|
|
|
gimp_item_get_height (item)));
|
2003-05-07 19:09:00 +08:00
|
|
|
|
2012-03-22 04:46:03 +08:00
|
|
|
gimp_drawable_set_buffer_full (drawable, gimp_item_is_attached (item), NULL,
|
2012-03-22 06:37:16 +08:00
|
|
|
new_buffer,
|
2012-03-22 04:46:03 +08:00
|
|
|
new_offset_x, new_offset_y);
|
|
|
|
g_object_unref (new_buffer);
|
2003-05-07 19:09:00 +08:00
|
|
|
}
|
|
|
|
|
2003-05-07 21:01:17 +08:00
|
|
|
static void
|
2004-04-15 07:37:34 +08:00
|
|
|
gimp_drawable_resize (GimpItem *item,
|
|
|
|
GimpContext *context,
|
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
2003-05-07 21:01:17 +08:00
|
|
|
{
|
2004-03-16 04:05:31 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (item);
|
2012-03-21 17:10:20 +08:00
|
|
|
GeglBuffer *new_buffer;
|
2003-05-14 23:32:07 +08:00
|
|
|
gint new_offset_x;
|
|
|
|
gint new_offset_y;
|
|
|
|
gint copy_x, copy_y;
|
|
|
|
gint copy_width, copy_height;
|
2013-11-16 16:38:29 +08:00
|
|
|
gboolean intersect;
|
2003-05-07 21:01:17 +08:00
|
|
|
|
2004-11-23 17:32:54 +08:00
|
|
|
/* if the size doesn't change, this is a nop */
|
2008-11-03 08:09:01 +08:00
|
|
|
if (new_width == gimp_item_get_width (item) &&
|
|
|
|
new_height == gimp_item_get_height (item) &&
|
2013-11-16 16:38:29 +08:00
|
|
|
offset_x == 0 &&
|
2004-11-26 22:45:10 +08:00
|
|
|
offset_y == 0)
|
2004-11-23 17:32:54 +08:00
|
|
|
return;
|
|
|
|
|
2008-12-28 20:43:07 +08:00
|
|
|
new_offset_x = gimp_item_get_offset_x (item) - offset_x;
|
|
|
|
new_offset_y = gimp_item_get_offset_y (item) - offset_y;
|
2003-05-07 21:01:17 +08:00
|
|
|
|
2013-11-16 16:38:29 +08:00
|
|
|
intersect = gimp_rectangle_intersect (gimp_item_get_offset_x (item),
|
|
|
|
gimp_item_get_offset_y (item),
|
|
|
|
gimp_item_get_width (item),
|
|
|
|
gimp_item_get_height (item),
|
|
|
|
new_offset_x,
|
|
|
|
new_offset_y,
|
|
|
|
new_width,
|
|
|
|
new_height,
|
|
|
|
©_x,
|
|
|
|
©_y,
|
|
|
|
©_width,
|
|
|
|
©_height);
|
2003-05-07 21:01:17 +08:00
|
|
|
|
2012-06-21 03:44:09 +08:00
|
|
|
new_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
|
|
|
|
new_width, new_height),
|
|
|
|
gimp_drawable_get_format (drawable));
|
2012-03-16 09:21:26 +08:00
|
|
|
|
2013-11-16 16:38:29 +08:00
|
|
|
if (! intersect ||
|
|
|
|
copy_width != new_width ||
|
2003-05-14 23:32:07 +08:00
|
|
|
copy_height != new_height)
|
2003-05-07 21:01:17 +08:00
|
|
|
{
|
2012-03-16 09:21:26 +08:00
|
|
|
/* Clear the new tiles if needed */
|
2003-05-14 23:32:07 +08:00
|
|
|
|
2012-03-18 23:52:07 +08:00
|
|
|
GimpRGB bg;
|
2012-03-16 09:21:26 +08:00
|
|
|
GeglColor *col;
|
2003-05-07 21:01:17 +08:00
|
|
|
|
2003-05-14 23:32:07 +08:00
|
|
|
if (! gimp_drawable_has_alpha (drawable) && ! GIMP_IS_CHANNEL (drawable))
|
2012-03-18 23:52:07 +08:00
|
|
|
gimp_context_get_background (context, &bg);
|
|
|
|
else
|
|
|
|
gimp_rgba_set (&bg, 0.0, 0.0, 0.0, 0.0);
|
2003-05-14 23:32:07 +08:00
|
|
|
|
2012-03-20 17:27:28 +08:00
|
|
|
col = gimp_gegl_color_new (&bg);
|
2012-03-16 09:21:26 +08:00
|
|
|
|
2012-03-21 17:10:20 +08:00
|
|
|
gegl_buffer_set_color (new_buffer, NULL, col);
|
2012-03-16 09:21:26 +08:00
|
|
|
g_object_unref (col);
|
2003-05-07 21:01:17 +08:00
|
|
|
}
|
|
|
|
|
2013-11-16 16:38:29 +08:00
|
|
|
if (intersect && copy_width && copy_height)
|
2003-05-07 21:01:17 +08:00
|
|
|
{
|
2012-03-16 09:21:26 +08:00
|
|
|
/* Copy the pixels in the intersection */
|
2012-03-21 10:57:53 +08:00
|
|
|
gegl_buffer_copy (gimp_drawable_get_buffer (drawable),
|
2012-04-02 21:19:47 +08:00
|
|
|
GEGL_RECTANGLE (copy_x - gimp_item_get_offset_x (item),
|
2012-03-21 10:57:53 +08:00
|
|
|
copy_y - gimp_item_get_offset_y (item),
|
|
|
|
copy_width,
|
2015-05-25 04:32:55 +08:00
|
|
|
copy_height), GEGL_ABYSS_NONE,
|
2012-03-21 17:10:20 +08:00
|
|
|
new_buffer,
|
2012-04-02 21:19:47 +08:00
|
|
|
GEGL_RECTANGLE (copy_x - new_offset_x,
|
2012-03-21 10:57:53 +08:00
|
|
|
copy_y - new_offset_y, 0, 0));
|
2003-05-07 21:01:17 +08:00
|
|
|
}
|
|
|
|
|
2012-03-21 17:10:20 +08:00
|
|
|
gimp_drawable_set_buffer_full (drawable, gimp_item_is_attached (item), NULL,
|
2012-03-22 06:37:16 +08:00
|
|
|
new_buffer,
|
2012-03-21 17:10:20 +08:00
|
|
|
new_offset_x, new_offset_y);
|
|
|
|
g_object_unref (new_buffer);
|
2003-05-07 21:01:17 +08:00
|
|
|
}
|
|
|
|
|
2003-05-13 21:57:11 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_flip (GimpItem *item,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-05-13 21:57:11 +08:00
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis,
|
|
|
|
gboolean clip_result)
|
|
|
|
{
|
2016-05-09 00:35:40 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (item);
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
GimpColorProfile *buffer_profile;
|
|
|
|
gint off_x, off_y;
|
|
|
|
gint new_off_x, new_off_y;
|
2003-05-13 21:57:11 +08:00
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (item, &off_x, &off_y);
|
2003-05-13 21:57:11 +08:00
|
|
|
|
2012-03-21 21:30:47 +08:00
|
|
|
buffer = gimp_drawable_transform_buffer_flip (drawable, context,
|
|
|
|
gimp_drawable_get_buffer (drawable),
|
|
|
|
off_x, off_y,
|
|
|
|
flip_type, axis,
|
|
|
|
clip_result,
|
2016-05-09 00:35:40 +08:00
|
|
|
&buffer_profile,
|
2012-03-21 21:30:47 +08:00
|
|
|
&new_off_x, &new_off_y);
|
2003-05-13 21:57:11 +08:00
|
|
|
|
2012-03-21 21:30:47 +08:00
|
|
|
if (buffer)
|
2003-05-27 01:02:06 +08:00
|
|
|
{
|
2016-05-09 00:35:40 +08:00
|
|
|
gimp_drawable_transform_paste (drawable, buffer, buffer_profile,
|
2011-03-26 15:30:15 +08:00
|
|
|
new_off_x, new_off_y, FALSE);
|
2012-03-21 21:30:47 +08:00
|
|
|
g_object_unref (buffer);
|
2003-05-27 01:02:06 +08:00
|
|
|
}
|
2003-05-13 21:57:11 +08:00
|
|
|
}
|
|
|
|
|
2003-05-20 18:36:29 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_rotate (GimpItem *item,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-05-20 18:36:29 +08:00
|
|
|
GimpRotationType rotate_type,
|
|
|
|
gdouble center_x,
|
|
|
|
gdouble center_y,
|
|
|
|
gboolean clip_result)
|
|
|
|
{
|
2016-05-09 00:35:40 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (item);
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
GimpColorProfile *buffer_profile;
|
|
|
|
gint off_x, off_y;
|
|
|
|
gint new_off_x, new_off_y;
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (item, &off_x, &off_y);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2012-03-21 21:30:47 +08:00
|
|
|
buffer = gimp_drawable_transform_buffer_rotate (drawable, context,
|
|
|
|
gimp_drawable_get_buffer (drawable),
|
|
|
|
off_x, off_y,
|
|
|
|
rotate_type, center_x, center_y,
|
|
|
|
clip_result,
|
2016-05-09 00:35:40 +08:00
|
|
|
&buffer_profile,
|
2012-03-21 21:30:47 +08:00
|
|
|
&new_off_x, &new_off_y);
|
2003-05-20 18:36:29 +08:00
|
|
|
|
2012-03-21 21:30:47 +08:00
|
|
|
if (buffer)
|
2003-05-27 01:02:06 +08:00
|
|
|
{
|
2016-05-09 00:35:40 +08:00
|
|
|
gimp_drawable_transform_paste (drawable, buffer, buffer_profile,
|
2011-03-26 15:30:15 +08:00
|
|
|
new_off_x, new_off_y, FALSE);
|
2012-03-21 21:30:47 +08:00
|
|
|
g_object_unref (buffer);
|
2003-05-27 01:02:06 +08:00
|
|
|
}
|
2003-05-20 18:36:29 +08:00
|
|
|
}
|
|
|
|
|
2003-05-13 21:57:11 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_transform (GimpItem *item,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2003-07-07 21:50:48 +08:00
|
|
|
const GimpMatrix3 *matrix,
|
2003-05-13 21:57:11 +08:00
|
|
|
GimpTransformDirection direction,
|
|
|
|
GimpInterpolationType interpolation_type,
|
2006-12-25 00:48:08 +08:00
|
|
|
GimpTransformResize clip_result,
|
2004-08-11 02:47:21 +08:00
|
|
|
GimpProgress *progress)
|
2003-05-13 21:57:11 +08:00
|
|
|
{
|
2016-05-09 00:35:40 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (item);
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
GimpColorProfile *buffer_profile;
|
|
|
|
gint off_x, off_y;
|
|
|
|
gint new_off_x, new_off_y;
|
2003-05-13 21:57:11 +08:00
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (item, &off_x, &off_y);
|
2003-05-13 21:57:11 +08:00
|
|
|
|
2012-03-21 21:30:47 +08:00
|
|
|
buffer = gimp_drawable_transform_buffer_affine (drawable, context,
|
|
|
|
gimp_drawable_get_buffer (drawable),
|
|
|
|
off_x, off_y,
|
|
|
|
matrix, direction,
|
|
|
|
interpolation_type,
|
|
|
|
clip_result,
|
2016-05-09 00:35:40 +08:00
|
|
|
&buffer_profile,
|
2012-03-21 21:30:47 +08:00
|
|
|
&new_off_x, &new_off_y,
|
|
|
|
progress);
|
|
|
|
|
|
|
|
if (buffer)
|
2003-05-27 01:02:06 +08:00
|
|
|
{
|
2016-05-09 00:35:40 +08:00
|
|
|
gimp_drawable_transform_paste (drawable, buffer, buffer_profile,
|
2011-03-26 23:50:38 +08:00
|
|
|
new_off_x, new_off_y, FALSE);
|
2012-03-21 21:30:47 +08:00
|
|
|
g_object_unref (buffer);
|
2003-05-27 01:02:06 +08:00
|
|
|
}
|
2003-05-13 21:57:11 +08:00
|
|
|
}
|
|
|
|
|
2016-05-01 05:41:32 +08:00
|
|
|
static const guint8 *
|
|
|
|
gimp_drawable_get_icc_profile (GimpColorManaged *managed,
|
|
|
|
gsize *len)
|
|
|
|
{
|
|
|
|
GimpColorProfile *profile = gimp_color_managed_get_color_profile (managed);
|
|
|
|
|
|
|
|
return gimp_color_profile_get_icc_profile (profile, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpColorProfile *
|
|
|
|
gimp_drawable_get_color_profile (GimpColorManaged *managed)
|
|
|
|
{
|
|
|
|
const Babl *format = gimp_drawable_get_format (GIMP_DRAWABLE (managed));
|
|
|
|
|
|
|
|
return gimp_babl_format_get_color_profile (format);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_drawable_profile_changed (GimpColorManaged *managed)
|
|
|
|
{
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (managed));
|
|
|
|
}
|
|
|
|
|
2007-04-28 00:07:49 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_drawable_get_pixel_at (GimpPickable *pickable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
2012-04-21 16:03:32 +08:00
|
|
|
const Babl *format,
|
|
|
|
gpointer pixel)
|
2007-04-28 00:07:49 +08:00
|
|
|
{
|
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (pickable);
|
|
|
|
|
|
|
|
/* do not make this a g_return_if_fail() */
|
2008-11-03 08:09:01 +08:00
|
|
|
if (x < 0 || x >= gimp_item_get_width (GIMP_ITEM (drawable)) ||
|
|
|
|
y < 0 || y >= gimp_item_get_height (GIMP_ITEM (drawable)))
|
2007-04-28 00:07:49 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2012-03-21 07:42:44 +08:00
|
|
|
gegl_buffer_sample (gimp_drawable_get_buffer (drawable),
|
2012-04-21 16:03:32 +08:00
|
|
|
x, y, NULL, pixel, format,
|
2012-03-26 08:17:24 +08:00
|
|
|
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
|
2007-04-28 00:07:49 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_real_update (GimpDrawable *drawable,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (drawable));
|
|
|
|
}
|
|
|
|
|
2007-12-04 19:30:31 +08:00
|
|
|
static gint64
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_real_estimate_memsize (GimpDrawable *drawable,
|
|
|
|
GimpComponentType component_type,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2007-12-04 19:30:31 +08:00
|
|
|
{
|
2014-08-15 15:23:02 +08:00
|
|
|
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
|
|
|
|
gboolean linear = gimp_drawable_get_linear (drawable);
|
2014-06-15 05:12:22 +08:00
|
|
|
const Babl *format;
|
|
|
|
|
2014-08-15 15:23:02 +08:00
|
|
|
format = gimp_image_get_format (image,
|
|
|
|
gimp_drawable_get_base_type (drawable),
|
|
|
|
gimp_babl_precision (component_type, linear),
|
|
|
|
gimp_drawable_has_alpha (drawable));
|
2012-04-25 19:35:37 +08:00
|
|
|
|
|
|
|
return (gint64) babl_format_get_bytes_per_pixel (format) * width * height;
|
2007-12-04 19:30:31 +08:00
|
|
|
}
|
|
|
|
|
2012-10-14 03:46:56 +08:00
|
|
|
/* FIXME: this default impl is currently unused because no subclass
|
2016-04-29 06:42:42 +08:00
|
|
|
* chains up. the goal is to handle the almost identical subclass code
|
2012-10-14 03:46:56 +08:00
|
|
|
* here again.
|
|
|
|
*/
|
2009-09-12 03:23:35 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_real_convert_type (GimpDrawable *drawable,
|
|
|
|
GimpImage *dest_image,
|
2012-10-14 04:56:32 +08:00
|
|
|
const Babl *new_format,
|
2009-09-14 01:24:19 +08:00
|
|
|
GimpImageBaseType new_base_type,
|
2012-04-25 18:09:45 +08:00
|
|
|
GimpPrecision new_precision,
|
2016-04-29 06:42:42 +08:00
|
|
|
GimpColorProfile *dest_profile,
|
2012-10-14 03:46:56 +08:00
|
|
|
gint layer_dither_type,
|
|
|
|
gint mask_dither_type,
|
2015-10-22 04:22:30 +08:00
|
|
|
gboolean push_undo,
|
|
|
|
GimpProgress *progress)
|
2009-09-12 03:23:35 +08:00
|
|
|
{
|
2012-04-12 00:50:57 +08:00
|
|
|
GeglBuffer *dest_buffer;
|
2009-09-12 03:23:35 +08:00
|
|
|
|
2012-04-12 00:50:57 +08:00
|
|
|
dest_buffer =
|
2012-06-21 03:44:09 +08:00
|
|
|
gegl_buffer_new (GEGL_RECTANGLE (0, 0,
|
|
|
|
gimp_item_get_width (GIMP_ITEM (drawable)),
|
|
|
|
gimp_item_get_height (GIMP_ITEM (drawable))),
|
2015-08-16 21:47:43 +08:00
|
|
|
new_format);
|
2012-03-18 05:53:17 +08:00
|
|
|
|
2015-05-25 04:32:55 +08:00
|
|
|
gegl_buffer_copy (gimp_drawable_get_buffer (drawable), NULL, GEGL_ABYSS_NONE,
|
2012-04-12 00:50:57 +08:00
|
|
|
dest_buffer, NULL);
|
|
|
|
|
|
|
|
gimp_drawable_set_buffer (drawable, push_undo, NULL, dest_buffer);
|
|
|
|
g_object_unref (dest_buffer);
|
2009-09-12 03:23:35 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 07:07:48 +08:00
|
|
|
static GeglBuffer *
|
|
|
|
gimp_drawable_real_get_buffer (GimpDrawable *drawable)
|
2007-12-18 19:20:23 +08:00
|
|
|
{
|
2012-03-22 07:07:48 +08:00
|
|
|
return drawable->private->buffer;
|
2007-12-18 19:20:23 +08:00
|
|
|
}
|
|
|
|
|
2004-03-13 21:56:09 +08:00
|
|
|
static void
|
2012-03-22 06:37:16 +08:00
|
|
|
gimp_drawable_real_set_buffer (GimpDrawable *drawable,
|
|
|
|
gboolean push_undo,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
2004-03-13 21:56:09 +08:00
|
|
|
{
|
2012-03-22 06:37:16 +08:00
|
|
|
GimpItem *item = GIMP_ITEM (drawable);
|
2004-03-16 03:34:35 +08:00
|
|
|
gboolean old_has_alpha;
|
2004-03-15 23:37:12 +08:00
|
|
|
|
|
|
|
old_has_alpha = gimp_drawable_has_alpha (drawable);
|
|
|
|
|
2015-06-24 22:26:45 +08:00
|
|
|
g_object_freeze_notify (G_OBJECT (drawable));
|
|
|
|
|
2004-03-16 01:53:55 +08:00
|
|
|
gimp_drawable_invalidate_boundary (drawable);
|
|
|
|
|
2004-03-16 04:58:07 +08:00
|
|
|
if (push_undo)
|
|
|
|
gimp_image_undo_push_drawable_mod (gimp_item_get_image (item), undo_desc,
|
2010-03-18 17:25:18 +08:00
|
|
|
drawable, FALSE);
|
2004-03-16 04:58:07 +08:00
|
|
|
|
2004-03-17 00:23:06 +08:00
|
|
|
/* ref new before unrefing old, they might be the same */
|
2012-03-22 06:37:16 +08:00
|
|
|
g_object_ref (buffer);
|
2004-03-17 00:23:06 +08:00
|
|
|
|
2012-03-22 04:26:05 +08:00
|
|
|
if (drawable->private->buffer)
|
|
|
|
g_object_unref (drawable->private->buffer);
|
2004-03-13 21:56:09 +08:00
|
|
|
|
2012-03-22 06:37:16 +08:00
|
|
|
drawable->private->buffer = buffer;
|
2012-03-15 09:42:59 +08:00
|
|
|
|
2015-06-24 22:26:45 +08:00
|
|
|
if (drawable->private->buffer_source_node)
|
|
|
|
gegl_node_set (drawable->private->buffer_source_node,
|
|
|
|
"buffer", gimp_drawable_get_buffer (drawable),
|
|
|
|
NULL);
|
|
|
|
|
2008-11-03 07:16:47 +08:00
|
|
|
gimp_item_set_offset (item, offset_x, offset_y);
|
2009-08-26 19:03:40 +08:00
|
|
|
gimp_item_set_size (item,
|
2012-03-22 06:37:16 +08:00
|
|
|
gegl_buffer_get_width (buffer),
|
|
|
|
gegl_buffer_get_height (buffer));
|
2004-03-16 03:34:35 +08:00
|
|
|
|
2004-03-15 23:37:12 +08:00
|
|
|
if (old_has_alpha != gimp_drawable_has_alpha (drawable))
|
|
|
|
gimp_drawable_alpha_changed (drawable);
|
2008-10-10 04:44:23 +08:00
|
|
|
|
2013-09-05 16:37:09 +08:00
|
|
|
g_object_notify (G_OBJECT (drawable), "buffer");
|
2015-06-24 22:26:45 +08:00
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (drawable));
|
2004-03-13 21:56:09 +08:00
|
|
|
}
|
|
|
|
|
2004-04-01 22:51:58 +08:00
|
|
|
static void
|
|
|
|
gimp_drawable_real_push_undo (GimpDrawable *drawable,
|
|
|
|
const gchar *undo_desc,
|
2012-03-22 21:13:17 +08:00
|
|
|
GeglBuffer *buffer,
|
2004-04-01 22:51:58 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2012-03-22 21:13:17 +08:00
|
|
|
if (! buffer)
|
2004-04-01 22:51:58 +08:00
|
|
|
{
|
2012-05-21 04:00:27 +08:00
|
|
|
buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height),
|
|
|
|
gimp_drawable_get_format (drawable));
|
2012-03-15 19:30:41 +08:00
|
|
|
|
2012-03-21 10:57:53 +08:00
|
|
|
gegl_buffer_copy (gimp_drawable_get_buffer (drawable),
|
2015-05-25 04:32:55 +08:00
|
|
|
GEGL_RECTANGLE (x, y, width, height), GEGL_ABYSS_NONE,
|
2012-03-22 21:13:17 +08:00
|
|
|
buffer,
|
2012-04-02 21:19:47 +08:00
|
|
|
GEGL_RECTANGLE (0, 0, 0, 0));
|
2012-03-22 21:13:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_ref (buffer);
|
2004-04-01 22:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gimp_image_undo_push_drawable (gimp_item_get_image (GIMP_ITEM (drawable)),
|
|
|
|
undo_desc, drawable,
|
2012-03-22 21:25:45 +08:00
|
|
|
buffer, x, y);
|
2004-04-01 22:51:58 +08:00
|
|
|
|
2012-03-22 21:13:17 +08:00
|
|
|
g_object_unref (buffer);
|
2004-04-01 22:51:58 +08:00
|
|
|
}
|
|
|
|
|
2004-03-15 22:10:30 +08:00
|
|
|
static void
|
2006-04-07 17:21:18 +08:00
|
|
|
gimp_drawable_real_swap_pixels (GimpDrawable *drawable,
|
2012-03-22 21:13:17 +08:00
|
|
|
GeglBuffer *buffer,
|
2006-04-07 17:21:18 +08:00
|
|
|
gint x,
|
2012-03-22 21:25:45 +08:00
|
|
|
gint y)
|
2004-03-15 22:10:30 +08:00
|
|
|
{
|
2012-03-22 21:13:17 +08:00
|
|
|
GeglBuffer *tmp;
|
2012-03-22 21:25:45 +08:00
|
|
|
gint width = gegl_buffer_get_width (buffer);
|
|
|
|
gint height = gegl_buffer_get_height (buffer);
|
2004-03-15 22:10:30 +08:00
|
|
|
|
2012-05-21 04:00:27 +08:00
|
|
|
tmp = gegl_buffer_dup (buffer);
|
2004-03-15 22:10:30 +08:00
|
|
|
|
2012-03-22 21:13:17 +08:00
|
|
|
gegl_buffer_copy (gimp_drawable_get_buffer (drawable),
|
2015-05-25 04:32:55 +08:00
|
|
|
GEGL_RECTANGLE (x, y, width, height), GEGL_ABYSS_NONE,
|
2012-03-22 21:13:17 +08:00
|
|
|
buffer,
|
2012-04-02 21:19:47 +08:00
|
|
|
GEGL_RECTANGLE (0, 0, 0, 0));
|
2012-03-22 21:13:17 +08:00
|
|
|
gegl_buffer_copy (tmp,
|
2015-05-25 04:32:55 +08:00
|
|
|
GEGL_RECTANGLE (0, 0, width, height), GEGL_ABYSS_NONE,
|
2012-03-22 21:13:17 +08:00
|
|
|
gimp_drawable_get_buffer (drawable),
|
2012-04-02 21:19:47 +08:00
|
|
|
GEGL_RECTANGLE (x, y, 0, 0));
|
2004-03-15 22:10:30 +08:00
|
|
|
|
2012-03-22 21:13:17 +08:00
|
|
|
g_object_unref (tmp);
|
2004-03-15 22:10:30 +08:00
|
|
|
|
|
|
|
gimp_drawable_update (drawable, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2011-02-01 19:47:24 +08:00
|
|
|
GimpDrawable *
|
|
|
|
gimp_drawable_new (GType type,
|
|
|
|
GimpImage *image,
|
|
|
|
const gchar *name,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
2012-03-22 03:21:11 +08:00
|
|
|
const Babl *format)
|
2011-02-01 19:47:24 +08:00
|
|
|
{
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
g_return_val_if_fail (g_type_is_a (type, GIMP_TYPE_DRAWABLE), NULL);
|
|
|
|
g_return_val_if_fail (width > 0 && height > 0, NULL);
|
2012-03-22 03:21:11 +08:00
|
|
|
g_return_val_if_fail (format != NULL, NULL);
|
2011-02-01 19:47:24 +08:00
|
|
|
|
|
|
|
drawable = GIMP_DRAWABLE (gimp_item_new (type,
|
|
|
|
image, name,
|
|
|
|
offset_x, offset_y,
|
|
|
|
width, height));
|
|
|
|
|
2012-06-21 03:44:09 +08:00
|
|
|
drawable->private->buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
|
|
|
|
width, height),
|
|
|
|
format);
|
2011-02-01 19:47:24 +08:00
|
|
|
|
|
|
|
return drawable;
|
|
|
|
}
|
|
|
|
|
2007-12-04 19:30:31 +08:00
|
|
|
gint64
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_estimate_memsize (GimpDrawable *drawable,
|
|
|
|
GimpComponentType component_type,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2007-12-04 19:30:31 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), 0);
|
|
|
|
|
|
|
|
return GIMP_DRAWABLE_GET_CLASS (drawable)->estimate_memsize (drawable,
|
2014-06-15 05:12:22 +08:00
|
|
|
component_type,
|
2007-12-04 19:30:31 +08:00
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
|
2001-07-08 06:49:01 +08:00
|
|
|
void
|
|
|
|
gimp_drawable_update (GimpDrawable *drawable,
|
2004-07-14 18:31:59 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2001-07-08 06:49:01 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
|
2010-04-18 21:03:16 +08:00
|
|
|
g_signal_emit (drawable, gimp_drawable_signals[UPDATE], 0,
|
|
|
|
x, y, width, height);
|
2001-07-08 06:49:01 +08:00
|
|
|
}
|
|
|
|
|
2003-10-06 22:40:12 +08:00
|
|
|
void
|
|
|
|
gimp_drawable_alpha_changed (GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
|
|
|
|
g_signal_emit (drawable, gimp_drawable_signals[ALPHA_CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_drawable_invalidate_boundary (GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
GimpDrawableClass *drawable_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
|
|
|
|
drawable_class = GIMP_DRAWABLE_GET_CLASS (drawable);
|
|
|
|
|
|
|
|
if (drawable_class->invalidate_boundary)
|
|
|
|
drawable_class->invalidate_boundary (drawable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_active_components (GimpDrawable *drawable,
|
|
|
|
gboolean *active)
|
2003-10-06 22:40:12 +08:00
|
|
|
{
|
|
|
|
GimpDrawableClass *drawable_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (active != NULL);
|
|
|
|
|
|
|
|
drawable_class = GIMP_DRAWABLE_GET_CLASS (drawable);
|
|
|
|
|
|
|
|
if (drawable_class->get_active_components)
|
|
|
|
drawable_class->get_active_components (drawable, active);
|
|
|
|
}
|
|
|
|
|
2012-04-26 05:23:31 +08:00
|
|
|
GimpComponentMask
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_active_mask (GimpDrawable *drawable)
|
2012-04-26 05:23:31 +08:00
|
|
|
{
|
|
|
|
GimpDrawableClass *drawable_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), 0);
|
|
|
|
|
|
|
|
drawable_class = GIMP_DRAWABLE_GET_CLASS (drawable);
|
|
|
|
|
|
|
|
if (drawable_class->get_active_mask)
|
|
|
|
return drawable_class->get_active_mask (drawable);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-12 03:23:35 +08:00
|
|
|
void
|
|
|
|
gimp_drawable_convert_type (GimpDrawable *drawable,
|
|
|
|
GimpImage *dest_image,
|
2009-09-14 01:24:19 +08:00
|
|
|
GimpImageBaseType new_base_type,
|
2012-04-25 18:09:45 +08:00
|
|
|
GimpPrecision new_precision,
|
2016-04-29 06:42:42 +08:00
|
|
|
GimpColorProfile *dest_profile,
|
2012-10-14 03:46:56 +08:00
|
|
|
gint layer_dither_type,
|
|
|
|
gint mask_dither_type,
|
2015-10-22 04:22:30 +08:00
|
|
|
gboolean push_undo,
|
|
|
|
GimpProgress *progress)
|
2009-09-12 03:23:35 +08:00
|
|
|
{
|
2012-10-14 04:56:32 +08:00
|
|
|
const Babl *new_format;
|
|
|
|
|
2009-09-12 03:23:35 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
2012-04-12 00:50:57 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (dest_image));
|
2012-04-25 18:09:45 +08:00
|
|
|
g_return_if_fail (new_base_type != gimp_drawable_get_base_type (drawable) ||
|
2015-08-16 21:47:43 +08:00
|
|
|
new_precision != gimp_drawable_get_precision (drawable) ||
|
2016-04-29 06:42:42 +08:00
|
|
|
dest_profile);
|
|
|
|
g_return_if_fail (dest_profile == NULL || GIMP_IS_COLOR_PROFILE (dest_profile));
|
2015-10-22 04:22:30 +08:00
|
|
|
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
|
2009-09-12 03:23:35 +08:00
|
|
|
|
2009-09-14 01:24:19 +08:00
|
|
|
if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
|
|
|
|
push_undo = FALSE;
|
|
|
|
|
2012-10-14 04:56:32 +08:00
|
|
|
new_format = gimp_image_get_format (dest_image,
|
|
|
|
new_base_type,
|
|
|
|
new_precision,
|
|
|
|
gimp_drawable_has_alpha (drawable));
|
|
|
|
|
2009-09-12 03:23:35 +08:00
|
|
|
GIMP_DRAWABLE_GET_CLASS (drawable)->convert_type (drawable, dest_image,
|
2012-10-14 04:56:32 +08:00
|
|
|
new_format,
|
2012-04-25 18:09:45 +08:00
|
|
|
new_base_type,
|
|
|
|
new_precision,
|
2016-04-29 06:42:42 +08:00
|
|
|
dest_profile,
|
2012-10-14 03:46:56 +08:00
|
|
|
layer_dither_type,
|
|
|
|
mask_dither_type,
|
2015-10-22 04:22:30 +08:00
|
|
|
push_undo,
|
|
|
|
progress);
|
|
|
|
|
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, 1.0);
|
2009-09-12 03:23:35 +08:00
|
|
|
}
|
|
|
|
|
2012-03-23 01:40:40 +08:00
|
|
|
void
|
|
|
|
gimp_drawable_apply_buffer (GimpDrawable *drawable,
|
|
|
|
GeglBuffer *buffer,
|
2012-03-23 06:45:11 +08:00
|
|
|
const GeglRectangle *buffer_region,
|
2012-03-23 01:40:40 +08:00
|
|
|
gboolean push_undo,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpLayerModeEffects mode,
|
2012-03-23 07:12:13 +08:00
|
|
|
GeglBuffer *base_buffer,
|
2012-03-24 07:57:11 +08:00
|
|
|
gint base_x,
|
2012-05-19 06:14:51 +08:00
|
|
|
gint base_y)
|
2012-03-23 01:40:40 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
|
|
|
g_return_if_fail (GEGL_IS_BUFFER (buffer));
|
2012-03-23 06:45:11 +08:00
|
|
|
g_return_if_fail (buffer_region != NULL);
|
2012-03-23 07:12:13 +08:00
|
|
|
g_return_if_fail (base_buffer == NULL || GEGL_IS_BUFFER (base_buffer));
|
2003-10-06 22:40:12 +08:00
|
|
|
|
2012-03-23 06:45:11 +08:00
|
|
|
GIMP_DRAWABLE_GET_CLASS (drawable)->apply_buffer (drawable, buffer,
|
|
|
|
buffer_region,
|
2003-10-06 22:40:12 +08:00
|
|
|
push_undo, undo_desc,
|
|
|
|
opacity, mode,
|
2012-03-23 07:12:13 +08:00
|
|
|
base_buffer,
|
2012-05-19 06:14:51 +08:00
|
|
|
base_x, base_y);
|
2003-10-06 22:40:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-23 19:31:21 +08:00
|
|
|
gimp_drawable_replace_buffer (GimpDrawable *drawable,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
const GeglRectangle *buffer_region,
|
|
|
|
gboolean push_undo,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
gdouble opacity,
|
2012-04-23 06:32:14 +08:00
|
|
|
GeglBuffer *mask,
|
|
|
|
const GeglRectangle *mask_region,
|
2012-03-23 19:31:21 +08:00
|
|
|
gint x,
|
|
|
|
gint y)
|
2003-10-06 22:40:12 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
2012-03-23 19:31:21 +08:00
|
|
|
g_return_if_fail (GEGL_IS_BUFFER (buffer));
|
2012-04-23 06:32:14 +08:00
|
|
|
g_return_if_fail (GEGL_IS_BUFFER (mask));
|
2003-10-06 22:40:12 +08:00
|
|
|
|
2012-03-23 19:31:21 +08:00
|
|
|
GIMP_DRAWABLE_GET_CLASS (drawable)->replace_buffer (drawable, buffer,
|
|
|
|
buffer_region,
|
2003-10-06 22:40:12 +08:00
|
|
|
push_undo, undo_desc,
|
2012-04-23 06:32:14 +08:00
|
|
|
opacity,
|
|
|
|
mask, mask_region,
|
2003-10-06 22:40:12 +08:00
|
|
|
x, y);
|
|
|
|
}
|
2008-11-08 08:16:40 +08:00
|
|
|
|
2012-03-15 09:42:59 +08:00
|
|
|
GeglBuffer *
|
2012-03-21 07:42:44 +08:00
|
|
|
gimp_drawable_get_buffer (GimpDrawable *drawable)
|
2012-03-15 09:42:59 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
|
2012-03-22 07:07:48 +08:00
|
|
|
return GIMP_DRAWABLE_GET_CLASS (drawable)->get_buffer (drawable);
|
2012-03-15 09:42:59 +08:00
|
|
|
}
|
|
|
|
|
2004-03-13 21:56:09 +08:00
|
|
|
void
|
2012-03-22 06:37:16 +08:00
|
|
|
gimp_drawable_set_buffer (GimpDrawable *drawable,
|
|
|
|
gboolean push_undo,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
GeglBuffer *buffer)
|
2004-03-16 03:34:35 +08:00
|
|
|
{
|
|
|
|
gint offset_x, offset_y;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
2012-03-22 06:37:16 +08:00
|
|
|
g_return_if_fail (GEGL_IS_BUFFER (buffer));
|
2004-03-16 03:34:35 +08:00
|
|
|
|
2004-11-16 21:41:55 +08:00
|
|
|
if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
|
|
|
|
push_undo = FALSE;
|
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &offset_x, &offset_y);
|
2004-03-16 03:34:35 +08:00
|
|
|
|
2012-03-22 06:37:16 +08:00
|
|
|
gimp_drawable_set_buffer_full (drawable, push_undo, undo_desc, buffer,
|
|
|
|
offset_x, offset_y);
|
2004-03-16 03:34:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-22 06:37:16 +08:00
|
|
|
gimp_drawable_set_buffer_full (GimpDrawable *drawable,
|
|
|
|
gboolean push_undo,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
2004-03-13 21:56:09 +08:00
|
|
|
{
|
2011-05-02 05:23:19 +08:00
|
|
|
GimpItem *item;
|
2004-03-16 04:05:31 +08:00
|
|
|
|
2004-03-13 21:56:09 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
2012-03-22 06:37:16 +08:00
|
|
|
g_return_if_fail (GEGL_IS_BUFFER (buffer));
|
2004-03-13 21:56:09 +08:00
|
|
|
|
2011-05-02 05:23:19 +08:00
|
|
|
item = GIMP_ITEM (drawable);
|
2004-04-13 21:54:54 +08:00
|
|
|
|
2004-11-16 21:41:55 +08:00
|
|
|
if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
|
|
|
|
push_undo = FALSE;
|
|
|
|
|
2012-03-22 06:37:16 +08:00
|
|
|
if (gimp_item_get_width (item) != gegl_buffer_get_width (buffer) ||
|
|
|
|
gimp_item_get_height (item) != gegl_buffer_get_height (buffer) ||
|
|
|
|
gimp_item_get_offset_x (item) != offset_x ||
|
2008-12-28 20:43:07 +08:00
|
|
|
gimp_item_get_offset_y (item) != offset_y)
|
2004-03-16 04:05:31 +08:00
|
|
|
{
|
2007-12-24 00:58:41 +08:00
|
|
|
gimp_drawable_update (drawable,
|
|
|
|
0, 0,
|
2008-11-03 08:09:01 +08:00
|
|
|
gimp_item_get_width (item),
|
|
|
|
gimp_item_get_height (item));
|
2004-03-16 04:05:31 +08:00
|
|
|
}
|
|
|
|
|
2009-08-26 19:20:18 +08:00
|
|
|
g_object_freeze_notify (G_OBJECT (drawable));
|
|
|
|
|
2012-03-22 06:37:16 +08:00
|
|
|
GIMP_DRAWABLE_GET_CLASS (drawable)->set_buffer (drawable,
|
|
|
|
push_undo, undo_desc,
|
|
|
|
buffer,
|
|
|
|
offset_x, offset_y);
|
2004-03-16 04:05:31 +08:00
|
|
|
|
2009-08-26 19:20:18 +08:00
|
|
|
g_object_thaw_notify (G_OBJECT (drawable));
|
|
|
|
|
2007-12-24 00:58:41 +08:00
|
|
|
gimp_drawable_update (drawable,
|
|
|
|
0, 0,
|
2008-11-03 08:09:01 +08:00
|
|
|
gimp_item_get_width (item),
|
|
|
|
gimp_item_get_height (item));
|
2004-03-13 21:56:09 +08:00
|
|
|
}
|
|
|
|
|
2008-10-10 04:44:23 +08:00
|
|
|
GeglNode *
|
|
|
|
gimp_drawable_get_source_node (GimpDrawable *drawable)
|
|
|
|
{
|
2013-04-12 01:06:23 +08:00
|
|
|
GeglNode *filter;
|
|
|
|
GeglNode *output;
|
|
|
|
|
2008-10-10 04:44:23 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
|
2009-02-04 07:57:11 +08:00
|
|
|
if (drawable->private->source_node)
|
|
|
|
return drawable->private->source_node;
|
2008-10-10 04:44:23 +08:00
|
|
|
|
2009-02-04 07:57:11 +08:00
|
|
|
drawable->private->source_node = gegl_node_new ();
|
2009-01-27 06:05:07 +08:00
|
|
|
|
2012-03-22 07:18:22 +08:00
|
|
|
drawable->private->buffer_source_node =
|
2009-02-04 07:57:11 +08:00
|
|
|
gegl_node_new_child (drawable->private->source_node,
|
2012-03-14 17:05:01 +08:00
|
|
|
"operation", "gegl:buffer-source",
|
2012-03-21 07:42:44 +08:00
|
|
|
"buffer", gimp_drawable_get_buffer (drawable),
|
2009-01-27 06:05:07 +08:00
|
|
|
NULL);
|
|
|
|
|
2013-04-12 01:06:23 +08:00
|
|
|
filter = gimp_filter_stack_get_graph (GIMP_FILTER_STACK (drawable->private->filter_stack));
|
|
|
|
|
|
|
|
gegl_node_add_child (drawable->private->source_node, filter);
|
|
|
|
|
|
|
|
gegl_node_connect_to (drawable->private->buffer_source_node, "output",
|
|
|
|
filter, "input");
|
|
|
|
|
|
|
|
output = gegl_node_get_output_proxy (drawable->private->source_node, "output");
|
|
|
|
|
|
|
|
gegl_node_connect_to (filter, "output",
|
|
|
|
output, "input");
|
|
|
|
|
2016-05-19 23:38:55 +08:00
|
|
|
if (gimp_drawable_get_floating_sel (drawable))
|
|
|
|
_gimp_drawable_add_floating_sel_filter (drawable);
|
2008-10-10 04:44:23 +08:00
|
|
|
|
2009-02-04 07:57:11 +08:00
|
|
|
return drawable->private->source_node;
|
2008-10-10 04:44:23 +08:00
|
|
|
}
|
|
|
|
|
2008-10-15 02:32:07 +08:00
|
|
|
GeglNode *
|
|
|
|
gimp_drawable_get_mode_node (GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
|
2009-02-04 07:57:11 +08:00
|
|
|
if (! drawable->private->mode_node)
|
2013-04-11 08:54:42 +08:00
|
|
|
gimp_filter_get_node (GIMP_FILTER (drawable));
|
2008-10-11 03:36:17 +08:00
|
|
|
|
2009-02-04 07:57:11 +08:00
|
|
|
return drawable->private->mode_node;
|
2008-10-11 03:36:17 +08:00
|
|
|
}
|
|
|
|
|
2004-03-15 22:10:30 +08:00
|
|
|
void
|
|
|
|
gimp_drawable_swap_pixels (GimpDrawable *drawable,
|
2012-03-22 21:13:17 +08:00
|
|
|
GeglBuffer *buffer,
|
2004-03-15 22:10:30 +08:00
|
|
|
gint x,
|
2012-03-22 21:25:45 +08:00
|
|
|
gint y)
|
2004-03-15 22:10:30 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
2012-03-22 21:13:17 +08:00
|
|
|
g_return_if_fail (GEGL_IS_BUFFER (buffer));
|
2004-03-15 22:10:30 +08:00
|
|
|
|
2012-03-22 21:25:45 +08:00
|
|
|
GIMP_DRAWABLE_GET_CLASS (drawable)->swap_pixels (drawable, buffer, x, y);
|
2004-03-15 22:10:30 +08:00
|
|
|
}
|
|
|
|
|
2001-07-08 06:49:01 +08:00
|
|
|
void
|
2003-02-14 22:14:29 +08:00
|
|
|
gimp_drawable_push_undo (GimpDrawable *drawable,
|
|
|
|
const gchar *undo_desc,
|
2012-03-22 21:13:17 +08:00
|
|
|
GeglBuffer *buffer,
|
2009-06-17 04:59:07 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
2012-03-22 21:13:17 +08:00
|
|
|
gint height)
|
2001-07-08 06:49:01 +08:00
|
|
|
{
|
2004-03-15 22:10:30 +08:00
|
|
|
GimpItem *item;
|
|
|
|
|
2001-07-08 06:49:01 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
2012-03-22 21:13:17 +08:00
|
|
|
g_return_if_fail (buffer == NULL || GEGL_IS_BUFFER (buffer));
|
2004-03-15 22:10:30 +08:00
|
|
|
|
|
|
|
item = GIMP_ITEM (drawable);
|
|
|
|
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_if_fail (gimp_item_is_attached (item));
|
2004-03-15 22:10:30 +08:00
|
|
|
|
2012-03-22 21:13:17 +08:00
|
|
|
if (! buffer &&
|
|
|
|
! gimp_rectangle_intersect (x, y,
|
2009-06-17 04:59:07 +08:00
|
|
|
width, height,
|
2004-03-15 22:10:30 +08:00
|
|
|
0, 0,
|
2008-11-03 08:09:01 +08:00
|
|
|
gimp_item_get_width (item),
|
|
|
|
gimp_item_get_height (item),
|
2004-03-15 22:10:30 +08:00
|
|
|
&x, &y, &width, &height))
|
|
|
|
{
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: tried to push empty region", G_STRFUNC);
|
2004-03-15 22:10:30 +08:00
|
|
|
return;
|
|
|
|
}
|
2001-07-08 06:49:01 +08:00
|
|
|
|
2004-04-01 22:51:58 +08:00
|
|
|
GIMP_DRAWABLE_GET_CLASS (drawable)->push_undo (drawable, undo_desc,
|
2012-03-22 21:13:17 +08:00
|
|
|
buffer,
|
2004-04-01 22:51:58 +08:00
|
|
|
x, y, width, height);
|
2001-07-08 06:49:01 +08:00
|
|
|
}
|
|
|
|
|
2012-03-16 07:01:34 +08:00
|
|
|
const Babl *
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_format (GimpDrawable *drawable)
|
2012-03-16 07:01:34 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
|
2012-03-30 05:19:27 +08:00
|
|
|
return gegl_buffer_get_format (drawable->private->buffer);
|
2012-03-16 07:01:34 +08:00
|
|
|
}
|
|
|
|
|
2012-03-18 04:21:36 +08:00
|
|
|
const Babl *
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_format_with_alpha (GimpDrawable *drawable)
|
2012-03-18 04:21:36 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
|
2012-04-12 00:40:30 +08:00
|
|
|
return gimp_image_get_format (gimp_item_get_image (GIMP_ITEM (drawable)),
|
|
|
|
gimp_drawable_get_base_type (drawable),
|
2012-05-08 03:46:47 +08:00
|
|
|
gimp_drawable_get_precision (drawable),
|
2012-04-12 00:40:30 +08:00
|
|
|
TRUE);
|
2012-03-18 04:21:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-18 23:24:29 +08:00
|
|
|
const Babl *
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_format_without_alpha (GimpDrawable *drawable)
|
2012-03-18 23:24:29 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
|
2012-04-12 00:40:30 +08:00
|
|
|
return gimp_image_get_format (gimp_item_get_image (GIMP_ITEM (drawable)),
|
|
|
|
gimp_drawable_get_base_type (drawable),
|
2012-05-08 03:46:47 +08:00
|
|
|
gimp_drawable_get_precision (drawable),
|
2012-04-12 00:40:30 +08:00
|
|
|
FALSE);
|
2012-03-18 23:24:29 +08:00
|
|
|
}
|
|
|
|
|
2013-04-27 14:41:06 +08:00
|
|
|
gboolean
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_linear (GimpDrawable *drawable)
|
2013-04-27 14:41:06 +08:00
|
|
|
{
|
2013-05-01 06:05:53 +08:00
|
|
|
const Babl *format;
|
|
|
|
|
2013-04-27 14:41:06 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
|
|
|
|
2013-05-01 06:05:53 +08:00
|
|
|
format = gegl_buffer_get_format (drawable->private->buffer);
|
|
|
|
|
|
|
|
return gimp_babl_format_get_linear (format);
|
2013-04-27 14:41:06 +08:00
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
gboolean
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_has_alpha (GimpDrawable *drawable)
|
1999-08-22 19:45:31 +08:00
|
|
|
{
|
2012-03-30 05:19:27 +08:00
|
|
|
const Babl *format;
|
|
|
|
|
2000-02-17 19:44:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
|
|
|
|
2012-03-30 05:19:27 +08:00
|
|
|
format = gegl_buffer_get_format (drawable->private->buffer);
|
|
|
|
|
|
|
|
return babl_format_has_alpha (format);
|
1999-08-22 19:45:31 +08:00
|
|
|
}
|
1998-10-14 10:54:02 +08:00
|
|
|
|
2012-04-07 07:51:08 +08:00
|
|
|
GimpImageBaseType
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_base_type (GimpDrawable *drawable)
|
2012-04-07 07:34:44 +08:00
|
|
|
{
|
|
|
|
const Babl *format;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
|
|
|
|
|
|
|
|
format = gegl_buffer_get_format (drawable->private->buffer);
|
|
|
|
|
2012-04-07 08:27:58 +08:00
|
|
|
return gimp_babl_format_get_base_type (format);
|
2012-04-07 07:34:44 +08:00
|
|
|
}
|
|
|
|
|
2013-06-23 22:51:24 +08:00
|
|
|
GimpComponentType
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_component_type (GimpDrawable *drawable)
|
2013-06-23 22:51:24 +08:00
|
|
|
{
|
|
|
|
const Babl *format;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
|
|
|
|
|
|
|
|
format = gegl_buffer_get_format (drawable->private->buffer);
|
|
|
|
|
|
|
|
return gimp_babl_format_get_component_type (format);
|
|
|
|
}
|
|
|
|
|
2012-04-22 23:31:32 +08:00
|
|
|
GimpPrecision
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_precision (GimpDrawable *drawable)
|
2012-04-22 23:31:32 +08:00
|
|
|
{
|
|
|
|
const Babl *format;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
|
|
|
|
|
|
|
|
format = gegl_buffer_get_format (drawable->private->buffer);
|
|
|
|
|
|
|
|
return gimp_babl_format_get_precision (format);
|
|
|
|
}
|
|
|
|
|
2001-12-13 07:48:18 +08:00
|
|
|
gboolean
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_is_rgb (GimpDrawable *drawable)
|
2001-12-13 07:48:18 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
|
|
|
|
2012-04-07 08:27:58 +08:00
|
|
|
return (gimp_drawable_get_base_type (drawable) == GIMP_RGB);
|
2001-12-13 07:48:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_is_gray (GimpDrawable *drawable)
|
2001-12-13 07:48:18 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
|
|
|
|
2012-04-07 08:27:58 +08:00
|
|
|
return (gimp_drawable_get_base_type (drawable) == GIMP_GRAY);
|
2001-12-13 07:48:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_is_indexed (GimpDrawable *drawable)
|
2001-12-13 07:48:18 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
|
|
|
|
|
2012-04-07 08:27:58 +08:00
|
|
|
return (gimp_drawable_get_base_type (drawable) == GIMP_INDEXED);
|
2001-12-13 07:48:18 +08:00
|
|
|
}
|
|
|
|
|
2014-06-02 08:31:42 +08:00
|
|
|
const Babl *
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_component_format (GimpDrawable *drawable,
|
|
|
|
GimpChannelType channel)
|
2014-06-02 08:31:42 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
|
|
|
|
switch (channel)
|
|
|
|
{
|
|
|
|
case GIMP_RED_CHANNEL:
|
|
|
|
return gimp_babl_component_format (GIMP_RGB,
|
|
|
|
gimp_drawable_get_precision (drawable),
|
|
|
|
RED);
|
|
|
|
|
|
|
|
case GIMP_GREEN_CHANNEL:
|
|
|
|
return gimp_babl_component_format (GIMP_RGB,
|
|
|
|
gimp_drawable_get_precision (drawable),
|
|
|
|
GREEN);
|
|
|
|
|
|
|
|
case GIMP_BLUE_CHANNEL:
|
|
|
|
return gimp_babl_component_format (GIMP_RGB,
|
|
|
|
gimp_drawable_get_precision (drawable),
|
|
|
|
BLUE);
|
|
|
|
|
|
|
|
case GIMP_ALPHA_CHANNEL:
|
|
|
|
return gimp_babl_component_format (GIMP_RGB,
|
|
|
|
gimp_drawable_get_precision (drawable),
|
|
|
|
ALPHA);
|
|
|
|
|
|
|
|
case GIMP_GRAY_CHANNEL:
|
|
|
|
return gimp_babl_component_format (GIMP_GRAY,
|
|
|
|
gimp_drawable_get_precision (drawable),
|
|
|
|
GRAY);
|
|
|
|
|
|
|
|
case GIMP_INDEXED_CHANNEL:
|
|
|
|
return babl_format ("Y u8"); /* will extract grayscale, the best
|
|
|
|
* we can do here */
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_component_index (GimpDrawable *drawable,
|
|
|
|
GimpChannelType channel)
|
2014-06-02 08:31:42 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
|
|
|
|
|
|
|
|
switch (channel)
|
|
|
|
{
|
|
|
|
case GIMP_RED_CHANNEL: return RED;
|
|
|
|
case GIMP_GREEN_CHANNEL: return GREEN;
|
|
|
|
case GIMP_BLUE_CHANNEL: return BLUE;
|
|
|
|
case GIMP_GRAY_CHANNEL: return GRAY;
|
|
|
|
case GIMP_INDEXED_CHANNEL: return INDEXED;
|
|
|
|
case GIMP_ALPHA_CHANNEL:
|
|
|
|
switch (gimp_drawable_get_base_type (drawable))
|
|
|
|
{
|
|
|
|
case GIMP_RGB: return ALPHA;
|
|
|
|
case GIMP_GRAY: return ALPHA_G;
|
|
|
|
case GIMP_INDEXED: return ALPHA_I;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-09-24 01:31:50 +08:00
|
|
|
const guchar *
|
2016-05-20 05:51:44 +08:00
|
|
|
gimp_drawable_get_colormap (GimpDrawable *drawable)
|
2004-04-13 21:54:54 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image;
|
2004-04-13 21:54:54 +08:00
|
|
|
|
2011-09-24 01:31:50 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
2004-04-13 21:54:54 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image = gimp_item_get_image (GIMP_ITEM (drawable));
|
2004-04-13 21:54:54 +08:00
|
|
|
|
2011-09-24 01:31:50 +08:00
|
|
|
return image ? gimp_image_get_colormap (image) : NULL;
|
2004-04-13 21:54:54 +08:00
|
|
|
}
|