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 Dec 14, 2023
1 parent e68e4c2 commit f193db3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 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
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const LMS_Oklab = [
export const LMSg_OkLab = [
[0.210454268309314, 0.7936177747023054, -0.0040720430116193],
[1.9779985324311684, -2.4285922420485799, 0.450593709617411],
[0.0259040424655478, 0.7827717124575296, -0.8086757549230774],
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 f193db3

Please sign in to comment.