保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* Convert between Lab and XYZ
/* ========================================================================== */
 
export function lab2lch(labL, labA, labB) {
    const [ lchC, lchH ] = [
        Math.sqrt(Math.pow(labA, 2) + Math.pow(labB, 2)), // convert to chroma
        Math.atan2(labB, labA) * 180 / Math.PI // convert to hue, in degrees
    ];
 
    return [ labL, lchC, lchH ];
}
 
export function lch2lab(lchL, lchC, lchH) {
    // convert to Lab a and b from the polar form
    const [ labA, labB ] = [
        lchC * Math.cos(lchH * Math.PI / 180),
        lchC * Math.sin(lchH * Math.PI / 180)
    ];
 
    return [ lchL, labA, labB ];
}
 
/*
 
References
----------
 
- https://www.w3.org/TR/css-color-4/#lch-to-lab
- https://www.w3.org/TR/css-color-4/#color-conversion-code
 
/* ========================================================================== */