Skip to content

Commit

Permalink
Support for PSD with transparency in merged image data.
Browse files Browse the repository at this point in the history
1. Using '>h' to read signed short for layer count.
2. Reading 'RGBA' for merged data with channel count 4,
and color mode 3.

For a PSD with transparency a negative layer count in
the layer info struct its absolute value is the number
of layers and the first alpha channel contains the
transparency data for the merged result.

According to:
http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/PhotoshopFileFormats.htm#50577409_16000
  • Loading branch information
Mark Palange committed May 30, 2012
1 parent 797f2be commit e69129a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion psdparser.py
Expand Up @@ -371,7 +371,7 @@ def parse_layers_and_masks(self):
(layerlen,) = self._readf(">L")
if layerlen:
# layers structure
(self.num_layers,) = self._readf(">H")
(self.num_layers,) = self._readf(">h")
if self.num_layers < 0:
self.num_layers = -self.num_layers
logging.debug(INDENT_OUTPUT(1, "First alpha is transparency for merged image"))
Expand Down Expand Up @@ -537,6 +537,8 @@ def parse_image_data(self):
self.merged_image = self.merged_image[0]
elif li['channels'] == 3:
self.merged_image = Image.merge('RGB', self.merged_image)
elif li['channels'] == 4 and self.header['mode'] == 3:
self.merged_image = Image.merge('RGBA', self.merged_image)
else:
raise ValueError('Unsupported number of channels')

Expand Down

0 comments on commit e69129a

Please sign in to comment.