[gimp/goat-invasion: 108/412] app: let Babl handle converting layers to indexed
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/goat-invasion: 108/412] app: let Babl handle converting layers to indexed
- Date: Tue, 3 Apr 2012 09:42:11 +0000 (UTC)
commit 8d35f43aa5a4640b1627309a0c91782baaf8c3a1
Author: Michael Natterer <mitch gimp org>
Date: Sat Mar 17 22:53:17 2012 +0100
app: let Babl handle converting layers to indexed
Except of course the initial indexed conversion which needs more logic
than a simple color mapping.
app/core/gimpdrawable-convert.c | 74 ++++++++++++++++++++++-----------------
app/core/gimpdrawable-convert.h | 16 ++++-----
app/core/gimpdrawable.c | 6 ++-
app/core/gimplayer.c | 67 ++++-------------------------------
4 files changed, 60 insertions(+), 103 deletions(-)
---
diff --git a/app/core/gimpdrawable-convert.c b/app/core/gimpdrawable-convert.c
index babdac6..4734903 100644
--- a/app/core/gimpdrawable-convert.c
+++ b/app/core/gimpdrawable-convert.c
@@ -32,6 +32,7 @@
#include "gimpdrawable.h"
#include "gimpdrawable-convert.h"
#include "gimpimage.h"
+#include "gimpimage-colormap.h"
void
@@ -40,6 +41,7 @@ gimp_drawable_convert_rgb (GimpDrawable *drawable,
{
GimpImageType type;
TileManager *tiles;
+ GeglBuffer *dest_buffer;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (! gimp_drawable_is_rgb (drawable));
@@ -53,7 +55,12 @@ gimp_drawable_convert_rgb (GimpDrawable *drawable,
gimp_item_get_height (GIMP_ITEM (drawable)),
GIMP_IMAGE_TYPE_BYTES (type));
- gimp_drawable_convert_tiles_rgb (drawable, tiles);
+ dest_buffer = gimp_tile_manager_create_buffer (tiles, NULL, TRUE);
+
+ gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), NULL,
+ dest_buffer, NULL);
+
+ g_object_unref (dest_buffer);
gimp_drawable_set_tiles (drawable, push_undo, NULL,
tiles, type);
@@ -66,6 +73,7 @@ gimp_drawable_convert_grayscale (GimpDrawable *drawable,
{
GimpImageType type;
TileManager *tiles;
+ GeglBuffer *dest_buffer;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (! gimp_drawable_is_gray (drawable));
@@ -79,55 +87,57 @@ gimp_drawable_convert_grayscale (GimpDrawable *drawable,
gimp_item_get_height (GIMP_ITEM (drawable)),
GIMP_IMAGE_TYPE_BYTES (type));
- gimp_drawable_convert_tiles_grayscale (drawable, tiles);
-
- gimp_drawable_set_tiles (drawable, push_undo, NULL,
- tiles, type);
- tile_manager_unref (tiles);
-}
-
-void
-gimp_drawable_convert_tiles_rgb (GimpDrawable *drawable,
- TileManager *new_tiles)
-{
- GeglBuffer *dest_buffer;
- gboolean has_alpha;
-
- g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
- g_return_if_fail (! gimp_drawable_is_rgb (drawable));
- g_return_if_fail (new_tiles != NULL);
-
- has_alpha = gimp_drawable_has_alpha (drawable);
-
- g_return_if_fail (tile_manager_bpp (new_tiles) == (has_alpha ? 4 : 3));
-
- dest_buffer = gimp_tile_manager_create_buffer (new_tiles, NULL, TRUE);
+ dest_buffer = gimp_tile_manager_create_buffer (tiles, NULL, TRUE);
gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), NULL,
dest_buffer, NULL);
g_object_unref (dest_buffer);
+
+ gimp_drawable_set_tiles (drawable, push_undo, NULL,
+ tiles, type);
+ tile_manager_unref (tiles);
}
void
-gimp_drawable_convert_tiles_grayscale (GimpDrawable *drawable,
- TileManager *new_tiles)
+gimp_drawable_convert_indexed (GimpDrawable *drawable,
+ GimpImage *dest_image,
+ gboolean push_undo)
{
- GeglBuffer *dest_buffer;
- gboolean has_alpha;
+ GimpImageType type;
+ TileManager *tiles;
+ GeglBuffer *dest_buffer;
+ const Babl *format;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
+ g_return_if_fail (GIMP_IS_IMAGE (dest_image));
g_return_if_fail (! gimp_drawable_is_gray (drawable));
- g_return_if_fail (new_tiles != NULL);
- has_alpha = gimp_drawable_has_alpha (drawable);
+ type = GIMP_INDEXED_IMAGE;
- g_return_if_fail (tile_manager_bpp (new_tiles) == (has_alpha ? 2 : 1));
+ if (gimp_drawable_has_alpha (drawable))
+ {
+ type = GIMP_IMAGE_TYPE_WITH_ALPHA (type);
- dest_buffer = gimp_tile_manager_create_buffer (new_tiles, NULL, TRUE);
+ format = gimp_image_colormap_get_rgba_format (dest_image);
+ }
+ else
+ {
+ format = gimp_image_colormap_get_rgb_format (dest_image);
+ }
+
+ tiles = tile_manager_new (gimp_item_get_width (GIMP_ITEM (drawable)),
+ gimp_item_get_height (GIMP_ITEM (drawable)),
+ GIMP_IMAGE_TYPE_BYTES (type));
+
+ dest_buffer = gimp_tile_manager_create_buffer (tiles, format, TRUE);
gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), NULL,
dest_buffer, NULL);
g_object_unref (dest_buffer);
+
+ gimp_drawable_set_tiles (drawable, push_undo, NULL,
+ tiles, type);
+ tile_manager_unref (tiles);
}
diff --git a/app/core/gimpdrawable-convert.h b/app/core/gimpdrawable-convert.h
index 2ae8ae7..d640f70 100644
--- a/app/core/gimpdrawable-convert.h
+++ b/app/core/gimpdrawable-convert.h
@@ -19,15 +19,13 @@
#define __GIMP_DRAWABLE_CONVERT_H__
-void gimp_drawable_convert_rgb (GimpDrawable *drawable,
- gboolean push_undo);
-void gimp_drawable_convert_grayscale (GimpDrawable *drawable,
- gboolean push_undo);
-
-void gimp_drawable_convert_tiles_rgb (GimpDrawable *drawable,
- TileManager *new_tiles);
-void gimp_drawable_convert_tiles_grayscale (GimpDrawable *drawable,
- TileManager *new_tiles);
+void gimp_drawable_convert_rgb (GimpDrawable *drawable,
+ gboolean push_undo);
+void gimp_drawable_convert_grayscale (GimpDrawable *drawable,
+ gboolean push_undo);
+void gimp_drawable_convert_indexed (GimpDrawable *drawable,
+ GimpImage *dest_image,
+ gboolean push_undo);
#endif /* __GIMP_DRAWABLE_CONVERT_H__ */
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 2baa9f4..92fcf3b 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -787,8 +787,6 @@ gimp_drawable_real_convert_type (GimpDrawable *drawable,
GimpImageBaseType new_base_type,
gboolean push_undo)
{
- g_return_if_fail (new_base_type != GIMP_INDEXED);
-
switch (new_base_type)
{
case GIMP_RGB:
@@ -799,6 +797,10 @@ gimp_drawable_real_convert_type (GimpDrawable *drawable,
gimp_drawable_convert_grayscale (drawable, push_undo);
break;
+ case GIMP_INDEXED:
+ gimp_drawable_convert_indexed (drawable, dest_image, push_undo);
+ break;
+
default:
break;
}
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 5fc0168..4833d97 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -165,10 +165,6 @@ static gint64 gimp_layer_estimate_memsize (const GimpDrawable *drawable,
static void gimp_layer_invalidate_boundary (GimpDrawable *drawable);
static void gimp_layer_get_active_components (const GimpDrawable *drawable,
gboolean *active);
-static void gimp_layer_convert_type (GimpDrawable *drawable,
- GimpImage *dest_image,
- GimpImageBaseType new_base_type,
- gboolean push_undo);
static gint gimp_layer_get_opacity_at (GimpPickable *pickable,
gint x,
@@ -318,7 +314,6 @@ gimp_layer_class_init (GimpLayerClass *klass)
drawable_class->estimate_memsize = gimp_layer_estimate_memsize;
drawable_class->invalidate_boundary = gimp_layer_invalidate_boundary;
drawable_class->get_active_components = gimp_layer_get_active_components;
- drawable_class->convert_type = gimp_layer_convert_type;
drawable_class->project_region = gimp_layer_project_region;
klass->opacity_changed = NULL;
@@ -967,60 +962,6 @@ gimp_layer_get_active_components (const GimpDrawable *drawable,
active[gimp_drawable_bytes (drawable) - 1] = FALSE;
}
-static void
-gimp_layer_convert_type (GimpDrawable *drawable,
- GimpImage *dest_image,
- GimpImageBaseType new_base_type,
- gboolean push_undo)
-{
- switch (new_base_type)
- {
- case GIMP_RGB:
- case GIMP_GRAY:
- GIMP_DRAWABLE_CLASS (parent_class)->convert_type (drawable, dest_image,
- new_base_type,
- push_undo);
- break;
-
- case GIMP_INDEXED:
- {
- GimpItem *item = GIMP_ITEM (drawable);
- TileManager *new_tiles;
- GimpImageType new_type;
- PixelRegion layerPR;
- PixelRegion newPR;
-
- new_type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (new_base_type);
-
- if (gimp_drawable_has_alpha (drawable))
- new_type = GIMP_IMAGE_TYPE_WITH_ALPHA (new_type);
-
- new_tiles = tile_manager_new (gimp_item_get_width (item),
- gimp_item_get_height (item),
- GIMP_IMAGE_TYPE_BYTES (new_type));
-
- pixel_region_init (&layerPR, gimp_drawable_get_tiles (drawable),
- 0, 0,
- gimp_item_get_width (item),
- gimp_item_get_height (item),
- FALSE);
- pixel_region_init (&newPR, new_tiles,
- 0, 0,
- gimp_item_get_width (item),
- gimp_item_get_height (item),
- TRUE);
-
- gimp_layer_transform_color (dest_image,
- &layerPR, gimp_drawable_type (drawable),
- &newPR, new_type);
-
- gimp_drawable_set_tiles (drawable, push_undo, NULL,
- new_tiles, new_type);
- tile_manager_unref (new_tiles);
- }
- }
-}
-
static gint
gimp_layer_get_opacity_at (GimpPickable *pickable,
gint x,
@@ -1754,7 +1695,13 @@ gimp_layer_create_mask (const GimpLayer *layer,
gimp_item_get_height (item),
GIMP_IMAGE_TYPE_BYTES (copy_type));
- gimp_drawable_convert_tiles_grayscale (drawable, copy_tiles);
+ dest_buffer = gimp_tile_manager_create_buffer (copy_tiles, NULL,
+ TRUE);
+
+ gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), NULL,
+ dest_buffer, NULL);
+
+ g_object_unref (dest_buffer);
src_buffer = gimp_tile_manager_create_buffer (copy_tiles, NULL,
FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]