color-space

v3.5.0
io.github.colorjs/color-space Checked 7 hours ago Published 1 month ago

Conversions across 221 color spaces, tested against cited sources: CSS strings, gamut, LUTs

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

convert Convert color

Convert a color between any two of the 221 color spaces, identity included, in each space's conventional ranges (rgb 0-255, oklch L 0-1 / C 0-0.4 / H 0-360, lab L 0-100 …). The color goes in as a CSS string (`color`) or as channel values (`from` + `values`); a batch as `colors` – tuples in `from`, CSS strings, or both. Out-of-range in, unclamped out: `inRange` flags each channel against the target's conventional range (rgb below 0 means outside sRGB); null = undefined at that coordinate.

ParameterTypeDescription
to *stringtarget space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
colorstringa CSS color instead of `from` + `values`: '#ff8000', 'rebeccapurple', 'oklch(0.7 0.1 50)', 'lab(54% 80 67)', 'color(display-p3 1 0.5 0)'
colorsarraya batch: one tuple (in `from`) or CSS string per color, e.g. [[255, 128, 0], '#00ff80', 'oklch(0.7 0.1 50)']
fromstringsource space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
valuesarrayone color in the source space, e.g. [255, 128, 0] for rgb

gamut Gamut membership

Which standard display gamuts hold a color — sRGB ⊂ Display P3 ⊂ Rec. 2020, each tested in its own RGB box straight from the source space, the same ladder as the color-space.io gamut pill. `smallest` is the tightest one; null = beyond Rec. 2020. Membership only: nothing is gamut-mapped.

ParameterTypeDescription
colorstringa CSS color instead of `from` + `values`: '#ff8000', 'rebeccapurple', 'oklch(0.7 0.1 50)', 'lab(54% 80 67)', 'color(display-p3 1 0.5 0)'
fromstringsource space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
valuesarrayone color in the source space

css CSS color strings

A color as CSS Color 4 strings — rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch() and color(display-p3 | a98-rgb | prophoto-rgb | rec2020 | srgb-linear | xyz-d65 | xyz-d50) — plus #hex inside sRGB. Converted, never gamut-mapped: a string is null where CSS would clamp it into a different color (rgb/hsl/hwb outside sRGB, lightness out of range). `gamut` is the smallest display gamut that holds the color.

ParameterTypeDescription
colorstringa CSS color instead of `from` + `values`: '#ff8000', 'rebeccapurple', 'oklch(0.7 0.1 50)', 'lab(54% 80 67)', 'color(display-p3 1 0.5 0)'
fromstringsource space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
notationsarrayonly these, by library space id (default: all)
valuesarrayone color in the source space

space Space dossier

The dossier of one color space: display name (as color-space.io shows it), description, channels + conventional ranges, defining references, provenance (year, author), illuminant/observer, encoding class, family and purpose, and its direct conversion neighbours.

ParameterTypeDescription
name *stringthe space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)

spaces Space catalog

List the 221 color spaces with display name, family, purpose, channels and one-line use. Optional filters: `query` (words matched against id, name, use line and description; best matches first), `family`, `purpose`.

ParameterTypeDescription
familystring
purposestring
querystringfree text, e.g. 'camera log', 'cielab', 'display p3'

cube .cube LUT

Render a conversion as a .cube LUT file (Resolve, Premiere, Final Cut, OBS, ffmpeg). The header carries the measured deviation vs the direct conversion. Pure per-channel transfers auto-emit 1D. Size ≤ 33 here (larger via the library or https://color-space.io/).

ParameterTypeDescription
from *stringsource space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
to *stringtarget space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
sizeinteger3D lattice size (default 17)

shader Shader code

The conversion as shader source – GLSL (WebGL2; WebGL1 too unless the path reads a table), WGSL (WebGPU), HLSL (DirectX, Unity, Unreal) or MSL (Metal) – with an entry function `<from>_<to>` (hyphens stripped), e.g. `vec3 rgb_oklch(vec3 c)`, plus every function on the path. Each language is differentially tested against the library and compiled on real GPUs: use it instead of writing color matrices. HLSL and MSL need the optional peer `naga-wasm` installed beside color-space.

ParameterTypeDescription
from *stringsource space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
to *stringtarget space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
languagestringdefault glsl

icc ICC profile

One space as an ICC v2 profile (.icc): matrix + tone curve where the space is an RGB working space (Photoshop, OS color management), a CLUT on a Lab PCS otherwise (lcms, ArgyllCMS, ImageMagick). Returned as a base64 embedded resource; `class`, `pcs` and `bytes` describe it.

ParameterTypeDescription
name *stringthe space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
gridintegerCLUT lattice points per channel, CLUT profiles only (default 33 for 3 channels; fewer = a smaller file)

code Library code

The conversion as code to paste: the color-space JS call with its result and – where one exists for the space on the non-sRGB side – the colour-science (Python) equivalent verified against color-space (sRGB ↔ that space), with any named caveat. The color goes in as a CSS string or as values in `from` (default: sRGB 200, 100, 50).

ParameterTypeDescription
to *stringtarget space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
colorstringa CSS color instead of `from` + `values`: '#ff8000', 'rebeccapurple', 'oklch(0.7 0.1 50)', 'lab(54% 80 67)', 'color(display-p3 1 0.5 0)'
fromstringsource space id, e.g. 'rgb', 'oklch', 'lab', 'slog3', 'rec709' (the 'spaces' tool lists all 221)
valuesarraythe color in the source space