[gimp] Add gimp_drawable_convert_rgb() and gimp_drawable_convert_grayscale()



commit f2f741a26e5a796ec8f17fcf47d4a0e15e285c4d
Author: Michael Natterer <mitch gimp org>
Date:   Tue Sep 8 20:36:51 2009 +0200

    Add gimp_drawable_convert_rgb() and gimp_drawable_convert_grayscale()
    
    The new functions reall convert the drawable this time, using the
    previously renamed convert_tiles functions. Remove tile manager
    fiddling from all callers and leave it there only for converting to
    indexed.

 app/core/gimpchannel.c          |   16 +-----------
 app/core/gimpdrawable-convert.c |   52 +++++++++++++++++++++++++++++++++++++++
 app/core/gimpdrawable-convert.h |    3 ++
 app/core/gimpimage-convert.c    |   48 +++++++++++++++++++----------------
 app/core/gimplayer.c            |   39 ++++++++++++++---------------
 5 files changed, 101 insertions(+), 57 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 43ab0b8..d212ab9 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -435,21 +435,7 @@ gimp_channel_convert (GimpItem  *item,
 
   if (! gimp_drawable_is_gray (drawable))
     {
-      TileManager   *new_tiles;
-      GimpImageType  new_type = GIMP_GRAY_IMAGE;
-
-      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));
-
-      gimp_drawable_convert_tiles_grayscale (drawable, new_tiles);
-
-      gimp_drawable_set_tiles (drawable, FALSE, NULL,
-                               new_tiles, new_type);
-      tile_manager_unref (new_tiles);
+      gimp_drawable_convert_grayscale (drawable);
     }
 
   if (gimp_drawable_has_alpha (drawable))
diff --git a/app/core/gimpdrawable-convert.c b/app/core/gimpdrawable-convert.c
index 7ae8978..d084834 100644
--- a/app/core/gimpdrawable-convert.c
+++ b/app/core/gimpdrawable-convert.c
@@ -33,6 +33,58 @@
 
 
 void
