{
ImageContents imageContents = readImageContents(byteSource);
// ImageContents imageContents = readImage(byteSource, false);
if (imageContents == null)
throw new ImageReadException("PSD: Couldn't read blocks");
PSDHeaderInfo header = imageContents.header;
if (header == null)
throw new ImageReadException("PSD: Couldn't read Header");
// ImageDescriptor id = (ImageDescriptor)
// findBlock(fImageContents.blocks,
// kImageSeperator);
// if (id == null)
// throw new ImageReadException("PSD: Couldn't read Image Descriptor");
// GraphicControlExtension gce = (GraphicControlExtension) findBlock(
// fImageContents.blocks, kGraphicControlExtension);
ArrayList blocks = readImageResourceBlocks(byteSource,
// fImageContents.ImageResources,
null, -1);
int width = header.Columns;
int height = header.Rows;
// int height = header.Columns;
// int transfer_type;
// transfer_type = DataBuffer.TYPE_BYTE;
boolean hasAlpha = false;
BufferedImage result = getBufferedImageFactory(params)
.getColorBufferedImage(width, height, hasAlpha);
DataParser dataParser;
switch (imageContents.header.Mode)
{
case 0: // bitmap
dataParser = new DataParserBitmap();
break;
case 1:
case 8: // Duotone=8;
dataParser = new DataParserGrayscale();
break;
case 3:
dataParser = new DataParserRGB();
break;
case 4:
dataParser = new DataParserCMYK();
break;
case 9:
dataParser = new DataParserLab();
break;
case COLOR_MODE_INDEXED:
// case 2 : // Indexed=2;
{
byte ColorModeData[] = getData(byteSource, PSD_SECTION_COLOR_MODE);
// ImageResourceBlock block = findImageResourceBlock(blocks,
// 0x03EB);
// if (block == null)
// throw new ImageReadException(
// "Missing: Indexed Color Image Resource Block");
dataParser = new DataParserIndexed(ColorModeData);
break;
}
case 7: // Multichannel=7;
// fDataParser = new DataParserStub();
// break;
// case 1 :
// fDataReader = new CompressedDataReader();
// break;
default:
throw new ImageReadException("Unknown Mode: "
+ imageContents.header.Mode);
}
DataReader fDataReader;
switch (imageContents.Compression)
{
case 0:
fDataReader = new UncompressedDataReader(dataParser);
break;
case 1:
fDataReader = new CompressedDataReader(dataParser);
break;
default:
throw new ImageReadException("Unknown Compression: "
+ imageContents.Compression);
}
{
InputStream is = null;