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.

Re-exports§

pub use colorgrad;

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.

Constants§

PRESET_GRADIENTS
Every name preset_gradient accepts.

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
Black through dark red, orange and yellow to white.
gradient_health
Health bar colours: red at 0, amber at 0.5, green at 1.
gradient_ice
Black through deep blue and sky blue to white, blended in Oklab.
gradient_inferno
Matplotlib’s inferno.
gradient_neon
Magenta to cyan and back to magenta, blended in Oklab.
gradient_plasma
Matplotlib’s plasma.
gradient_viridis
Matplotlib’s viridis.
hsl_to_rgb
HSL (hue in degrees) to (r, g, b).
hsv_to_rgb
HSV (hue in degrees, wrapped to 0..360) to (r, g, b).
linear_to_srgb
Encode linear RGB to sRGB gamma (alpha unchanged).
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.
preset_gradient
A named colour map, baked into a Gradient (see PRESET_GRADIENTS).
rgb_to_hsl
(r, g, b) to HSL with hue in degrees.
rgb_to_hsv
(r, g, b) to HSV with hue in degrees, 0 to 360.
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
Decode sRGB gamma to linear RGB (alpha unchanged).
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).