private void loadColorImage() throws InvalidFileStructureException, IOException
{
RGBIntegerImage image = null;
RGB24Image image24 = null;
RGB48Image image48 = null;
if (maxSample <= 255)
{
image24 = new MemoryRGB24Image(width, height);
image = image24;
setImage(image);
}
else
{
image48 = new MemoryRGB48Image(width, height);
image = image48;
setImage(image);
}
for (int y = 0, destY = - getBoundsY1(); y < height; y++, destY++)
{
if (getAscii().booleanValue())
{
for (int x = 0; x < width; x++)
{
int red = loadAsciiNumber();
if (red < 0 || red > maxSample)
{
throw new InvalidFileStructureException("Invalid " +
"sample value " + red + " for red sample at " +
"(x=" + x + ", y=" + y + ").");
}
image.putSample(RGBIndex.INDEX_RED, x, y, red);
int green = loadAsciiNumber();
if (green < 0 || green > maxSample)
{
throw new InvalidFileStructureException("Invalid " +
"sample value " + green + " for green sample at " +
"(x=" + x + ", y=" + y + ").");
}
image.putSample(RGBIndex.INDEX_GREEN, x, y, green);
int blue = loadAsciiNumber();
if (blue < 0 || blue > maxSample)
{
throw new InvalidFileStructureException("Invalid " +
"sample value " + blue + " for blue sample at " +
"(x=" + x + ", y=" + y + ").");
}
image.putSample(RGBIndex.INDEX_BLUE, x, y, blue);
}
}
else
{
if (image24 != null)
{
for (int x = 0; x < width; x++)
{
int red = in.read();
if (red == -1)
{
throw new InvalidFileStructureException("Unexpected " +
"end of file while reading red sample for pixel " +
"x=" + x + ", y=" + y + ".");
}
image24.putByteSample(RGBIndex.INDEX_RED, x, y, (byte)(red & 0xff));
int green = in.read();
if (green == -1)
{
throw new InvalidFileStructureException("Unexpected " +
"end of file while reading green sample for pixel " +
"x=" + x + ", y=" + y + ".");
}
image24.putByteSample(RGBIndex.INDEX_GREEN, x, y, (byte)(green & 0xff));
int blue = in.read();
if (blue == -1)
{
throw new InvalidFileStructureException("Unexpected " +
"end of file while reading blue sample for pixel " +
"x=" + x + ", y=" + y + ".");
}
image24.putByteSample(RGBIndex.INDEX_BLUE, x, y, (byte)(blue & 0xff));
}
}
else if (image48 != null)
{
for (int x = 0; x < width; x++)
{
int red = read16BitBinaryValue();
if (red == -1)
{
throw new InvalidFileStructureException("Unexpected " +
"end of file while reading red sample for pixel " +
"x=" + x + ", y=" + y + ".");
}
image48.putShortSample(RGBIndex.INDEX_RED, x, y, (short)(red & 0xffff));
int green = read16BitBinaryValue();
if (green == -1)
{
throw new InvalidFileStructureException("Unexpected " +
"end of file while reading green sample for pixel " +
"x=" + x + ", y=" + y + ".");
}
image48.putShortSample(RGBIndex.INDEX_GREEN, x, y, (short)(green & 0xffff));
int blue = read16BitBinaryValue();
if (blue == -1)
{
throw new InvalidFileStructureException("Unexpected " +
"end of file while reading blue sample for pixel " +
"x=" + x + ", y=" + y + ".");
}
image48.putShortSample(RGBIndex.INDEX_BLUE, x, y, (short)(blue & 0xffff));
}
}
}
setProgress(y, getBoundsHeight());
}