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 int
The number of bands.(package private) final int
The visible band.Fields inherited from class java.awt.image.ColorModel
pixel_bits, transferType
Fields 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 aSampleModel
with the specified width and height that has a data layout compatible with thisColorModel
.createCompatibleWritableRaster
(int width, int height) Creates aWritableRaster
with the specified width and height that has a data layout (SampleModel
) compatible with thisColorModel
.(package private) final IndexColorModel
createSubsetColorModel
(int[] bands) Creates a new color model with only a subset of the bands in this color model.int
Returns the alpha component for the specified pixel, scaled from 0 to 255.private int[]
getARGB()
Returns all ARGB colors in this color model.int
Returns 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.int
Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace
.int
Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace
.boolean
isCompatibleRaster
(Raster raster) Returnstrue
ifraster
is compatible with thisColorModel
.boolean
Checks if the specifiedSampleModel
is compatible with thisColorModel
.private int
Returns the pixel value as an integer.Methods inherited from class java.awt.image.IndexColorModel
convertToIntDiscrete, equals, getAlpha, getAlphas, getBlue, getBlues, getComponents, getComponentSize, getDataElement, getDataElements, getGreen, getGreens, getMapSize, getRed, getReds, getRGB, getRGBs, getTransparency, getTransparentPixel, getValidPixels, hashCode, isValid, isValid, toString
Methods inherited from class java.awt.image.ColorModel
coerceData, getAlphaRaster, getColorSpace, getComponentSize, getDataElement, getDataElements, getNormalizedComponents, getNormalizedComponents, getNumColorComponents, getNumComponents, getPixelSize, getRGB, getRGBdefault, getTransferType, getUnnormalizedComponents, hasAlpha, 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 thecmap
array.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
- ifbits
is less than 1 or greater than 16.IllegalArgumentException
- ifsize
is less than 1.IllegalArgumentException
- iftransferType
is not one ofDataBuffer.TYPE_BYTE
orDataBuffer.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 twoIndexColorModel
s. -
getARGB
private int[] getARGB()Returns all ARGB colors in this color model. This is a copy of thecmap
used 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 (IndexColorModel
would 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 underlyingDataBuffer
were 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:
getDataElements
in 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:
getComponents
in classIndexColorModel
-
getRed
Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace
.- Overrides:
getRed
in classColorModel
-
getGreen
Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace
.- Overrides:
getGreen
in classColorModel
-
getBlue
Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace
.- Overrides:
getBlue
in classColorModel
-
getAlpha
Returns the alpha component for the specified pixel, scaled from 0 to 255.- Overrides:
getAlpha
in classColorModel
-
createCompatibleWritableRaster
Creates aWritableRaster
with 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:
createCompatibleWritableRaster
in classIndexColorModel
-
createCompatibleSampleModel
Creates aSampleModel
with the specified width and height that has a data layout compatible with thisColorModel
.- Overrides:
createCompatibleSampleModel
in classIndexColorModel
-
isCompatibleRaster
Returnstrue
ifraster
is 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 tonumBands
instead of 1. The actual checks are delegated toisCompatibleSampleModel(SampleModel)
instead of duplicated in this method.- Overrides:
isCompatibleRaster
in classIndexColorModel
-
isCompatibleSampleModel
Checks if the specifiedSampleModel
is compatible with thisColorModel
. This method performs the same checks than the standard implementation except for the number of bands and for not acceptingMultiPixelPackedSampleModel
.- Overrides:
isCompatibleSampleModel
in classIndexColorModel
-