PixelImage in = getInputImage();
boolean rgb24 = in instanceof RGB24Image;
boolean rgb48 = in instanceof RGB48Image;
if (!(rgb24 || rgb48))
{
throw new WrongParameterException(
"Input image must be either RGB24Image or RGB48Image.");
}
if (rgb24 && bits >= 8)
{
throw new WrongParameterException(
"Number of output bits per sample must be 7 or lower for RGB24Image.");
}
PixelImage out = getOutputImage();
int inDepth = 0;
if (rgb24)
{
inDepth = 8;
}
if (rgb48)
{
inDepth = 16;
}
int maxOutputValue = 1;
int maxShiftedValue = (1 << bits) - 1;
if (bits <= 8)
{
if (out == null)
{
out = new MemoryRGB24Image(in.getWidth(), in.getHeight());
setOutputImage(out);
}
else
{
if (!(out instanceof RGB24Image))
{
throw new WrongParameterException(
"Output image must be of type RGB24Image.");
}
}
maxOutputValue = 255;
}
else
if (bits <= 16)
{
if (out == null)
{
out = new MemoryRGB48Image(in.getWidth(), in.getHeight());
setOutputImage(out);
}
else
{
if (!(out instanceof RGB48Image))
{
throw new WrongParameterException(
"Output image must be of type RGB48Image.");
}
}
maxOutputValue = 65535;
}
else
{
throw new WrongParameterException("Can only process up to 16 bits per sample.");
}
final int SHIFT = inDepth - bits;
IntegerImage ii = (IntegerImage)in;
IntegerImage oo = (IntegerImage)out;
for (int y = 0; y < in.getHeight(); y++)