Debian Codegraph @

DisplayCAL/report/jsapi-patches.js

raw
1 function sortNumber(a, b) {
2 return a - b;
3 };
4 jsapi.array.flat = function(a) {
5 var r = [];
6 for (var i = 0; i < a.length; i ++) {
7 if (a[i] != null && a[i].constructor == Array) r = r.concat(jsapi.array.flat(a[i]));
8 else r.push(a[i])
9 };
10 return r
11 };
12 jsapi.array.flat._args = [Array];
13 jsapi.math.median = function () {
14 // http://en.wikipedia.org/wiki/Median
15 var a = jsapi.array.flat(arguments), median,
16 sorted = a.sort(sortNumber), half = sorted.length / 2;
17 if (sorted.length % 2 == 0) median = (sorted[half - 1] + sorted[half]) / 2;
18 else median = sorted[Math.floor(half)];
19 return median
20 };
21 jsapi.math.mad = function () {
22 // http://en.wikipedia.org/wiki/Median_absolute_deviation
23 var a = jsapi.array.flat(arguments), median = jsapi.math.median(a),
24 sorted = a.sort(sortNumber);
25 for (var i = 0; i < sorted.length; i++)
26 sorted[i] = Math.abs(sorted[i] - median);
27 return jsapi.math.median(sorted);
28 };
29 jsapi.math.percentile = function (a, n) {
30 // n is assumed to be scaled to 0..1 range without bounds
31 if (a.length === 0) return 0;
32
33 a = jsapi.array.flat(a);
34
35 // Sort numbers ascending
36 a.sort(function (a, b) { return a - b; });
37
38 if (n <= 0) return a[0];
39 if (n >= 1) return a[a.length - 1];
40
41 var index = (a.length - 1) * n, lower = Math.floor(index),
42 upper = lower + 1, weight = index % 1;
43
44 if (upper >= a.length) return a[lower];
45 return a[lower] * (1 - weight) + a[upper] * weight;
46 };
47 jsapi.math.stddev = function () {
48 // http://en.wikipedia.org/wiki/Standard_deviation
49 // http://jsfromhell.com/array/average
50 return Math.sqrt(jsapi.math.variance(jsapi.array.flat(arguments)));
51 };
52 jsapi.math.variance = function () {
53 // http://jsfromhell.com/array/average
54 var a = jsapi.array.flat(arguments);
55 for (var m, s = 0, l = a.length; l--; s += a[l]);
56 for (m = s / a.length, l = a.length, s = 0; l--; s += Math.pow(a[l] - m, 2));
57 return s / a.length;
58 };
59 jsapi.math.color.adapt = function (XS, YS, ZS, whitepoint_source, whitepoint_destination, MA) {
60 // chromatic adaption
61 // based on formula http://brucelindbloom.com/Eqn_ChromAdapt.html
62 // MA = adaption matrix or predefined choice (e.g. 'CAT02', 'Bradford', 'HPE D65', 'XYZ scaling'),
63 // defaults to 'Bradford'
64 if (!MA) MA = 'Bradford';
65 if (typeof MA == 'string')
66 MA = jsapi.math.color.cat_matrices[MA] || jsapi.math.color.cat_matrices['Bradford'];
67 else if (MA.constructor != jsapi.math.Matrix3x3) MA = new jsapi.math.Matrix3x3(MA);
68 var XYZWS = jsapi.math.color.get_whitepoint(whitepoint_source),
69 pybs = MA.multiply(XYZWS),
70 XYZWD = jsapi.math.color.get_whitepoint(whitepoint_destination),
71 pybd = MA.multiply(XYZWD);
72 return MA.invert().multiply([[pybd[0]/pybs[0], 0, 0], [0, pybd[1]/pybs[1], 0], [0, 0, pybd[2]/pybs[2]]]).multiply(MA).multiply([XS, YS, ZS]);
73 };
74 jsapi.math.color.Lab2RGB = function (L, a, b, whitepoint, whitepoint_source, scale, round_, cat, clamp) {
75 var XYZ = jsapi.math.color.Lab2XYZ(L, a, b, whitepoint);
76 if (whitepoint != 'D50') XYZ = jsapi.math.color.adapt(XYZ[0], XYZ[1], XYZ[2], whitepoint, "D65", cat);
77 return jsapi.math.color.XYZ2RGB(XYZ[0], XYZ[1], XYZ[2], "D65", scale, round_, clamp)
78 };
79 jsapi.math.color.Lab2XYZ = function(L, a, b, whitepoint, scale) {
80 // based on http://www.easyrgb.com/math.php?MATH=M8
81 // whitepoint can be a color temperature in Kelvin or an array containing XYZ values
82 if (!scale) scale = 1.0;
83
84 var Y = ( L + 16 ) / 116,
85 X = a / 500 + Y,
86 Z = Y - b / 200;
87
88 // Bruce Lindbloom's fix for the discontinuity of the CIE L* function
89 // (http://brucelindbloom.com/LContinuity.html)
90 var E = 216 / 24389, // Intent of CIE standard, actual CIE standard = 0.008856
91 K = 24389 / 27; // Intent of CIE standard, actual CIE standard = 903.3
92 // K / 116 is used instead of 7.787
93
94 if ( Math.pow(Y, 3) > E ) Y = Math.pow(Y, 3);
95 else Y = ( Y - 16 / 116 ) / (K / 116);
96 if ( Math.pow(X, 3) > E ) X = Math.pow(X, 3);
97 else X = ( X - 16 / 116 ) / (K / 116);
98 if ( Math.pow(Z, 3) > E ) Z = Math.pow(Z, 3);
99 else Z = ( Z - 16 / 116 ) / (K / 116);
100
101 var ref_XYZ = jsapi.math.color.get_whitepoint(whitepoint, scale);
102 X *= ref_XYZ[0];
103 Y *= ref_XYZ[1];
104 Z *= ref_XYZ[2];
105
106 return [X, Y, Z]
107 };
108 jsapi.math.color.LinearRec2020RGB2ICtCp = function(R, G, B, oetf) {
109 // http://www.dolby.com/us/en/technologies/dolby-vision/ICtCp-white-paper.pdf
110 if (!oetf) oetf = jsapi.math.color.SMPTE2084_OETF;
111 var LMS, L_M_S_, ICtCp;
112 LMS = jsapi.math.color.LinearRec2020RGB2LMS_matrix.multiply([R, G, B]);
113 L_M_S_ = [];
114 for (var i = 0; i < 3; i ++) L_M_S_[i] = oetf(LMS[i]);
115 ICtCp = jsapi.math.color.L_M_S_2ICtCp_matrix.multiply(L_M_S_);
116 return ICtCp;
117 };
118 jsapi.math.color.SMPTE2084_M1 = (2610.0 / 4096) * .25;
119 jsapi.math.color.SMPTE2084_M2 = (2523.0 / 4096) * 128;
120 jsapi.math.color.SMPTE2084_C1 = (3424.0 / 4096);
121 jsapi.math.color.SMPTE2084_C2 = (2413.0 / 4096) * 32;
122 jsapi.math.color.SMPTE2084_C3 = (2392.0 / 4096) * 32;
123 jsapi.math.color.SMPTE2084_EOTF = function (v) {
124 return Math.pow(Math.max(Math.pow(v, (1.0 / jsapi.math.color.SMPTE2084_M2)) - jsapi.math.color.SMPTE2084_C1, 0) /
125 (jsapi.math.color.SMPTE2084_C2 - jsapi.math.color.SMPTE2084_C3 * Math.pow(v, (1.0 / jsapi.math.color.SMPTE2084_M2))), (1.0 / jsapi.math.color.SMPTE2084_M1));
126 };
127 jsapi.math.color.SMPTE2084_OETF = function (v) {
128 return Math.pow((2413.0 * Math.pow(v, jsapi.math.color.SMPTE2084_M1) + 107) /
129 (2392.0 * Math.pow(v, jsapi.math.color.SMPTE2084_M1) + 128), jsapi.math.color.SMPTE2084_M2);
130 };
131 jsapi.math.color.XYZ2ICtCp = function (X, Y, Z, oetf) {
132 LinearRec2020RGB = jsapi.math.color.xyz_to_rgb_matrix(0.708, 0.292, 0.17, 0.797, 0.131, 0.046, "D65", 1.0).multiply([X, Y, Z]);
133 return jsapi.math.color.LinearRec2020RGB2ICtCp(LinearRec2020RGB[0], LinearRec2020RGB[1], LinearRec2020RGB[2], oetf || jsapi.math.color.SMPTE2084_OETF);
134 };
135 jsapi.math.color.XYZ2RGB = function (X, Y, Z, whitepoint, scale, round_, clamp) {
136 if (!scale) scale = 1.0;
137
138 var RGB = jsapi.math.color.xyz_to_rgb_matrix(0.6400, 0.3300, 0.3000, 0.6000, 0.1500, 0.0600, whitepoint || "D65", 1.0).multiply([X, Y, Z]); // sRGB
139
140 for (var i = 0; i < 3; i ++) {
141 if (RGB[i] > 0.0031308) {
142 RGB[i] = 1.055 * Math.pow(RGB[i], 1 / 2.4) - 0.055;
143 } else {
144 RGB[i] *= 12.92;
145 }
146 if (clamp == undefined || !!clamp)
147 RGB[i] = Math.min(1.0, Math.max(0, RGB[i]));
148 RGB[i] *= scale;
149 if (round_) RGB[i] = Math.round(RGB[i]);
150 }
151 return RGB;
152 };
153 jsapi.math.color.CIEDCorColorTemp2XYZ = function(T, scale) {
154 var xyY = jsapi.math.color.CIEDCorColorTemp2xyY(T, scale);
155 return jsapi.math.color.xyY2XYZ(xyY[0], xyY[1], xyY[2]);
156 };
157 jsapi.math.color.CIEDCorColorTemp2xyY = function(T, scale) {
158 // Based on formula from http://brucelindbloom.com/Eqn_T_to_xy.html
159 if (!scale) scale = 1.0;
160 if (typeof T == "string") {
161 // Assume standard illuminant, e.g. "D50"
162 var illuminant = jsapi.math.color.get_standard_illuminant(T, null, scale);
163 return jsapi.math.color.XYZ2xyY(illuminant[0], illuminant[1], illuminant[2]);
164 }
165 // Lower limit of 2500 is consistent with Argyll xicc/xspect.c daylight_il
166 // Actual usable lower limit lies at roughly 2244
167 // Only accurate down to about 4000
168 var xD = 2500 <= T && T <= 7000
169 ? ((-4.607 * Math.pow(10, 9)) / Math.pow(T, 3))
170 + ((2.9678 * Math.pow(10, 6)) / Math.pow(T, 2))
171 + ((0.09911 * Math.pow(10, 3)) / T)
172 + 0.244063
173 : (7000 < T && T <= 25000
174 ? ((-2.0064 * Math.pow(10, 9)) / Math.pow(T, 3))
175 + ((1.9018 * Math.pow(10, 6)) / Math.pow(T, 2))
176 + ((0.24748 * Math.pow(10, 3)) / T)
177 + 0.237040
178 : null),
179 yD = xD != null ? -3 * Math.pow(xD, 2) + 2.87 * xD - 0.275 : null;
180 return xD == null ? null : [xD, yD, scale];
181 };
182 jsapi.math.color.CMYK2RGB = function(C, M, Y, K, scale, round_) {
183 // http://www.easyrgb.com/math.php?MATH=M14
184 if (!scale) scale = 1.0;
185 C = ( C * ( 1 - K ) + K );
186 M = ( M * ( 1 - K ) + K );
187 Y = ( Y * ( 1 - K ) + K );
188 // http://www.easyrgb.com/math.php?MATH=M12
189 var R, G, B;
190 R = ( 1 - C ) * scale;
191 G = ( 1 - M ) * scale;
192 B = ( 1 - Y ) * scale;
193 if (round_) {
194 R = Math.round(R);
195 G = Math.round(G);
196 B = Math.round(B);
197 }
198 return [R, G, B];
199 };
200 jsapi.math.color.XYZ2Lab = function(X, Y, Z, whitepoint) {
201 /*
202 Convert from XYZ to Lab.
203
204 The input Y value needs to be in the nominal range [0.0, 100.0] and
205 other input values scaled accordingly.
206 The output L value is in the nominal range [0.0, 100.0].
207
208 whitepoint can be string (e.g. "D50"), list/tuple of XYZ coordinates or
209 color temperature as float or int. Defaults to D50 if not set.
210
211 Based on formula from http://brucelindbloom.com/Eqn_XYZ_to_Lab.html
212
213 */
214 whitepoint = jsapi.math.color.get_whitepoint(whitepoint, 100);
215
216 var E = 216 / 24389, // Intent of CIE standard, actual CIE standard = 0.008856
217 K = 24389 / 27, // Intent of CIE standard, actual CIE standard = 903.3
218 xr = X / whitepoint[0],
219 yr = Y / whitepoint[1],
220 zr = Z / whitepoint[2],
221 fx = xr > E ? jsapi.math.cbrt(xr) : (K * xr + 16) / 116,
222 fy = yr > E ? jsapi.math.cbrt(yr) : (K * yr + 16) / 116,
223 fz = zr > E ? jsapi.math.cbrt(zr) : (K * zr + 16) / 116,
224 L = 116 * fy - 16,
225 a = 500 * (fx - fy),
226 b = 200 * (fy - fz);
227
228 return [L, a, b];
229 };
230 jsapi.math.color.XYZ2Lu_v_ = function(X, Y, Z, whitepoint) {
231 /* Convert from XYZ to CIE Lu'v' */
232
233 if (X + Y + Z == 0) {
234 // We can't check for X == Y == Z == 0 because they may actually add up
235 // to 0, thus resulting in ZeroDivisionError later
236 var XYZ = jsapi.math.color.get_whitepoint(whitepoint),
237 Lu_v_ = jsapi.math.color.XYZ2Lu_v_(XYZ[0], XYZ[1], XYZ[2]);
238 return [0, Lu_v_[1], Lu_v_[2]];
239 }
240
241 var XYZr = jsapi.math.color.get_whitepoint(whitepoint, 100),
242 yr = Y / XYZr[1],
243 L = yr > 216 / 24389 ? 116 * jsapi.math.cbrt(yr) - 16 : 24389 / 27 * yr,
244 u_ = (4 * X) / (X + 15 * Y + 3 * Z),
245 v_ = (9 * Y) / (X + 15 * Y + 3 * Z);
246
247 return [L, u_, v_];
248 };
249 jsapi.math.color.xyY2XYZ = function(x, y, Y) {
250 /*
251 Convert from xyY to XYZ.
252
253 Based on formula from http://brucelindbloom.com/Eqn_xyY_to_XYZ.html
254
255 Implementation Notes:
256 1. Watch out for the case where y = 0. In that case, X = Y = Z = 0 is
257 returned.
258 2. The output XYZ values are in the nominal range [0.0, Y[xyY]].
259
260 */
261 if (y == 0) return [0, 0, 0];
262 if (Y == null) Y = 1.0;
263 var X = (x * Y) / y,
264 Z = (1 - x - y) * Y / y;
265 return [X, Y, Z];
266 };
267 jsapi.math.color.XYZ2xyY = function (X, Y, Z, whitepoint) {
268 /*
269 Convert from XYZ to xyY.
270
271 Based on formula from http://brucelindbloom.com/Eqn_XYZ_to_xyY.html
272
273 Implementation Notes:
274 1. Watch out for black, where X = Y = Z = 0. In that case, x and y are set
275 to the chromaticity coordinates of the reference whitepoint.
276 2. The output Y value is in the nominal range [0.0, Y[XYZ]].
277
278 */
279 if (X == Y && Y == Z && Z == 0) {
280 whitepoint = jsapi.math.color.get_whitepoint(whitepoint);
281 var xyY = jsapi.math.color.XYZ2xyY(whitepoint[0], whitepoint[1], whitepoint[2]);
282 return [xyY[0], xyY[1], 0.0];
283 }
284 var x = X / (X + Y + Z),
285 y = Y / (X + Y + Z);
286 return [x, y, Y];
287 };
288 jsapi.math.color.planckianCT2XYZ = function(T) {
289 var xyY = jsapi.math.color.planckianCT2xyY(T);
290 return jsapi.math.color.xyY2XYZ(xyY[0], xyY[1], xyY[2]);
291 };
292 jsapi.math.color.planckianCT2xyY = function (T) {
293 /* Convert from planckian temperature to xyY.
294
295 T = temperature in Kelvin.
296
297 Formula from http://en.wikipedia.org/wiki/Planckian_locus
298
299 */
300 var x, y;
301 if (1667 <= T && T <= 4000)
302 x = ( -0.2661239 * (Math.pow(10, 9) / Math.pow(T, 3))
303 - 0.2343580 * (Math.pow(10, 6) / Math.pow(T, 2))
304 + 0.8776956 * (Math.pow(10, 3) / T)
305 + 0.179910);
306 else if (4000 <= T && T <= 25000)
307 x = ( -3.0258469 * (Math.pow(10, 9) / Math.pow(T, 3))
308 + 2.1070379 * (Math.pow(10, 6) / Math.pow(T, 2))
309 + 0.2226347 * (Math.pow(10, 3) / T)
310 + 0.24039);
311 else return null;
312 if (1667 <= T && T <= 2222)
313 y = ( -1.1063814 * Math.pow(x, 3)
314 - 1.34811020 * Math.pow(x, 2)
315 + 2.18555832 * x
316 - 0.20219683);
317 else if (2222 <= T && T <= 4000)
318 y = ( -0.9549476 * Math.pow(x, 3)
319 - 1.37418593 * Math.pow(x, 2)
320 + 2.09137015 * x
321 - 0.16748867);
322 else if (4000 <= T && T <= 25000)
323 y = ( 3.0817580 * Math.pow(x, 3)
324 - 5.87338670 * Math.pow(x, 2)
325 + 3.75112997 * x
326 - 0.37001483);
327 return [x, y, 1.0]
328 };
329 jsapi.math.color.xyz_to_rgb_matrix = function (xr, yr, xg, yg, xb, yb, whitepoint, scale) {
330 // Create and return an XYZ to RGB matrix
331 if (!scale) scale = 1.0;
332 var cachehash = [xr, yr, xg, yg, xb, yb, whitepoint, scale].join(","),
333 cache = jsapi.math.color.xyz_to_rgb_matrix.cache[cachehash];
334 if (cache) return cache;
335 whitepoint = jsapi.math.color.get_whitepoint(whitepoint, scale);
336 var XYZr = jsapi.math.color.xyY2XYZ(xr, yr, scale),
337 XYZg = jsapi.math.color.xyY2XYZ(xg, yg, scale),
338 XYZb = jsapi.math.color.xyY2XYZ(xb, yb, scale),
339 SrSgSb = new jsapi.math.Matrix3x3([[XYZr[0], XYZg[0], XYZb[0]],
340 [XYZr[1], XYZg[1], XYZb[1]],
341 [XYZr[2], XYZg[2], XYZb[2]]]).invert().multiply(whitepoint);
342 return jsapi.math.color.xyz_to_rgb_matrix.cache[cachehash] =
343 new jsapi.math.Matrix3x3([[SrSgSb[0] * XYZr[0], SrSgSb[1] * XYZg[0], SrSgSb[2] * XYZb[0]],
344 [SrSgSb[0] * XYZr[1], SrSgSb[1] * XYZg[1], SrSgSb[2] * XYZb[1]],
345 [SrSgSb[0] * XYZr[2], SrSgSb[1] * XYZg[2], SrSgSb[2] * XYZb[2]]]).invert();
346 };
347 jsapi.math.color.xyz_to_rgb_matrix.cache = {};
348 jsapi.math.color.standard_illuminants = {
349 // 1st level is the standard name => illuminant definitions
350 // 2nd level is the illuminant name => CIE XYZ coordinates
351 // (Y should always assumed to be 1.0 and is not explicitly defined)
352 "None": {"E": {"X": 1.00000, "Z": 1.00000}},
353 "ASTM E308-01": {"A": {"X": 1.09850, "Z": 0.35585},
354 "C": {"X": 0.98074, "Z": 1.18232},
355 "D50": {"X": 0.96422, "Z": 0.82521},
356 "D55": {"X": 0.95682, "Z": 0.92149},
357 "D65": {"X": 0.95047, "Z": 1.08883},
358 "D75": {"X": 0.94972, "Z": 1.22638},
359 "F2": {"X": 0.99186, "Z": 0.67393},
360 "F7": {"X": 0.95041, "Z": 1.08747},
361 "F11": {"X": 1.00962, "Z": 0.64350}},
362 "ICC": {"D50": {"X": 0.9642, "Z": 0.8249},
363 "D65": {"X": 0.9505, "Z": 1.0890}},
364 "ISO 11664-2:2007": {"D65": {"X": jsapi.math.color.xyY2XYZ(0.3127, 0.329)[0],
365 "Z": jsapi.math.color.xyY2XYZ(0.3127, 0.329)[2]}},
366 "Wyszecki & Stiles": {"A": {"X": 1.09828, "Z": 0.35547},
367 "B": {"X": 0.99072, "Z": 0.85223},
368 "C": {"X": 0.98041, "Z": 1.18103},
369 "D55": {"X": 0.95642, "Z": 0.92085},
370 "D65": {"X": 0.95017, "Z": 1.08813},
371 "D75": {"X": 0.94939, "Z": 1.22558}}
372 };
373 jsapi.math.color.get_standard_illuminant = function (illuminant_name, priority, scale) {
374 if (!priority) priority = ["ISO 11664-2:2007", "ICC", "ASTM E308-01", "Wyszecki & Stiles", "None"];
375 if (!scale) scale = 1.0;
376 var cachehash = [illuminant_name, priority, scale].join(","),
377 cache = jsapi.math.color.get_standard_illuminant.cache[cachehash];
378 if (cache) return cache;
379 var illuminant = null;
380 for (var i = 0; i < priority.length; i ++) {
381 if (!jsapi.math.color.standard_illuminants[priority[i]])
382 throw 'Unrecognized standard "' + priority[i] + '"';
383 illuminant = jsapi.math.color.standard_illuminants[priority[i]][illuminant_name.toUpperCase()];
384 if (illuminant)
385 return jsapi.math.color.get_standard_illuminant.cache[cachehash] = [illuminant["X"] * scale, 1.0 * scale, illuminant["Z"] * scale];
386 }
387 throw 'Unrecognized illuminant "' + illuminant_name + '"';
388 };
389 jsapi.math.color.get_standard_illuminant.cache = {};
390 jsapi.math.color.get_whitepoint = function (whitepoint, scale) {
391 // Return a whitepoint as XYZ coordinates
392 if (whitepoint && whitepoint.constructor == Array)
393 return whitepoint;
394 if (!scale) scale = 1.0;
395 if (!whitepoint)
396 whitepoint = "D50";
397 var cachehash = [whitepoint, scale].join(","),
398 cache = jsapi.math.color.get_whitepoint.cache[cachehash];
399 if (cache) return cache;
400 if (typeof whitepoint == "string")
401 whitepoint = jsapi.math.color.get_standard_illuminant(whitepoint);
402 else if (typeof whitepoint == "number")
403 whitepoint = jsapi.math.color.CIEDCorColorTemp2XYZ(whitepoint);
404 if (scale > 1.0 && whitepoint[1] == 100)
405 scale = 1.0;
406 return jsapi.math.color.get_whitepoint.cache[cachehash] =
407 [whitepoint[0] * scale, whitepoint[1] * scale, whitepoint[2] * scale];
408 };
409 jsapi.math.color.get_whitepoint.cache = {};
410 jsapi.math.Matrix3x3 = function (matrix) {
411 if (matrix.length != 3)
412 throw 'Invalid number of rows for 3x3 matrix: ' + matrix.length;
413 for (var i=0; i<matrix.length; i++) {
414 if (matrix[i].length != 3)
415 throw 'Invalid number of columns for 3x3 matrix: ' + matrix[i].length;
416 this[i] = [];
417 for (var j=0; j<matrix[i].length; j++) {
418 this[i][j] = matrix[i][j];
419 }
420 };
421 this.length = matrix.length;
422 };
423 jsapi.math.Matrix3x3.prototype = {
424 add: function (matrix) {
425 return new jsapi.math.Matrix3x3([[this[0][0] + matrix[0][0],
426 this[0][1] + matrix[0][1],
427 this[0][2] + matrix[0][2]],
428 [this[1][0] + matrix[1][0],
429 this[1][1] + matrix[1][1],
430 this[1][2] + matrix[1][2]],
431 [this[2][0] + matrix[2][0],
432 this[2][1] + matrix[2][1],
433 this[2][2] + matrix[2][2]]]);
434 },
435 adjoint: function () {
436 return this.cofactors().transpose();
437
438 },
439 cofactors: function () {
440 return new jsapi.math.Matrix3x3([
441 [(this[1][1]*this[2][2] - this[1][2]*this[2][1]),
442 -1 * (this[1][0]*this[2][2] - this[1][2]*this[2][0]),
443 (this[1][0]*this[2][1] - this[1][1]*this[2][0])],
444 [-1 * (this[0][1]*this[2][2] - this[0][2]*this[2][1]),
445 (this[0][0]*this[2][2] - this[0][2]*this[2][0]),
446 -1 * (this[0][0]*this[2][1] -this[0][1]*this[2][0])],
447 [(this[0][1]*this[1][2] - this[0][2]*this[1][1]),
448 -1 * (this[0][0]*this[1][2] - this[1][0]*this[0][2]),
449 (this[0][0]*this[1][1] - this[0][1]*this[1][0])]]);
450 },
451 determinant: function () {
452 return ((this[0][0]*this[1][1]*this[2][2] +
453 this[1][0]*this[2][1]*this[0][2] +
454 this[0][1]*this[1][2]*this[2][0]) -
455 (this[2][0]*this[1][1]*this[0][2] +
456 this[1][0]*this[0][1]*this[2][2] +
457 this[2][1]*this[1][2]*this[0][0]));
458 },
459 invert: function () {
460 if (this._inverted) return this._inverted;
461 var determinant = this.determinant(),
462 matrix = this.adjoint();
463 return this._inverted = new jsapi.math.Matrix3x3([[matrix[0][0] / determinant,
464 matrix[0][1] / determinant,
465 matrix[0][2] / determinant],
466 [matrix[1][0] / determinant,
467 matrix[1][1] / determinant,
468 matrix[1][2] / determinant],
469 [matrix[2][0] / determinant,
470 matrix[2][1] / determinant,
471 matrix[2][2] / determinant]]);
472 },
473 multiply: function (matrix) {
474 if (typeof matrix[0] == "number") {
475 return [matrix[0] * this[0][0] + matrix[1] * this[0][1] + matrix[2] * this[0][2],
476 matrix[0] * this[1][0] + matrix[1] * this[1][1] + matrix[2] * this[1][2],
477 matrix[0] * this[2][0] + matrix[1] * this[2][1] + matrix[2] * this[2][2]];
478 }
479 return new jsapi.math.Matrix3x3([[this[0][0]*matrix[0][0] + this[0][1]*matrix[1][0] + this[0][2]*matrix[2][0],
480 this[0][0]*matrix[0][1] + this[0][1]*matrix[1][1] + this[0][2]*matrix[2][1],
481 this[0][0]*matrix[0][2] + this[0][1]*matrix[1][2] + this[0][2]*matrix[2][2]],
482
483 [this[1][0]*matrix[0][0] + this[1][1]*matrix[1][0] + this[1][2]*matrix[2][0],
484 this[1][0]*matrix[0][1] + this[1][1]*matrix[1][1] + this[1][2]*matrix[2][1],
485 this[1][0]*matrix[0][2] + this[1][1]*matrix[1][2] + this[1][2]*matrix[2][2]],
486
487 [this[2][0]*matrix[0][0] + this[2][1]*matrix[1][0] + this[2][2]*matrix[2][0],
488 this[2][0]*matrix[0][1] + this[2][1]*matrix[1][1] + this[2][2]*matrix[2][1],
489 this[2][0]*matrix[0][2] + this[2][1]*matrix[1][2] + this[2][2]*matrix[2][2]]]);
490 },
491 transpose: function () {
492 return new jsapi.math.Matrix3x3([[this[0][0], this[1][0], this[2][0]],
493 [this[0][1], this[1][1], this[2][1]],
494 [this[0][2], this[1][2], this[2][2]]]);
495 },
496 toString: function () {
497 var str = '[';
498 for (var i=0; i<this.length; i++) {
499 if (i > 0) str += ', ';
500 str += '[' + this[i].join(', ') + ']';
501 };
502 return str + ']';
503 }
504 };
505 jsapi.math.color.LinearRec2020RGB2LMS_matrix = new jsapi.math.Matrix3x3([[1688 / 4096., 2146 / 4096., 262 / 4096.],
506 [683 / 4096., 2951 / 4096., 462 / 4096.],
507 [99 / 4096., 309 / 4096., 3688 / 4096.]]);
508 jsapi.math.color.L_M_S_2ICtCp_matrix = new jsapi.math.Matrix3x3([[.5, .5, 0],
509 [6610 / 4096., -13613 / 4096., 7003 / 4096.],
510 [17933 / 4096., -17390 / 4096., -543 / 4096.]]);
511 jsapi.math.color.cat_matrices = {
512 'Bradford': new jsapi.math.Matrix3x3(
513 [[ 0.8951, 0.2664, -0.1614],
514 [-0.7502, 1.7135, 0.0367],
515 [ 0.0389, -0.0685, 1.0296]]
516 ),
517 'CAT02': new jsapi.math.Matrix3x3(
518 [[ 0.7328, 0.4296, -0.1624],
519 [-0.7036, 1.6975, 0.0061],
520 [ 0.0030, 0.0136, 0.9834]]
521 ),
522 // Brill & Süsstrunk modification also found in ArgyllCMS
523 'CAT02BS': new jsapi.math.Matrix3x3(
524 [[ 0.7328, 0.4296, -0.1624],
525 [-0.7036, 1.6975, 0.0061],
526 [ 0.0000, 0.0000, 1.0000]]
527 ),
528 'CAT97s': new jsapi.math.Matrix3x3(
529 [[ 0.8562, 0.3372, -0.1934],
530 [-0.8360, 1.8327, 0.0033],
531 [ 0.0357, -0.0469, 1.0112]]
532 ),
533 'CMCCAT2000': new jsapi.math.Matrix3x3(
534 [[ 0.7982, 0.3389, -0.1371],
535 [-0.5918, 1.5512, 0.0406],
536 [ 0.0008, 0.0239, 0.9753]]
537 ),
538 // Hunt-Pointer-Estevez, equal-energy illuminant
539 'HPE E': new jsapi.math.Matrix3x3(
540 [[ 0.38971, 0.68898, -0.07868],
541 [-0.22981, 1.18340, 0.04641],
542 [ 0.00000, 0.00000, 1.00000]]
543 ),
544 // Süsstrunk et al.15 optimized spectrally sharpened matrix
545 'Sharp': new jsapi.math.Matrix3x3(
546 [[ 1.2694, -0.0988, -0.1706],
547 [-0.8364, 1.8006, 0.0357],
548 [ 0.0297, -0.0315, 1.0018]]
549 ),
550 // 'Von Kries' as found on Bruce Lindbloom's site:
551 // Hunt-Pointer-Estevez normalized to D65
552 'HPE D65': new jsapi.math.Matrix3x3(
553 [[ 0.40024, 0.70760, -0.08081],
554 [-0.22630, 1.16532, 0.04570],
555 [ 0.00000, 0.00000, 0.91822]]
556 ),
557 'XYZ scaling': new jsapi.math.Matrix3x3(
558 [[1, 0, 0],
559 [0, 1, 0],
560 [0, 0, 1]]
561 ),
562 'IPT': new jsapi.math.Matrix3x3(
563 [[ 0.4002, 0.7075, -0.0807],
564 [-0.2280, 1.1500, 0.0612],
565 [ 0.0000, 0.0000, 0.9184]]
566 ),
567 // Inverse CIE 2012 2deg LMS to XYZ matrix from Argyll/icc/icc.c
568 'CIE2012_2': new jsapi.math.Matrix3x3(
569 [[ 0.2052445519046028, 0.8334486497310412, -0.0386932016356441],
570 [-0.4972221301804286, 1.4034846060306130, 0.0937375241498157],
571 [ 0.0000000000000000, 0.0000000000000000, 1.0000000000000000]]
572 ),
573 // Inverse CIE 2015 2deg LMS to XYZ matrix from Argyll/icc/icc.c
574 'CIE2012_5': new jsapi.math.Matrix3x3(
575 [[ 0.2052445519046028, 0.8334486497310412, -0.0386932016356441],
576 [-0.4972221301804286, 1.4034846060306130, 0.0937375241498157],
577 [ 0.0000000000000000, 0.0000000000000000, 1.0000000000000000]]
578 ),
579 // Bianco and Schettini (2010)
580 'BS': new jsapi.math.Matrix3x3(
581 [[ 0.8752, 0.2787, -0.1539],
582 [-0.8904, 1.8709, 0.0195],
583 [-0.0061, 0.0162, 0.9899]]
584 ),
585 // Bianco and Schettini (2010) with positivity constraint
586 'BS-PC': new jsapi.math.Matrix3x3(
587 [[ 0.6489, 0.3915, -0.0404],
588 [-0.3775, 1.3055, 0.0720],
589 [-0.0271, 0.0888, 0.9383]]
590 )
591 };