-
Notifications
You must be signed in to change notification settings - Fork 25
/
lchab.js
57 lines (46 loc) · 873 Bytes
/
lchab.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Cylindrical LAB
*
* @module color-space/lchab
*/
import xyz from './xyz.js';
import lab from './lab.js';
//cylindrical lab
var lchab = {
name: 'lchab',
min: [0,0,0],
max: [100,100,360],
channel: ['lightness', 'chroma', 'hue'],
alias: ['LCHab', 'cielch', 'LCH', 'HLC', 'LSH'],
xyz: function(arg) {
return lab.xyz(lchab.lab(arg));
},
lab: function(lch) {
var l = lch[0],
c = lch[1],
h = lch[2],
a, b, hr;
hr = h / 360 * 2 * Math.PI;
a = c * Math.cos(hr);
b = c * Math.sin(hr);
return [l, a, b];
}
};
//extend lab
lab.lchab = function(lab) {
var l = lab[0],
a = lab[1],
b = lab[2],
hr, h, c;
hr = Math.atan2(b, a);
h = hr * 360 / 2 / Math.PI;
if (h < 0) {
h += 360;
}
c = Math.sqrt(a * a + b * b);
return [l, c, h];
};
xyz.lchab = function(arg){
return lab.lchab(xyz.lab(arg));
};
export default lchab;