{
list = createColorList((RGB24Image)in);
}
else
{
throw new WrongParameterException("Input image must implement RGB24Image.");
}
root = new MedianCutNode(null, 0, list.getNumEntries() - 1);
root.setMinColor(0, 0, 0);
root.setMaxColor(maxValue, maxValue, maxValue);
findPalette();
if (doNotMap)
{
return;
}
PixelImage out = getOutputImage();
if (getTruecolorOutput())
{
if (out == null)
{
out = in.createCompatibleImage(in.getWidth(), in.getHeight());
setOutputImage(out);
}
else
{
if (!(out instanceof RGB24Image))
{
throw new WrongParameterException("Output image must implement RGB24Image.");
}
}
mapImage((RGB24Image)in, (RGB24Image)out);
}
else
{
Palette palette = createPalette();
if (out == null)
{
out = new MemoryPaletted8Image(in.getWidth(), in.getHeight(), palette);
setOutputImage(out);
}
else
{
if (out instanceof Paletted8Image)
{
((Paletted8Image)out).setPalette(palette);
}
else
{
throw new WrongParameterException("Output image must implement Paletted8Image.");
}
}
mapImage((RGB24Image)in, (Paletted8Image)out);
}
}