[gimp] plug-ins: export with explicit PNG's sRGB chunk when no profile written.



commit f77e261cd4d145d02bf5ccddbc5522d563d4c597
Author: Jehan <jehan girinstud io>
Date:   Sat Jan 16 16:31:06 2021 +0100

    plug-ins: export with explicit PNG's sRGB chunk when no profile written.
    
    When a profile is set, we should not set the sRGB chunk, because it
    would be a contradiction. But when we don't set the profile, then our
    code explicitly saves as sRGB. So let's add the sRGB chunk.
    
    Also when we do so, let's also set the relevant gAMA and cHRM chunks
    corresponding to sRGB as recommended by the PNG spec:
    
    > An application that writes the sRGB chunk should also write a gAMA
    > chunk (and perhaps a cHRM chunk) for compatibility with applications
    > that do not use the sRGB chunk. In this situation, only the following
    > values may be used: […]
    
    This is why I use png_set_sRGB_gAMA_and_cHRM() and not just
    png_set_sRGB().
    See also discussions in #5363.

 plug-ins/common/file-png.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
---
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 32e6fb53a4..2f3a102a51 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -1714,7 +1714,34 @@ save_image (GFile        *file,
 
       g_object_unref (profile);
     }
+  else
 #endif
+    {
+      /* Be more specific by writing into the file that the image is in
+       * sRGB color space.
+       */
+      GimpColorConfig *config = gimp_get_color_configuration ();
+      int              srgb_intent;
+
+      switch (gimp_color_config_get_display_intent (config))
+        {
+        case GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL:
+          srgb_intent = PNG_sRGB_INTENT_PERCEPTUAL;
+          break;
+        case GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC:
+          srgb_intent = PNG_sRGB_INTENT_RELATIVE;
+          break;
+        case GIMP_COLOR_RENDERING_INTENT_SATURATION:
+          srgb_intent = PNG_sRGB_INTENT_SATURATION;
+          break;
+        case GIMP_COLOR_RENDERING_INTENT_ABSOLUTE_COLORIMETRIC:
+          srgb_intent = PNG_sRGB_INTENT_ABSOLUTE;
+          break;
+        }
+      png_set_sRGB_gAMA_and_cHRM (pp, info, srgb_intent);
+
+      g_object_unref (config);
+    }
 
 #ifdef PNG_zTXt_SUPPORTED
 /* Small texts are not worth compressing and will be even bigger if compressed.


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