[gimp] Issue #3264 - Wrong colors from opening and exporting non-sRGB tiffs...



commit 6740c0af92e0fbb7bfb2ca2901cd0952f67f82dd
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jun 16 14:52:48 2019 +0200

    Issue #3264 - Wrong colors from opening and exporting non-sRGB tiffs...
    
    ...and pngs
    
    Fix PNG import and export:
    
    When importing, set the color profile on the image *before* creating
    the layer, so its buffer has the right format with space.
    
    When exporting, create the saving babl format with the layer's space
    so no color conversion happens when reading the layer's pixels.

 plug-ins/common/file-png.c | 56 +++++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 26 deletions(-)
---
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index d60b9334b7..1dabd09c04 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -1086,6 +1086,31 @@ load_image (const gchar  *filename,
       return -1;
     }
 
+  /*
+   * Attach the color profile, if any
+   */
+
+  if (profile)
+    {
+      gimp_image_set_color_profile (image, profile);
+      g_object_unref (profile);
+
+      if (profile_name)
+        {
+          GimpParasite *parasite;
+
+          parasite = gimp_parasite_new ("icc-profile-name",
+                                        GIMP_PARASITE_PERSISTENT |
+                                        GIMP_PARASITE_UNDOABLE,
+                                        strlen (profile_name),
+                                        profile_name);
+          gimp_image_attach_parasite (image, parasite);
+          gimp_parasite_free (parasite);
+
+          g_free (profile_name);
+        }
+    }
+
   /*
    * Create the "background" layer to hold the image...
    */
@@ -1309,31 +1334,6 @@ load_image (const gchar  *filename,
       g_free (comment);
     }
 
-  /*
-   * Attach the color profile, if any
-   */
-
-  if (profile)
-    {
-      gimp_image_set_color_profile (image, profile);
-      g_object_unref (profile);
-
-      if (profile_name)
-        {
-          GimpParasite *parasite;
-
-          parasite = gimp_parasite_new ("icc-profile-name",
-                                        GIMP_PARASITE_PERSISTENT |
-                                        GIMP_PARASITE_UNDOABLE,
-                                        strlen (profile_name),
-                                        profile_name);
-          gimp_image_attach_parasite (image, parasite);
-          gimp_parasite_free (parasite);
-
-          g_free (profile_name);
-        }
-    }
-
   /*
    * Done with the file...
    */
@@ -1736,7 +1736,7 @@ save_image (const gchar  *filename,
   else
     {
       switch (pngvals.export_format)
-      {
+        {
         case PNG_FORMAT_RGB8:
           color_type = PNG_COLOR_TYPE_RGB;
           if (out_linear)
@@ -1806,6 +1806,10 @@ save_image (const gchar  *filename,
       }
     }
 
+  if (! babl_format_is_palette (file_format))
+    file_format = babl_format_with_space (babl_format_get_encoding (file_format),
+                                          gimp_drawable_get_format (drawable_ID));
+
   bpp = babl_format_get_bytes_per_pixel (file_format);
 
   /* Note: png_set_IHDR() must be called before any other png_set_*()


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