Commit 86a264e9 authored by Michael Natterer's avatar Michael Natterer 😴

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.
parent f857e70e
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "gimpchannel.h" #include "gimpchannel.h"
#include "gimpcontext.h" #include "gimpcontext.h"
#include "gimpdrawable-combine.h" #include "gimpdrawable-combine.h"
#include "gimpdrawable-convert.h"
#include "gimpdrawable-preview.h" #include "gimpdrawable-preview.h"
#include "gimpdrawable-private.h" #include "gimpdrawable-private.h"
#include "gimpdrawable-shadow.h" #include "gimpdrawable-shadow.h"
...@@ -125,6 +126,10 @@ static gint64 gimp_drawable_real_estimate_memsize (const GimpDrawable *drawable ...@@ -125,6 +126,10 @@ static gint64 gimp_drawable_real_estimate_memsize (const GimpDrawable *drawable
gint width, gint width,
gint height); 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 TileManager * gimp_drawable_real_get_tiles (GimpDrawable *drawable);
static void gimp_drawable_real_set_tiles (GimpDrawable *drawable, static void gimp_drawable_real_set_tiles (GimpDrawable *drawable,
gboolean push_undo, gboolean push_undo,
...@@ -226,6 +231,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass) ...@@ -226,6 +231,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
klass->estimate_memsize = gimp_drawable_real_estimate_memsize; klass->estimate_memsize = gimp_drawable_real_estimate_memsize;
klass->invalidate_boundary = NULL; klass->invalidate_boundary = NULL;
klass->get_active_components = NULL; klass->get_active_components = NULL;
klass->convert_type = gimp_drawable_real_convert_type;
klass->apply_region = gimp_drawable_real_apply_region; klass->apply_region = gimp_drawable_real_apply_region;
klass->replace_region = gimp_drawable_real_replace_region; klass->replace_region = gimp_drawable_real_replace_region;
klass->get_tiles = gimp_drawable_real_get_tiles; klass->get_tiles = gimp_drawable_real_get_tiles;
...@@ -719,6 +725,28 @@ gimp_drawable_real_estimate_memsize (const GimpDrawable *drawable, ...@@ -719,6 +725,28 @@ gimp_drawable_real_estimate_memsize (const GimpDrawable *drawable,
return (gint64) gimp_drawable_bytes (drawable) * width * height; 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);
gimp_drawable_convert_grayscale (drawable);
static TileManager * static TileManager *
gimp_drawable_real_get_tiles (GimpDrawable *drawable) gimp_drawable_real_get_tiles (GimpDrawable *drawable)
{ {
...@@ -1199,6 +1227,25 @@ gimp_drawable_get_active_components (const GimpDrawable *drawable, ...@@ -1199,6 +1227,25 @@ gimp_drawable_get_active_components (const GimpDrawable *drawable,
drawable_class->get_active_components (drawable, active); drawable_class->get_active_components (drawable, active);
} }
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,
void void
gimp_drawable_apply_region (GimpDrawable *drawable, gimp_drawable_apply_region (GimpDrawable *drawable,
PixelRegion *src2PR, PixelRegion *src2PR,
...@@ -63,6 +63,9 @@ struct _GimpDrawableClass ...@@ -63,6 +63,9 @@ struct _GimpDrawableClass
void (* invalidate_boundary) (GimpDrawable *drawable); void (* invalidate_boundary) (GimpDrawable *drawable);
void (* get_active_components) (const GimpDrawable *drawable, void (* get_active_components) (const GimpDrawable *drawable,
gboolean *active); gboolean *active);
void (* convert_type) (GimpDrawable *drawable,
GimpImage *dest_image,
GimpImageBaseType new_base_type);
void (* apply_region) (GimpDrawable *drawable, void (* apply_region) (GimpDrawable *drawable,
PixelRegion *src2PR, PixelRegion *src2PR,
gboolean push_undo, gboolean push_undo,
...@@ -140,6 +143,10 @@ void gimp_drawable_invalidate_boundary (GimpDrawable *drawable); ...@@ -140,6 +143,10 @@ void gimp_drawable_invalidate_boundary (GimpDrawable *drawable);
void gimp_drawable_get_active_components (const GimpDrawable *drawable, void gimp_drawable_get_active_components (const GimpDrawable *drawable,
gboolean *active); gboolean *active);
void gimp_drawable_convert_type (GimpDrawable *drawable,
GimpImage *dest_image,
GimpImageBaseType new_base_type);
void gimp_drawable_apply_region (GimpDrawable *drawable, void gimp_drawable_apply_region (GimpDrawable *drawable,
PixelRegion *src2PR, PixelRegion *src2PR,
gboolean push_undo, gboolean push_undo,
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment