PSD - Photoshop Document

PSD, Photoshop Document, represents Adobe Photoshop's native file format used for graphics designing and development.

PSD, Photoshop Document, represents Adobe Photoshop's native file format used for graphics designing and development. PSD files may include image layers, adjustment layers, layer masks, annotations, file information, keywords and other Photoshop-specific elements. Photoshop files have default extension as .PSD and has a maximum height and width of 30,000 pixels, and a length limit of two gigabytes.

File Format Specifications

Data in a PSD file is stored in big endian byte order. This implies swapping the short and long integers when reading or writing on Windows platform. The Photoshop file format is divided into five major parts. It has many length markers that can be used to move from one section to the next. The length markers are usually padded with bytes to round to the nearest 2 or 4 byte interval. The five major parts are:

  • File Header

  • Color Mode Data

  • Image Resources

  • Layer and Mask Information

  • Image Data

For conformance, data should be written to all these fields in the section, as Photoshop may try to read the entire section. It also implies that zeroes be written to skipped fields while writing to a file. The length field in the length-delimited sections should be used to decide when to stop reading. In most cases, the length field indicates the number of bytes, not records, following. The following points need to be remembered while reading a file.

  • The values in "Length" column in all tables are in bytes.

  • All values defined as Unicode string consist of:

  • A 4-byte length field, representing the number of characters in the string (not bytes).

  • The string of Unicode values, two bytes per character.

File Header

The file header contains the basic properties of the image.

Color Mode Data Section

The color mode data section is structured as follows:

Color mode data is available only for indexed color and duotone as defined by the mode field in the File Header section. For all other modes, this section is represented by 4-byte zeroed values. For Indexed color images, the length is 768 and the color data contains the color table for the image, in non-interleaved order. For Duotone images, color data contains the duotone specification (the format of which is not documented). Other applications that read Photoshop files can treat a duotone image as a gray image, and just preserve the contents of the duotone information when reading and writing the file.

Image Resources Section

The third section of the file contains image resources. It starts with a length field, followed by a series of resource blocks.

Image resources are used to store non-pixel data associated with images such as pen tool paths. They are referred to as resource blocks because they hold data that was stored in the Macintosh's resource in early versions of Photoshop.The basic structure of image resource blocks is as shown below:

Image resources use several standard ID numbers.

Layer and Mask Information

The fourth section of a Photoshop file contains information about layers and masks such as number of layers, channels in the layers, blending ranges, adjustment layer keys, effects layers, and mask parameters. If there are no layers or masks, this section is represented by zeroed 4-byte field. Special attention needs to be paid to the length of sections while reading this section due to the zeroed values. The arrangement of Layer and Mask section is as follow:

Layer Info

The following table shows the high-level organization of the layer information.

Image Data

The image pixel data is contained in the Image Data section of the file. Arrangement of data in Image Data section is in planar order i.e. first all the red data, then all the green data, etc. Each plane is stored in scan-line order, with no pad bytes, The image data section is arrange in a format as shown in the following table.

Last updated