[gimp] Add new virtual function GimpDrawable::convert_type()
- From: Michael Natterer <mitch src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gimp] Add new virtual function GimpDrawable::convert_type()
- Date: Fri, 11 Sep 2009 20:06:42 +0000 (UTC)
commit 86a264e9f2c4e7291d9c7f29d939b0303bb4a11a
Author: Michael Natterer <mitch gimp org>
Date: Fri Sep 11 21:23:35 2009 +0200
Add new virtual function GimpDrawable::convert_type()
This may look like duplication of GimpItem::convert() but in fact will
fix the longstanding uglyness that GimpItem::convert() both transfers
an item to another image *and* converts the image type of drawables.
When this refactoring is done, GimpItem::convert() will only move an
item to another image, and its implementation in GimpDrawable classes
will call GimpDrawable::convert_type() to convert the pixels to
whatever format.
Takes a "dest_image" parameter anyway because for converting to
indexed we need the destination colormap. The default impl in
GimpDrawable can only convert to gray and rgb however.
app/core/gimpdrawable.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
app/core/gimpdrawable.h | 7 +++++++
2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index c49e9c6..0be4f5c 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -35,6 +35,7 @@
#include "gimpchannel.h"
#include "gimpcontext.h"
#include "gimpdrawable-combine.h"
+#include "gimpdrawable-convert.h"
#include "gimpdrawable-preview.h"
#include "gimpdrawable-private.h"
#include "gimpdrawable-shadow.h"
@@ -125,6 +126,10 @@ static gint64 gimp_drawable_real_estimate_memsize (const GimpDrawable *drawable
gint width,
gint height);
+static void gimp_drawable_real_convert_type (GimpDrawable *drawable,
+ GimpImage *dest_image,
+ GimpImageBaseType new_base_type);
+
static TileManager * gimp_drawable_real_get_tiles (GimpDrawable *drawable);
static void gimp_drawable_real_set_tiles (GimpDrawable *drawable,
gboolean push_undo,
@@ -226,6 +231,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
klass->estimate_memsize = gimp_drawable_real_estimate_memsize;
klass->invalidate_boundary = NULL;
klass->get_active_components = NULL;
+ klass->convert_type = gimp_drawable_real_convert_type;
klass->apply_region = gimp_drawable_real_apply_region;
klass->replace_region = gimp_drawable_real_replace_region;
klass->get_tiles = gimp_drawable_real_get_tiles;
@@ -719,6 +725,28 @@ gimp_drawable_real_estimate_memsize (const GimpDrawable *drawable,
return (gint64) gimp_drawable_bytes (drawable) * width * height;
}
+static void
+gimp_drawable_real_convert_type (GimpDrawable *drawable,
+ GimpImage *dest_image,
+ GimpImageBaseType new_base_type)
+{
+ g_return_if_fail (new_base_type != GIMP_INDEXED);
+
+ switch (new_base_type)
+ {
+ case GIMP_RGB:
+ gimp_drawable_convert_rgb (drawable);
+ break;
+
+ case GIMP_GRAY:
+ gimp_drawable_convert_grayscale (drawable);
+ break;
+
+ default:
+ break;
+ }
+}
+
static TileManager *
gimp_drawable_real_get_tiles (GimpDrawable *drawable)
{
@@ -1200,6 +1228,25 @@ gimp_drawable_get_active_components (const GimpDrawable *drawable,
}
void
+gimp_drawable_convert_type (GimpDrawable *drawable,
+ GimpImage *dest_image,
+ GimpImageBaseType new_base_type)
+{
+ GimpImageType type;
+
+ g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
+ g_return_if_fail (dest_image == NULL || GIMP_IS_IMAGE (dest_image));
+ g_return_if_fail (new_base_type != GIMP_INDEXED || GIMP_IS_IMAGE (dest_image));
+
+ type = gimp_drawable_type (drawable);
+
+ g_return_if_fail (new_base_type != GIMP_IMAGE_TYPE_BASE_TYPE (type));
+
+ GIMP_DRAWABLE_GET_CLASS (drawable)->convert_type (drawable, dest_image,
+ new_base_type);
+}
+
+void
gimp_drawable_apply_region (GimpDrawable *drawable,
PixelRegion *src2PR,
gboolean push_undo,
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index e358d12..3b338ab 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -63,6 +63,9 @@ struct _GimpDrawableClass
void (* invalidate_boundary) (GimpDrawable *drawable);
void (* get_active_components) (const GimpDrawable *drawable,
gboolean *active);
+ void (* convert_type) (GimpDrawable *drawable,
+ GimpImage *dest_image,
+ GimpImageBaseType new_base_type);
void (* apply_region) (GimpDrawable *drawable,
PixelRegion *src2PR,
gboolean push_undo,
@@ -140,6 +143,10 @@ void gimp_drawable_invalidate_boundary (GimpDrawable *drawable);
void gimp_drawable_get_active_components (const GimpDrawable *drawable,
gboolean *active);
+void gimp_drawable_convert_type (GimpDrawable *drawable,
+ GimpImage *dest_image,
+ GimpImageBaseType new_base_type);
+
void gimp_drawable_apply_region (GimpDrawable *drawable,
PixelRegion *src2PR,
gboolean push_undo,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]