Search in sources :

Example 86 with ColorSpace

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);
}
Also used : DirectColorModel(java.awt.image.DirectColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) PackedColorModel(java.awt.image.PackedColorModel) ColorModel(java.awt.image.ColorModel) IndexColorModel(java.awt.image.IndexColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ColorSpace(java.awt.color.ColorSpace)

Aggregations

ColorSpace (java.awt.color.ColorSpace)86 ColorModel (java.awt.image.ColorModel)33 BufferedImage (java.awt.image.BufferedImage)30 ComponentColorModel (java.awt.image.ComponentColorModel)29 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)24 IndexColorModel (java.awt.image.IndexColorModel)17 SampleModel (java.awt.image.SampleModel)17 WritableRaster (java.awt.image.WritableRaster)13 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)11 ColorConvertOp (java.awt.image.ColorConvertOp)10 DirectColorModel (java.awt.image.DirectColorModel)10 Point (java.awt.Point)8 DataBuffer (java.awt.image.DataBuffer)8 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)8 DataBufferByte (java.awt.image.DataBufferByte)6 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)6 IIOException (javax.imageio.IIOException)5 Test (org.junit.Test)5 Rectangle (java.awt.Rectangle)4 ComponentSampleModel (java.awt.image.ComponentSampleModel)4