Added support for 16-bit PSD loading.

This extends the current PSD loader to add support for 16-bit images, by
quantizing them down to 8-bit upon load.
pull/146/head
rmitton 2015-07-07 15:15:38 -07:00
parent b53c08a148
commit a371b204f5
1 changed files with 11 additions and 4 deletions

View File

@ -5054,6 +5054,7 @@ static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int
int pixelCount;
int channelCount, compression;
int channel, i, count, len;
int bitdepth;
int w,h;
stbi_uc *out;
@ -5078,8 +5079,9 @@ static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int
w = stbi__get32be(s);
// Make sure the depth is 8 bits.
if (stbi__get16be(s) != 8)
return stbi__errpuc("unsupported bit depth", "PSD bit depth is not 8 bit");
bitdepth = stbi__get16be(s);
if (bitdepth != 8 && bitdepth != 16)
return stbi__errpuc("unsupported bit depth", "PSD bit depth is not 8 or 16 bit");
// Make sure the color mode is RGB.
// Valid options are:
@ -5191,8 +5193,13 @@ static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int
*p = channel == 3 ? 255 : 0;
} else {
// Read the data.
for (i = 0; i < pixelCount; i++, p += 4)
*p = stbi__get8(s);
if (bitdepth == 16) {
for (i = 0; i < pixelCount; i++, p += 4)
*p = (stbi__get16le(s) + 127) >> 8;
} else {
for (i = 0; i < pixelCount; i++, p += 4)
*p = stbi__get8(s);
}
}
}
}