Class: AdaptiveOklab

color-utils/aoklab.AdaptiveOklab(optionsopt)

new AdaptiveOklab(optionsopt)

Creates an instance of the AdaptiveOklab converter.
Parameters:
Name Type Attributes Default Description
options AdaptiveOklabOptions <optional>
{} Configuration options.
Source:
Example
const aokWhite = new AdaptiveOklab({ surround: 'white' });
const aokGray = new AdaptiveOklab(); // Defaults to 'gray' surround
const aokDarkHighX0 = new AdaptiveOklab({ surround: 'dark', x0: 0.6 });

Members

params

Get internal adaptation parameters (for testing/debugging)
Source:

(readonly) surround :AdaptiveOklabSurround

The configured viewing surround.
Type:
  • AdaptiveOklabSurround
Source:

Methods

fromSrgb(srgbColor) → {OklabColor}

Converts an sRGB color object to an Adaptive Oklab color object for the configured surround of this converter instance.
Parameters:
Name Type Description
srgbColor SrgbColor The sRGB color object {r, g, b} with components in [0, 1].
Source:
Throws:
if `srgbColor` is not a valid SrgbColor object.
Type
TypeError
Returns:
The Adaptive Oklab color object {L, a, b}.
Type
OklabColor
Example
const aokConverter = new AdaptiveOklab({ surround: 'dark' });
const adaptiveColor = aokConverter.fromSrgb({ r: 0.8, g: 0.2, b: 0.3 });
console.log(adaptiveColor); // { L: ..., a: ..., b: ... }

fromXyz(xyzColor) → {OklabColor}

Converts a CIE XYZ (D65) color object to an Adaptive Oklab color object. Input `XyzColor` should have Y scaled relative to Y_n=1.0.
Parameters:
Name Type Description
xyzColor XyzColor The CIE XYZ color object {X, Y, Z}.
Source:
Throws:
if `xyzColor` is not a valid XyzColor object.
Type
TypeError
Returns:
The Adaptive Oklab color object {L, a, b}.
Type
OklabColor

toHex(adaptiveOklabColor) → {string}

Converts an Adaptive Oklab color object to an sRGB hex string using the settings of this converter instance.
Parameters:
Name Type Description
adaptiveOklabColor OklabColor The Adaptive Oklab color {L, a, b}.
Source:
Throws:
if `adaptiveOklabColor` is not a valid OklabColor object.
Type
TypeError
Returns:
The sRGB hex string (e.g., "#RRGGBB").
Type
string
Example
const aokConverter = new AdaptiveOklab({ surround: 'dark' });
const aokColor = aokConverter.fromHex("#336699");
const hexOutput = aokConverter.toHex(aokColor);

toLinearSrgb(adaptiveOklabColor) → {LinearSrgbColor}

Converts an Adaptive Oklab color object back to a Linear sRGB color object. This method reverses the adaptive transformation applied by this instance.
Parameters:
Name Type Description
adaptiveOklabColor OklabColor The Adaptive Oklab color {L, a, b} to convert.
Source:
Throws:
if `adaptiveOklabColor` is not a valid OklabColor object.
Type
TypeError
Returns:
The corresponding Linear sRGB color object {r, g, b}. Components may be outside [0, 1] if the color is out of sRGB gamut.
Type
LinearSrgbColor

toSrgb(adaptiveOklabColor) → {SrgbColor}

Converts an Adaptive Oklab color object to an sRGB (gamma-corrected) color object using the settings of this converter instance.
Parameters:
Name Type Description
adaptiveOklabColor OklabColor The Adaptive Oklab color {L, a, b}.
Source:
Throws:
if `adaptiveOklabColor` is not a valid OklabColor object.
Type
TypeError
Returns:
The sRGB color object {r, g, b}. (Values may be outside [0,1]).
Type
SrgbColor
Example
const aokConverter = new AdaptiveOklab({ surround: 'white' });
const aokColor = aokConverter.fromSrgb({r:0.5, g:0.5, b:0.5});
const srgbOutput = aokConverter.toSrgb(aokColor); // srgbOutput reflects adaptation

toXyz(adaptiveOklabColor) → {XyzColor}

Converts an Adaptive Oklab color object to a CIE XYZ (D65) color object using the settings of this converter instance. Output XYZ has Y scaled relative to Y_n=1.0.
Parameters:
Name Type Description
adaptiveOklabColor OklabColor The Adaptive Oklab color {L, a, b}.
Source:
Throws:
if `adaptiveOklabColor` is not a valid OklabColor object.
Type
TypeError
Returns:
The CIE XYZ color object {X, Y, Z}.
Type
XyzColor
Example
const aokConverter = new AdaptiveOklab(); // Gray surround
const aokColor = { L: 0.7, a: 0.05, b: -0.02 }; // Example AOkLab color
const xyzOutput = aokConverter.toXyz(aokColor);

(static) fromHex(hexString, optionsopt) → {OklabColor}

Static helper method to convert an sRGB hex string directly to an Adaptive Oklab color object. Creates a temporary AdaptiveOklab converter instance with the specified options.
Parameters:
Name Type Attributes Default Description
hexString string The sRGB hex color string (e.g., "#FF0000", "aabbcc").
options AdaptiveOklabOptions <optional>
{} Configuration options for the AdaptiveOklab conversion.
Source:
Throws:
if `hexString` is invalid.
Type
TypeError | SyntaxError
Returns:
The Adaptive Oklab color object {L, a, b}.
Type
OklabColor