-
Method Summary
Modifier and TypeMethodDescriptionclone()Clone this color.Get the component of this color named byname.floatCompute the difference to the given color, according to ΔEOK.getAlpha()Get the alpha channel of this color.Get the color model that this color uses.Get the color space to which this color belongs.intThe number of component values plus the alpha channel.booleanIs this color inside the given gamut?item(int index) Get the component of this color located atindex.Pack this color into a new CSS value.toColorSpace(String colorSpace) Convert this color to the given CSS color space.Gives a minified string representation of this color.double[]Convert the color components to a normalized form and put them in an array.double[]toXYZ(double[] white) Convert this color to the XYZ space using the given reference white.double[]toXYZ(Illuminant white) Convert this color to the XYZ space using the given reference illuminant.
-
Method Details
-
getColorModel
CSSColorValue.ColorModel getColorModel()Get the color model that this color uses.If this methods returns the
PROFILEvalue, this color belongs to a custom profile.- Returns:
- the color model.
-
getColorSpace
String getColorSpace()Get the color space to which this color belongs.See
ColorSpace.- Returns:
- the color space.
-
getAlpha
CSSPrimitiveValue getAlpha()Get the alpha channel of this color.- Returns:
- the alpha channel.
-
item
Get the component of this color located atindex.The alpha channel is considered the component
0, so the actual color component index starts at1.- Parameters:
index- the index.0is always the alpha channel.- Returns:
- the component, or
nullif the index is out of range.
-
component
Get the component of this color named byname.Percentages are normalized to numbers in the
[0-1]interval, and angles to degrees.- Parameters:
name- the component name.alphais the alpha channel.- Returns:
- the component, or
nullif the component name is unknown.
-
getLength
int getLength()The number of component values plus the alpha channel.- Returns:
- the number of component values plus the alpha channel.
-
toNumberArray
Convert the color components to a normalized form and put them in an array.The array does not include the alpha channel (that is, the array length is
getLength()- 1).For RGB colors, the components are in the [0,1] interval.
- Returns:
- the array with the non-alpha normalized color components.
- Throws:
DOMException- INVALID_STATE_ERR if the components cannot be converted to numbers.
-
isInGamut
Is this color inside the given gamut?- Parameters:
colorSpace- the color gamut to check.- Returns:
trueif this color is in the gamut of the given color space.- Throws:
DOMException- NOT_SUPPORTED_ERR if the color space is not supported, INVALID_STATE_ERR if the color components have to be converted to typed values.
-
toColorSpace
Convert this color to the given CSS color space.- Parameters:
colorSpace- the destination color space. The color spaces inColorSpaceare supported, as well as the other valid CSS space names (hslandhwb).- Returns:
- a color converted to the given color space.
- Throws:
DOMException- if the color space is not supported.IllegalStateException- if the color components have to be converted to typed values.
-
toXYZ
Convert this color to the XYZ space using the given reference illuminant.- Parameters:
white- the standard illuminant. If you need a conversion for an illuminant not included in theIlluminantenumeration, please usetoXYZ(double[]).- Returns:
- the color expressed in XYZ coordinates with the given white point.
-
toXYZ
double[] toXYZ(double[] white) Convert this color to the XYZ space using the given reference white.If your white happens to be D65 or D50, please use
toXYZ(Illuminant)instead which is faster.- Parameters:
white- the white point tristimulus value, normalized so theYcomponent is always1.- Returns:
- the color expressed in XYZ coordinates with the given white point.
-
deltaEOK
Compute the difference to the given color, according to ΔEOK.If the delta is inferior to
0.02, it is considered that the two colors are difficult to distinguish.- Parameters:
color- the color to compute the delta from.- Returns:
- the ΔEOK.
-
toMinifiedString
String toMinifiedString()Gives a minified string representation of this color.- Returns:
- a minified serialization.
-
packInValue
CSSColorValue packInValue()Pack this color into a new CSS value.Colors that come from a conversion sometimes aren't packed into a
CSSColorValue, and this method provides a way to create one.- Returns:
- the new CSS value packing this color.
-
clone
CSSColor clone()Clone this color.- Returns:
- a clone of this color.
-