[gimp] Fix the palette handling in gimp_drawable_get_format()



commit 641848ea0be5b8d6daffb5e35c39d244163f7877
Author: Simon Budig <simon budig de>
Date:   Sun Apr 29 01:22:20 2012 +0200

    Fix the palette handling in gimp_drawable_get_format()

 libgimp/gimpdrawable.c     |   34 ++++++++++++++++++++++++++--------
 plug-ins/common/file-png.c |    2 --
 2 files changed, 26 insertions(+), 10 deletions(-)
---
diff --git a/libgimp/gimpdrawable.c b/libgimp/gimpdrawable.c
index f7d9f2a..61756c5 100644
--- a/libgimp/gimpdrawable.c
+++ b/libgimp/gimpdrawable.c
@@ -739,6 +739,7 @@ gimp_drawable_get_shadow_buffer (gint32 drawable_ID)
 const Babl *
 gimp_drawable_get_format (gint32 drawable_ID)
 {
+  static GHashTable *palette_formats = NULL;
   const Babl *format     = NULL;
   gchar      *format_str = _gimp_drawable_get_format (drawable_ID);
 
@@ -747,24 +748,41 @@ gimp_drawable_get_format (gint32 drawable_ID)
       if (gimp_drawable_is_indexed (drawable_ID))
         {
           gint32      image_ID = gimp_item_get_image (drawable_ID);
-          const Babl *palette;
-          const Babl *palette_alpha;
           guchar     *colormap;
           gint        n_colors;
 
           colormap = gimp_image_get_colormap (image_ID, &n_colors);
 
-          babl_new_palette (format_str, &palette, &palette_alpha);
-          babl_palette_set_palette (palette,
+          if (!palette_formats)
+            palette_formats = g_hash_table_new (g_str_hash, g_str_equal);
+
+          format = g_hash_table_lookup (palette_formats, format_str);
+
+          if (!format)
+            {
+              const Babl *palette;
+              const Babl *palette_alpha;
+
+              babl_new_palette (format_str, &palette, &palette_alpha);
+              g_hash_table_insert (palette_formats,
+                                   (gpointer) babl_get_name (palette),
+                                   (gpointer) palette);
+              g_hash_table_insert (palette_formats,
+                                   (gpointer) babl_get_name (palette_alpha),
+                                   (gpointer) palette_alpha);
+
+              if (gimp_drawable_has_alpha (drawable_ID))
+                format = palette_alpha;
+              else
+                format = palette;
+            }
+
+          babl_palette_set_palette (format,
                                     babl_format ("R'G'B' u8"),
                                     colormap, n_colors);
 
           g_free (colormap);
 
-          if (gimp_drawable_has_alpha (drawable_ID))
-            format = palette_alpha;
-          else
-            format = palette;
         }
       else
         {
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index cd77006..f13a328 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -1196,9 +1196,7 @@ load_image (const gchar  *filename,
   if (trns)
     {
 #warning this crashes horribly.
-      g_printerr ("pre-add-alpha: %s\n", babl_get_name (gimp_drawable_get_format (layer)));
       gimp_layer_add_alpha (layer);
-      g_printerr ("post-add-alpha: %s\n", babl_get_name (gimp_drawable_get_format (layer)));
       file_format = gimp_drawable_get_format (layer);
       buffer = gimp_drawable_get_buffer (layer);
 



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