-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathydbdr.js
74 lines (61 loc) · 1.29 KB
/
ydbdr.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
/**
* https://en.wikipedia.org/?title=YDbDr
*
* @module color-space/ydbdr
*/
import rgb from './rgb.js';
import yuv from './yuv.js';
/** @type {Partial<import('./index.js').ColorSpace>} */
var ydbdr = {
name: 'ydbdr',
min: [0,-1.333,-1.333],
max: [1, 1.333, 1.333],
channel: ['Y','Db','Dr'],
alias: ['YDbDr']
};
/**
* YDbDr to RGB
*
* @param {Array<number>} ydbdr RGB values
*
* @return {Array<number>} YDbDr values
*/
ydbdr.rgb = function(ydbdr) {
var y = ydbdr[0], db = ydbdr[1], dr = ydbdr[2];
var r = y + 0.000092303716148*db - 0.525912630661865*dr;
var g = y - 0.129132898890509*db + 0.267899328207599*dr;
var b = y + 0.664679059978955*db - 0.000079202543533*dr;
return [r*255, g*255, b*255];
};
/**
* RGB to YDbDr
*
* @param {Array<number>} rgb YDbDr values
*
* @return {Array<number>} RGB values
*/
rgb.ydbdr = function(rgb) {
var r = rgb[0]/255, g = rgb[1]/255, b = rgb[2]/255;
return [
0.299*r + 0.587*g + 0.114*b,
-0.450*r - 0.883*g + 1.333*b,
-1.333*r + 1.116*g + 0.217*b
];
};
/**
* To YUV
*/
yuv.ydbdr = function (yuv) {
return [
yuv[0], 3.059*yuv[1], -2.169*yuv[2]
]
};
/**
* From YUV
*/
ydbdr.yuv = function (ydbdr) {
return [
ydbdr[0], ydbdr[1] / 3.059, -ydbdr[2] / 2.169
]
};
export default /** @type {import('./index.js').ColorSpace} */ (ydbdr);