+gimp_drawable_convert_rgb (GimpDrawable *drawable)
+{
+  GimpImageType  type;
+  TileManager   *tiles;
+
+  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
+  g_return_if_fail (! gimp_drawable_is_rgb (drawable));
+
+  type = GIMP_RGB_IMAGE;
+
+  if (gimp_drawable_has_alpha (drawable))
+    type = GIMP_IMAGE_TYPE_WITH_ALPHA (type);
+
+  tiles = tile_manager_new (gimp_item_get_width  (GIMP_ITEM (drawable)),
+                            gimp_item_get_height (GIMP_ITEM (drawable)),
+                            GIMP_IMAGE_TYPE_BYTES (type));
+
+  gimp_drawable_convert_tiles_rgb (drawable, tiles);
+
+  gimp_drawable_set_tiles (drawable,
+                           gimp_item_is_attached (GIMP_ITEM (drawable)), NULL,
+                           tiles, type);
+  tile_manager_unref (tiles);
+}
+
+void
+gimp_drawable_convert_grayscale (GimpDrawable *drawable)
+{
+  GimpImageType  type;
+  TileManager   *tiles;
+
+  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
+  g_return_if_fail (! gimp_drawable_is_gray (drawable));
+
+  type = GIMP_GRAY_IMAGE;
+
+  if (gimp_drawable_has_alpha (drawable))
+    type = GIMP_IMAGE_TYPE_WITH_ALPHA (type);
+
+  tiles = tile_manager_new (gimp_item_get_width  (GIMP_ITEM (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,
+                           gimp_item_is_attached (GIMP_ITEM (drawable)), NULL,
+                           tiles, type);
+  tile_manager_unref (tiles);
+}
+
+void
 gimp_drawable_convert_tiles_rgb (GimpDrawable *drawable,
                                  TileManager  *new_tiles)
 {
diff --git a/app/core/gimpdrawable-convert.h b/app/core/gimpdrawable-convert.h
index a258ac2..12d20c7 100644
--- a/app/core/gimpdrawable-convert.h
+++ b/app/core/gimpdrawable-convert.h
@@ -19,6 +19,9 @@
 #define __GIMP_DRAWABLE_CONVERT_H__
 
 
+void   gimp_drawable_convert_rgb             (GimpDrawable *drawable);
+void   gimp_drawable_convert_grayscale       (GimpDrawable *drawable);
+
 void   gimp_drawable_convert_tiles_rgb       (GimpDrawable *drawable,
                                               TileManager  *new_tiles);
 void   gimp_drawable_convert_tiles_grayscale (GimpDrawable *drawable,
diff --git a/app/core/gimpimage-convert.c b/app/core/gimpimage-convert.c
index 081f51a..8acfa1e 100644
--- a/app/core/gimpimage-convert.c
+++ b/app/core/gimpimage-convert.c
@@ -958,40 +958,44 @@ gimp_image_convert (GimpImage               *image,
        list;
        list = g_list_next (list), nth_layer++)
     {
-      GimpLayer     *layer = list->data;
-      GimpImageType  new_layer_type;
-      TileManager   *new_tiles;
-
-      new_layer_type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (new_type);
-
-      if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
-        new_layer_type = GIMP_IMAGE_TYPE_WITH_ALPHA (new_layer_type);
-
-      new_tiles = tile_manager_new (gimp_item_get_width  (GIMP_ITEM (layer)),
-                                    gimp_item_get_height (GIMP_ITEM (layer)),
-                                    GIMP_IMAGE_TYPE_BYTES (new_layer_type));
+      GimpLayer *layer = list->data;
 
       switch (new_type)
         {
         case GIMP_RGB:
-          gimp_drawable_convert_tiles_rgb (GIMP_DRAWABLE (layer),
-                                           new_tiles);
+          gimp_drawable_convert_rgb (GIMP_DRAWABLE (layer));
           break;
+
         case GIMP_GRAY:
-          gimp_drawable_convert_tiles_grayscale (GIMP_DRAWABLE (layer),
-                                                 new_tiles);
+          gimp_drawable_convert_grayscale (GIMP_DRAWABLE (layer));
           break;
+
         case GIMP_INDEXED:
-          quantobj->nth_layer = nth_layer;
-          (* quantobj->second_pass) (quantobj, layer, new_tiles);
+          {
+            GimpImageType  new_layer_type;
+            TileManager   *new_tiles;
+
+            new_layer_type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (new_type);
+
+            if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
+              new_layer_type = GIMP_IMAGE_TYPE_WITH_ALPHA (new_layer_type);
+
+            new_tiles = tile_manager_new (gimp_item_get_width  (GIMP_ITEM (layer)),
+                                          gimp_item_get_height (GIMP_ITEM (layer)),
+                                          GIMP_IMAGE_TYPE_BYTES (new_layer_type));
+
+            quantobj->nth_layer = nth_layer;
+            (* quantobj->second_pass) (quantobj, layer, new_tiles);
+
+            gimp_drawable_set_tiles (GIMP_DRAWABLE (layer), TRUE, NULL,
+                                     new_tiles, new_layer_type);
+            tile_manager_unref (new_tiles);
+          }
           break;
+
         default:
           break;
         }
-
-      gimp_drawable_set_tiles (GIMP_DRAWABLE (layer), TRUE, NULL,
-                               new_tiles, new_layer_type);
-      tile_manager_unref (new_tiles);
     }
 
   switch (new_type)
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 1a38bf5..2e4fca4 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -542,32 +542,31 @@ gimp_layer_convert (GimpItem  *item,
 
   if (old_base_type != new_base_type)
     {
-      TileManager   *new_tiles;
-      GimpImageType  new_type;
-
-      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));
-
       switch (new_base_type)
         {
         case GIMP_RGB:
-          gimp_drawable_convert_tiles_rgb (drawable, new_tiles);
+          gimp_drawable_convert_rgb (drawable);
           break;
 
         case GIMP_GRAY:
-          gimp_drawable_convert_tiles_grayscale (drawable, new_tiles);
+          gimp_drawable_convert_grayscale (drawable);
           break;
 
         case GIMP_INDEXED:
           {
-            PixelRegion layerPR;
-            PixelRegion newPR;
+            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,
@@ -583,13 +582,13 @@ gimp_layer_convert (GimpItem  *item,
             gimp_layer_transform_color (dest_image,
                                         &layerPR, gimp_drawable_type (drawable),
                                         &newPR,   new_type);
+
+            gimp_drawable_set_tiles (drawable, FALSE, NULL,
+                                     new_tiles, new_type);
+            tile_manager_unref (new_tiles);
           }
           break;
         }
-
-      gimp_drawable_set_tiles (drawable, FALSE, NULL,
-                               new_tiles, new_type);
-      tile_manager_unref (new_tiles);
     }
 
   if (layer->mask)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]