Register»Forums»How to read PSD file format?
41 posts
How to read PSD file format?
1 month, 1 week ago Edited by BernFeth on March 7, 2021, 5:34 p.m. Reason: Initial post
Hey guys,

I want to make a little tool that I can feed psd files to and will spit out a png with all the layers in that psd side by side (basically make a texture atlas out of it).

I found this documentation but sadly I can't seem to find all the information I need.

It does say:

This document does not explain how to interpret the data. This document describes the format of the data only.

Still, their table gives length values for a header so I tried reading that out:
typedef struct __attribute__((__packed__)) psd_file_header
    char Signature[4];
    u16 Version;
    char Reserved[6];
    u16 NumberOfChannels;
    u32 ImageHeight;
    u32 ImageWidth;
    u16 BitsPerChannel;
    i16 ColorMode;
} psd_file_header;

That reads out the Signature correctly but that's about it...

For example, ImageHeight and Width should be 512 but they are both 2147483648 which makes me believe the values are there but I'm reading it incorrectly.

I am not sure if the types I chose are right since they don't seem to tell if they are signed or unsigned, not even the type, the only thing it says is the length of it.

Anyway, do you guys know how to deal with this?

Any help is much appreciated,

Mārtiņš Možeiko
2205 posts / 1 project
How to read PSD file format?
1 month, 1 week ago
You could check how stb_image.h is loading psd file format:
41 posts
How to read PSD file format?
1 month, 1 week ago
Ah! I didn't know stb_image.h could load psds.

This is harder than I expected but I will look into that,