# ColorUtils

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/ColorUtils.java+class:androidx.core.graphics.ColorUtils) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

<br />

```
class ColorUtils
```

<br />

*** ** * ** ***

A set of color-related utility methods, building upon those available in `Color`.

## Summary

| ### Public functions |
|---|---|
| `java-static @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#HSLToColor(float[])(hsl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>)` Convert HSL (hue-saturation-lightness) components to a RGB color. |
| `java-static @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#LABToColor(double,double,double)( l: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 100) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, a: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = "-128", to = 127) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, b: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = "-128", to = 127) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html )` Converts a color from CIE Lab to its RGB representation. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#LABToXYZ(double,double,double,double[])( l: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 100) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, a: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = "-128", to = 127) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, b: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = "-128", to = 127) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, outXyz: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html> )` Converts a color from CIE Lab to CIE XYZ representation. |
| `java-static @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#M3HCTToColor(float,float,float)( hue: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 360, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, chroma: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = https://developer.android.com/reference/java/lang/Double.html#POSITIVE_INFINITY, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, tone: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 100) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Generate an ARGB color using M3HCT color parameters. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#RGBToHSL(int,int,int,float[])( r: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, g: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, b: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outHsl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> )` Convert RGB components to HSL (hue-saturation-lightness). |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#RGBToLAB(int,int,int,double[])( r: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, g: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, b: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outLab: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html> )` Convert RGB components to its CIE Lab representative components. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#RGBToXYZ(int,int,int,double[])( r: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, g: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, b: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outXyz: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html> )` Convert RGB components to its CIE XYZ representative components. |
| `java-static @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#XYZToColor(double,double,double)( x: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 95.047) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, y: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 100.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, z: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 108.883) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html )` Converts a color from CIE XYZ to its RGB representation. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#XYZToLAB(double,double,double,double[])( x: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 95.047) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, y: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 100.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, z: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 108.883) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, outLab: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html> )` Converts a color from CIE XYZ to CIE Lab representation. |
| `java-static @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#blendARGB(int,int,float)( color1: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, color2: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, ratio: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Blend between two ARGB colors using the given ratio. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#blendHSL(float[],float[],float,float[])( hsl1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>, hsl2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>, ratio: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, outResult: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> )` Blend between `hsl1` and `hsl2` using the given ratio. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#blendLAB(double[],double[],double,double[])( lab1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>, lab2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>, ratio: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html, outResult: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html> )` Blend between two CIE-LAB colors using the given ratio. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#calculateContrast(int,int)(foreground: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, background: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the contrast ratio between `foreground` and `background`. |
| `java-static @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#calculateLuminance(int)(color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the luminance of a color as a float between `0.0` and `1.0`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#calculateMinimumAlpha(int,int,float)( foreground: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, background: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, minContrastRatio: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Calculates the minimum alpha value which can be applied to `foreground` so that would have a contrast value of at least `minContrastRatio` when compared to `background`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#colorToHSL(int,float[])(color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outHsl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>)` Convert the ARGB color to its HSL (hue-saturation-lightness) components. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#colorToLAB(int,double[])(color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outLab: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>)` Convert the ARGB color to its CIE Lab representative components. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#colorToM3HCT(int,float[])( color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outM3HCT: @https://developer.android.com/reference/kotlin/androidx/annotation/Size(value = 3) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> )` Generate a M3HCT color from an ARGB color. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#colorToXYZ(int,double[])(color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outXyz: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>)` Convert the ARGB color to its CIE XYZ representative components. |
| `java-static https://developer.android.com/reference/android/graphics/Color.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#compositeColors(android.graphics.Color,android.graphics.Color)(foreground: https://developer.android.com/reference/android/graphics/Color.html, background: https://developer.android.com/reference/android/graphics/Color.html)` Composites two translucent colors together. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#compositeColors(int,int)(foreground: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, background: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Composite two potentially translucent colors over each other and returns the result. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#distanceEuclidean(double[],double[])(labX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>, labY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>)` Returns the euclidean distance between two LAB colors. |
| `java-static @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/graphics/ColorUtils#setAlphaComponent(int,int)(color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, alpha: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Set the alpha component of `color` to be `alpha`. |

## Public functions

### HSLToColor

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun HSLToColor(hsl: FloatArray<Float>): @ColorInt Int
```

Convert HSL (hue-saturation-lightness) components to a RGB color.

- hsl\[0\] is Hue \[0, 360)
- hsl\[1\] is Saturation \[0, 1\]
- hsl\[2\] is Lightness \[0, 1\]

If hsv values are out of range, they are pinned.

