-
Notifications
You must be signed in to change notification settings - Fork 25
/
ycbcr.js
79 lines (66 loc) · 1.32 KB
/
ycbcr.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* https://en.wikipedia.org/?title=YCbCr
*
* YCbCr is a digital form of YPbPr conversion
* Thence limits are [16...235], according to the ITU-R BT.709 or ITU-R BT.601
*
* @module color-space/ycbcr
*/
import rgb from './rgb.js'
import ypbpr from './ypbpr.js'
var ycbcr = {
name: 'ycbcr',
min: [16, 16, 16],
max: [235, 240, 240],
channel: ['Y','Cb','Cr'],
alias: ['YCbCr', 'YCC']
};
/**
* From analog to digital form.
* Simple scale to min/max ranges
*
* @return {Array} Resulting digitized form
*/
ypbpr.ycbcr = function (ypbpr) {
var y = ypbpr[0], pb = ypbpr[1], pr = ypbpr[2];
return [
16 + 219 * y,
128 + 224 * pb,
128 + 224 * pr
];
}
/**
* From digital to analog form.
* Scale to min/max ranges
*/
ycbcr.ypbpr = function (ycbcr) {
var y = ycbcr[0], cb = ycbcr[1], cr = ycbcr[2];
return [
(y - 16) / 219,
(cb - 128) / 224,
(cr - 128) / 224
];
}
/**
* YCbCr to RGB
* transform through analog form
*
* @param {Array} ycbcr RGB values
*
* @return {Array} YCbCr values
*/
ycbcr.rgb = function (arr, kb, kr) {
return ypbpr.rgb(ycbcr.ypbpr(arr), kb, kr);
};
/**
* RGB to YCbCr
* transform through analog form
*
* @param {Array} ycbcr YCbCr values
*
* @return {Array} RGB values
*/
rgb.ycbcr = function(arr, kb, kr) {
return ypbpr.ycbcr(rgb.ypbpr(arr, kb, kr));
};
export default ycbcr;