@pbroom/color-kitConversion

linearRgbToOklabInto

Convert linear sRGB to OKLAB, writing into out (allocation-free). Based on Björn Ottosson's OKLab model, using the CSS Color 4 matrices recalculated in float64 for a consistent D65 reference white. bottosson.github.io/posts/oklab/

functionimport { linearRgbToOklabInto } from '@pbroom/color-kit';oklab.ts:34
function linearRgbToOklabInto(  out: Oklab, ,  rgb: LinearRgb,): Oklab;

Parameters

outOklab
Object to write the result into
rgbLinearRgb
Linear-light sRGB color (unclamped)

Returns

Oklabout

Example

TypeScript
import { linearRgbToOklabInto } from '@pbroom/color-kit';

const lab = { L: 0, a: 0, b: 0, alpha: 1 };
linearRgbToOklabInto(lab, { r: 1, g: 0, b: 0, alpha: 1 });
lab.L; // → ≈ 0.628

See also