-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcmy.js
55 lines (47 loc) · 852 Bytes
/
cmy.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
/**
* @module color-space/cmy
*/
import rgb from './rgb.js';
/** @type {Partial<import('./index.js').ColorSpace>} */
var cmy = {
name: 'cmy',
min: [0,0,0],
max: [100,100,100],
channel: ['cyan', 'magenta', 'yellow'],
alias: ['CMY']
};
/**
* CMY to RGB
*
* @param {Array<number>} cmy Channels
*
* @return {Array<number>} RGB channels
*/
cmy.rgb = function(cmy) {
var c = cmy[0] / 100,
m = cmy[1] / 100,
y = cmy[2] / 100;
return [
(1 - c) * 255,
(1 - m) * 255,
(1 - y) * 255
];
};
/**
* RGB to CMY
*
* @param {Array<number>} rgb channels
*
* @return {Array<number>} CMY channels
*/
rgb.cmy = function(rgb) {
var r = rgb[0] / 255,
g = rgb[1] / 255,
b = rgb[2] / 255;
return [
(1-r) * 100 || 0,
(1-g) * 100 || 0,
(1-b) * 100 || 0
];
}
export default /** @type {import('./index.js').ColorSpace} */ (cmy);