Incorrect use of user-defined channels converting PSD files

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Incorrect use of user-defined channels converting PSD files

Post by fmw42 » 2017-10-21T16:14:59-07:00

I got your attachments from dropbox.

Reviewing with GIMP. Your PSD file shows the second character as a tomato with white background with the extra channel off. It shows the second character as a reddish tomato with a mostly reddish background when the extra channel is on. Your PNG file shows the second character as transparent with partially transparent and white background. So it seems that IM is treating the extra channel as an alpha channel.

What should be happening in your opinion for the PNG output?

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Incorrect use of user-defined channels converting PSD files

Post by fmw42 » 2017-10-21T16:17:42-07:00

Please note that IM has limited capabiities with regard to PSD file. Currently, it does not know about extra channels in PSD files or TIFF files. However there has been some effort to develop the capability for TIFF files, but it is not complete. No effort has been made yet to my knowledge for PSD files.

Nevertheless, the IM developers will likely get to this as part of the improvement as time permits. So your help in understanding what should happen will be useful and important.

brooksrichardbrown
Posts: 22
Joined: 2016-11-09T11:32:58-07:00
Authentication code: 1151

Re: Incorrect use of user-defined channels converting PSD files

Post by brooksrichardbrown » 2017-10-21T21:21:39-07:00

Whew! Glad you got the sample. I thought was going crazy. Much thanks for looking into this.

In my opinion, what should be happening is that the PNG output should show the second character, the tomato 'o'.

I don't test with GIMP because most of the creative professionals that use my product use Photoshop. So, my opinion is based on the behavior of Photoshop.

If you have access to Photoshop, try these steps:
1. Open the PSD in Photoshop.
2. Enable the user-defined alpha channel.
3. Save and close the PSD.
4. Open the PSD again.
Observe: The user-defined channel has been disabled.

In other words, Photoshop disables user-defined alpha channels when it saves PSD files, therefore the channels should not show up in converted files.

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Incorrect use of user-defined channels converting PSD files

Post by fmw42 » 2017-10-21T22:18:36-07:00

As I understand it, as it is today, IM treats the extra channel in the PSD file as an alpha channel (transparency). If as you say, PS turns off the extra channel when it closes the file and IM did not do this, then there would be no way to save the transparency (alpha channel) when convert to a PNG file. Therefore, if you do not want the alpha channel in the PNG, you should just do

Code: Select all

convert image.psd[0] -alpha off image.png

brooksrichardbrown
Posts: 22
Joined: 2016-11-09T11:32:58-07:00
Authentication code: 1151

Re: Incorrect use of user-defined channels converting PSD files

Post by brooksrichardbrown » 2017-10-22T09:54:35-07:00

That would work for the particular image, but not in general because it would ignore transparent regions/convert them to a background color in images that actually have transparency.

Another way to think about this is that ImageMagick is processing alpha channels that are disabled.

As stated in the original post, I have a patch for psd.c that addresses this problem. It allows processing the alpha channel that contains the transparency but avoids the user-defined alpha channels that are effectively disabled.

I'm thinking that in order to better share the patch, I will make a clone of ImageMagick on github and rebase my changes on the latest version 6.

brooksrichardbrown
Posts: 22
Joined: 2016-11-09T11:32:58-07:00
Authentication code: 1151

Re: Incorrect use of user-defined channels converting PSD files

Post by brooksrichardbrown » 2017-10-22T10:20:53-07:00

Here is a link to the change on github:

https://github.com/Extensis/ImageMagick ... b3601b3464

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Incorrect use of user-defined channels converting PSD files

Post by fmw42 » 2017-10-22T10:28:35-07:00

This is something that the IM developers will need to review.

brooksrichardbrown
Posts: 22
Joined: 2016-11-09T11:32:58-07:00
Authentication code: 1151

Re: Incorrect use of user-defined channels converting PSD files

Post by brooksrichardbrown » 2017-10-22T10:39:26-07:00

By all means! I imagine that someone more familiar with the code base could do this more simply and elegantly and probably find some issues with my changes.

I was trying to get some insight into why Photoshop users make user-defined channels that are always ignored when the image is displayed. This link explains it. They are used for saving selections that can be loaded later on.

http://www.laughing-lion-design.com/201 ... photoshop/

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Incorrect use of user-defined channels converting PSD files

Post by fmw42 » 2017-10-22T10:45:11-07:00

How does photoshop distinguish a normal alpha or mask channel from an extra channel that is not used. Are they not both the same? Can you provide a psd image that has a normal alpha channel that one would want to save in the png conversion (as opposed to background transparency in psd). That is one that is enabled when the psd is saved.

brooksrichardbrown
Posts: 22
Joined: 2016-11-09T11:32:58-07:00
Authentication code: 1151

Re: Incorrect use of user-defined channels converting PSD files

Post by brooksrichardbrown » 2017-10-22T12:19:02-07:00

If the high order bit in the number of channels is set, then the file has an enabled alpha channel. This logic was in pre-existing code. Otherwise, alpha channels are ignored.

Code: Select all

      number_layers=(short) ReadBlobShort(image);

      if (number_layers < 0)
        {
          /*
            The first alpha channel in the merged result contains the
            transparency data for the merged result.
          */
          number_layers=MagickAbsoluteValue(number_layers);
          if (image->debug != MagickFalse)
            (void) LogMagickEvent(CoderEvent,GetMagickModule(),
              "  negative layer count corrected for");
          image->matte=MagickTrue;
        }

brooksrichardbrown
Posts: 22
Joined: 2016-11-09T11:32:58-07:00
Authentication code: 1151

Re: Incorrect use of user-defined channels converting PSD files

Post by brooksrichardbrown » 2017-10-22T12:23:16-07:00

Also, although I can provide a sample with an enabled alpha channel and disabled user-defined alpha channels, it _looks_ like images with a "real" alpha channel don't exhibit the issue.

brooksrichardbrown
Posts: 22
Joined: 2016-11-09T11:32:58-07:00
Authentication code: 1151

Re: Incorrect use of user-defined channels converting PSD files

Post by brooksrichardbrown » 2017-10-22T12:42:24-07:00

Probably because ImageMagick only uses the first alpha channel (not a bad thing).

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Incorrect use of user-defined channels converting PSD files

Post by fmw42 » 2017-10-22T13:00:51-07:00

So is this resolved or is there still an issue?

brooksrichardbrown
Posts: 22
Joined: 2016-11-09T11:32:58-07:00
Authentication code: 1151

Re: Incorrect use of user-defined channels converting PSD files

Post by brooksrichardbrown » 2017-10-22T16:48:08-07:00

Still an issue. Although ImageMagick knows about the flag, it nevertheless processes user-defined alpha channels when the flag is not set which results in incorrect conversions. That's what my patch addresses.

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Incorrect use of user-defined channels converting PSD files

Post by fmw42 » 2017-10-22T16:51:25-07:00

At this point, I will have to leave it to the IM developers for further action.

Post Reply