| Parameters |
|---|---|
| `hsl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | 3-element array which holds the input HSL components |

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the resulting RGB color |

### LABToColor

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun LABToColor(
    l: @FloatRange(from = 0.0, to = 100) Double,
    a: @FloatRange(from = "-128", to = 127) Double,
    b: @FloatRange(from = "-128", to = 127) Double
): @ColorInt Int
```

Converts a color from CIE Lab to its RGB representation.

| Parameters |
|---|---|
| `l: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 100) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | L component value \[0, 100\] |
| `a: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = "-128", to = 127) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | A component value \[-128, 127\] |
| `b: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = "-128", to = 127) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | B component value \[-128, 127\] |

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | int containing the RGB representation |

### LABToXYZ

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun LABToXYZ(
    l: @FloatRange(from = 0.0, to = 100) Double,
    a: @FloatRange(from = "-128", to = 127) Double,
    b: @FloatRange(from = "-128", to = 127) Double,
    outXyz: DoubleArray<Double>
): Unit
```

Converts a color from CIE Lab to CIE XYZ representation.

The resulting XYZ representation will use the D65 illuminant and the CIE 2° Standard Observer (1931).

- outXyz\[0\] is X \[0, 95.047)
- outXyz\[1\] is Y \[0, 100)
- outXyz\[2\] is Z \[0, 108.883)

| Parameters |
|---|---|
| `l: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 100) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | L component value \[0, 100\] |
| `a: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = "-128", to = 127) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | A component value \[-128, 127) |
| `b: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = "-128", to = 127) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | B component value \[-128, 127) |
| `outXyz: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>` | 3-element array which holds the resulting XYZ components |

### M3HCTToColor

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

```
java-static fun M3HCTToColor(
    hue: @FloatRange(from = 0.0, to = 360, toInclusive = false) Float,
    chroma: @FloatRange(from = 0.0, to = Double.POSITIVE_INFINITY, toInclusive = false) Float,
    tone: @FloatRange(from = 0.0, to = 100) Float
): @ColorInt Int
```

Generate an ARGB color using M3HCT color parameters. HCT color space is a new color space proposed in Material Design 3

| Parameters |
|---|---|
| `hue: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 360, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | is Hue in M3HCT \[0, 360); invalid values are corrected. |
| `chroma: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = https://developer.android.com/reference/java/lang/Double.html#POSITIVE_INFINITY, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | is Chroma in M3HCT \[0, ?); Chroma may decrease because chroma has a different maximum for any given hue and tone. |
| `tone: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 100) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | is Tone in M3HCT \[0, 100\]; invalid values are corrected. |

