-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathucs.js
58 lines (51 loc) · 870 Bytes
/
ucs.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
58
/**
* https://en.wikipedia.org/wiki/CIE_1960_color_space
*
* Obsolete color space
*
* @module color-space/ucs
*/
import xyz from './xyz.js';
/** @type {Partial<import('./index.js').ColorSpace>} */
var ucs = {
name: 'ucs',
min: [0,0,0],
max: [100, 100, 100],
channel: ['U','V','W'],
alias: ['UCS', 'cie1960']
};
export default /** @type {import('./index.js').ColorSpace} */ (ucs);
/**
* UCS to XYZ
*
* @param {Array<number>} ucs XYZ values
*
* @return {Array<number>} UCS values
*/
ucs.xyz = function(ucs) {
var u = ucs[0],
v = ucs[1],
w = ucs[2];
return [
1.5 * u,
v,
1.5 * u - 3 * v + 2 * w
];
};
/**
* XYZ to UCS
*
* @param {Array<number>} xyz UCS values
*
* @return {Array<number>} XYZ values
*/
xyz.ucs = function(xyz) {
var x = xyz[0],
y = xyz[1],
z = xyz[2];
return [
x * 2/3,
y,
0.5 * (-x + 3*y + z)
];
};