Skip to content

Commit

Permalink
feature: upgrade oklab and lms matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
tychota committed Nov 23, 2023
1 parent 9b8d149 commit 375f5fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/colorspace/oklab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { _LMSg, _LMSgColorspace } from "./oklab/_lmsg";
import { ToXYZColorspaceVisitor } from "./xyz";
import { ToRGBColorspaceVisitor } from "./rgb";

import { LMS_Oklab } from "../constants";
import { LMSg_OkLab } from "../constants";

export class ToOkLabColorspaceVisitor extends ColorspaceVisitor<InstanceType<typeof Color.OkLab>> {
public visitRGBColor(color: InstanceType<typeof Color.RGB>) {
Expand All @@ -18,7 +18,7 @@ export class ToOkLabColorspaceVisitor extends ColorspaceVisitor<InstanceType<typ
return this.visitRGBColor(rgb);
}
private visiteLMSgColor(color: _LMSg) {
const lab = matMul(LMS_Oklab, [color.l, color.m, color.s]);
const lab = matMul(LMSg_OkLab, [color.l, color.m, color.s]);
const oklab = new Color.OkLab(lab[0], lab[1], lab[2]);
return this.visitOkLabColor(oklab);
}
Expand Down
26 changes: 13 additions & 13 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
export const LMS_Oklab = [
[0.2104542553, 0.793617785, -0.0040720468],
[1.9779984951, -2.428592205, 0.4505937099],
[0.0259040371, 0.7827717662, -0.808675766],
export const LMSg_OkLab = [
[0.210454268309314, 0.7936177747023054, -0.0040720430116193],
[1.9779985324311684, -2.4285922420485799, 0.450593709617411],
[0.0259040424655478, 0.7827717124575296, -0.8086757549230774],
];

export const OkLab_LMSg = [
[0.99999999845051981432, 0.39633779217376785678, 0.21580375806075880339],
[1.0000000088817607767, -0.1055613423236563494, -0.063854174771705903402],
[1.0000000546724109177, -0.089484182094965759684, -1.2914855378640917399],
[1.0, 0.3963377773761749, 0.2158037573099136],
[1.0, -0.1055613458156586, -0.0638541728258133],
[1.0, -0.0894841775298119, -1.2914855480194092],
];

export const XYZ_LMS = [
[0.8190224432164319, 0.3619062562801221, -0.12887378261216414],
[0.0329836671980271, 0.9292868468965546, 0.03614466816999844],
[0.048177199566046255, 0.26423952494422764, 0.6335478258136937],
[0.819022437996703, 0.3619062600528904, -0.1288737815209879],
[0.0329836539323885, 0.9292868615863434, 0.0361446663506424],
[0.0481771893596242, 0.2642395317527308, 0.6335478284694309],
];

export const LMS_XYZ = [
[1.2268798733741557, -0.5578149965554813, 0.28139105017721583],
[-0.04057576262431372, 1.1122868293970594, -0.07171106666151701],
[-0.07637294974672142, -0.4214933239627914, 1.5869240244272418],
[1.2268798758459243, -0.5578149944602171, 0.2813910456659647],
[-0.0405757452148008, 1.112286803280317, -0.0717110580655164],
[-0.0763729366746601, -0.4214933324022432, 1.5869240198367816],
];

export const XYZ_to_RGB = [
Expand Down
12 changes: 6 additions & 6 deletions src/gamut/rgb/oklab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ export abstract class OkLabInterpolateGamutMapping extends OkLabGamutMapping {
// this gives an error less than 10e6, except for some blue hues where the dS/dh is close to infinite
// this should be sufficient for most applications, otherwise do two/three steps

let k_l = +0.3963377774 * a + 0.2158037573 * b;
let k_m = -0.1055613458 * a - 0.0638541728 * b;
let k_s = -0.0894841775 * a - 1.291485548 * b;
let k_l = +0.3963377773761749 * a + 0.2158037573099136 * b;
let k_m = -0.1055613458156586 * a - 0.0638541728258133 * b;
let k_s = -0.0894841775298119 * a - 1.2914855480194092 * b;

const halleyStep = () => {
let l_ = 1 + maxSaturation * k_l;
Expand Down Expand Up @@ -238,9 +238,9 @@ export abstract class OkLabInterpolateGamutMapping extends OkLabGamutMapping {
let dL = L1 - L0;
let dC = C1 - 0;

let k_l = +0.3963377774 * a + 0.2158037573 * b;
let k_m = -0.1055613458 * a - 0.0638541728 * b;
let k_s = -0.0894841775 * a - 1.291485548 * b;
let k_l = +0.3963377773761749 * a + 0.2158037573099136 * b;
let k_m = -0.1055613458156586 * a - 0.0638541728258133 * b;
let k_s = -0.0894841775298119 * a - 1.2914855480194092 * b;

let l_dt = dL + dC * k_l;
let m_dt = dL + dC * k_m;
Expand Down

0 comments on commit 375f5fb

Please sign in to comment.