[gimp] plug-ins: PSD layers with clipping set need clip to backdrop as composite mode



commit e7f85f7b3f3390d01060c52499644806aebc6e43
Author: Jacob Boerema <jgboerema gmail com>
Date:   Mon Dec 13 18:59:20 2021 -0500

    plug-ins: PSD layers with clipping set need clip to backdrop as composite mode
    
    Certain PSD layers have a flag called clipping set to 1. We were not
    handling this flag and had some reports about colors bleeding where
    they were not supposed to.
    We are going to set GIMP's layer composite_mode to
    GIMP_LAYER_COMPOSITE_CLIP_TO_BACKDROP, which is the closest we can get
    to PhotoShop's clipping. With this, the colors won't bleed anymore.
    This isn't the whole solution since PS apparently stops compositing when
    it encounters a layer without clipping set, while GIMP doesn't stop until
    it reaches the bottom layer of a group or the image.
    
    This is the first part of a fix for issue #5438.

 plug-ins/file-psd/psd-load.c |  2 +-
 plug-ins/file-psd/psd-util.c | 14 +++++++++-----
 plug-ins/file-psd/psd-util.h |  2 +-
 3 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c
index 7d2db5d376..cc768f8a43 100644
--- a/plug-ins/file-psd/psd-load.c
+++ b/plug-ins/file-psd/psd-load.c
@@ -1954,7 +1954,7 @@ add_layers (GimpImage     *image,
               if (lyr_a[lidx]->group_type != 3)
                 {
                   /* Mode */
-                  psd_to_gimp_blend_mode (lyr_a[lidx]->blend_mode, &mode_info);
+                  psd_to_gimp_blend_mode (lyr_a[lidx], &mode_info);
                   gimp_layer_set_mode (layer, mode_info.mode);
                   gimp_layer_set_blend_space (layer, mode_info.blend_space);
                   gimp_layer_set_composite_space (layer, mode_info.composite_space);
diff --git a/plug-ins/file-psd/psd-util.c b/plug-ins/file-psd/psd-util.c
index b22731497f..5cf8a9b585 100644
--- a/plug-ins/file-psd/psd-util.c
+++ b/plug-ins/file-psd/psd-util.c
@@ -774,7 +774,7 @@ encode_packbits (const gchar *src,
 }
 
 void
-psd_to_gimp_blend_mode (const gchar   *psd_mode,
+psd_to_gimp_blend_mode (PSDlayer      *psd_layer,
                         LayerModeInfo *mode_info)
 {
   gint i;
@@ -785,11 +785,14 @@ psd_to_gimp_blend_mode (const gchar   *psd_mode,
    */
   mode_info->blend_space     = GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL;
   mode_info->composite_space = GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL;
-  mode_info->composite_mode  = GIMP_LAYER_COMPOSITE_UNION;
+  if (psd_layer->clipping == 1)
+    mode_info->composite_mode  = GIMP_LAYER_COMPOSITE_CLIP_TO_BACKDROP;
+  else
+    mode_info->composite_mode  = GIMP_LAYER_COMPOSITE_UNION;
 
   for (i = 0; i < G_N_ELEMENTS (layer_mode_map); i++)
     {
-      if (g_ascii_strncasecmp (psd_mode, layer_mode_map[i].psd_mode, 4) == 0)
+      if (g_ascii_strncasecmp (psd_layer->blend_mode, layer_mode_map[i].psd_mode, 4) == 0)
         {
           if (! layer_mode_map[i].exact && CONVERSION_WARNINGS)
             {
@@ -806,7 +809,7 @@ psd_to_gimp_blend_mode (const gchar   *psd_mode,
 
   if (CONVERSION_WARNINGS)
     {
-      gchar *mode_name = g_strndup (psd_mode, 4);
+      gchar *mode_name = g_strndup (psd_layer->blend_mode, 4);
       g_message ("Unsupported blend mode: %s. Mode reverts to normal",
                  mode_name);
       g_free (mode_name);
@@ -842,7 +845,8 @@ gimp_to_psd_blend_mode (const LayerModeInfo *mode_info)
     }
 
   if (mode_info->composite_mode != GIMP_LAYER_COMPOSITE_AUTO &&
-      mode_info->composite_mode != GIMP_LAYER_COMPOSITE_UNION)
+      mode_info->composite_mode != GIMP_LAYER_COMPOSITE_UNION &&
+      mode_info->composite_mode != GIMP_LAYER_COMPOSITE_CLIP_TO_BACKDROP)
     {
       if (CONVERSION_WARNINGS)
         g_message ("Unsupported composite mode: %s. "
diff --git a/plug-ins/file-psd/psd-util.h b/plug-ins/file-psd/psd-util.h
index 1c3ca2524a..9fdc75988b 100644
--- a/plug-ins/file-psd/psd-util.h
+++ b/plug-ins/file-psd/psd-util.h
@@ -90,7 +90,7 @@ gchar                 * encode_packbits        (const gchar         *src,
                                                 guint32              unpacked_len,
                                                 guint16             *packed_len);
 
-void                    psd_to_gimp_blend_mode (const gchar          *psd_mode,
+void                    psd_to_gimp_blend_mode (PSDlayer             *psd_layer,
                                                 LayerModeInfo        *mode_info);
 
 const gchar *           gimp_to_psd_blend_mode (const LayerModeInfo  *mode_info);


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