From 3f17f528d1cf54d439e911c74257579592c99e16 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Mon, 23 Mar 2026 20:27:38 +0000 Subject: [PATCH] plug-ins: Load more multichannel PSD channels Multichannel PSD images reuse their first channel as the main grayscale "layer". Our PSD plug-in did not take this into account, resulting in the channels being off-by-one and mislabeled. This patch prevents chn_a[0].data from being freed after it is used to load the layer, and then resets the counts so that it is reused as the first imported channel. --- plug-ins/file-psd/psd-load.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c index 0cbaa25492..d9a24829f7 100644 --- a/plug-ins/file-psd/psd-load.c +++ b/plug-ins/file-psd/psd-load.c @@ -3153,7 +3153,11 @@ add_merged_image (GimpImage *image, memcpy (&pixels[((i * base_channels) + cidx) * bps], &chn_a[cidx].data[i * bps], bps); } - g_free (chn_a[cidx].data); + + /* For multichannel images, the first layer is also + * the first channel, so we don't want to free it yet */ + if (img_a->color_mode != PSD_MULTICHANNEL) + g_free (chn_a[cidx].data); } /* Add background layer */ @@ -3241,9 +3245,12 @@ add_merged_image (GimpImage *image, else { /* Free merged image data for layered image */ - if (extra_channels) - for (cidx = 0; cidx < base_channels; ++cidx) - g_free (chn_a[cidx].data); + if (extra_channels && + img_a->color_mode != PSD_MULTICHANNEL) + { + for (cidx = 0; cidx < base_channels; ++cidx) + g_free (chn_a[cidx].data); + } } if (img_a->transparency) @@ -3257,6 +3264,14 @@ add_merged_image (GimpImage *image, } } + /* Multichannel mode uses the first channel as the grayscale layer, + * so we need to reset the index to grab it again */ + if (img_a->color_mode == PSD_MULTICHANNEL) + { + base_channels = 0; + extra_channels = img_a->alpha_id_count; + } + /* ----- Draw extra alpha channels ----- */ if (extra_channels /* Extra alpha channels */ && image)