if (isRgbGray((RGB24Image)inputImage))
{
type = TYPE_GRAY8;
if (doConvert)
{
outputImage = new MemoryGray8Image(inputImage.getWidth(), inputImage.getHeight());
createGrayFromRgb((RGB24Image)inputImage, (Gray8Image)outputImage);
}
}
else
if (isRgb24Paletted8((RGB24Image)inputImage))
{
type = TYPE_PALETTED8;
if (doConvert)
{
createPaletted8FromRgb24((RGB24Image)inputImage);
}
}
}
else
// RGB48
if (inputImage instanceof RGB48Image)
{
if (isRgbBilevel((RGB48Image)inputImage))
{
type = TYPE_BILEVEL;
if (doConvert)
{
createBilevelFromGrayOrRgb((RGB48Image)inputImage);
}
}
else
if (isRgb48Gray8((RGB48Image)inputImage))
{
type = TYPE_GRAY8;
if (doConvert)
{
outputImage = new MemoryGray8Image(inputImage.getWidth(), inputImage.getHeight());
// this create method works because it works with int and the least significant 8
// bits are equal to the most significant 8 bits if isRgb48Gray8 returned true
createGrayFromRgb((RGB48Image)inputImage, (Gray8Image)outputImage);
}
}
else
if (isRgbGray((RGB48Image)inputImage))
{
type = TYPE_GRAY16;
if (doConvert)
{
outputImage = new MemoryGray8Image(inputImage.getWidth(), inputImage.getHeight());
createGrayFromRgb((RGB24Image)inputImage, (Gray8Image)outputImage);
}
}
else
if (isRgb48Rgb24((RGB48Image)inputImage))
{
// RGB48 input is RGB24; is it also Paletted8?
if (isRgb48Paletted8((RGB48Image)inputImage))
{
type = TYPE_PALETTED8;
if (doConvert)
{
createPaletted8FromRgb48((RGB48Image)inputImage);
}
}
else
{
type = TYPE_RGB24;
if (doConvert)
{
outputImage = new MemoryRGB24Image(inputImage.getWidth(), inputImage.getHeight());
createRgb24FromRgb48((RGB48Image)inputImage, (RGB24Image)outputImage);
}
}
}
}
else
// PALETTED8
if (inputImage instanceof Paletted8Image)
{
Paletted8Image in = (Paletted8Image)inputImage;
Palette palette = in.getPalette();
if (palette.isBlackAndWhite())
{
type = TYPE_BILEVEL;
if (doConvert)
{
createBilevelFromPaletted(in);
}
}
else
if (palette.isGray())
{
type = TYPE_GRAY8;
if (doConvert)
{
Gray8Image out = new MemoryGray8Image(in.getWidth(), in.getHeight());
createGray8FromPaletted8(in, out);
}
}
}
else