[gimp] app: fix the layer formats of indexed images to contain the space



commit a338220fa6d6e23ff4172c64df1490dc2be3359b
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jan 1 19:00:29 2019 +0100

    app: fix the layer formats of indexed images to contain the space
    
    Add gimp_image_colormap_update_formats() which does:
    
    - always update the cached palette formats based on the current space
      of the image
    - always set the palette entries on the palette formats
    
    Make sure the function is called whenever the space or the colormap
    change.
    
    Fix gimp_image_convert_profile_colormap() to convert the colormap
    entries between the right spaces.

 app/core/gimpimage-color-profile.c | 31 +++++++++++++++-------
 app/core/gimpimage-colormap.c      | 53 ++++++++++++++++++++++++++++++--------
 app/core/gimpimage-colormap.h      |  2 ++
 app/core/gimpimage.c               | 18 +------------
 4 files changed, 67 insertions(+), 37 deletions(-)
---
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index 649650ad0e..472ad3932f 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -484,6 +484,9 @@ gimp_image_assign_color_profile (GimpImage         *image,
   /*  omg...  */
   gimp_image_parasite_detach (image, "icc-profile-name");
 
+  if (gimp_image_get_base_type (image) == GIMP_INDEXED)
+    gimp_image_colormap_update_formats (image);
+
   gimp_image_fix_layer_format_spaces (image, progress);
 
   gimp_image_undo_group_end (image);
@@ -784,8 +787,11 @@ _gimp_image_update_color_profile (GimpImage          *image,
                                       GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
                                       &error);
       if (! private->layer_space)
-        g_printerr ("%s: failed to create Babl space from profile: %s\n",
-                    G_STRFUNC, error->message);
+        {
+          g_printerr ("%s: failed to create Babl space from profile: %s\n",
+                      G_STRFUNC, error->message);
+          g_clear_error (&error);
+        }
     }
 
   gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image));
