API Reference Color v#0.12.1

Copy Markdown

Modules

Top-level color conversion dispatch.

ANSI SGR (Select Graphic Rendition) colour parsing and encoding.

Raised when Color.ANSI.parse/1 cannot interpret an ANSI SGR escape sequence.

Adobe RGB (1998) color space, using the Lindbloom Adobe working space (primaries from Adobe RGB (1998) specification, D65 reference white) and simple gamma companding with γ = 2.19921875.

Apple RGB color space, using the Lindbloom Apple RGB working space (primaries from the original Apple 13" RGB display, D65 reference white) and simple gamma companding with γ = 1.8.

Behaviour implemented by every color-space struct module in the library.

CSS Compositing and Blending Level 1 blend modes.

CAM16-UCS perceptual color space.

Device CMYK color space. This is the simple "subtractive from sRGB" device CMYK — it does NOT use an ICC profile, so it is not suitable for color-accurate print workflows. For that, pass the sRGB (or AdobeRGB) struct through a real CMS.

CSS Color Module Level 4 / 5 parsing and serialisation.

A tiny calc() expression evaluator for CSS color components.

The 148 named colors defined by CSS Color Module Level 4, mapped to their 8-bit sRGB values.

A small, paren-aware tokenizer for the bodies of CSS color functions (rgb(...), hsl(...), lab(...), color(...), device-cmyk(...), etc).

Chromatic adaptation transforms between reference whites.

Contrast and luminance computations.

Color space conversion functions based on the formulas published by Bruce Lindbloom at http://www.brucelindbloom.com/index.html?Math.html.

Pure math for the Oklab perceptual color space, published by Björn Ottosson in 2020 (https://bottosson.github.io/posts/oklab/).

Encode and decode W3C Design Tokens Community Group color tokens, per the October 2025 draft of the DTCG Color spec.

Raised (or returned) when a Design Tokens (DTCG 2025.10) token cannot be decoded into a Color.* struct.

Color difference (ΔE) metrics between two colors.

Gamut checking and gamut mapping.

Geometric primitives for drawing chromaticity diagrams — the "horseshoe" plots used to visualise gamuts side-by-side.

Renders a chromaticity diagram — the horseshoe, gamut triangles, Planckian locus, and optional palette / seed overlays — as a self-contained SVG string.

HPLuv — the "pastel" sibling of HSLuv.

HSL color space — hue, saturation, lightness.

HSLuv — a perceptually-uniform alternative to HSL, built on CIELUV.

Helpers that compute the sRGB gamut boundary inside CIELUV for HSLuv and HPLuv.

HSV color space — hue, saturation, value.

Color harmony helpers — rotations and named combinations on the hue circle.

Raised when Color.ICC.Profile.load/1 or parse/1 cannot interpret an ICC profile.

Reader for ICC v2 / v4 matrix profiles — the form used by sRGB IEC61966-2.1.icc, Display P3.icc, AdobeRGB1998.icc, Generic Lab Profile.icc, and most camera and scanner profiles.

ICtCp color space (ITU-R BT.2100).

IPT perceptual color space (Ebner & Fairchild, 1998).

Raised when Color.new/1,2 cannot interpret its input as a color.

Raised when one or more channel values fall outside the legal range for a color space, are the wrong numeric type, or contain NaN / infinity.

Raised when a hex color string cannot be parsed.

JzAzBz perceptually-uniform color space for HDR and wide-gamut content, from Safdar, Cui, Kim & Luo (2017), "Perceptually uniform color space for image signals including high dynamic range and wide gamut".

Cylindrical representation of CIE L*a*b*: lightness, chroma, hue.

Cylindrical representation of CIE L*u*v*: lightness, chroma, hue.

Colour conversion for multi-channel addressable LEDs — fixtures with one or more extra white channels alongside R, G, B.

A four-channel RGBW LED pixel — red, green, blue plus one fixed-temperature white channel.

A five-channel RGBWW / RGB+CCT LED pixel — red, green, blue plus a warm white and a cool white channel.

CIE 1976 L*a*b* color space.

CIE 1976 L*u*v* color space.

A physically-based-rendering (PBR) material wrapper around a base colour.

Raised when Color.convert/2 is called with Color.RGB as the target. Linear Color.RGB requires a named working space, supplied via Color.convert/3 or convert/4.

Color interpolation and gradient generation.

Oklab perceptual color space (Björn Ottosson, 2020).

Cylindrical representation of Oklab: lightness, chroma, hue.

Palette generation for design systems and web sites.

A contrast-targeted palette — shades of a seed colour chosen so each stop hits a specific contrast ratio against a fixed background.

A contrast-constrained tonal scale — the hybrid algorithm described by Matt Ström-Awn in Generating colour palettes with math.

Sort a list of colours into a perceptually-ordered sequence.

A complete theme — a coordinated set of five tonal scales — generated from a single seed colour.

A tonal scale — N shades of one hue, from light to dark — generated from a single seed colour.

A web-based visualizer for the palettes produced by Color.Palette.

A tiny helper that runs Color.Palette.Visualizer as a standalone web server for local development.

Raised when a palette cannot be generated — typically because of invalid options (bad stop list, out-of-range anchor, unreachable contrast target, etc.).

Raised when CSS Color Module Level 4 parsing fails. Used by Color.CSS.parse/1, Color.CSS.Tokenizer, and Color.CSS.Calc.

Linear (un-companded) RGB relative to a named working space.

ITU-R BT.2020 / Rec. 2020 color space, using the Rec. 2020 wide-gamut primaries (D65 reference white) and the BT.2020 SDR opto-electronic transfer function at 12-bit precision.

sRGB color space, using the Lindbloom sRGB working space (primaries from IEC 61966-2-1, D65 reference white) and the sRGB companding function.

A sigil for writing color literals in code. Import this module and use ~COLOR to build any supported color.

Spectral power distributions, spectral reflectances, and spectrum → XYZ integration.

Standard CIE color matching functions and illuminant spectral power distributions, tabulated at 5 nm intervals from 380 nm to 780 nm (81 samples).

Correlated colour temperature (CCT) on the Planckian locus.

Authoritative source of illuminant reference white data.

Shared type aliases used across the Color library.

Raised when Color.Blend.blend/3 is called with an unknown blend mode.

Raised when a CSS named-color lookup fails.

Raised when an atom or module passed as a color-space identifier is not recognised.

Raised when Color.Gamut.to_gamut/3 is called with an unknown gamut-mapping method.

Raised when an illuminant atom is not recognised by Color.Tristimulus.

Raised when Color.sort/2 is called with a :by value that is neither a recognised preset atom nor a 1-arity function.

Raised when an RGB working-space identifier or its CSS Color 4 name is not recognised.

Raised when Color.convert/2,3,4 is called with a target module that is not part of the supported color-space hub.

CIE 1931 XYZ tristimulus color space.

CIE xyY color space — chromaticity coordinates x, y and luminance Y.

YCbCr digital-video color space with BT.601, BT.709 and BT.2020 variants.