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§
- Color
Stop - 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],aandbare 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§
- Gradient
Mode - Interpolation mode for gradient stops.
Constants§
- PRESET_
GRADIENTS - Every name
preset_gradientaccepts.
Functions§
- adjust_
brightness - Adjust brightness (additive offset).
- adjust_
contrast - Adjust contrast around 0.5 midpoint (factor >1 = more contrast).
- adjust_
hue - Adjust hue by
deltadegrees. - 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(seePRESET_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
cwith black byfactor ∈ [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
cwith white byfactor ∈ [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).