# 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)

*** ** * ** ***


```
public final class ColorUtils
```

<br />

*** ** * ** ***

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

## Summary

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

## Public methods

### HSLToColor

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

```
public static @ColorInt int HSLToColor(@NonNull float[] hsl)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html float[] hsl` | 3-element array which holds the input HSL components |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int` | the resulting RGB color |

### LABToColor

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

```
public static @ColorInt int LABToColor(
    @FloatRange(from = 0.0, to = 100) double l,
    @FloatRange(from = "-128", to = 127) double a,
    @FloatRange(from = "-128", to = 127) double b
)
```

Converts a color from CIE Lab to its RGB representation.

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int` | int containing the RGB representation |

### LABToXYZ

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

```
public static void LABToXYZ(
    @FloatRange(from = 0.0, to = 100) double l,
    @FloatRange(from = "-128", to = 127) double a,
    @FloatRange(from = "-128", to = 127) double b,
    @NonNull double[] outXyz
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 100) double l` | L component value \[0, 100\] |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = "-128", to = 127) double a` | A component value \[-128, 127) |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = "-128", to = 127) double b` | B component value \[-128, 127) |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html double[] outXyz` | 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)

```
public static @ColorInt int M3HCTToColor(
    @FloatRange(from = 0.0, to = 360, toInclusive = false) float hue,
    @FloatRange(from = 0.0, to = Double.POSITIVE_INFINITY, toInclusive = false) float chroma,
    @FloatRange(from = 0.0, to = 100) float tone
)
```

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

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

```
public static void RGBToHSL(
    @IntRange(from = 0, to = 255) int r,
    @IntRange(from = 0, to = 255) int g,
    @IntRange(from = 0, to = 255) int b,
    @NonNull float[] outHsl
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int r` | red component value \[0, 255\] |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int g` | green component value \[0, 255\] |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int b` | blue component value \[0, 255\] |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html float[] outHsl` | 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)

```
public static void RGBToLAB(
    @IntRange(from = 0, to = 255) int r,
    @IntRange(from = 0, to = 255) int g,
    @IntRange(from = 0, to = 255) int b,
    @NonNull double[] outLab
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int r` | red component value \[0, 255\] |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int g` | green component value \[0, 255\] |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int b` | blue component value \[0, 255\] |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html double[] outLab` | 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)

```
public static void RGBToXYZ(
    @IntRange(from = 0, to = 255) int r,
    @IntRange(from = 0, to = 255) int g,
    @IntRange(from = 0, to = 255) int b,
    @NonNull double[] outXyz
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int r` | red component value \[0, 255\] |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int g` | green component value \[0, 255\] |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int b` | blue component value \[0, 255\] |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html double[] outXyz` | 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)

```
public static @ColorInt int XYZToColor(
    @FloatRange(from = 0.0, to = 95.047) double x,
    @FloatRange(from = 0.0, to = 100.0) double y,
    @FloatRange(from = 0.0, to = 108.883) double z
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 95.047) double x` | X component value \[0, 95.047) |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 100.0) double y` | Y component value \[0, 100) |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 108.883) double z` | Z component value \[0, 108.883) |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int` | int containing the RGB representation |

### XYZToLAB

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

```
public static void XYZToLAB(
    @FloatRange(from = 0.0, to = 95.047) double x,
    @FloatRange(from = 0.0, to = 100.0) double y,
    @FloatRange(from = 0.0, to = 108.883) double z,
    @NonNull double[] outLab
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 95.047) double x` | X component value \[0, 95.047) |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 100.0) double y` | Y component value \[0, 100) |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 108.883) double z` | Z component value \[0, 108.883) |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html double[] outLab` | 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)

```
public static @ColorInt int blendARGB(
    @ColorInt int color1,
    @ColorInt int color2,
    @FloatRange(from = 0.0, to = 1.0) float ratio
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int color1` | the first ARGB color |
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int color2` | the second ARGB color |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float ratio` | the blend ratio of `color1` to `color2` |

### blendHSL

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

```
public static void blendHSL(
    @NonNull float[] hsl1,
    @NonNull float[] hsl2,
    @FloatRange(from = 0.0, to = 1.0) float ratio,
    @NonNull float[] outResult
)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html float[] hsl1` | 3-element array which holds the first HSL color |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html float[] hsl2` | 3-element array which holds the second HSL color |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float ratio` | the blend ratio of `hsl1` to `hsl2` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html float[] outResult` | 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)

```
public static void blendLAB(
    @NonNull double[] lab1,
    @NonNull double[] lab2,
    @FloatRange(from = 0.0, to = 1.0) double ratio,
    @NonNull double[] outResult
)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html double[] lab1` | 3-element array which holds the first LAB color |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html double[] lab2` | 3-element array which holds the second LAB color |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) double ratio` | the blend ratio of `lab1` to `lab2` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html double[] outResult` | 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)

```
public static double calculateContrast(@ColorInt int foreground, @ColorInt int background)
```

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)

```
public static @FloatRange(from = 0.0, to = 1.0) double calculateLuminance(@ColorInt int color)
```

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)

```
public static int calculateMinimumAlpha(
    @ColorInt int foreground,
    @ColorInt int background,
    float minContrastRatio
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int foreground` | the foreground color |
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int background` | the opaque background color |
| `float minContrastRatio` | the minimum contrast ratio |

| Returns |
|---|---|
| `int` | 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)

```
public static void colorToHSL(@ColorInt int color, @NonNull float[] outHsl)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int color` | the ARGB color to convert. The alpha component is ignored |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html float[] outHsl` | 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)

```
public static void colorToLAB(@ColorInt int color, @NonNull double[] outLab)
```

Convert the ARGB color to its CIE Lab representative components.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int color` | the ARGB color to convert. The alpha component is ignored |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html double[] outLab` | 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)

```
public static void colorToM3HCT(@ColorInt int color, @Size(value = 3) @NonNull float[] outM3HCT)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int color` | is the ARGB color value we use to get its respective M3HCT values. |
| `@https://developer.android.com/reference/androidx/annotation/Size(value = 3) @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html float[] outM3HCT` | 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)

```
public static void colorToXYZ(@ColorInt int color, @NonNull double[] outXyz)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int color` | the ARGB color to convert. The alpha component is ignored |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html double[] outXyz` | 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)
public static @NonNull Color compositeColors(@NonNull Color foreground, @NonNull Color background)
```

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:

```
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)

```
public static int compositeColors(@ColorInt int foreground, @ColorInt int background)
```

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)

```
public static double distanceEuclidean(@NonNull double[] labX, @NonNull double[] labY)
```

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)

```
public static @ColorInt int setAlphaComponent(@ColorInt int color, @IntRange(from = 0, to = 255) int alpha)
```

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