private IntegerImage readImage() throws
InvalidFileStructureException,
java.io.IOException
{
RGB24Image rgb24Image = null;
Paletted8Image paletted8Image = null;
IntegerImage result = null;
int numChannels = 1;
int bytesPerRow = 0;
switch(depth)
{
case(8):
{
paletted8Image = new MemoryPaletted8Image(width, height, palette);
result = paletted8Image;
numChannels = 1;
bytesPerRow = width;
break;
}
case(24):
{
rgb24Image = new MemoryRGB24Image(width, height);
result = rgb24Image;
numChannels = 3;
bytesPerRow = width;
break;
}
}
setImage(result);
byte[][] buffer = new byte[numChannels][];
for (int i = 0; i < numChannels; i++)
{
buffer[i] = new byte[bytesPerRow];
}
for (int y = 0, destY = -getBoundsY1(); destY <= getBoundsY2(); y++, destY++)
{
if (rgb24Image != null)
{
for (int x = 0; x < width; x++)
{
buffer[RGBIndex.INDEX_BLUE][x] = in.readByte();
buffer[RGBIndex.INDEX_GREEN][x] = in.readByte();
buffer[RGBIndex.INDEX_RED][x] = in.readByte();
}
rgb24Image.putByteSamples(RGBIndex.INDEX_RED, 0, destY, getBoundsWidth(), 1, buffer[0], getBoundsX1());
rgb24Image.putByteSamples(RGBIndex.INDEX_GREEN, 0, destY, getBoundsWidth(), 1, buffer[1], getBoundsX1());
rgb24Image.putByteSamples(RGBIndex.INDEX_BLUE, 0, destY, getBoundsWidth(), 1, buffer[2], getBoundsX1());
}
else
if (paletted8Image != null)
{
in.readFully(buffer[0], 0, width);