}
if (colorMode != COLOR_MODE_RGB_TRUECOLOR &&
colorMode != COLOR_MODE_GRAYSCALE &&
colorMode != COLOR_MODE_INDEXED)
{
throw new UnsupportedTypeException("Cannot load image. Only RGB" +
" truecolor and indexed color are supported for PSD files. " +
"Found: " +getColorTypeName(colorMode));
}
if (depth != 8)
{
throw new UnsupportedTypeException("Cannot load image. Only a depth of 8 bits " +
"per channel is supported (found " + depth +
" bits).");
}
// COLOR MODE DATA
int colorModeSize = in.readInt();
//System.out.println("colorModeSize=" + colorModeSize);
byte[] colorMap = null;
if (colorMode == COLOR_MODE_INDEXED)
{
if (colorModeSize != 768)
{
throw new InvalidFileStructureException("Cannot load image." +
" Color map length was expected to be 768 (found " +
colorModeSize + ").");
}
colorMap = new byte[colorModeSize];
in.readFully(colorMap);
palette = new Palette(256, 255);
for (int index = 0; index < 256; index++)
{
palette.putSample(Palette.INDEX_RED, index, colorMap[index] & 0xff);
palette.putSample(Palette.INDEX_GREEN, index, colorMap[256 + index] & 0xff);
palette.putSample(Palette.INDEX_BLUE, index, colorMap[512 + index] & 0xff);
}
}
else
{
in.skipBytes(colorModeSize);
}
// IMAGE RESOURCES
int resourceLength = in.readInt();
in.skipBytes(resourceLength);
//System.out.println("resourceLength=" + resourceLength);
// LAYER AND MASK INFORMATION
int miscLength = in.readInt();
in.skipBytes(miscLength);
//System.out.println("miscLength=" + miscLength);
// IMAGE DATA
compression = in.readShort();
if (compression != COMPRESSION_NONE && compression != COMPRESSION_PACKBITS)
{
throw new UnsupportedTypeException("Cannot load image. Unsupported PSD " +
"compression type (" + compression + ")");
}
//System.out.println("compression=" + compression);
loadImageData();
}