Skip to content

Color Spaces

Colormath has a number of built-in color spaces and models.

A note on terminology

A color model defines the components of a color. For example, RGB is a color model that defines colors with the additive combination of red, green, and blue light.

A color space is a color model plus the details necessary to represent a color in that model. sRGB and DCI P3 are both color spaces the use the RGB model, but they define different values for the exact colors of their RGB primaries.

Built-in color models

RGB

Component Description Range
r red [0, 1]
g green [0, 1]
b blue [0, 1]

The RGB color model defines colors with the additive combination of reg, green, and blue lights. RGB components are stored as floating point numbers in the range [0, 1]. You can also represent sRGB colors as packed integers with RGBInt, or create them from integers in the range [0, 255] with RGB.from255().

RGB color spaces

Colormath includes a number of built-in RGB color spaces, and you can define your own with RGBColorSpace. The default RGB space is sRGB.

HSL

Component Description Range
h hue, degrees, NaN for monochrome colors [0, 360)
s saturation [0, 1]
l lightness [0, 1]

A cylindrical representation of sRGB using Hue, Saturation, and Lightness.

HSV

Component Description Range
h hue, degrees, NaN for monochrome colors [0, 360)
s saturation [0, 1]
v value [0, 1]

A cylindrical representation of sRGB using Hue, Saturation, and Value / brightness.

HWB

Component Description Range
h hue, degrees [0, 360)
w whiteness [0, 1]
b blackness [0, 1]

A cylindrical representation of sRGB using Hue, Whiteness, and Blackness.

HSLuv and HPLuv

Component Description Range
h hue, degrees, NaN for monochrome colors [0, 360)
s saturation [0, 100]
l lightness [0, 100]
Component Description Range
h hue, degrees, NaN for monochrome colors [0, 360)
p percentage saturation [0, 100]
l lightness [0, 100]

HSLuv and HPLuv are color spaces designed as a human friendly alternative to HSL.

ICtCp

Component Description Range
I intensity [0, 1]
Ct Tritan (blue-yellow) [-0.5, 0.5]
Cp Protan (red-green) [-0.5, 0.5]

ICtCp is a color space designed for high dynamic range and wide color gamut imagery.

JzAzBz and JzCzHz

Component Description Range
Jz lightness [0, 1]
Az green-red [-1, 1]
Bz blue-yellow [-1, 1]
Component Description Range
Jz lightness [0, 1]
Cz chroma [-1, 1]
Hz hue, degrees, NaN for monochrome colors [0, 360)

JzAzBz is a perceptually uniform space where euclidean distance predicts perceptual difference. JzCzHz is its cylindrical representation.

CIE L*a*b* and LCHab

Component Description Range
L lightness [0, 100]
a* green-red [-128, 128]
b* blue-yellow [-128, 128]
Component Description Range
L lightness [0, 100]
c chroma [0, 150]
h hue, degrees, NaN for monochrome colors [0, 360)

LAB is a color model intended to be perceptually uniform. Its cylindrical representation is LCHab.

LAB and LCHab color spaces

LAB and LCHab models each have multiple color spaces that are defined relative to a white point. The default white point is D65.

CIE L*u*v* and LCHuv

Component Description Range
L lightness [0, 100]
u [-100, 100]
v [-100, 100]
Component Description Range
L lightness [0, 100]
c chroma [0, 100]
h hue, degrees, NaN for monochrome colors [0, 360)

LUV is a color model intended to be perceptually uniform. Its cylindrical representation is LCHuv.

LUV and LCHuv color spaces

LUV and LCHuv models each have multiple color spaces that are defined relative to a white point. The default white point is D65.

Oklab and Oklch

Component Description Range
L lightness [0, 1]
a green-red [-0.4, 0.4]
b blue-yellow [-0.4, 0.4]
Component Description Range
L lightness [0, 1]
c chroma [0, 0.4]
h hue, degrees, NaN for monochrome colors [0, 360)

Oklab is a perceptual color space for image processing. Its cylindrical representation is Oklch.

CIE XYZ

Component Range
X [0, 1]
Y [0, 1]
Z [0, 1]

The XYZ color model is common used as a profile connection space when converting between other models.

XYZ color spaces

The XYZ model has multiple color spaces that are defined relative to a white point. The default white point is D65.

ANSI color codes

Based on the VGA color palette, there are models for 4-bit, 16 color codes and 8-bit, 256 color codes

CMYK

Component Description Range
c cyan [0, 1]
m magenta [0, 1]
y yellow [0, 1]
k key / black [0, 1]

Colormath’s CMYK model uses device-independent conversions. Device CMYK profiles are not currently supported.