Skip to content

Commit 928af8f

Browse files
committed
add prophoto to matrixmaker code
1 parent 7582b3d commit 928af8f

File tree

1 file changed

+46
-32
lines changed

1 file changed

+46
-32
lines changed

css-color-4/matrixmaker.html

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<html>
22
<script src="math.js"></script>
33
<script>
4-
4+
55
// Make matrices for converting to and from an arbitrary RGB colorspace,
66
// given the x,y chromaticities of red, green, blue and white.
7-
// To use these matrices, the RGB components are assumed be be
7+
// To use these matrices, the RGB components are assumed be be
88
// linearized and in the range 0 to 1.
99
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
1010

@@ -13,61 +13,75 @@
1313

1414

1515
// these are for ITU Rec BT.2020
16-
/*
16+
/*
1717
const xred=0.708 ;
1818
const yred=0.292 ;
19-
19+
2020
const xgreen=0.170 ;
2121
const ygreen=0.797 ;
22-
22+
2323
const xblue=0.131 ;
2424
const yblue=0.046 ;
2525
*/
26-
26+
2727
// these are for DCI P3
28-
const xred=0.680 ;
29-
const yred=0.320 ;
30-
31-
const xgreen=0.265 ;
32-
const ygreen=0.690 ;
33-
34-
const xblue=0.150 ;
35-
const yblue=0.060 ;
36-
28+
// const xred=0.680 ;
29+
// const yred=0.320 ;
30+
31+
// const xgreen=0.265 ;
32+
// const ygreen=0.690 ;
33+
34+
// const xblue=0.150 ;
35+
// const yblue=0.060 ;
36+
37+
// ProPhoto
38+
const xred=0.7347 ;
39+
const yred=0.2653 ;
40+
41+
const xgreen=0.1596 ;
42+
const ygreen=0.8404 ;
43+
44+
const xblue=0.0366 ;
45+
const yblue=0.0001 ;
46+
3747
// AdobeRGB, for testing
3848
/*
3949
const xred=0.640 ;
4050
const yred=0.330 ;
41-
51+
4252
const xgreen=0.210 ;
4353
const ygreen=0.710 ;
44-
54+
4555
const xblue=0.150 ;
4656
const yblue=0.060 ;
4757
*/
48-
58+
4959
// D65
50-
const xwhite=0.3127 ;
51-
const ywhite=0.3290 ;
52-
53-
60+
// const xwhite=0.3127 ;
61+
// const ywhite=0.3290 ;
62+
63+
// D50
64+
const xwhite=0.3457 ;
65+
const ywhite=0.3585 ;
66+
67+
5468
// Relative XYZ values. Copy-paste-o-rama
5569
var XWhite=xwhite/ywhite;
5670
var YWhite=1;
5771
var ZWhite=(1 - xwhite - ywhite)/ywhite;
58-
72+
5973
var XRed=xred/yred;
6074
var YRed=1;
6175
var ZRed=(1 - xred - yred)/yred;
62-
76+
6377
var XGreen=xgreen/ygreen;
6478
var YGreen=1;
6579
var ZGreen=(1 - xgreen - ygreen)/ygreen;
66-
80+
6781
var XBlue=xblue/yblue;
6882
var YBlue=1;
6983
var ZBlue=(1 - xblue - yblue)/yblue;
70-
84+
7185
var white = math.matrix([XWhite, YWhite, ZWhite]);
7286
console.log(white.valueOf());
7387
var primaries = math.matrix([
@@ -76,27 +90,27 @@
7690
[ZRed, ZGreen, ZBlue]
7791
]);
7892
console.log(primaries.valueOf());
79-
93+
8094
var iprimaries = math.inv(primaries);
8195
console.log(iprimaries.valueOf());
82-
96+
8397
// S is easier if it ends up as an array than a matrix
8498
// but we use matrix math to calculate it
8599
var S = math.multiply(math.inv(primaries),white).valueOf();
86-
100+
87101
var M = [
88102
[S[0] * XRed, S[1] * XGreen, S[2] * XBlue],
89103
[S[0] * YRed, S[1] * YGreen, S[2] * YBlue],
90104
[S[0] * ZRed, S[1] * ZGreen, S[2] * ZBlue]
91105
];
92-
106+
93107
console.log("RGB to XYZ");
94108
console.log(M);
95109
console.log("XYZ to RGB");
96110
console.log(math.inv(math.matrix(M)).valueOf());
97-
111+
98112
// for code verification: with AdobeRGB primaries, correct result is
99-
// M =
113+
// M =
100114
// [[0.5767309 0.1855540 0.1881852],
101115
// [0.2973769 0.6273491 0.0752741],
102116
// [0.0270343 0.0706872 0.9911085]];

0 commit comments

Comments
 (0)