Skip to content

color.toOklab

Summary

color.toOklab converts linear RGB to OKLab lightness and opponent-color coordinates for perceptual color operations. Convert edited or interpolated coordinates back with color.fromOklab. The conversion preserves alpha and may produce linear RGB outside the displayable range.

Syntax

toOklab(color: Color4): [number, number, number, number]
fromOklab(lab: readonly [number, number, number, number]): Color4
const lab = WasmGPU.color.toOklab([0.2, 0.4, 0.6, 1]);

Parameters

Name Type Required Description
color Color4 For toOklab Linear RGBA tuple. Decode sRGB before calling.
lab readonly [number, number, number, number] For fromOklab OKLab lightness, two opponent components and alpha.

Returns

A fresh four-number tuple with alpha unchanged. fromOklab can produce RGB channels outside [0, 1] for colors outside the RGB gamut. Both functions are also named package exports.

Example

const color = WasmGPU.color;
const lab = color.toOklab(color.parse("#268bd2"));
const lighter = color.fromOklab([lab[0] + 0.05, lab[1], lab[2], lab[3]]);
console.log(lighter);

See Also