Class ScaledColorModel
java.lang.Object
java.awt.image.ColorModel
java.awt.image.ComponentColorModel
org.apache.sis.internal.coverage.j2d.ScaledColorModel
- All Implemented Interfaces:
Transparency
A color model for use with
ScaledColorSpace
(gray scale image with missing values).
This color model is slightly more efficient than the default ComponentColorModel
by
reducing the amount of object allocations, made possible by the knowledge that we use only
one sample value and returns only one color component (the gray).
In addition, this class renders the Float.NaN
values as transparent.- Since:
- 1.1
- Version:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ScaledColorSpace
The object from which to get the coefficients for converting values to colors.private static final int
The mask to apply for getting a single color component.(package private) static final int
Size of the range of color values.Fields inherited from class java.awt.image.ColorModel
pixel_bits, transferType
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
-
Constructor Summary
ConstructorsConstructorDescriptionScaledColorModel
(ScaledColorSpace colorSpace, int type) Creates a new color model for the range of values in the given color space. -
Method Summary
Modifier and TypeMethodDescription(package private) final ScaledColorModel
createSubsetColorModel
(int[] bands) Creates a new color model with only a subset of the bands in this color model.boolean
Returnstrue
if the given object is also an instance ofScaledColorModel
with equals color space and same transfer type.int
getAlpha
(int value) int
Returns the alpha value for the given sample values.int
getBlue
(int value) int
int
getGreen
(int value) int
int
getRed
(int value) Defined for consistency but should not be used.int
int
getRGB
(int value) Returns the color/alpha components of the pixel.int
Returns the color/alpha components for the specified pixel in the default RGB color model format.int
Returns whether this color model is capable to handle transparent pixels.Methods inherited from class java.awt.image.ComponentColorModel
coerceData, createCompatibleSampleModel, createCompatibleWritableRaster, getAlphaRaster, getComponents, getComponents, getDataElement, getDataElement, getDataElements, getDataElements, getDataElements, getNormalizedComponents, getNormalizedComponents, getUnnormalizedComponents, hashCode, isCompatibleRaster, isCompatibleSampleModel
Methods inherited from class java.awt.image.ColorModel
finalize, getColorSpace, getComponentSize, getComponentSize, getNumColorComponents, getNumComponents, getPixelSize, getRGBdefault, getTransferType, hasAlpha, isAlphaPremultiplied, toString
-
Field Details
-
MASK
private static final int MASKThe mask to apply for getting a single color component. This is also the maximum (inclusive) color/alpha value.- See Also:
-
RANGE
static final int RANGESize of the range of color values. Since minimum value is zero, this range is also the maximum (exclusive) color/alpha value.- See Also:
-
cs
The object from which to get the coefficients for converting values to colors. This is a reference to the same object thanColorModel.getColorSpace()
, but stored as aScaledColorSpace
for avoiding the need to perform casts.
-
-
Constructor Details
-
ScaledColorModel
ScaledColorModel(ScaledColorSpace colorSpace, int type) Creates a new color model for the range of values in the given color space.- Parameters:
colorSpace
- the color space to use with this color model.type
- one of theDataBuffer
constants.
-
-
Method Details
-
createSubsetColorModel
Creates a new color model with only a subset of the bands in this color model. -
getRed
public int getRed(int value) Defined for consistency but should not be used.- Overrides:
getRed
in classComponentColorModel
-
getRed
- Overrides:
getRed
in classComponentColorModel
-
getGreen
public int getGreen(int value) - Overrides:
getGreen
in classComponentColorModel
-
getGreen
- Overrides:
getGreen
in classComponentColorModel
-
getBlue
public int getBlue(int value) - Overrides:
getBlue
in classComponentColorModel
-
getBlue
- Overrides:
getBlue
in classComponentColorModel
-
getAlpha
public int getAlpha(int value) - Overrides:
getAlpha
in classComponentColorModel
-
getTransparency
public int getTransparency()Returns whether this color model is capable to handle transparent pixels.- Specified by:
getTransparency
in interfaceTransparency
- Overrides:
getTransparency
in classColorModel
-
getAlpha
Returns the alpha value for the given sample values. This is based only on whether or not the value is NaN.- Overrides:
getAlpha
in classComponentColorModel
-
getRGB
Returns the color/alpha components for the specified pixel in the default RGB color model format.- Overrides:
getRGB
in classComponentColorModel
-
getRGB
public int getRGB(int value) Returns the color/alpha components of the pixel.- Overrides:
getRGB
in classComponentColorModel
-
equals
Returnstrue
if the given object is also an instance ofScaledColorModel
with equals color space and same transfer type.Note: we have to override this method because theComponentColorModel.equals(Object)
implementation is confused by our overriding ofgetTransparency()
method. However, we do not need to overrideComponentColorModel.hashCode()
.- Overrides:
equals
in classComponentColorModel
-