| See also |
|---|---|
| `https://developer.android.com/design/ui/mobile/guides/styles/color#about-color-spaces` | [About Color Spaces](https://developer.android.com/design/ui/mobile/guides/styles/color#about-color-spaces) |

### RGBToHSL

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun RGBToHSL(
    r: @IntRange(from = 0, to = 255) Int,
    g: @IntRange(from = 0, to = 255) Int,
    b: @IntRange(from = 0, to = 255) Int,
    outHsl: FloatArray<Float>
): Unit
```

Convert RGB components to HSL (hue-saturation-lightness).

- outHsl\[0\] is Hue \[0, 360)
- outHsl\[1\] is Saturation \[0, 1\]
- outHsl\[2\] is Lightness \[0, 1\]

| Parameters |
|---|---|
| `r: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | red component value \[0, 255\] |
| `g: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | green component value \[0, 255\] |
| `b: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | blue component value \[0, 255\] |
| `outHsl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | 3-element array which holds the resulting HSL components |

### RGBToLAB

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun RGBToLAB(
    r: @IntRange(from = 0, to = 255) Int,
    g: @IntRange(from = 0, to = 255) Int,
    b: @IntRange(from = 0, to = 255) Int,
    outLab: DoubleArray<Double>
): Unit
```

Convert RGB components to its CIE Lab representative components.

- outLab\[0\] is L \[0, 100\]
- outLab\[1\] is a \[-128, 127)
- outLab\[2\] is b \[-128, 127)

| Parameters |
|---|---|
| `r: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | red component value \[0, 255\] |
| `g: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | green component value \[0, 255\] |
| `b: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | blue component value \[0, 255\] |
| `outLab: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>` | 3-element array which holds the resulting LAB components |

### RGBToXYZ

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun RGBToXYZ(
    r: @IntRange(from = 0, to = 255) Int,
    g: @IntRange(from = 0, to = 255) Int,
    b: @IntRange(from = 0, to = 255) Int,
    outXyz: DoubleArray<Double>
): Unit
```

Convert RGB components to its CIE XYZ representative components.

The resulting XYZ representation will use the D65 illuminant and the CIE 2° Standard Observer (1931).

- outXyz\[0\] is X \[0, 95.047)
- outXyz\[1\] is Y \[0, 100)
- outXyz\[2\] is Z \[0, 108.883)

| Parameters |
|---|---|
| `r: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | red component value \[0, 255\] |
| `g: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | green component value \[0, 255\] |
| `b: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | blue component value \[0, 255\] |
| `outXyz: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>` | 3-element array which holds the resulting XYZ components |

### XYZToColor

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun XYZToColor(
    x: @FloatRange(from = 0.0, to = 95.047) Double,
    y: @FloatRange(from = 0.0, to = 100.0) Double,
    z: @FloatRange(from = 0.0, to = 108.883) Double
): @ColorInt Int
```

Converts a color from CIE XYZ to its RGB representation.

This method expects the XYZ representation to use the D65 illuminant and the CIE 2° Standard Observer (1931).

| Parameters |
|---|---|
| `x: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 95.047) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | X component value \[0, 95.047) |
| `y: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 100.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | Y component value \[0, 100) |
| `z: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 108.883) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | Z component value \[0, 108.883) |

| Returns |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | int containing the RGB representation |

### XYZToLAB

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun XYZToLAB(
    x: @FloatRange(from = 0.0, to = 95.047) Double,
    y: @FloatRange(from = 0.0, to = 100.0) Double,
    z: @FloatRange(from = 0.0, to = 108.883) Double,
    outLab: DoubleArray<Double>
): Unit
```

Converts a color from CIE XYZ to CIE Lab representation.

This method expects the XYZ representation to use the D65 illuminant and the CIE 2° Standard Observer (1931).

- outLab\[0\] is L \[0, 100\]
- outLab\[1\] is a \[-128, 127)
- outLab\[2\] is b \[-128, 127)

| Parameters |
|---|---|
| `x: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 95.047) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | X component value \[0, 95.047) |
| `y: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 100.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | Y component value \[0, 100) |
| `z: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 108.883) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | Z component value \[0, 108.883) |
| `outLab: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>` | 3-element array which holds the resulting Lab components |

### blendARGB

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun blendARGB(
    color1: @ColorInt Int,
    color2: @ColorInt Int,
    ratio: @FloatRange(from = 0.0, to = 1.0) Float
): @ColorInt Int
```

Blend between two ARGB colors using the given ratio.

A blend ratio of 0.0 will result in `color1`, 0.5 will give an even blend, 1.0 will result in `color2`.

| Parameters |
|---|---|
| `color1: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the first ARGB color |
| `color2: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the second ARGB color |
| `ratio: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the blend ratio of `color1` to `color2` |

### blendHSL

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun blendHSL(
    hsl1: FloatArray<Float>,
    hsl2: FloatArray<Float>,
    ratio: @FloatRange(from = 0.0, to = 1.0) Float,
    outResult: FloatArray<Float>
): Unit
```

Blend between `hsl1` and `hsl2` using the given ratio. This will interpolate the hue using the shortest angle.

A blend ratio of 0.0 will result in `hsl1`, 0.5 will give an even blend, 1.0 will result in `hsl2`.

| Parameters |
|---|---|
| `hsl1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | 3-element array which holds the first HSL color |
| `hsl2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | 3-element array which holds the second HSL color |
| `ratio: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the blend ratio of `hsl1` to `hsl2` |
| `outResult: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | 3-element array which holds the resulting HSL components |

### blendLAB

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun blendLAB(
    lab1: DoubleArray<Double>,
    lab2: DoubleArray<Double>,
    ratio: @FloatRange(from = 0.0, to = 1.0) Double,
    outResult: DoubleArray<Double>
): Unit
```

Blend between two CIE-LAB colors using the given ratio.

A blend ratio of 0.0 will result in `lab1`, 0.5 will give an even blend, 1.0 will result in `lab2`.

| Parameters |
|---|---|
| `lab1: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>` | 3-element array which holds the first LAB color |
| `lab2: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>` | 3-element array which holds the second LAB color |
| `ratio: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | the blend ratio of `lab1` to `lab2` |
| `outResult: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>` | 3-element array which holds the resulting LAB components |

### calculateContrast

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun calculateContrast(foreground: @ColorInt Int, background: @ColorInt Int): Double
```

Returns the contrast ratio between `foreground` and `background`. `background` must be opaque.

Formula defined [here](http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef).

### calculateLuminance

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun calculateLuminance(color: @ColorInt Int): @FloatRange(from = 0.0, to = 1.0) Double
```

Returns the luminance of a color as a float between `0.0` and `1.0`.

Defined as the Y component in the XYZ representation of `color`.

### calculateMinimumAlpha

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun calculateMinimumAlpha(
    foreground: @ColorInt Int,
    background: @ColorInt Int,
    minContrastRatio: Float
): Int
```

Calculates the minimum alpha value which can be applied to `foreground` so that would have a contrast value of at least `minContrastRatio` when compared to `background`.

| Parameters |
|---|---|
| `foreground: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the foreground color |
| `background: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the opaque background color |
| `minContrastRatio: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the minimum contrast ratio |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the alpha value in the range \[0, 255\] or -1 if no value could be calculated |

### colorToHSL

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun colorToHSL(color: @ColorInt Int, outHsl: FloatArray<Float>): Unit
```

Convert the ARGB color to its HSL (hue-saturation-lightness) components.

- outHsl\[0\] is Hue \[0, 360)
- outHsl\[1\] is Saturation \[0, 1\]
- outHsl\[2\] is Lightness \[0, 1\]

| Parameters |
|---|---|
| `color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the ARGB color to convert. The alpha component is ignored |
| `outHsl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | 3-element array which holds the resulting HSL components |

### colorToLAB

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun colorToLAB(color: @ColorInt Int, outLab: DoubleArray<Double>): Unit
```

Convert the ARGB color to its CIE Lab representative components.

| Parameters |
|---|---|
| `color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the ARGB color to convert. The alpha component is ignored |
| `outLab: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>` | 3-element array which holds the resulting LAB components |

### colorToM3HCT

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

```
java-static fun colorToM3HCT(
    color: @ColorInt Int,
    outM3HCT: @Size(value = 3) FloatArray<Float>
): Unit
```

Generate a M3HCT color from an ARGB color. HCT color space is a new color space proposed in Material Design 3

| Parameters |
|---|---|
| `color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | is the ARGB color value we use to get its respective M3HCT values. |
| `outM3HCT: @https://developer.android.com/reference/kotlin/androidx/annotation/Size(value = 3) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | 3-element array which holds the resulting M3HCT components (Hue, Chroma, Tone). |

| See also |
|---|---|
| `https://developer.android.com/design/ui/mobile/guides/styles/color#about-color-spaces` | [About Color Spaces](https://developer.android.com/design/ui/mobile/guides/styles/color#about-color-spaces) - outM3HCT\[0\] is Hue in M3HCT \[0, 360); invalid values are corrected. - outM3HCT\[1\] is Chroma in M3HCT \[0, ?); Chroma may decrease because chroma has a different maximum for any given hue and tone. - outM3HCT\[2\] is Tone in M3HCT \[0, 100\]; invalid values are corrected. |

### colorToXYZ

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun colorToXYZ(color: @ColorInt Int, outXyz: DoubleArray<Double>): Unit
```

Convert the ARGB color to its CIE XYZ representative components.

The resulting XYZ representation will use the D65 illuminant and the CIE 2° Standard Observer (1931).

- outXyz\[0\] is X \[0, 95.047)
- outXyz\[1\] is Y \[0, 100)
- outXyz\[2\] is Z \[0, 108.883)

| Parameters |
|---|---|
| `color: @https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the ARGB color to convert. The alpha component is ignored |
| `outXyz: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html>` | 3-element array which holds the resulting LAB components |

### compositeColors

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
@RequiresApi(value = 26)
java-static fun compositeColors(foreground: Color, background: Color): Color
```

Composites two translucent colors together. More specifically, adds two colors using the `https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html#SRC_OVER` blending mode. The colors must not be pre-multiplied and the result is a non pre-multiplied color.

If the two colors have different color spaces, the foreground color is converted to the color space of the background color.

The following example creates a purple color by blending opaque blue with semi-translucent red:

```kotlin
Color purple = ColorUtils.compositeColors(
        Color.valueOf(1f, 0f, 0f, 0.5f),
        Color.valueOf(0f, 0f, 1f));
```
*Note:* This method requires API 26 or newer.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the `https://developer.android.com/reference/android/graphics/Color.html#getModel()` of the colors do not match |

### compositeColors

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun compositeColors(foreground: @ColorInt Int, background: @ColorInt Int): Int
```

Composite two potentially translucent colors over each other and returns the result.

### distanceEuclidean

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun distanceEuclidean(labX: DoubleArray<Double>, labY: DoubleArray<Double>): Double
```

Returns the euclidean distance between two LAB colors.

### setAlphaComponent

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
java-static fun setAlphaComponent(color: @ColorInt Int, alpha: @IntRange(from = 0, to = 255) Int): @ColorInt Int
```

Set the alpha component of `color` to be `alpha`.