Skip to content

Commit a8eee03

Browse files
committed
checking conversion matrices
1 parent 61b11ae commit a8eee03

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

css-color-4/LCH-examples.html

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
};
3131

3232
console.log("image-p3");
33+
P3results.value += `image-p3
3334
3435
// I am a bad person
3536

css-color-4/conversions.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ function lin_sRGB_to_XYZ(rgb) {
3434
// convert an array of linear-light sRGB values to CIE XYZ
3535
// using sRGB's own white, D65 (no chromatic adaptation)
3636
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
37+
// also
38+
// https://www.image-engineering.de/library/technotes/958-how-to-convert-between-srgb-and-ciexyz
3739
var M = math.matrix([
3840
[0.4124564, 0.3575761, 0.1804375],
3941
[0.2126729, 0.7151522, 0.0721750],
@@ -54,7 +56,7 @@ function XYZ_to_lin_sRGB(XYZ) {
5456
return math.multiply(M, XYZ).valueOf();
5557
}
5658

57-
// display-p3-related functions
59+
// image-p3-related functions
5860

5961

6062
function lin_P3(RGB) {
@@ -168,10 +170,12 @@ function gam_a98rgb(RGB) {
168170

169171
function lin_a98rgb_to_XYZ(rgb) {
170172
// convert an array of linear-light a98-rgb values to CIE XYZ
171-
// using D50 (so no chromatic adaptation needed afterwards)
172173
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
173-
// which has greater numerical precsion than section 4.3.5.3 of
174+
// has greater numerical precsion than section 4.3.5.3 of
174175
// https://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf
176+
// but the vaues below were calculated from first principles
177+
// from the chromaticity coordinates of R G B W
178+
// see matrixmaker.html
175179
var M = math.matrix([
176180
[ 0.5766690429101305, 0.1855582379065463, 0.1882286462349947 ],
177181
[ 0.29734497525053605, 0.6273635662554661, 0.07529145849399788 ],

css-color-4/images/P3-prim-sec.svg

+11-7
Loading

css-color-4/matrixmaker.html

+20-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@
2222
// const xblue=0.131 ;
2323
// const yblue=0.046 ;
2424

25+
// these are for sRGB
26+
const xred=0.640 ;
27+
const yred=0.330 ;
28+
29+
const xgreen=0.300 ;
30+
const ygreen=0.600 ;
31+
32+
const xblue=0.150 ;
33+
const yblue=0.060 ;
2534

26-
// these are for DCI P3
35+
// these are for image-p3
2736
// const xred=0.680 ;
2837
// const yred=0.320 ;
2938

@@ -45,14 +54,14 @@
4554

4655
// AdobeRGB, for testing
4756

48-
const xred=0.640 ;
49-
const yred=0.330 ;
57+
// const xred=0.640 ;
58+
// const yred=0.330 ;
5059

51-
const xgreen=0.210 ;
52-
const ygreen=0.710 ;
60+
// const xgreen=0.210 ;
61+
// const ygreen=0.710 ;
5362

54-
const xblue=0.150 ;
55-
const yblue=0.060 ;
63+
// const xblue=0.150 ;
64+
// const yblue=0.060 ;
5665

5766

5867
// D65
@@ -65,6 +74,7 @@
6574

6675

6776
// Relative XYZ values. Copy-paste-o-rama
77+
// method from http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
6878
var XWhite=xwhite/ywhite;
6979
var YWhite=1;
7080
var ZWhite=(1 - xwhite - ywhite)/ywhite;
@@ -82,20 +92,22 @@
8292
var ZBlue=(1 - xblue - yblue)/yblue;
8393

8494
var white = math.matrix([XWhite, YWhite, ZWhite]);
95+
console.log("White X Y Z")
8596
console.log(white.valueOf());
8697
var primaries = math.matrix([
8798
[XRed, XGreen, XBlue],
8899
[YRed, YGreen, YBlue],
89100
[ZRed, ZGreen, ZBlue]
90101
]);
102+
console.log("Primaries X Y Z")
91103
console.log(primaries.valueOf());
92104

93105
var iprimaries = math.inv(primaries);
94106
console.log(iprimaries.valueOf());
95107

96108
// S is easier if it ends up as an array than a matrix
97109
// but we use matrix math to calculate it
98-
var S = math.multiply(math.inv(primaries),white).valueOf();
110+
var S = math.multiply(iprimaries,white).valueOf();
99111

100112
var M = [
101113
[S[0] * XRed, S[1] * XGreen, S[2] * XBlue],

0 commit comments

Comments
 (0)