| 6737 | } |
| 6738 | |
| 6739 | static void* stbi__psd_load( |
| 6740 | stbi__context* s, int* x, int* y, int* comp, int req_comp, |
| 6741 | stbi__result_info* ri, int bpc) { |
| 6742 | int pixelCount; |
| 6743 | int channelCount, compression; |
| 6744 | int channel, i; |
| 6745 | int bitdepth; |
| 6746 | int w, h; |
| 6747 | stbi_uc* out; |
| 6748 | STBI_NOTUSED(ri); |
| 6749 | |
| 6750 | // Check identifier |
| 6751 | if (stbi__get32be(s) != 0x38425053) // "8BPS" |
| 6752 | return stbi__errpuc("not PSD", "Corrupt PSD image"); |
| 6753 | |
| 6754 | // Check file type version. |
| 6755 | if (stbi__get16be(s) != 1) |
| 6756 | return stbi__errpuc("wrong version", "Unsupported version of PSD image"); |
| 6757 | |
| 6758 | // Skip 6 reserved bytes. |
| 6759 | stbi__skip(s, 6); |
| 6760 | |
| 6761 | // Read the number of channels (R, G, B, A, etc). |
| 6762 | channelCount = stbi__get16be(s); |
| 6763 | if (channelCount < 0 || channelCount > 16) |
| 6764 | return stbi__errpuc( |
| 6765 | "wrong channel count", "Unsupported number of channels in PSD image"); |
| 6766 | |
| 6767 | // Read the rows and columns of the image. |
| 6768 | h = stbi__get32be(s); |
| 6769 | w = stbi__get32be(s); |
| 6770 | |
| 6771 | if (h > STBI_MAX_DIMENSIONS) |
| 6772 | return stbi__errpuc("too large", "Very large image (corrupt?)"); |
| 6773 | if (w > STBI_MAX_DIMENSIONS) |
| 6774 | return stbi__errpuc("too large", "Very large image (corrupt?)"); |
| 6775 | |
| 6776 | // Make sure the depth is 8 bits. |
| 6777 | bitdepth = stbi__get16be(s); |
| 6778 | if (bitdepth != 8 && bitdepth != 16) |
| 6779 | return stbi__errpuc( |
| 6780 | "unsupported bit depth", "PSD bit depth is not 8 or 16 bit"); |
| 6781 | |
| 6782 | // Make sure the color mode is RGB. |
| 6783 | // Valid options are: |
| 6784 | // 0: Bitmap |
| 6785 | // 1: Grayscale |
| 6786 | // 2: Indexed color |
| 6787 | // 3: RGB color |
| 6788 | // 4: CMYK color |
| 6789 | // 7: Multichannel |
| 6790 | // 8: Duotone |
| 6791 | // 9: Lab color |
| 6792 | if (stbi__get16be(s) != 3) |
| 6793 | return stbi__errpuc("wrong color format", "PSD is not in RGB color format"); |
| 6794 | |
| 6795 | // Skip the Mode Data. (It's the palette for indexed color; other info for other |
| 6796 | // modes.) |
no test coverage detected