-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcmyk-to-rgb.js
71 lines (65 loc) · 1.98 KB
/
cmyk-to-rgb.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
/* Adapted from pdf.js's colorspace module
(https://github.com/mozilla/pdf.js/blob/a18290759227c894f8f97f58c8da8ce942f5a38f/src/core/colorspace.js)
Released under the Apache 2.0 license:
https://github.com/mozilla/pdf.js/blob/master/LICENSE
*/
/**
*
* @param {[number,number,number,number]} src CMYK values (0-100)
* @returns {Uint8ClampedArray} RGB values (0-255)
*/
module.exports = function convertToRgb(src) {
const toFraction = 1 / 100
const rgb = new Uint8ClampedArray(3)
const c = src[0] * toFraction
const m = src[1] * toFraction
const y = src[2] * toFraction
const k = src[3] * toFraction
rgb[0] =
255 +
c *
(-4.387332384609988 * c +
54.48615194189176 * m +
18.82290502165302 * y +
212.25662451639585 * k +
-285.2331026137004) +
m *
(1.7149763477362134 * m -
5.6096736904047315 * y +
-17.873870861415444 * k -
5.497006427196366) +
y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) +
k * (-21.86122147463605 * k - 189.48180835922747)
rgb[1] =
255 +
c *
(8.841041422036149 * c +
60.118027045597366 * m +
6.871425592049007 * y +
31.159100130055922 * k +
-79.2970844816548) +
m *
(-15.310361306967817 * m +
17.575251261109482 * y +
131.35250912493976 * k -
190.9453302588951) +
y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
k * (-20.737325471181034 * k - 187.80453709719578)
rgb[2] =
255 +
c *
(0.8842522430003296 * c +
8.078677503112928 * m +
30.89978309703729 * y -
0.23883238689178934 * k +
-14.183576799673286) +
m *
(10.49593273432072 * m +
63.02378494754052 * y +
50.606957656360734 * k -
112.23884253719248) +
y *
(0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) +
k * (-22.33816807309886 * k - 180.12613974708367)
return rgb
}