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.
This commit is contained in:
Michael Natterer 2009-09-11 21:23:35 +02:00
parent f857e70e26
commit 86a264e9f2
2 changed files with 54 additions and 0 deletions

View File

@ -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)
{
@ -1199,6 +1227,25 @@ gimp_drawable_get_active_components (const GimpDrawable *drawable,
drawable_class->get_active_components (drawable, active);
}
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,

View File

@ -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,