smatchit_tailwind_project/node_modules/culori/src/dlch/convertDlchToLab65.js

29 lines
678 B
JavaScript
Raw Normal View History

2024-07-15 12:57:41 +00:00
import { kCH, kE, sinθ, cosθ, θ, factor } from './constants.js';
/*
Convert DIN99o LCh to CIELab D65
--------------------------------
*/
const convertDlchToLab65 = ({ l, c, h, alpha }) => {
let res = {
mode: 'lab65',
l: (Math.exp((l * kE) / factor) - 1) / 0.0039
};
if (h === undefined) {
res.a = res.b = 0;
} else {
let G = (Math.exp(0.0435 * c * kCH * kE) - 1) / 0.075;
let e = G * Math.cos((h / 180) * Math.PI - θ);
let f = G * Math.sin((h / 180) * Math.PI - θ);
res.a = e * cosθ - (f / 0.83) * sinθ;
res.b = e * sinθ + (f / 0.83) * cosθ;
}
if (alpha !== undefined) res.alpha = alpha;
return res;
};
export default convertDlchToLab65;