ColorSpace
abstract class ColorSpace
kotlin.Any | |
↳ | androidx.compose.ui.graphics.colorspace.ColorSpace |
A ColorSpace is used to identify a specific organization of colors. Each color space is characterized by a color model that defines how a color value is represented (for instance the RGB color model defines a color value as a triplet of numbers).
Each component of a color must fall within a valid range, specific to each
color space, defined by getMinValue and getMaxValue
This range is commonly [0..1]
. While it is recommended to use values in the
valid range, a color space always clamps input and output values when performing
operations such as converting to a different color space.
Using color spaces
This implementation provides a pre-defined set of common color spaces described in the ColorSpaces object.
The documentation of ColorSpaces provides a detailed description of the various characteristics of each available color space.
Color space conversions
To allow conversion between color spaces, this implementation uses the CIE XYZ profile connection space (PCS). Color values can be converted to and from this PCS using toXyz and fromXyz.
For color space with a non-RGB color model, the white point of the PCS must be the CIE standard illuminant D50. RGB color spaces use their native white point (D65 for sRGB for instance and must undergo chromatic adaptation as necessary.
Since the white point of the PCS is not defined for RGB color space, it is highly recommended to use the connect method to perform conversions between color spaces. A color space can be manually adapted to a specific white point using adapt. Please refer to the documentation of RGB color spaces for more information. Several common CIE standard illuminants are provided in this class as reference (see Illuminant.D65 or Illuminant.D50 for instance).
Here is an example of how to convert from a color space to another:
// Convert from DCI-P3 to Rec.2020 val connector = ColorSpaces.DciP3.connect(ColorSpaces.BT2020) val bt2020Values = connector.transform(p3r, p3g, p3b);
You can easily convert to sRGB by omitting the color space parameter:
// Convert from DCI-P3 to sRGB val connector = ColorSpaces.DciP3.connect() val sRGBValues = connector.transform(p3r, p3g, p3b);
Conversions also work between color spaces with different color models:
// Convert from CIE L*a*b* (color model Lab) to Rec.709 (color model RGB) val connector = ColorSpaces.CieLab.connect(ColorSpaces.Bt709)
Color spaces and multi-threading
Color spaces and other related classes (Connector for instance) are immutable and stateless. They can be safely used from multiple concurrent threads.
Summary
Public constructors | |
---|---|
<init>(name: String, model: ColorModel) |
Public methods | |
---|---|
open Boolean | |
FloatArray |
Converts tristimulus values from the CIE XYZ space to this color space's color model. |
abstract FloatArray |
fromXyz(v: FloatArray) Converts tristimulus values from the CIE XYZ space to this color space's color model. |
abstract Float |
getMaxValue(component: Int) Returns the maximum valid value for the specified component of this color space's color model. |
abstract Float |
getMinValue(component: Int) Returns the minimum valid value for the specified component of this color space's color model. |
open Int |
hashCode() |
open String |
toString() Returns a string representation of the object. |
FloatArray |
Converts a color value from this color space's model to tristimulus CIE XYZ values. |
abstract FloatArray |
toXyz(v: FloatArray) Converts a color value from this color space's model to tristimulus CIE XYZ values. |
Extension functions | ||||
---|---|---|---|---|
From androidx.compose.ui.graphics.colorspace
|
Properties | |
---|---|
Int |
Returns the number of components that form a color value according to this color space's color model. |
open Boolean |
Indicates whether this color space is the sRGB color space or equivalent to the sRGB color space. |
abstract Boolean |
Returns whether this color space is a wide-gamut color space. |
ColorModel |
The color model of this color space. |
String |
Returns the name of this color space. |
Public constructors
<init>
ColorSpace(
name: String,
model: ColorModel)
Public methods
equals
open fun equals(