Skip to content

Commit 8f691f3

Browse files
committed
[css-color-4] Correct sRGB matrices, see w3c#5922
1 parent dc337ab commit 8f691f3

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

css-color-4/conversions.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,28 @@ function gam_sRGB(RGB) {
4242
function lin_sRGB_to_XYZ(rgb) {
4343
// convert an array of linear-light sRGB values to CIE XYZ
4444
// using sRGB's own white, D65 (no chromatic adaptation)
45-
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
46-
// also
47-
// https://www.image-engineering.de/library/technotes/958-how-to-convert-between-srgb-and-ciexyz
45+
4846
var M = [
49-
[0.4124564, 0.3575761, 0.1804375],
50-
[0.2126729, 0.7151522, 0.0721750],
51-
[0.0193339, 0.1191920, 0.9503041]
47+
[ 0.41239079926595934, 0.357584339383878, 0.1804807884018343 ],
48+
[ 0.21263900587151027, 0.715168678767756, 0.07219231536073371 ],
49+
[ 0.01933081871559182, 0.11919477979462598, 0.9505321522496607 ]
5250
];
53-
5451
return multiplyMatrices(M, rgb);
5552
}
5653

5754
function XYZ_to_lin_sRGB(XYZ) {
5855
// convert XYZ to linear-light sRGB
56+
5957
var M = [
60-
[ 3.2404542, -1.5371385, -0.4985314],
61-
[-0.9692660, 1.8760108, 0.0415560],
62-
[ 0.0556434, -0.2040259, 1.0572252]
58+
[ 3.2409699419045226, -1.537383177570094, -0.4986107602930034 ],
59+
[ -0.9692436362808796, 1.8759675015077202, 0.04155505740717559 ],
60+
[ 0.05563007969699366, -0.20397695888897652, 1.0569715142428786 ]
6361
];
6462

6563
return multiplyMatrices(M, XYZ);
6664
}
6765

68-
// image-p3-related functions
66+
// display-p3-related functions
6967

7068

7169
function lin_P3(RGB) {

css-color-4/matrixmaker.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<html>
22
<script src="math.js"></script>
3-
<script> src="multiply-matrices.js"></script>
3+
<script src="multiply-matrices.js"></script>
44
<script>
55

66
// Make matrices for converting to and from an arbitrary RGB colorspace,
@@ -33,7 +33,7 @@
3333
const xblue=0.150 ;
3434
const yblue=0.060 ;
3535

36-
// these are for image-p3
36+
// these are for display-p3
3737
// const xred=0.680 ;
3838
// const yred=0.320 ;
3939

0 commit comments

Comments
 (0)