Advanced color conversions for special color spaces.
Includes:
- CIE XYZ
- CIELAB
- YUV (BT.601)
- YCbCr (BT.601)
- Color temperature (Kelvin)
- Delta E (color distance)
- WCAG contrast
Summary
Functions
Calculates the WCAG 2.1 contrast ratio between two colors.
Calculates the Delta E 1976 distance between two colors.
Converts CIELAB to RGB (sRGB D65).
Converts OKLab to RGB (sRGB D65).
Converts OKLCH to RGB (sRGB D65).
Converts CIE XYZ to RGB (sRGB D65).
Converts YCbCr (BT.601) to RGB.
Converts YUV (BT.601) to RGB.
Converts temperature in Kelvin to RGB.
Finds the closest Pantone color for an RGB color.
Finds the closest Pantone name for an RGB color.
Returns only the name, or nil if there is no close match.
Calculates the WCAG 2.1 relative luminance of a color.
Approximates the correlated color temperature (CCT) in Kelvin from an RGB color.
Converts RGB to CIELAB (D65 illuminant).
Converts RGB to OKLab (Ottosson's perceptual space).
Converts RGB to OKLCH (OKLab in polar form).
Converts RGB to CIE XYZ using the sRGB D65 matrix.
Converts RGB to YCbCr (BT.601, digital video).
Converts RGB to YUV (BT.601, PAL/NTSC broadcast).
Returns the WCAG 2.1 conformance level for a given contrast ratio.
Types
Functions
Calculates the WCAG 2.1 contrast ratio between two colors.
WCAG AA requires 4.5:1 for normal text, 7:1 for AAA.
Calculates the Delta E 1976 distance between two colors.
This is the Euclidean distance in CIELAB space. Values < 1.0 are imperceptible.
Converts CIELAB to RGB (sRGB D65).
Converts OKLab to RGB (sRGB D65).
Converts OKLCH to RGB (sRGB D65).
Converts CIE XYZ to RGB (sRGB D65).
Converts YCbCr (BT.601) to RGB.
Converts YUV (BT.601) to RGB.
@spec kelvin_to_rgb(pos_integer()) :: rgb()
Converts temperature in Kelvin to RGB.
Based on Tanner Helland's algorithm for black-body radiation approximation.
Finds the closest Pantone color for an RGB color.
Uses a curated list of popular Pantone colors and searches for the closest match using Delta E distance in CIELAB space.
Parameters
rgb- RGB tuple{r, g, b}
Returns
- tuple
{pantone_name, distance}ornilif there is no close match
Example
iex> Pote.Converters.Advanced.nearest_pantone({255, 0, 0})
{"Red 032 C", 0.0}
Finds the closest Pantone name for an RGB color.
Returns only the name, or nil if there is no close match.
Example
iex> Pote.Converters.Advanced.nearest_pantone_name({255, 0, 0})
"Red 032 C"
Calculates the WCAG 2.1 relative luminance of a color.
@spec rgb_to_kelvin(rgb()) :: pos_integer() | nil
Approximates the correlated color temperature (CCT) in Kelvin from an RGB color.
Uses an iterative search over kelvin_to_rgb/1 to find the
closest matching temperature.
Converts RGB to CIELAB (D65 illuminant).
Converts RGB to OKLab (Ottosson's perceptual space).
OKLab is a perceptual color space designed for smooth, uniform interpolation: midpoints stay perceptually consistent, avoiding the "muddy middle" of RGB/HSL interpolation.
Converts RGB to OKLCH (OKLab in polar form).
Returns {l, c, h} where l is perceptual lightness (0..1),
c is chroma, and h is hue in degrees (0..360).
Converts RGB to CIE XYZ using the sRGB D65 matrix.
Converts RGB to YCbCr (BT.601, digital video).
Converts RGB to YUV (BT.601, PAL/NTSC broadcast).
@spec wcag_level(float(), :normal | :large) :: :aaa | :aa | :fail
Returns the WCAG 2.1 conformance level for a given contrast ratio.
Levels (for normal text):
:aaa— 7.0+ (enhanced):aa— 4.5+ (minimum):fail— < 4.5
For large text (18pt+ or 14pt+ bold), the thresholds are lower:
:aaa— 4.5+:aa— 3.0+:fail— < 3.0
Examples
iex> Pote.Converters.Advanced.wcag_level(7.5)
:aaa
iex> Pote.Converters.Advanced.wcag_level(4.5)
:aa
iex> Pote.Converters.Advanced.wcag_level(2.0)
:fail