MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / stbi__psd_load

Function stbi__psd_load

Source/Utils/stb_image.h:6123–6322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6121}
6122
6123static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc)
6124{
6125 int pixelCount;
6126 int channelCount, compression;
6127 int channel, i;
6128 int bitdepth;
6129 int w,h;
6130 stbi_uc *out;
6131 STBI_NOTUSED(ri);
6132
6133 // Check identifier
6134 if (stbi__get32be(s) != 0x38425053) // "8BPS"
6135 return stbi__errpuc("not PSD", "Corrupt PSD image");
6136
6137 // Check file type version.
6138 if (stbi__get16be(s) != 1)
6139 return stbi__errpuc("wrong version", "Unsupported version of PSD image");
6140
6141 // Skip 6 reserved bytes.
6142 stbi__skip(s, 6 );
6143
6144 // Read the number of channels (R, G, B, A, etc).
6145 channelCount = stbi__get16be(s);
6146 if (channelCount < 0 || channelCount > 16)
6147 return stbi__errpuc("wrong channel count", "Unsupported number of channels in PSD image");
6148
6149 // Read the rows and columns of the image.
6150 h = stbi__get32be(s);
6151 w = stbi__get32be(s);
6152
6153 if (h > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)");
6154 if (w > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)");
6155
6156 // Make sure the depth is 8 bits.
6157 bitdepth = stbi__get16be(s);
6158 if (bitdepth != 8 && bitdepth != 16)
6159 return stbi__errpuc("unsupported bit depth", "PSD bit depth is not 8 or 16 bit");
6160
6161 // Make sure the color mode is RGB.
6162 // Valid options are:
6163 // 0: Bitmap
6164 // 1: Grayscale
6165 // 2: Indexed color
6166 // 3: RGB color
6167 // 4: CMYK color
6168 // 7: Multichannel
6169 // 8: Duotone
6170 // 9: Lab color
6171 if (stbi__get16be(s) != 3)
6172 return stbi__errpuc("wrong color format", "PSD is not in RGB color format");
6173
6174 // Skip the Mode Data. (It's the palette for indexed color; other info for other modes.)
6175 stbi__skip(s,stbi__get32be(s) );
6176
6177 // Skip the image resources. (resolution, pen tool paths, etc)
6178 stbi__skip(s, stbi__get32be(s) );
6179
6180 // Skip the reserved data.

Callers 1

stbi__load_mainFunction · 0.85

Calls 10

stbi__get32beFunction · 0.85
stbi__get16beFunction · 0.85
stbi__skipFunction · 0.85
stbi__mad3sizes_validFunction · 0.85
stbi__malloc_mad3Function · 0.85
stbi__mallocFunction · 0.85
stbi__psd_decode_rleFunction · 0.85
stbi__get8Function · 0.85
stbi__convert_format16Function · 0.85
stbi__convert_formatFunction · 0.85

Tested by

no test coverage detected