[gimp] plug-ins: also generate grayscale color profiles from gAMA/cHRM chunks.



commit f0a8c0c3f547d32a6f6fdc8bda0951ee20c2a7fb
Author: Jehan <jehan girinstud io>
Date:   Tue Mar 2 12:02:23 2021 +0100

    plug-ins: also generate grayscale color profiles from gAMA/cHRM chunks.
    
    The PNG specs says:
    > The cHRM chunk is allowed in all PNG datastreams, although it is of
    little value for greyscale images.
    
    Though it doesn't say it's completely useless though. So let's still
    extract the info and give it to Little-CMS.
    As for the gAMA chunk, it doesn't say it's not usable for grayscale
    images.
    
    Note that if one of the 2 values is not set, it will use default values
    for sRGB (i.e. default simili-sRGB gamma or d65 whitepoint). Not sure if
    this is totally right.
    
    See also issue #6501.

 plug-ins/common/file-png.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 196bdeb5ed..d675b9ba98 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -739,7 +739,13 @@ load_image (GFile        *file,
           memcpy (&whitepoint, &d65_whitepoint, sizeof whitepoint);
           memcpy (&primaries, &rec709_primaries, sizeof primaries);
         }
-      cms_profile = cmsCreateRGBProfile (&whitepoint, &primaries, gamma_curve);
+
+      if (png_get_color_type (pp, info) == PNG_COLOR_TYPE_GRAY ||
+          png_get_color_type (pp, info) == PNG_COLOR_TYPE_GRAY_ALPHA)
+        cms_profile = cmsCreateGrayProfile (&whitepoint, gamma_curve[0]);
+      else /* RGB, RGB with Alpha and Indexed. */
+        cms_profile = cmsCreateRGBProfile (&whitepoint, &primaries, gamma_curve);
+
       cmsFreeToneCurve (gamma_curve[0]);
       g_warn_if_fail (cms_profile != NULL);
 
@@ -758,13 +764,20 @@ load_image (GFile        *file,
            * descriptions to be localized. XXX
            */
           if ((png_get_valid (pp, info, PNG_INFO_gAMA) && png_get_valid (pp, info, PNG_INFO_cHRM)))
-            profile_desc = g_strdup_printf ("Generated RGB profile from PNG's gAMA (gamma %.4f) and cHRM 
chunks",
-                                            1.0 / gamma);
+            profile_desc = g_strdup_printf ("Generated %s profile from PNG's gAMA (gamma %.4f) and cHRM 
chunks",
+                                            (png_get_color_type (pp, info) == PNG_COLOR_TYPE_GRAY ||
+                                             png_get_color_type (pp, info) == PNG_COLOR_TYPE_GRAY_ALPHA) ?
+                                            "grayscale" : "RGB", 1.0 / gamma);
           else if (png_get_valid (pp, info, PNG_INFO_gAMA))
-            profile_desc = g_strdup_printf ("Generated RGB profile from PNG's gAMA chunk (gamma %.4f)",
-                                            1.0 / gamma);
+            profile_desc = g_strdup_printf ("Generated %s profile from PNG's gAMA chunk (gamma %.4f)",
+                                            (png_get_color_type (pp, info) == PNG_COLOR_TYPE_GRAY ||
+                                             png_get_color_type (pp, info) == PNG_COLOR_TYPE_GRAY_ALPHA) ?
+                                            "grayscale" : "RGB", 1.0 / gamma);
           else
-            profile_desc = g_strdup_printf ("Generated RGB profile from PNG's cHRM chunk");
+            profile_desc = g_strdup_printf ("Generated %s profile from PNG's cHRM chunk",
+                                            (png_get_color_type (pp, info) == PNG_COLOR_TYPE_GRAY ||
+                                             png_get_color_type (pp, info) == PNG_COLOR_TYPE_GRAY_ALPHA) ?
+                                            "grayscale" : "RGB");
 
           description_mlu  = cmsMLUalloc (context_id, 1);
 


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