Class ColorModelFactory
java.lang.Object
org.apache.sis.internal.coverage.j2d.ColorModelFactory
A factory for
ColorModel objects built from a sequence of colors.- Since:
- 1.0
- Version:
- 1.3
- Author:
- Martin Desruisseaux (IRD, Geomatys), Johann Sorel (Geomatys), Alexis Manin (Geomatys)
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ColorModelcreateColorScale(int dataType, int numBands, int visibleBand, double lower, double upper, Color... colors) Returns a color model interpolated for the given range of values.static ColorModelcreateGrayScale(int dataType, int numComponents, int visibleBand, double minimum, double maximum) Creates a color model for opaque images storing pixels as real numbers.static ColorModelcreateGrayScale(SampleModel model, int visibleBand, NumberRange<?> range) Creates a color model for opaque images storing pixels using the given sample model.static IndexColorModelcreateIndexColorModel(int numBands, int visibleBand, int[] ARGB, boolean hasAlpha, int transparent) Returns a tolerant index color model for the specified ARGB codes.static ColorModelcreatePiecewise(int dataType, int numBands, int visibleBand, Map<NumberRange<?>, Color[]> colors) Returns a color model interpolated for the ranges in the given map entries.static ColorModelcreateRGB(int bitsPerSample, boolean packed, boolean hasAlpha) Creates a RGB color model.static ColorModelcreateRGB(SampleModel model) Creates a RGB color model for the given sample model.static Optional<ColorModel> createSubset(ColorModel cm, int[] bands) Creates a color model with only a subset of the bands of the given color model.booleanPublic as an implementation side-effect.static voidexpand(int[] colors, int[] ARGB, int lower, int upper) CopiescolorsintoARGBarray from indexlowerinclusive to indexupperexclusive.static voidformatDescription(ColorSpace cs, StringBuilder buffer) Appends a description of the given color space in the given buffer.static intgetBitCount(int mapSize) Returns a bit count for anIndexColorModelmappingmapSizecolors.inthashCode()Public as an implementation side-effect.toString()Returns a string representation for debugging purposes.
-
Field Details
-
TRANSPARENT
The fully transparent color.
-
-
Method Details
-
hashCode
public int hashCode()Public as an implementation side-effect. -
equals
Public as an implementation side-effect. -
createPiecewise
public static ColorModel createPiecewise(int dataType, int numBands, int visibleBand, Map<NumberRange<?>, Color[]> colors) Returns a color model interpolated for the ranges in the given map entries. Returned instances ofColorModelare shared among all callers in the running virtual machine.- Parameters:
dataType- the color model type. One ofDataBuffer.TYPE_BYTE,DataBuffer.TYPE_USHORT,DataBuffer.TYPE_SHORT,DataBuffer.TYPE_INT,DataBuffer.TYPE_FLOATorDataBuffer.TYPE_DOUBLE.numBands- the number of bands for the color model (usually 1). The returned color model will render only thevisibleBandand ignore the others, but the existence of allnumBandswill be at least tolerated. Supplemental bands, even invisible, are useful for processing.visibleBand- the band to be made visible (usually 0). All other bands (if any) will be ignored.colors- the colors to use for each range of sample values. The map may containnullvalues, which means transparent.- Returns:
- a color model suitable for
RenderedImageobjects with values in the given ranges. - See Also:
-
createIndexColorModel
public static IndexColorModel createIndexColorModel(int numBands, int visibleBand, int[] ARGB, boolean hasAlpha, int transparent) Returns a tolerant index color model for the specified ARGB codes. This color model accepts image with the specified number of bands.This methods caches previously created instances using weak references, because index color model may be big (up to 256 kb).
- Parameters:
numBands- the number of bands.visibleBand- the band to display.ARGB- an array of ARGB values.hasAlpha- indicates whether alpha values are contained in theARGBarray.transparent- the transparent pixel, or -1 for auto-detection.- Returns:
- An index color model for the specified array.
-
createColorScale
public static ColorModel createColorScale(int dataType, int numBands, int visibleBand, double lower, double upper, Color... colors) Returns a color model interpolated for the given range of values. This is a convenience method forcreatePiecewise(int, int, int, Map)when the map contains only one element.- Parameters:
dataType- the color model type.numBands- the number of bands for the color model (usually 1).visibleBand- the band to be made visible (usually 0). All other bands (if any) will be ignored.lower- the minimum value, inclusive.upper- the maximum value, exclusive.colors- the colors to use for the range of sample values.- Returns:
- a color model suitable for
RenderedImageobjects with values in the given ranges.
-
createGrayScale
public static ColorModel createGrayScale(int dataType, int numComponents, int visibleBand, double minimum, double maximum) Creates a color model for opaque images storing pixels as real numbers. The color model can have an arbitrary number of bands, but in current implementation only one band is used.Warning: the use of this color model is very slow. It should be used only when no standard color model can be used.
- Parameters:
dataType- the color model type as one ofDataBuffer.TYPE_*constants.numComponents- the number of components.visibleBand- the band to use for computing colors.minimum- the minimal sample value expected.maximum- the maximal sample value expected.- Returns:
- the color model for the given range of values.
- See Also:
-
createGrayScale
Creates a color model for opaque images storing pixels using the given sample model. The color model can have an arbitrary number of bands, but in current implementation only one band is used.Warning: the use of this color model may be very slow and the color stretching may not be a good fit. This method should be used only when no standard color model can be used. This is a last resort method.
- Parameters:
model- the sample model for which to create a gray scale color model.visibleBand- the band to use for computing colors.range- the minimal and maximal sample value expected, ornullif none.- Returns:
- the color model for the given range of values.
-
createRGB
Creates a RGB color model for the given sample model. The sample model shall use integer type and have 3 or 4 bands.- Parameters:
model- the sample model for which to create a color model.- Returns:
- the color model.
-
createRGB
Creates a RGB color model. Thepackedargument should betruefor color model used withSinglePixelPackedSampleModel, andfalsefor color model used withBandedSampleModel.- Parameters:
bitsPerSample- number of bits per sample, between 1 and 8 inclusive.packed- whether sample values are packed in a single element.hasAlpha- whether the color model should have an alpha channel.- Returns:
- the color model.
-
createSubset
Creates a color model with only a subset of the bands of the given color model. The returned color model is compatible with a subset sample model created with the same argument than thebandsargument given to this method. This method might not produce a result in following cases:- Input color model is null.
- Given color model is not assignable from the following types:
ComponentColorModelMultiBandsIndexColorModelScaledColorModel
- Input color model is recognized, but we cannot infer a proper color interpretation for given number of bands.
PackedColorModelandDirectColorModel: they're not managed for now, because they're really designed for a "rigid" case where data buffer values are interpreted directly by the color model.- Parameters:
cm- the color model, ornull.bands- the bands to select. Must neither be null nor empty.- Returns:
- the subset color model, or empty if input was null or if a subset cannot be deduced.
-
formatDescription
Appends a description of the given color space in the given buffer. This is used fortoString()method implementations.- Parameters:
cs- the color space to describe, ornull.buffer- where to append the description.
-
getBitCount
public static int getBitCount(int mapSize) Returns a bit count for anIndexColorModelmappingmapSizecolors. It is guaranteed that the following relation is hold:- Parameters:
mapSize- the number of colors in the map.- Returns:
- the number of bits to use.
-
expand
public static void expand(int[] colors, int[] ARGB, int lower, int upper) CopiescolorsintoARGBarray from indexlowerinclusive to indexupperexclusive. Ifupper-loweris not equal to the length ofcolorsarray, then colors will be interpolated. The givencolorsarray must be initialized with zero values in thelower…upperrange.- Parameters:
colors- colors to copy into theARGBarray.ARGB- array of integer to write ARGB values into.lower- index (inclusive) of the first element ofARGBto change.upper- index (exclusive) of the last element ofARGBto change.
-
toString
Returns a string representation for debugging purposes.
-