Pote.Converters.Advanced (Pote v2.2.0)

Copy Markdown View Source

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 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 CIE XYZ using the sRGB D65 matrix.

Converts RGB to YCbCr (BT.601, digital video).

Converts RGB to YUV (BT.601, PAL/NTSC broadcast).

Types

lab()

@type lab() :: {float(), float(), float()}

rgb()

@type rgb() :: Pote.rgb()

xyz()

@type xyz() :: {float(), float(), float()}

ycbcr()

@type ycbcr() :: {integer(), integer(), integer()}

yuv()

@type yuv() :: {integer(), integer(), integer()}

Functions

contrast_ratio(rgb1, rgb2)

@spec contrast_ratio(rgb(), rgb()) :: float()

Calculates the WCAG 2.1 contrast ratio between two colors.

WCAG AA requiere 4.5:1 para texto normal, 7:1 para AAA.

delta_e(rgb1, rgb2)

@spec delta_e(rgb(), rgb()) :: float()

Calculates the Delta E 1976 distance between two colors.

This is the Euclidean distance in CIELAB space. Values < 1.0 are imperceptible.

from_lab(arg)

@spec from_lab(lab()) :: rgb()

Converts CIELAB to RGB (sRGB D65).

from_xyz(arg)

@spec from_xyz(xyz()) :: rgb()

Converts CIE XYZ to RGB (sRGB D65).

from_ycbcr(arg)

@spec from_ycbcr(ycbcr()) :: rgb()

Converts YCbCr (BT.601) to RGB.

from_yuv(arg)

@spec from_yuv(yuv()) :: rgb()

Converts YUV (BT.601) to RGB.

kelvin_to_rgb(kelvin)

@spec kelvin_to_rgb(pos_integer()) :: rgb()

Converts temperature in Kelvin to RGB.

Based on Tanner Helland's algorithm for black-body radiation approximation.

nearest_pantone(rgb)

@spec nearest_pantone(rgb()) :: {String.t(), float()} | nil

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} or nil if there is no close match

Example

iex> Pote.Converters.Advanced.nearest_pantone({255, 0, 0})
{"Red 032 C", 0.0}

nearest_pantone_name(rgb)

@spec nearest_pantone_name(rgb()) :: String.t() | nil

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"

relative_luminance(arg)

@spec relative_luminance(rgb()) :: float()

Calculates the WCAG 2.1 relative luminance of a color.

rgb_to_kelvin(rgb)

@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.

to_lab(rgb)

@spec to_lab(rgb()) :: lab()

Converts RGB to CIELAB (D65 illuminant).

to_xyz(arg)

@spec to_xyz(rgb()) :: xyz()

Converts RGB to CIE XYZ using the sRGB D65 matrix.

to_ycbcr(arg)

@spec to_ycbcr(rgb()) :: ycbcr()

Converts RGB to YCbCr (BT.601, digital video).

to_yuv(arg)

@spec to_yuv(rgb()) :: yuv()

Converts RGB to YUV (BT.601, PAL/NTSC broadcast).