[gimp/gimp-2-10] plug-ins: fix incorrect loading of CMYK PSD images without layers.



commit 6f13c5b21f75b90b2bc2a71237b8dc13f8321a62
Author: Jacob Boerema <jgboerema gmail com>
Date:   Wed Oct 27 19:17:05 2021 -0400

    plug-ins: fix incorrect loading of CMYK PSD images without layers.
    
    PSD images using CMYK as color mode and without layers didn't load
    correctly (wrong colors).
    When a PSD does not have any layers, CMYK color mode was not converted to
    RGB.
    Note that PSD color images that do have layers (e.g. CMYK and LAB) store
    the merged image as RGB!
    To do all this we added a conversion for CMYK PSD with 0 layers and added
    code to correctly determine whether an alpha channel exists.
    This also fixes the case where loading the merged image of a 16 bit per
    channel RGBA psd loads with the alpha channel opaque.
    
    (cherry picked from commit b7518195b5d010e12aca684f60fd7002cdad5d28)

 plug-ins/file-psd/psd-load.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c
index 0b0d167cdf..8d53d384c2 100644
--- a/plug-ins/file-psd/psd-load.c
+++ b/plug-ins/file-psd/psd-load.c
@@ -1871,6 +1871,7 @@ add_merged_image (gint32     image_id,
   gint                  offset;
   gint                  i;
   gboolean              alpha_visible;
+  gboolean              alpha_channel = FALSE;
   GeglBuffer           *buffer;
   GimpImageType         image_type;
   GimpRGB               alpha_rgb;
@@ -1881,6 +1882,14 @@ add_merged_image (gint32     image_id,
   if (bps == 0)
     bps++;
 
+  if (img_a->num_layers > 0 && img_a->color_mode == PSD_CMYK)
+    {
+      /* In this case there is no conversion. Merged image is RGB. */
+      img_a->color_mode = PSD_RGB;
+      if (! img_a->transparency)
+        total_channels--;
+    }
+
   if ((img_a->color_mode == PSD_BITMAP ||
        img_a->color_mode == PSD_MULTICHANNEL ||
        img_a->color_mode == PSD_GRAYSCALE ||
@@ -1907,6 +1916,11 @@ add_merged_image (gint32     image_id,
 
   if (img_a->merged_image_only)
     {
+      if (! img_a->transparency && extra_channels > 0)
+        {
+          alpha_channel = TRUE;
+          base_channels += 1;
+        }
       extra_channels = 0;
       total_channels = base_channels;
     }
@@ -2001,7 +2015,8 @@ add_merged_image (gint32     image_id,
   if (img_a->merged_image_only ||
       img_a->num_layers == 0)            /* Merged image - Photoshop 2 style */
     {
-      image_type = get_gimp_image_type (img_a->base_type, img_a->transparency);
+      image_type = get_gimp_image_type (img_a->base_type,
+                                        img_a->transparency || alpha_channel);
 
       layer_size = img_a->columns * img_a->rows;
       pixels = g_malloc (layer_size * base_channels * bps);
@@ -2026,15 +2041,30 @@ add_merged_image (gint32     image_id,
 
       buffer = gimp_drawable_get_buffer (layer_id);
       if (img_a->color_mode == PSD_CMYK)
-        img_a->color_mode = PSD_RGB;
+        {
+          guchar *dst0;
+
+          dst0 = g_malloc (base_channels * layer_size * sizeof(float));
+          psd_convert_cmyk_to_srgb ( img_a,
+                                     dst0, pixels,
+                                     img_a->columns, img_a->rows,
+                                     alpha_channel);
+          g_free (pixels);
+          pixels = dst0;
+       }
 
       gegl_buffer_set (buffer,
                        GEGL_RECTANGLE (0, 0,
                                        gegl_buffer_get_width (buffer),
                                        gegl_buffer_get_height (buffer)),
-                       0, get_layer_format (img_a, (base_channels % 2) == 0),
+                       0, get_layer_format (img_a,
+                                            img_a->transparency ||
+                                            alpha_channel),
                        pixels, GEGL_AUTO_ROWSTRIDE);
 
+      if (img_a->color_mode == PSD_CMYK)
+        img_a->color_mode = PSD_RGB;
+
       /* Merged image data is blended against white.  Unblend it. */
       if (img_a->transparency)
         {


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