RGBInt

value class RGBInt(val argb: UInt) : Color

A representation of RGB that packs color components into a single integer.

This is an inline value class stores the color as a packed argb integer, such as those returned from android.graphics.Color.argb or java.awt.image.BufferedImage.getRGB.

This color always uses the sRGB color space.

You can destructure this class into r, g, b, and a components: val (r, g, b, a) = RGBInt(0xaa112233u)

ComponentDescriptionRange
rred[0, 255]
ggreen[0, 255]
bblue[0, 255]

Constructors

Link copied to clipboard
constructor(r: UByte, g: UByte, b: UByte, alpha: UByte = 0xff.toUByte())
constructor(r: Int, g: Int, b: Int, alpha: Int = 255)
constructor(r: Float, g: Float, b: Float, alpha: Float = 1.0f)

Construct an RGBInt instance from Float value in the range [0, 1]

constructor(argb: UInt)

Types

Link copied to clipboard

Default constructors for RGBInt.

Properties

Link copied to clipboard
val a: UByte

The alpha component scaled to [0, 255]

Link copied to clipboard
open override val alpha: Float

The opacity of this color, in the range [0, 1], or NaN if the opacity is unspecified

Link copied to clipboard
val argb: UInt
Link copied to clipboard
val b: UByte

The blue component, in the range [0, 255]

Link copied to clipboard

The blue component as a Float in the range [0, 1]

Link copied to clipboard
val g: UByte

The green component, in the range [0, 255]

Link copied to clipboard

The green component as a Float in the range [0, 1]

Link copied to clipboard
val r: UByte

The red component, in the range [0, 255]

Link copied to clipboard

The red component as a Float in the range [0, 1]

Link copied to clipboard
open override val space: ColorSpace<RGBInt>

The color space describing this color

Functions

Link copied to clipboard
open override fun clamp(): RGBInt

Return a copy of this color with all component values in their reference range.

Link copied to clipboard
operator fun component1(): UByte
Link copied to clipboard
operator fun component2(): UByte
Link copied to clipboard
operator fun component3(): UByte
Link copied to clipboard
operator fun component4(): UByte
Link copied to clipboard
fun <T : Color> Color.convertTo(space: ColorSpace<T>): T

Convert this color to a given space.

Link copied to clipboard

Calculate the difference ΔEab between this color and other using the CIE 2000 recommendation.

Link copied to clipboard

Calculate the difference ΔEab between this color and other using the CIE 1976 recommendation.

Link copied to clipboard
fun Color.differenceCIE94(other: Color, textiles: Boolean = false): Float

Calculate the difference ΔEab between this color and other using the CIE 1994 recommendation.

Link copied to clipboard
fun Color.differenceCMC(other: Color, l: Float = 2.0f, c: Float = 1.0f): Float

Calculate the difference ΔEcmc between this color and other using the Colour Measurement Committee recommendation.

Link copied to clipboard

Calculate the difference ΔEz between this color and other using the JzAzBz color space.

Link copied to clipboard
fun Color.firstWithContrast(vararg colors: Color, targetContrast: Float): Color

Return the first color with a contrast ratio exceeding the targetContrast against this color. If no color meets the target, black or white will be returned, whichever has the most contrast.

Link copied to clipboard
fun Color.firstWithContrastOrNull(vararg colors: Color, targetContrast: Float): Color?

Return the first color with a contrast ratio greater or equal to the targetContrast against this color, or null if no color meets the target.

Link copied to clipboard
fun Color.formatCssString(hueUnit: AngleUnit = AngleUnit.AUTO, renderAlpha: RenderCondition = RenderCondition.AUTO, unitsPercent: Boolean = false, alphaPercent: Boolean = false, legacyName: Boolean = false, legacyFormat: Boolean = false, customColorSpaces: Map<String, ColorSpace<*>> = emptyMap()): String

Render this color in CSS functional notation.

Link copied to clipboard
fun Color.formatCssStringOrNull(hueUnit: AngleUnit = AngleUnit.AUTO, renderAlpha: RenderCondition = RenderCondition.AUTO, unitsPercent: Boolean = false, alphaPercent: Boolean = false, legacyName: Boolean = false, legacyFormat: Boolean = false, customColorSpaces: Map<String, ColorSpace<*>> = emptyMap()): String?

Render this color in CSS functional notation if this color space is defined in the CSS standard, or return null if this color is in another color space.

Link copied to clipboard

Return true if all channels of this color, when converted to sRGB, lie in the range [0, 1]

Link copied to clipboard
fun Color.mostContrasting(vararg colors: Color): Color

Return the color with the highest contrast ratio against this color.

Link copied to clipboard
open fun toAnsi16(): Ansi16

Convert this color to a 16-color ANSI code

Link copied to clipboard
open fun toAnsi256(): Ansi256

Convert this color to a 256-color ANSI code

Link copied to clipboard
open override fun toArray(): FloatArray

Create a FloatArray containing all components of this color, with the alpha as the last component

Link copied to clipboard
open fun toCMYK(): CMYK

Convert this color to device-independent CMYK

Link copied to clipboard
fun toHex(withNumberSign: Boolean = true, renderAlpha: RenderCondition = AUTO): String

Convert this color to an RGB hex string.

Link copied to clipboard
open fun toHPLuv(): HPLuv

Convert this color to HPLuv

Link copied to clipboard
open fun toHSL(): HSL

Convert this color to HSL

Link copied to clipboard
open fun toHSLuv(): HSLuv

Convert this color to HSLuv

Link copied to clipboard
open fun toHSV(): HSV

Convert this color to HSV

Link copied to clipboard
open fun toHWB(): HWB

Convert this color to HWB

Link copied to clipboard
open fun toICtCp(): ICtCp

Convert this color to ICtCp

Link copied to clipboard
open fun toJzAzBz(): JzAzBz

Convert this color to JzAzBz

Link copied to clipboard
open fun toJzCzHz(): JzCzHz

Convert this color to JzCzHz

Link copied to clipboard
open fun toLAB(): LAB

Convert this color to CIE LAB

Link copied to clipboard
open fun toLCHab(): LCHab

Convert this color to CIE LCh(ab)

Link copied to clipboard
open fun toLCHuv(): LCHuv

Convert this color to CIE LCh(uv)

Link copied to clipboard
open fun toLUV(): LUV

Convert this color to CIE LUV

Link copied to clipboard
open fun toOklab(): Oklab

Convert this color to Oklab

Link copied to clipboard
open fun toOklch(): Oklch

Convert this color to Oklch

Link copied to clipboard
fun toRGBA(): UInt

Convert this color to an integer packed in RGBA order.

Link copied to clipboard
open override fun toSRGB(): RGB

Convert this color to sRGB

Link copied to clipboard
open fun toXYZ(): XYZ

Convert this color to CIE XYZ

Link copied to clipboard

Calculate the contrast ration of this color with other according to the Web Content Accessibility Guidelines

Link copied to clipboard

Calculate the relative luminance of this color according to the Web Content Accessibility Guidelines