use of java.awt.color.ColorSpace in project sis by apache.
the class ColorModelFactory method createSubset.
/**
* Creates a color model with only a subset of the bands of the given color model.
*
* @param cm the color model, or {@code null}.
* @param bands the bands to select.
* @return the subset color model, or {@code null} if it can not be created.
*/
public static ColorModel createSubset(final ColorModel cm, final int[] bands) {
final ColorModel subset;
if (cm instanceof MultiBandsIndexColorModel) {
subset = ((MultiBandsIndexColorModel) cm).createSubsetColorModel(bands);
} else if (cm instanceof ScaledColorModel) {
subset = ((ScaledColorModel) cm).createSubsetColorModel(bands);
} else if (bands.length == 1 && cm instanceof ComponentColorModel) {
final int dataType = cm.getTransferType();
if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_USHORT) {
return Colorizer.NULL_COLOR_MODEL;
}
final ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
subset = new ComponentColorModel(cs, false, true, Transparency.OPAQUE, dataType);
} else {
// TODO: handle other color models.
return Colorizer.NULL_COLOR_MODEL;
}
return unique(subset);
}
Aggregations