1

Closed

Cannot load PSD files with missing channels

description

The attached psd file includes four layers. The second layer named "ACAD_0" has only of two channels with codes -1 and 0. The plugin doesn't check the channel count of the layer and tries to access other channels in the function SetPDNColor:
case PsdColorMode.RGB:
dstPixel->R = channels[0].ImageData[pos];
dstPixel->G = channels[1].ImageData[pos];
dstPixel->B = channels[2].ImageData[pos];
break;
Accessing channels[1] rises the out of range exception.

I can open the attached file in Photoshop and GIMP without problems.

Closed Apr 5 at 9:17 PM by taoyue
Fixed in revision cff753dac462.

We will set any missing channels to the default value of 255. This appears to be correct for all color modes.

Photoshop will reject some files with missing channels with the error message: "Could not complete your request because the file is not compatible with this version of Photoshop." We do not attempt to duplicate Photoshop behavior, but it is not such a bad thing for PSDPlugin to be *more* permissive than Photoshop when it comes to loading malformed files.

comments

taoyue wrote Apr 5 at 9:20 PM

Note: using Imagemagick 6.6.0-4 on Ubuntu 11.10, all of the EPS files in Hausgarten1_eps.zip convert to valid PSD files, with no missing channels.

However, most of the behavior can be tested using a hex editor.

vsmolkin wrote Feb 9 at 10:44 AM

And here are the source PostScript files.

vsmolkin wrote Feb 9 at 10:43 AM

I created another PSD file using the "original" ImageMagick. I just used the CONVERT tool from ImageMagick to produce a PSD file from several PostScript files. ImageMagick determines the source files as RGB, so I have only RGB files.

taoyue wrote Feb 7 at 6:23 PM

Could you please generate some additional PSD repro files and attach them to this work item? Please include CMYK and other non-RGB files if at all possible. It's much quicker for you to generate repro files than for me to do it, since you already have code in place.

If ImageMagick is omitting layers in this way to represent grayscale layers, then you should also file a bug against ImageMagick. This is not the way to generate grayscale layers in an otherwise RGB document. The channel is interpreted as red by Photoshop, which is why the line on layer 2 in bcad2.psd appears cyan instead of gray. (Note: grayscale, not monochrome -- I can see multiple levels in the ACAD_0 layer.)

vsmolkin wrote Feb 7 at 7:17 AM

This file was generated by the ImageMagick library which I use in my program. I use it to make a multi-layer PSD file from several PostScript files. The library checked each layer if it was a monochrome image (only black pixels on the white canvas) and wrote then only two channels. If there was a color layer, the whole image was marked as a color image and your plugin tried to access the missing channels.
Now I fixed my copy of the library, so that there are no missing channels any more. But if someone else uses the original library, he gets the same problems.

taoyue wrote Feb 7 at 4:39 AM

Which program generated this file, and can you generate more PSD files that also have missing channels? I need to have some PSD files that are *not* RGB, so that I can test their behavior.

The missing channels appear to default to 255, but this behavior is undocumented and I'd like to verify with CMYK and LAB and the other color modes. Just loading and saving bcad2.psd with Photoshop causes the missing channels to be filled in, and the bug no longer repros.