How to read PSD file format?

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:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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,

Thanks!

Edited by BernFeth on Reason: Initial post
You could check how stb_image.h is loading psd file format: https://github.com/nothings/stb/blob/master/stb_image.h#L5945
Ah! I didn't know stb_image.h could load psds.

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

Thanks!