ColorUtils

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

Functions

Link copied to clipboard
open fun blendARGB(@ColorInt color1: Int, @ColorInt color2: Int, @FloatRange(from = 0.0, to = 1.0) ratio: Float): Int
Blend between two ARGB colors using the given ratio.
Link copied to clipboard
open fun blendHSL(hsl1: @NonNull Array<Float>, hsl2: @NonNull Array<Float>, @FloatRange(from = 0.0, to = 1.0) ratio: Float, outResult: @NonNull Array<Float>)
Blend between hsl1 and hsl2 using the given ratio.
Link copied to clipboard
open fun blendLAB(lab1: @NonNull Array<Double>, lab2: @NonNull Array<Double>, @FloatRange(from = 0.0, to = 1.0) ratio: Double, outResult: @NonNull Array<Double>)
Blend between two CIE-LAB colors using the given ratio.
Link copied to clipboard
open fun calculateContrast(@ColorInt foreground: Int, @ColorInt background: Int): Double
Returns the contrast ratio between foreground and background.
Link copied to clipboard
@FloatRange(from = 0.0, to = 1.0)
open fun calculateLuminance(@ColorInt color: Int): Double
Returns the luminance of a color as a float between 0.0 and 1.0.
Link copied to clipboard
open fun calculateMinimumAlpha(@ColorInt foreground: Int, @ColorInt background: 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.
Link copied to clipboard
open fun colorToHSL(@ColorInt color: Int, outHsl: @NonNull Array<Float>)
Convert the ARGB color to its HSL (hue-saturation-lightness) components.
Link copied to clipboard
open fun colorToLAB(@ColorInt color: Int, outLab: @NonNull Array<Double>)
Convert the ARGB color to its CIE Lab representative components.
Link copied to clipboard
open fun colorToM3HCT(@ColorInt color: Int, @Size(value = 3) outM3HCT: @NonNull Array<Float>)
Generate a M3HCT color from an ARGB color.
Link copied to clipboard
open fun colorToXYZ(@ColorInt color: Int, outXyz: @NonNull Array<Double>)
Convert the ARGB color to its CIE XYZ representative components.
Link copied to clipboard
@RequiresApi(value = 26)
@NonNull
open fun compositeColors(@NonNull foreground: @NonNull Color, @NonNull background: @NonNull Color): @NonNull Color
Composites two translucent colors together.
open fun compositeColors(@ColorInt foreground: Int, @ColorInt background: Int): Int
Composite two potentially translucent colors over each other and returns the result.
Link copied to clipboard
open fun distanceEuclidean(labX: @NonNull Array<Double>, labY: @NonNull Array<Double>): Double
Returns the euclidean distance between two LAB colors.
Link copied to clipboard
open fun HSLToColor(hsl: @NonNull Array<Float>): Int
Convert HSL (hue-saturation-lightness) components to a RGB color.
Link copied to clipboard
open fun LABToColor(@FloatRange(from = 0.0, to = 100) l: Double, @FloatRange(from = "-128", to = 127) a: Double, @FloatRange(from = "-128", to = 127) b: Double): Int
Converts a color from CIE Lab to its RGB representation.
Link copied to clipboard
open fun LABToXYZ(@FloatRange(from = 0.0, to = 100) l: Double, @FloatRange(from = "-128", to = 127) a: Double, @FloatRange(from = "-128", to = 127) b: Double, outXyz: @NonNull Array<Double>)
Converts a color from CIE Lab to CIE XYZ representation.
Link copied to clipboard
open fun M3HCTToColor(@FloatRange(from = 0.0, to = 360, toInclusive = false) hue: Float, @FloatRange(from = 0.0, to = Double.POSITIVE_INFINITY, toInclusive = false) chroma: Float, @FloatRange(from = 0.0, to = 100) tone: Float): Int
Generate an ARGB color using M3HCT color parameters.
Link copied to clipboard
open fun RGBToHSL(@IntRange(from = 0, to = 255) r: Int, @IntRange(from = 0, to = 255) g: Int, @IntRange(from = 0, to = 255) b: Int, outHsl: @NonNull Array<Float>)
Convert RGB components to HSL (hue-saturation-lightness).
Link copied to clipboard
open fun RGBToLAB(@IntRange(from = 0, to = 255) r: Int, @IntRange(from = 0, to = 255) g: Int, @IntRange(from = 0, to = 255) b: Int, outLab: @NonNull Array<Double>)
Convert RGB components to its CIE Lab representative components.
Link copied to clipboard
open fun RGBToXYZ(@IntRange(from = 0, to = 255) r: Int, @IntRange(from = 0, to = 255) g: Int, @IntRange(from = 0, to = 255) b: Int, outXyz: @NonNull Array<Double>)
Convert RGB components to its CIE XYZ representative components.
Link copied to clipboard
open fun setAlphaComponent(@ColorInt color: Int, @IntRange(from = 0, to = 255) alpha: Int): Int
Set the alpha component of color to be alpha.
Link copied to clipboard
open fun XYZToColor(@FloatRange(from = 0.0, to = 95.047) x: Double, @FloatRange(from = 0.0, to = 100.0) y: Double, @FloatRange(from = 0.0, to = 108.883) z: Double): Int
Converts a color from CIE XYZ to its RGB representation.
Link copied to clipboard
open fun XYZToLAB(@FloatRange(from = 0.0, to = 95.047) x: Double, @FloatRange(from = 0.0, to = 100.0) y: Double, @FloatRange(from = 0.0, to = 108.883) z: Double, outLab: @NonNull Array<Double>)
Converts a color from CIE XYZ to CIE Lab representation.