Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
817 bytes
|
Line | |
---|
1 | /* Convert between Lab and XYZ
|
---|
2 | /* ========================================================================== */
|
---|
3 |
|
---|
4 | export function lab2lch(labL, labA, labB) {
|
---|
5 | const [ lchC, lchH ] = [
|
---|
6 | Math.sqrt(Math.pow(labA, 2) + Math.pow(labB, 2)), // convert to chroma
|
---|
7 | Math.atan2(labB, labA) * 180 / Math.PI // convert to hue, in degrees
|
---|
8 | ];
|
---|
9 |
|
---|
10 | return [ labL, lchC, lchH ];
|
---|
11 | }
|
---|
12 |
|
---|
13 | export function lch2lab(lchL, lchC, lchH) {
|
---|
14 | // convert to Lab a and b from the polar form
|
---|
15 | const [ labA, labB ] = [
|
---|
16 | lchC * Math.cos(lchH * Math.PI / 180),
|
---|
17 | lchC * Math.sin(lchH * Math.PI / 180)
|
---|
18 | ];
|
---|
19 |
|
---|
20 | return [ lchL, labA, labB ];
|
---|
21 | }
|
---|
22 |
|
---|
23 | /*
|
---|
24 |
|
---|
25 | References
|
---|
26 | ----------
|
---|
27 |
|
---|
28 | - https://www.w3.org/TR/css-color-4/#lch-to-lab
|
---|
29 | - https://www.w3.org/TR/css-color-4/#color-conversion-code
|
---|
30 |
|
---|
31 | /* ========================================================================== */
|
---|
Note:
See
TracBrowser
for help on using the repository browser.