The layer and mask information section comes after the image resources. It holds every layer: its bounds, blend mode, opacity, masks, name and pixel channels, followed by the global layer mask and the document’s additional layer information. A file with no layers has just a zero length here. Numbers are big-endian; lengths marked 4/8 are 8 bytes in a PSB file.
Section layout
| Size | Type | Name | Description |
|---|---|---|---|
| 4/8 | u32/u64 | Length | Length of the rest of the section. |
| varies | LayerInfo | Layer info, below. | |
| varies | GlobalLayerMask | Global layer mask info, below. | |
| varies | AdditionalInfo | Tagged blocks that apply to the whole document (Photoshop 4.0 and later), as described in additional layer information. In 16-bit and 32-bit documents the layers themselves may be stored in an Lr16 or Lr32 block here, with the same layout as the layer info. |
Layer info
| Size | Type | Name | Description |
|---|---|---|---|
| 4/8 | u32/u64 | Length | Length of the layer info, rounded up to a multiple of 2. |
| 2 | s16 | LayerCount | Number of layers. If negative, its absolute value is the count and the first alpha channel holds the transparency of the merged result. |
| varies | LayerRecords | One layer record per layer, bottom layer first. | |
| varies | ChannelImageData | The pixel data of every channel of every layer, in the same order as the records and their channel lists. |
Layer record
| Size | Type | Name | Description |
|---|---|---|---|
| 16 | s32[4] | Rect | Top, left, bottom, right of the layer’s pixels. |
| 2 | u16 | ChannelCount | Number of channels in the layer. |
| 6 or 10 each | ChannelInfo | For each channel: a 2-byte channel ID (below) and a 4-byte (PSB: 8-byte) length of its data in the channel image data. | |
| 4 | char[4] | BlendSignature | 8BIM. |
| 4 | char[4] | BlendMode | Blend mode key, below. |
| 1 | u8 | Opacity | 0 transparent to 255 opaque. |
| 1 | u8 | Clipping | 0 base, 1 non-base (the layer is clipped to the layer below). |
| 1 | u8 | Flags | Bit flags, below. |
| 1 | u8 | Filler | 0. |
| 4 | u32 | ExtraLength | Length of the rest of the record: mask data, blending ranges, name and additional layer information. |
| varies | MaskData | Layer mask and adjustment layer data, below. | |
| varies | BlendingRanges | Layer blending ranges, below. | |
| varies | Pascal string | Name | The layer name, padded to a multiple of 4 bytes. The full Unicode name is in the luni block. |
| varies | blocks | AdditionalInfo | The layer’s additional layer information blocks, up to the end of ExtraLength. |
Channel IDs
| ID | Channel |
|---|---|
| 0, 1, 2… | The colour channels in the mode’s order: red, green, blue for RGB; cyan, magenta, yellow, black for CMYK; and so on. |
| −1 | Transparency mask. |
| −2 | User-supplied layer mask. |
| −3 | Real user-supplied layer mask, used when the layer has both a user mask and a vector mask. |
Blend modes
Keys of fewer than four letters end in a space.
| Key | Mode | Key | Mode |
|---|---|---|---|
pass | Pass through (groups only) | lddg | Linear dodge |
norm | Normal | lgCl | Lighter colour |
diss | Dissolve | over | Overlay |
dark | Darken | sLit | Soft light |
mul | Multiply | hLit | Hard light |
idiv | Colour burn | vLit | Vivid light |
lbrn | Linear burn | lLit | Linear light |
dkCl | Darker colour | pLit | Pin light |
lite | Lighten | hMix | Hard mix |
scrn | Screen | diff | Difference |
div | Colour dodge | smud | Exclusion |
fsub | Subtract | fdiv | Divide |
hue | Hue | sat | Saturation |
colr | Colour | lum | Luminosity |
Layer flags
| Bit | Meaning |
|---|---|
| 0 | Transparency protected. |
| 1 | Named “visible” in the specification, but Photoshop sets it for a hidden layer, and readers treat the layer as visible when the bit is clear. |
| 2 | Obsolete. |
| 3 | Set by Photoshop 5.0 and later, to say that bit 4 is meaningful. |
| 4 | Pixel data irrelevant to the appearance of the document. |
Layer mask and adjustment layer data
| Size | Type | Name | Description |
|---|---|---|---|
| 4 | u32 | Size | Size of the data that follows: 0 (no mask, nothing follows), 20 or 36. |
| 16 | s32[4] | Rect | Top, left, bottom, right of the mask. |
| 1 | u8 | DefaultColor | Colour outside the rectangle: 0 or 255. |
| 1 | u8 | Flags | Mask flags, below. |
| 1 | u8 | MaskParameters | Only when flag bit 4 is set: which parameters follow (below). |
| varies | Parameters | Only when flag bit 4 is set: the parameters, in bit order. | |
| 2 | Padding | Only when Size is 20. | |
| 1 | u8 | RealFlags | Flags of the real user mask, same bits as Flags. |
| 1 | u8 | RealDefaultColor | Real user mask background: 0 or 255. |
| 16 | s32[4] | RealRect | Top, left, bottom, right of the real user mask. |
The last three fields are there only when the layer has both a user mask and a vector mask; the first rectangle then belongs to the vector mask.
Mask flags
| Bit | Meaning |
|---|---|
| 0 | Position relative to the layer. |
| 1 | Layer mask disabled. |
| 2 | Invert layer mask when blending. Obsolete. |
| 3 | The user mask came from rendering other data. |
| 4 | The user mask, the vector mask or both have parameters applied. |
Mask parameters
| Bit | Parameter that follows | Size |
|---|---|---|
| 0 | User mask density | 1 byte |
| 1 | User mask feather | 8 bytes, double |
| 2 | Vector mask density | 1 byte |
| 3 | Vector mask feather | 8 bytes, double |
Layer blending ranges
The “Blend If” sliders of the layer style dialog.
| Size | Type | Name | Description |
|---|---|---|---|
| 4 | u32 | Length | Length of the ranges that follow. |
| 4 | u8[4] | GraySource | Composite grey “this layer” range: black low, black high, white low, white high. Not used in Lab and greyscale. |
| 4 | u8[4] | GrayDest | Composite grey “underlying layer” range. |
| 8 each | u8[4] × 2 | ChannelRanges | For each channel: source range, then destination range. |
Channel image data
After the last layer record come the pixels: for each layer, for each channel in its channel list, one block of this shape. Its total length is the length given in the channel info.
| Size | Type | Name | Description |
|---|---|---|---|
| 2 | u16 | Compression | 0 raw, 1 RLE, 2 ZIP without prediction, 3 ZIP with prediction. |
| varies | bytes | Data | The channel’s rows. |
- The channel is
bottom − toprows byright − leftcolumns of the layer rectangle; a user mask channel uses the mask’s rectangle instead. - RLE data starts with one byte count per row, 2 bytes each (4 in PSB), then each row compressed with PackBits.
- If the data length is odd, a pad byte follows.
- Adjustment layers have channel data, but its content is undefined (probably all white).
Global layer mask info
| Size | Type | Name | Description |
|---|---|---|---|
| 4 | u32 | Length | Length of the rest; 0 if absent. |
| 2 | u16 | OverlayColorSpace | Undocumented. |
| 8 | u16[4] | ColorComponents | Four colour components. |
| 2 | u16 | Opacity | 0 transparent to 100 opaque. |
| 1 | u8 | Kind | 0 colour selected (inverted), 1 colour protected, 128 use the value stored per layer (preferred). Other values are for compatibility with beta versions. |
| varies | Filler | Zeros up to the length. |