Skip to content

Commit 2180747

Browse files
committed
[css-color] rec2020 matrices
1 parent d6f8026 commit 2180747

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

css-color/conversions.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,26 @@ function gam_2020(RGB) {
8383
});
8484
}
8585

86-
function lin_sRGB_to_XYZ(rgb) {
87-
// convert an array of linear-light sRGB values to CIE XYZ
88-
// using sRGB's own white, D65 (no chromatic adaptation)
86+
function lin_2020_to_XYZ(rgb) {
87+
// convert an array of linear-light rec.2020 values to CIE XYZ
88+
// using D65 (no chromatic adaptation)
8989
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
9090
var M = math.matrix([
91-
[ // calculate per Libdbloom
91+
[0.6369580483012914, 0.14461690358620832, 0.1688809751641721],
92+
[0.2627002120112671, 0.6779980715188708, 0.05930171646986196],
93+
[0.000000000000000, 0.028072693049087428, 1.060985057710791]
9294
]);
95+
// 0 is actually calculated as 4.994106574466076e-17
9396

9497
return math.multiply(M, rgb).valueOf();
9598
}
9699

97-
function XYZ_to_lin_sRGB(XYZ) {
98-
// convert XYZ to linear-light sRGB
100+
function XYZ_to_lin_2020(XYZ) {
101+
// convert XYZ to linear-light rec.2020
99102
var M = math.matrix([
100-
[ // calculate per Libdbloom
103+
[1.7166511879712674, -0.35567078377639233, -0.25336628137365974],
104+
[-0.6666843518324892, 1.6164812366349395, 0.01576854581391113],
105+
[0.017639857445310783, -0.042770613257808524, 0.9421031212354738]
101106
]);
102107

103108
return math.multiply(M, XYZ).valueOf();

css-color/matrixmaker.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
// these are for ITU Rec BT.2020
16-
/*
16+
1717
const xred=0.708 ;
1818
const yred=0.292 ;
1919

@@ -22,9 +22,10 @@
2222

2323
const xblue=0.131 ;
2424
const yblue=0.046 ;
25-
*/
25+
2626

2727
// AdobeRGB, for testing
28+
/*
2829
const xred=0.640 ;
2930
const yred=0.330 ;
3031
@@ -33,6 +34,7 @@
3334
3435
const xblue=0.150 ;
3536
const yblue=0.060 ;
37+
*/
3638

3739
// D65
3840
const xwhite=0.3127 ;

0 commit comments

Comments
 (0)