}
else
{
if (!(image instanceof Paletted8Image))
{
throw new WrongParameterException("Image to be used for loading must be paletted for this file.");
}
((Paletted8Image)image).setPalette(palette);
}
}
else
{
switch(bitsPerPixel)
{
case(1): // bilevel image (black and white)
{
if (image == null)
{
image = new MemoryBilevelImage(getBoundsWidth(), getBoundsHeight());
}
else
{
if (!(image instanceof BilevelImage))
{
throw new WrongParameterException("Image to be used for " +
"loading must implement BilevelImage for this file.");
}
}
break;
}
case(16): // RGB direct color
{
if (image == null)
{
image = new MemoryRGB24Image(getBoundsWidth(), getBoundsHeight());
}
else
{
if (!(image instanceof RGB24Image))
{
throw new WrongParameterException("Image to be used for " +
"loading must implement RGB24Image.");
}
}
rgb = new byte[width * 3];
break;
}
default: // grayscale, 2, 4 or 8 bits per pixel
{
if (image == null)
{
image = new MemoryGray8Image(getBoundsWidth(), getBoundsHeight());
}
else
{
if (!(image instanceof Gray8Image))
{
throw new WrongParameterException("Image to be used for " +
"loading must implement Gray8Image for this file.");
}
}
}
}
}
setImage(image);
// check if image has the correct pixel resolution
if (image.getWidth() != getBoundsWidth() || image.getHeight() != getBoundsHeight())
{
throw new WrongParameterException("Image to be reused has wrong resolution (must have " +
getBoundsWidth() + " x " + getBoundsHeight() + " pixels).");
}
loadImageData(in);
}