Expand description
prime-color — Color space math: sRGB, Oklab, HSL, and perceptual mixing.
All functions are pure (LOAD + COMPUTE only). No mutation, no side effects, no hidden state. Same inputs always produce the same output.
Colors are represented as bare (f32, f32, f32) tuples for simplicity and
FFI/WASM interop. No structs.
§Color spaces
- sRGB — standard display color space, gamma-encoded, components in
[0, 1] - Linear RGB — gamma-decoded sRGB; linear light values used for math
- Oklab — perceptually uniform opponent color space by Björn Ottosson
L∈[0, 1](lightness),a∈[-0.5, 0.5](green↔red),b∈[-0.5, 0.5](blue↔yellow)
- HSL — hue/saturation/lightness cylinder on sRGB
h∈[0, 360),s∈[0, 1],l∈[0, 1]
Functions§
- contrast_
ratio - WCAG contrast ratio between two sRGB colors. Returns value >= 1.
- hsl_
to_ srgb - Converts an HSL color to sRGB.
- hsv_
to_ srgb - Convert HSV to sRGB.
hin[0, 360),sandvin[0, 1]. - linear_
to_ srgb - Converts a linear RGB color to sRGB (gamma-encoded).
- luminance
- Relative luminance (ITU-R BT.709). Input is linear RGB.
- oklab_
mix - Mixes two sRGB colors in Oklab space for perceptually uniform blending.
- oklab_
to_ srgb - Converts an Oklab color back to sRGB.
- palette_
analogous - Analogous palette — two colors at +30 and -30 degrees in HSL.
- palette_
complementary - Complementary color — rotate hue by 180 degrees in HSL.
- palette_
triadic - Triadic palette — two colors at +120 and +240 degrees in HSL.
- srgb_
to_ hsl - Converts an sRGB color to HSL.
- srgb_
to_ hsv - Convert sRGB to HSV. Returns
(h, s, v)wherehin[0, 360),sandvin[0, 1]. - srgb_
to_ linear - Converts an sRGB color (gamma-encoded) to linear RGB.
- srgb_
to_ oklab - Converts an sRGB color to Oklab.