Search code examples
parsingadobetransparencyalphapsd

Reading transparency from PSD format


I'm trying to read merged RGBA data from PSD format. "Image data" section contains channels (RGBAA... where first A might be a merged transparency or Alpha mask). Can someone tell me how to know what is stored in first A? I noticed that:

  • when image contains no transparency, but has at least one Alpha mask, then first Alpha channel will contain that alpha mask
  • when image contains transparency, then first Alpha channel will contain merged transparency and other Alpha channels will contain alpha masks

So how do I reliable differentiate between Transparency and Alpha mask in first Alpha channel?


Solution

  • From PSD specification:

    Layer count. If it is a negative number, its absolute value is the number of layers and the first alpha channel contains the transparency data for the merged result.

    So simple (layerCount < 0) tells me if first A is transparency or Alpha-mask.