Skip to main content

Module color

Module color 

Source
Expand description

Color science utilities: color spaces, palettes, gradients, LUT generation.

Provides conversion between linear RGB, sRGB, HSV, HSL, Oklab, CIE Lab, CIE LCH, and XYZ color spaces. Also includes gradient building, palette generation, color harmonies, and LUT support.

Structs§

ColorStop
A color stop in a gradient.
Gradient
A multi-stop color gradient.
Hsl
HSL color: hue in [0, 360), saturation and lightness in [0, 1].
Hsv
HSV color: hue in [0, 360), saturation and value in [0, 1].
Lab
CIE Lab* color space (D65 white point).
Lch
CIE LCH (Lightness, Chroma, Hue in degrees).
Oklab
Oklab color: a perceptually uniform color space by Björn Ottosson. L = lightness [0,1], a and b are chroma axes (approx −0.5..0.5).
Palette
A named palette of colors.
Rgba
Linear RGB color with alpha, all in [0.0, 1.0].
Xyz
CIE XYZ (D65 white point).

Enums§

GradientMode
Interpolation mode for gradient stops.

Functions§

adjust_brightness
Adjust brightness (additive offset).
adjust_contrast
Adjust contrast around 0.5 midpoint (factor >1 = more contrast).
adjust_hue
Adjust hue by delta degrees.
adjust_saturation
Saturate or desaturate (1 = no change, 0 = greyscale, >1 = boost).
analogous
Generate analogous colors (±30°).
complementary
Generate a complementary color (180° hue rotation).
distance_lab_e76
Perceptual distance using CIE Lab Delta-E 1976.
distance_rgb
Euclidean distance in linear RGB space.
gradient_fire
gradient_health
gradient_ice
gradient_inferno
gradient_neon
gradient_plasma
gradient_viridis
hsl_to_rgb
hsv_to_rgb
linear_to_srgb
linear_to_srgb_channel
Apply sRGB gamma (linear → display).
nearest_in_palette
Find the nearest color in a palette (by Lab Delta-E).
palette_ansi16
ANSI 16-color terminal palette.
palette_chaos_elements
Chaos RPG element colors.
palette_crt
CRT terminal / retrowave palette.
rgb_to_hsl
rgb_to_hsv
shade_black
Mix color c with black by factor ∈ [0, 1] (0 = original, 1 = black).
split_complementary
Generate split-complementary colors (150° and 210°).
srgb_to_linear
srgb_to_linear_channel
Remove sRGB gamma (display → linear).
tetradic
Generate a tetradic (square) color scheme.
tint_white
Mix color c with white by factor ∈ [0, 1] (0 = original, 1 = white).
tonemap_aces
ACES filmic tone mapping approximation (Narkowicz 2015).
tonemap_reinhard
Reinhard tone mapping operator.
tonemap_uncharted2
Uncharted 2 “Hable” filmic tone mapping.
triadic
Generate triadic colors (120° apart).