Module colorizer.color

Color Utilities Provides color conversion and utility functions for RGB and HSL values.

Functions

apply_alpha (r, g, b, alpha) Apply alpha transparency to RGB color channels.
css_color_to_rgb (space, r, g, b) Converts a CSS color() function value to sRGB.
hsl_to_rgb (h, s, l) Converts an HSL color value to RGB.
hue_to_rgb (p, q, t) Converts an HSL component to RGB, used within hsl_to_rgb.
hwb_to_rgb (h, w, b) Converts an HWB color value to RGB.
is_bright (r, g, b) Determines whether a color is bright, helping decide text color.
lab_to_rgb (L, a, b_lab) Converts a CIE Lab color value to RGB.
lch_to_rgb (L, C, H) Converts a CIE LCH color value to RGB.
linear_to_srgb (c) Converts linear sRGB to gamma-corrected sRGB.
oklch_to_rgb (L, C, H) Converts an OKLCH color value to RGB.
srgb_to_linear (c) Converts sRGB gamma to linear sRGB.


Functions

apply_alpha (r, g, b, alpha)
Apply alpha transparency to RGB color channels. Multiplies each channel by the alpha value and floors the result.
css_color_to_rgb (space, r, g, b)
Converts a CSS color() function value to sRGB. Supports: srgb, srgb-linear, display-p3, a98-rgb, prophoto-rgb, rec2020.

References: - W3C CSS Color Module Level 4: https://www.w3.org/TR/css-color-4/#color-function - Color space matrices: https://www.w3.org/TR/css-color-4/#color-conversion

hsl_to_rgb (h, s, l)
Converts an HSL color value to RGB. Accepts hue, saturation, and lightness values, each within the range [0, 1], and converts them to an RGB color representation with values scaled to [0, 255].
hue_to_rgb (p, q, t)
Converts an HSL component to RGB, used within hsl_to_rgb. Source: https://gist.github.com/mjackson/5311256 This function computes one component of the RGB value by adjusting the color based on intermediate values p, q, and t.
hwb_to_rgb (h, w, b)

Converts an HWB color value to RGB. HWB (Hue, Whiteness, Blackness) is a CSS Color Level 4 color model. When whiteness + blackness >= 1, the result is a shade of gray.

References: - W3C CSS Color Module Level 4: https://www.w3.org/TR/css-color-4/#the-hwb-notation

     scaled to [0, 255], or nil if any input value is out of range.
is_bright (r, g, b)
Determines whether a color is bright, helping decide text color. ref: https://stackoverflow.com/a/1855903/837964 https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color Calculates the perceived luminance of the RGB color. Returns true if the color is bright enough to warrant black text and false otherwise. Formula based on the human eye’s sensitivity to different colors.
lab_to_rgb (L, a, b_lab)

Converts a CIE Lab color value to RGB. CIE Lab is a perceptually uniform color space.

References: - W3C CSS Color Module Level 4: https://www.w3.org/TR/css-color-4/#lab-colors - Conversion: Lab -> D50 XYZ -> D65 XYZ -> linear sRGB -> sRGB

     scaled to [0, 255], or nil if conversion fails.
lch_to_rgb (L, C, H)

Converts a CIE LCH color value to RGB. CIE LCH is the cylindrical form of CIE Lab.

References: - W3C CSS Color Module Level 4: https://www.w3.org/TR/css-color-4/#lab-colors

     scaled to [0, 255], or nil if conversion fails.
linear_to_srgb (c)
Converts linear sRGB to gamma-corrected sRGB. Shared by multiple color space converters.
oklch_to_rgb (L, C, H)

Converts an OKLCH color value to RGB. OKLCH is a perceptual color space that provides better uniformity than HSL. Accepts lightness, chroma, and hue values and converts them to RGB.

References: - OKLCH/OKLab specification: https://bottosson.github.io/posts/oklab/ - W3C CSS Color Module Level 4: https://www.w3.org/TR/css-color-4/#ok-lab - Conversion algorithms: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/oklch

     scaled to [0, 255], or nil if any input value is out of range.
srgb_to_linear (c)
Converts sRGB gamma to linear sRGB.
generated by LDoc 1.5.0 Last updated 2026-03-07 17:46:06