PixelImage in = getInputImage();
boolean gray8 = in instanceof Gray8Image;
boolean gray16 = in instanceof Gray16Image;
if (!(gray8 || gray16))
{
throw new WrongParameterException("Input image must be either Gray8Image or Gray16Image.");
}
if (destBits.intValue() == 1)
{
process((GrayIntegerImage)in, gray8 ? 0x80 : 0x8000, (BilevelImage)getOutputImage());
}
else
if (gray8)
{
if (destBits.intValue() > 7)
{
throw new WrongParameterException("For a Gray8Image destination bits must be 7 or less.");
}
PixelImage out = getOutputImage();
if (out == null)
{
out = new MemoryGray8Image(in.getWidth(), in.getHeight());
}
else
{
if (!(out instanceof Gray8Image))
{
throw new WrongParameterException("For this input image, output image must be a Gray8Image.");
}
}
createLut(8);
process((GrayIntegerImage)in, (GrayIntegerImage)out);
}
else
if (gray16)
{
PixelImage out = getOutputImage();
if (out == null)
{
out = new MemoryGray16Image(in.getWidth(), in.getHeight());
}
else
{
if (destBits.intValue() <= 8 && !(out instanceof Gray8Image))
{
throw new WrongParameterException("For this input image, output image must be a Gray8Image.");
}
if (destBits.intValue() <= 15 && !(out instanceof Gray16Image))
{
throw new WrongParameterException("For this input image, output image must be a Gray16Image.");
}
}
createLut(16);
process((GrayIntegerImage)in, (GrayIntegerImage)out);
}