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 ScaledColorSpaceThe object from which to get the coefficients for converting values to colors.private static final intThe mask to apply for getting a single color component.(package private) static final intSize of the range of color values.Fields inherited from class java.awt.image.ColorModel
pixel_bits, transferTypeFields 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 ScaledColorModelcreateSubsetColorModel(int[] bands) Creates a new color model with only a subset of the bands in this color model.booleanReturnstrueif the given object is also an instance ofScaledColorModelwith equals color space and same transfer type.intgetAlpha(int value) intReturns the alpha value for the given sample values.intgetBlue(int value) intintgetGreen(int value) intintgetRed(int value) Defined for consistency but should not be used.intintgetRGB(int value) Returns the color/alpha components of the pixel.intReturns the color/alpha components for the specified pixel in the default RGB color model format.intReturns 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, isCompatibleRaster, isCompatibleSampleModelMethods inherited from class java.awt.image.ColorModel
finalize, getColorSpace, getComponentSize, getComponentSize, getNumColorComponents, getNumComponents, getPixelSize, getRGBdefault, getTransferType, hasAlpha, hashCode, 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 aScaledColorSpacefor 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 theDataBufferconstants.
-
-
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:
getRedin classComponentColorModel
-
getRed
- Overrides:
getRedin classComponentColorModel
-
getGreen
public int getGreen(int value) - Overrides:
getGreenin classComponentColorModel
-
getGreen
- Overrides:
getGreenin classComponentColorModel
-
getBlue
public int getBlue(int value) - Overrides:
getBluein classComponentColorModel
-
getBlue
- Overrides:
getBluein classComponentColorModel
-
getAlpha
public int getAlpha(int value) - Overrides:
getAlphain classComponentColorModel
-
getTransparency
public int getTransparency()Returns whether this color model is capable to handle transparent pixels.- Specified by:
getTransparencyin interfaceTransparency- Overrides:
getTransparencyin classColorModel
-
getAlpha
Returns the alpha value for the given sample values. This is based only on whether or not the value is NaN.- Overrides:
getAlphain classComponentColorModel
-
getRGB
Returns the color/alpha components for the specified pixel in the default RGB color model format.- Overrides:
getRGBin classComponentColorModel
-
getRGB
public int getRGB(int value) Returns the color/alpha components of the pixel.- Overrides:
getRGBin classComponentColorModel
-
equals
Returnstrueif the given object is also an instance ofScaledColorModelwith 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 overrideColorModel.hashCode().- Overrides:
equalsin classComponentColorModel
-