@@ -858,6 +864,8 @@ gimp_image_convert_profile_colormap (GimpImage                *image,
                                      GimpProgress             *progress)
 {
   GimpColorTransform      *transform;
+  const Babl              *src_format;
+  const Babl              *dest_format;
   GimpColorTransformFlags  flags = 0;
   guchar                  *cmap;
   gint                     n_colors;
@@ -868,12 +876,17 @@ gimp_image_convert_profile_colormap (GimpImage                *image,
   if (bpc)
     flags |= GIMP_COLOR_TRANSFORM_FLAGS_BLACK_POINT_COMPENSATION;
 
-  transform = gimp_color_transform_new (src_profile,
-                                        /* EEK SPACE */
-                                        babl_format ("R'G'B' u8"),
-                                        dest_profile,
-                                        /* EEK SPACE */
-                                        babl_format ("R'G'B' u8"),
+  src_format  = gimp_color_profile_get_format (src_profile,
+                                               babl_format ("R'G'B' u8"),
+                                               GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                               NULL);
+  dest_format = gimp_color_profile_get_format (dest_profile,
+                                               babl_format ("R'G'B' u8"),
+                                               GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                                               NULL);
+
+  transform = gimp_color_transform_new (src_profile,  src_format,
+                                        dest_profile, dest_format,
                                         intent, flags);
 
   if (transform)
@@ -888,7 +901,7 @@ gimp_image_convert_profile_colormap (GimpImage                *image,
     }
   else
     {
-      g_warning ("cmsCreateTransform() failed!");
+      g_warning ("gimp_color_transform_new() failed!");
     }
 
   g_free (cmap);
diff --git a/app/core/gimpimage-colormap.c b/app/core/gimpimage-colormap.c
index 8dd666af7f..3a07fd6a9d 100644
--- a/app/core/gimpimage-colormap.c
+++ b/app/core/gimpimage-colormap.c
@@ -27,6 +27,8 @@
 
 #include "core-types.h"
 
+#include "gegl/gimp-babl.h"
+
 #include "gimp.h"
 #include "gimpcontainer.h"
 #include "gimpdatafactory.h"
@@ -72,17 +74,7 @@ gimp_image_colormap_init (GimpImage *image)
   private->colormap = g_new0 (guchar, GIMP_IMAGE_COLORMAP_SIZE);
   private->palette  = GIMP_PALETTE (gimp_palette_new (NULL, palette_name));
 
-  if (! private->babl_palette_rgb)
-    {
-      gchar *format_name = g_strdup_printf ("-gimp-indexed-format-%d",
-                                            gimp_image_get_ID (image));
-
-      babl_new_palette (format_name,
-                        &private->babl_palette_rgb,
-                        &private->babl_palette_rgba);
-
-      g_free (format_name);
-    }
+  gimp_image_colormap_update_formats (image);
 
   gimp_palette_set_columns (private->palette, 16);
 
@@ -135,6 +127,45 @@ gimp_image_colormap_free (GimpImage *image)
    */
 }
 
+void
+gimp_image_colormap_update_formats (GimpImage *image)
+{
+  GimpImagePrivate *private;
+  const Babl       *space;
+  gchar            *format_name;
+
+  g_return_if_fail (GIMP_IS_IMAGE (image));
+
+  private = GIMP_IMAGE_GET_PRIVATE (image);
+
+  space = gimp_image_get_layer_space (image);
+
+  format_name = g_strdup_printf ("-gimp-indexed-format-%d",
+                                 gimp_image_get_ID (image));
+
+  babl_new_palette_with_space (format_name, space,
+                               &private->babl_palette_rgb,
+                               &private->babl_palette_rgba);
+
+  g_free (format_name);
+
+  if (private->colormap && private->n_colors > 0)
+    {
+      babl_palette_set_palette (private->babl_palette_rgb,
+                                gimp_babl_format (GIMP_RGB,
+                                                  private->precision, FALSE,
+                                                  space),
+                                private->colormap,
+                                private->n_colors);
+      babl_palette_set_palette (private->babl_palette_rgba,
+                                gimp_babl_format (GIMP_RGB,
+                                                  private->precision, FALSE,
+                                                  space),
+                                private->colormap,
+                                private->n_colors);
+    }
+}
+
 const Babl *
 gimp_image_colormap_get_rgb_format (GimpImage *image)
 {
diff --git a/app/core/gimpimage-colormap.h b/app/core/gimpimage-colormap.h
index 703f5a242c..917b4b14c3 100644
--- a/app/core/gimpimage-colormap.h
+++ b/app/core/gimpimage-colormap.h
@@ -26,6 +26,8 @@ void           gimp_image_colormap_init            (GimpImage     *image);
 void           gimp_image_colormap_dispose         (GimpImage     *image);
 void           gimp_image_colormap_free            (GimpImage     *image);
 
+void           gimp_image_colormap_update_formats  (GimpImage     *image);
+
 const Babl   * gimp_image_colormap_get_rgb_format  (GimpImage     *image);
 const Babl   * gimp_image_colormap_get_rgba_format (GimpImage     *image);
 
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 3e165cb6c9..88df99f5c4 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -1349,23 +1349,7 @@ gimp_image_real_colormap_changed (GimpImage *image,
 {
   GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
 
-  if (private->colormap && private->n_colors > 0)
-    {
-      const Babl *space = gimp_image_get_layer_space (image);
-
-      babl_palette_set_palette (private->babl_palette_rgb,
-                                gimp_babl_format (GIMP_RGB,
-                                                  private->precision, FALSE,
-                                                  space),
-                                private->colormap,
-                                private->n_colors);
-      babl_palette_set_palette (private->babl_palette_rgba,
-                                gimp_babl_format (GIMP_RGB,
-                                                  private->precision, FALSE,
-                                                  space),
-                                private->colormap,
-                                private->n_colors);
-    }
+  gimp_image_colormap_update_formats (image);
 
   if (gimp_image_get_base_type (image) == GIMP_INDEXED)
     {


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