-
Notifications
You must be signed in to change notification settings - Fork 25
/
ycgco.js
57 lines (47 loc) · 852 Bytes
/
ycgco.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
/**
* https://en.wikipedia.org/?title=YCgCo
*
* @module color-space/ycgco
*/
import rgb from './rgb.js';
var ycgco = {
name: 'ycgco',
min: [0, -0.5, -0.5],
max: [1, 0.5, 0.5],
channel: ['Y','Cg','Co'],
alias: ['YCgCo']
};
/**
* YCgCo to RGB
* transform through analog form
*
* @param {Array} ycgco RGB values
*
* @return {Array} YCgCo values
*/
ycgco.rgb = function (arr) {
var y = arr[0], cg = arr[1], co = arr[2];
var tmp = y - cg;
return [
(tmp + co)*255,
(y + cg)*255,
(tmp - co)*255
];
};
/**
* RGB to YCgCo
* transform through analog form
*
* @param {Array} ycgco YCgCo values
*
* @return {Array} RGB values
*/
rgb.ycgco = function(arr) {
var r = arr[0]/255, g = arr[1]/255, b = arr[2]/255;
return [
0.25*r + 0.5*g + 0.25*b,
-0.25*r + 0.5*g - 0.25*b,
0.5*r - 0.5*b
];
};
export default ycgco;