Class MultiBandsIndexColorModel
java.lang.Object
java.awt.image.ColorModel
java.awt.image.IndexColorModel
org.apache.sis.internal.coverage.j2d.MultiBandsIndexColorModel
- All Implemented Interfaces:
Transparency
An
IndexColorModel tolerant with image having more than one band.
This class can support only the types supported by IndexColorModel
parent class. As of Java 14 they are restricted to DataBuffer.TYPE_BYTE
and DataBuffer#TYPE_USHORT.
Reminder: ColorModel.getNumComponents() will return 3 or 4 no matter
how many bands were specified to the constructor. This is not specific to this class;
IndexColorModel behave that way. So we cannot rely on this method for checking
the number of bands.
- Since:
- 1.0
- Version:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final intThe number of bands.(package private) final intThe visible band.Fields inherited from class java.awt.image.ColorModel
pixel_bits, transferTypeFields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT -
Constructor Summary
ConstructorsConstructorDescriptionMultiBandsIndexColorModel(int bits, int size, int[] cmap, int start, boolean hasAlpha, int transparent, int transferType, int numBands, int visibleBand) Constructs an index color model with the specified properties. -
Method Summary
Modifier and TypeMethodDescriptioncreateCompatibleSampleModel(int width, int height) Creates aSampleModelwith the specified width and height that has a data layout compatible with thisColorModel.createCompatibleWritableRaster(int width, int height) Creates aWritableRasterwith the specified width and height that has a data layout (SampleModel) compatible with thisColorModel.(package private) final IndexColorModelcreateSubsetColorModel(int[] bands) Creates a new color model with only a subset of the bands in this color model.intReturns the alpha component for the specified pixel, scaled from 0 to 255.private int[]getARGB()Returns all ARGB colors in this color model.intReturns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace.int[]getComponents(Object pixel, int[] components, int offset) Returns an array of unnormalized color/alpha components for a specified pixel in this color model.getDataElements(int RGB, Object pixel) Converts a RGB color to a representation of a pixel in this color model.intReturns the green color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace.intReturns the red color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace.booleanisCompatibleRaster(Raster raster) Returnstrueifrasteris compatible with thisColorModel.booleanChecks if the specifiedSampleModelis compatible with thisColorModel.private intReturns the pixel value as an integer.Methods inherited from class java.awt.image.IndexColorModel
convertToIntDiscrete, finalize, getAlpha, getAlphas, getBlue, getBlues, getComponents, getComponentSize, getDataElement, getDataElements, getGreen, getGreens, getMapSize, getRed, getReds, getRGB, getRGBs, getTransparency, getTransparentPixel, getValidPixels, isValid, isValid, toStringMethods inherited from class java.awt.image.ColorModel
coerceData, equals, getAlphaRaster, getColorSpace, getComponentSize, getDataElement, getDataElements, getNormalizedComponents, getNormalizedComponents, getNumColorComponents, getNumComponents, getPixelSize, getRGB, getRGBdefault, getTransferType, getUnnormalizedComponents, hasAlpha, hashCode, isAlphaPremultiplied
-
Field Details
-
numBands
final int numBandsThe number of bands. -
visibleBand
final int visibleBandThe visible band.
-
-
Constructor Details
-
MultiBandsIndexColorModel
public MultiBandsIndexColorModel(int bits, int size, int[] cmap, int start, boolean hasAlpha, int transparent, int transferType, int numBands, int visibleBand) Constructs an index color model with the specified properties.- Parameters:
bits- the number of bits each pixel occupies.size- the size of the color component arrays.cmap- the array of color components.start- the starting offset of the first color component.hasAlpha- indicates whether alpha values are contained in thecmaparray.transparent- The index of the fully transparent pixel.transferType- The data type of the array used to represent pixel values.numBands- the number of bands.visibleBand- the band to display.- Throws:
IllegalArgumentException- ifbitsis less than 1 or greater than 16.IllegalArgumentException- ifsizeis less than 1.IllegalArgumentException- iftransferTypeis not one ofDataBuffer.TYPE_BYTEorDataBuffer.TYPE_USHORT.
-
-
Method Details
-
createSubsetColorModel
Creates a new color model with only a subset of the bands in this color model.Note: the new color model will use a copy of the color map of this color model. There is no way to share the
int[]array of ARGB values between twoIndexColorModels. -
getARGB
private int[] getARGB()Returns all ARGB colors in this color model. This is a copy of thecmapused by this color model. -
getDataElements
Converts a RGB color to a representation of a pixel in this color model. This method returns an array with a length equal to the number of bands specified to the constructor (IndexColorModelwould returns an array of length 1). All array elements are set to the same value. Replicating the pixel value is a somewhat arbitrary choice, but this choice makes this image appears as a gray scale image if the underlyingDataBufferwere displayed again with a RGB color model instead of this one. Such a gray scale image seems more neutral than an image where only the Red component would vary.All other
getDataElement(…)methods in this color model are ultimately defined in terms of this method, so overriding this method if needed should be enough.- Overrides:
getDataElementsin classIndexColorModel
-
pixel
Returns the pixel value as an integer. -
getComponents
Returns an array of unnormalized color/alpha components for a specified pixel in this color model. This method is the converse ofgetDataElements(int, Object).- Overrides:
getComponentsin classIndexColorModel
-
getRed
Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace.- Overrides:
getRedin classColorModel
-
getGreen
Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace.- Overrides:
getGreenin classColorModel
-
getBlue
Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace.- Overrides:
getBluein classColorModel
-
getAlpha
Returns the alpha component for the specified pixel, scaled from 0 to 255.- Overrides:
getAlphain classColorModel
-
createCompatibleWritableRaster
Creates aWritableRasterwith the specified width and height that has a data layout (SampleModel) compatible with thisColorModel. The difference with standard implementation is that this method creates a banded raster on the assumption that the number of bands is greater than 1. By contrast, the standard implementation provides various optimizations for one-banded raster.- Overrides:
createCompatibleWritableRasterin classIndexColorModel
-
createCompatibleSampleModel
Creates aSampleModelwith the specified width and height that has a data layout compatible with thisColorModel.- Overrides:
createCompatibleSampleModelin classIndexColorModel
-
isCompatibleRaster
Returnstrueifrasteris compatible with thisColorModel. This method performs the same checks than the standard implementation except for the number of bands, which is required to be equal tonumBandsinstead of 1. The actual checks are delegated toisCompatibleSampleModel(SampleModel)instead of duplicated in this method.- Overrides:
isCompatibleRasterin classIndexColorModel
-
isCompatibleSampleModel
Checks if the specifiedSampleModelis compatible with thisColorModel. This method performs the same checks than the standard implementation except for the number of bands and for not acceptingMultiPixelPackedSampleModel.- Overrides:
isCompatibleSampleModelin classIndexColorModel
-