Debian Codegraph @

DisplayCAL/report/compare.functions.js

raw
1 var p;
2 var debug = window.location.href.indexOf("?debug") > -1,
3 get_gammaRGB = window.location.hash.indexOf("get_gammaRGB") > -1;
4
5 // Array methods
6 p=Array.prototype;
7 p.indexof = function(v, ignore_case) {
8 for (var i=0; i<this.length; i++) if (ignore_case?(this[i]+"").toUpperCase()==(v+"").toUpperCase():this[i]==v) return i;
9 return -1
10 };
11 if (!p.indexOf) p.indexOf = p.indexof;
12
13 // Object methods
14 p=Object.prototype;
15 p.clone = function() {
16 var o = new this.constructor();
17 for (var i in this) {
18 if (this[i] != null && (this[i].constructor == Array || this[i].constructor == Object)) o[i] = this[i].clone();
19 else o[i] = this[i]
20 };
21 return o
22 };
23
24 // Number methods
25 p=Number.prototype;
26 p.accuracy = function(ln) {
27 var n = Math.pow(10, ln || 0);
28 return Math.round(this * n) / n
29 };
30 p.fill=function(ipart, fpart) {
31 var i, v=(fpart!=null?this.toFixed(fpart):this+"");
32 if ((i = v.indexOf(".")) > -1) ipart+=v.substr(i).length;
33 while (v.length<ipart) v=0+v;
34 return v
35 };
36 p.lead=function(ln) {
37 var v=this+"";
38 while (v.length<ln+1) v=0+v;
39 return v
40 };
41
42 // String methods
43 p=String.prototype;
44 p.accuracy = function() {
45 return this
46 };
47 p.repeat = function(n) {
48 var str="";
49 for (var i=0; i<n; i++) str+=this;
50 return str
51 };
52
53 // dataset Constructor
54 function dataset(src) {
55 this.header = [];
56 this.data_format = [];
57 this.data = [];
58 this.decimal = ".";
59 this.id = "RGB";
60 var e = document.forms['F_data'].elements;
61 this.testchart = e['FF_testchart'].value;
62 //this.id = window.CRITERIA_GRAYSCALE ? 'RGB_GRAY' : splitext(basename(this.testchart))[0].toUpperCase();
63 this.id = splitext(basename(this.testchart))[0].toUpperCase();
64 if (src) {
65 this.src = src;
66 src=cr2lf(src);
67 var _data_format_regexp = /(^|\s)BEGIN_DATA_FORMAT\s+(.*)\s+END_DATA_FORMAT(\s|$)/i,
68 _data_regexp1 = /(^|\s)BEGIN_DATA\s+/i,
69 _data_regexp2 = /\sEND_DATA(\s|$)/i,
70 _header_regexp1 = /(^|\s)BEGIN_(\w+)\s+([\s\S]*)\s+END_\2(\s|$)/gi,
71 _header_regexp2 = /(^|\s)BEGIN_(\w+)\s+([\s\S]*)\s+END_\2(\s|$)/i,
72 data_begin,
73 data_end,
74 data_format = src.match(_data_format_regexp),
75 i,v;
76 if (data_format && data_format[2]) {
77 this.data_format = toarray(data_format[2], 1);
78 while ((data_begin = src.search(_data_regexp1))>-1 && (data_end = src.search(_data_regexp2))>data_begin) {
79 if (!this.data.length) { // 1st
80 var header = lf2cr(src).substr(0, data_begin).replace(_data_format_regexp, "");
81 if (v = header.match(_header_regexp1)) for (i=0; i<v.length; i++) {
82 header = header.replace(_header_regexp2, "\r" + (v[i].replace(_header_regexp2, "$2 $3").replace(/\r/g, "\n")))
83 };
84 header=trim(header).split(/\r/);
85 for (i=0; i<header.length; i++) {
86 header[i] = trim(header[i]).replace(/\s+/, "\r").split("\r");
87 this.header_set_field(header[i][0], header[i][1], "append")
88 }
89 };
90 this.data = this.data.concat(toarray(src.substring(data_begin, data_end).replace(_data_regexp1, "").replace(_data_regexp2, "")));
91 src = src.substr(data_end+9)
92 }
93 };
94 };
95 if (this.data_format.indexOf('CMYK_C') > -1 && this.data_format.indexOf('CMYK_M') > -1 && this.data_format.indexOf('CMYK_Y') > -1 && this.data_format.indexOf('CMYK_K') > -1)
96 this.device = 'CMYK';
97 else
98 this.device = 'RGB';
99 if (comparison_criteria[this.id]) this.id = comparison_criteria[this.id].id;
100 else this.id = this.device;
101 return src ? true : false
102 };
103
104 p=dataset.prototype;
105 p.header_get = function() {
106 var header=[], i, j, v;
107 for (i=0; i<this.header.length; i++) {
108 if (this.header[i][1] && this.header[i][1].indexOf("\n")>-1) {
109 header.push(["BEGIN_"+this.header[i][0]]);
110 v=this.header[i][1].split("\n");
111 for (j=0; j<v.length; j++) header.push([v[j]]);
112 header.push(["END_"+this.header[i][0]])
113 }
114 else header.push(this.header[i])
115 };
116 return fromarray(header)
117 };
118 p.header_set = function(header, mode) {
119 for (var i=0; i<header.length; i++) {
120 this.header_set_field(header[i][0], header[i][1], mode)
121 }
122 };
123 p.header_set_date = function(mode) {
124 var now=new Date();
125 this.header_set_field("CREATED", "\"" + (now.getMonth()+1) + "/" + now.getDate() + "/" + now.getFullYear() + "\" # Time: " + now.getHours().fill(2) + ":" + now.getMinutes().fill(2), mode)
126 };
127 p.header_set_defaults = function(mode) {
128 this.header_set_date(mode);
129 };
130 p.header_set_field = function(name, value, mode) {
131 if (!name) return false;
132 if (value != null) value += "";
133 if (name.toUpperCase() == "NUMBER_OF_FIELDS" || name.toUpperCase() == "NUMBER_OF_SETS") return false;
134 if (!this.header[name.toUpperCase()] || mode=="append" || name.toUpperCase() == "KEYWORD") {
135 var header=[name];
136 if(value!=null && value!=="") header.push(value);
137 this.header.push(header);
138 if (!this.header[name.toUpperCase()]) this.header[name.toUpperCase()]=[];
139 this.header[name.toUpperCase()].push(this.header[this.header.length-1])
140 }
141 else if (mode=="overwrite") {
142 for (var i=0; i<this.header[name.toUpperCase()].length; i++) {
143 if (value==null || value==="") this.header[name.toUpperCase()][i].splice(1, 1);
144 else this.header[name.toUpperCase()][i][1] = value
145 }
146 }
147 };
148 p.toString = function() {
149 return (this.header.length?this.header_get()+"\n":"") + "NUMBER_OF_FIELDS\t" + this.data_format.length + "\nBEGIN_DATA_FORMAT\n" + fromarray(this.data_format, 1) + "\nEND_DATA_FORMAT\nNUMBER_OF_SETS\t" + this.data.length + "\nBEGIN_DATA\n" + decimal(fromarray(this.data), this.decimal == "." ? "\\," : "\\." , this.decimal) + "\nEND_DATA"
150 };
151 p.generate_report = function(set_delta_calc_method) {
152 var f = document.forms,
153 e = f['F_data'].elements,
154 criteria = comparison_criteria[f['F_out'].elements['FF_criteria'].value];
155 if (set_delta_calc_method !== false) {
156 f['F_out'].elements['FF_delta_calc_method'].selectedIndex = ['CIE76', 'CIE94', 'CIE00', 'ICtCp'].indexOf(criteria.delta_calc_method);
157 f['F_out'].elements['FF_absolute'].checked = WHITEPOINT_SIMULATION && !WHITEPOINT_SIMULATION_RELATIVE && !!SIMULATION_PROFILE;
158 f['F_out'].elements['FF_use_profile_wp_as_ref'].checked = e['FF_profile'].value == SIMULATION_PROFILE;
159 }
160 f['F_out'].elements['FF_delta_calc_method'].disabled = criteria.lock_delta_calc_method;
161 var rules = criteria.rules,
162 result = [],
163 delta,
164 matched,
165 target,
166 target_Lab,
167 target_rgb,
168 target_rgb_html,
169 actual,
170 actual_Lab,
171 actual_rgb,
172 actual_rgb_html,
173 planckian = f['F_out'].elements['FF_planckian'].checked,
174 profile_wp = e['FF_profile_whitepoint'].value.split(/\s+/),
175 profile_wp_round = [],
176 profile_wp_norm = e['FF_profile_whitepoint_normalized'].value.split(/\s+/),
177 profile_wp_norm_1 = [],
178 profile_wp_norm_round = [],
179 profile_wp_xy = [],
180 profile_wp_xy_round = [],
181 profile_colortemp,
182 bp = e['FF_blackpoint'].value.split(/\s+/),
183 wp = e['FF_whitepoint'].value.split(/\s+/),
184 wp_round = [],
185 wp_norm = e['FF_whitepoint_normalized'].value.split(/\s+/),
186 wp_norm_1 = [],
187 wp_norm_round = [],
188 wp_xy = [],
189 wp_xy_round = [],
190 colortemp,
191 colortemp_assumed,
192 wp_assumed,
193 wp_assumed_round = [],
194 wp_assumed_xy = [],
195 wp_assumed_xy_round = [],
196 mode = f['F_out'].elements['FF_mode'].value,
197 absolute = f['F_out'].elements['FF_absolute'].checked,
198 use_profile_wp_as_ref = f['F_out'].elements['FF_use_profile_wp_as_ref'].checked,
199 cat = e['FF_adaption'].value,
200 target_Lab2RGB_wp_1 = absolute && (use_profile_wp_as_ref ? profile_wp_norm_1 : 'D50'),
201 actual_Lab2RGB_wp_1 = absolute && (use_profile_wp_as_ref ? profile_wp_norm_1 : 'D50'),
202 target_Lab2RGB_src_wp_1 = absolute && profile_wp_norm_1,
203 actual_Lab2RGB_src_wp_1 = absolute && wp_norm_1,
204 n = 0,
205 o = fields_match.length - 1, // offset for CIE values in fields_extract_indexes
206 devstart = criteria.fields_match.length > 3 ? 3 : 0, // start offset for device values in fields_match (CMYK if length > 3, else RGB)
207 devend = criteria.fields_match.length > 3 ? 6 : 2, // end offset for device values in fields_match (CMYK if length > 3, else RGB)
208 missing_data,
209 delta_calc_method = f['F_out'].elements['FF_delta_calc_method'].value,
210 delta_symbol = {'ICtCp': '',
211 'CIE00': "'"}[delta_calc_method] || '*',
212 weight_symbol = (delta_calc_method != "CIE76" ? '/w' : ''),
213 delta_E_desc = delta_calc_method == 'ICtCp' ? 'IC<sub>T</sub>C<sub>P</sub>' : delta_calc_method.replace(/CIE(.+)/, 'E<sub>$1</sub>'),
214 delta_L_desc = delta_calc_method == 'ICtCp' ? 'I' : delta_calc_method.replace(/CIE(.+)/, 'L*<sub>$1' + weight_symbol + '</sub>'),
215 delta_C_desc = delta_calc_method == 'ICtCp' ? 'C<sub>C<sub>T</sub>C<sub>P</sub></sub>' : delta_calc_method.replace(/CIE(.+)/, 'C' + delta_symbol + '<sub>$1' + weight_symbol + '</sub>'),
216 delta_H_desc = delta_calc_method == 'ICtCp' ? 'H<sub>C<sub>T</sub>C<sub>P</sub></sub>' : delta_calc_method.replace(/CIE(.+)/, 'H' + delta_symbol + '<sub>$1' + weight_symbol + '</sub>'),
217 patch_number_html,
218 verbosestats = f['F_out'].elements['FF_verbosestats'].checked,
219 warn_deviation = criteria.warn_deviation,
220 no_Lab = (this.data_format.indexof("LAB_L", true) < 0
221 || this.data_format.indexof("LAB_A", true) < 0
222 || this.data_format.indexof("LAB_B", true) < 0),
223 no_XYZ = (this.data_format.indexof("XYZ_X", true) < 0
224 || this.data_format.indexof("XYZ_Y", true) < 0
225 || this.data_format.indexof("XYZ_Z", true) < 0),
226 gray_balance_cal_only = f['F_out'].elements['FF_gray_balance_cal_only'].checked;
227
228 if (profile_wp.length == 3) {
229 for (var i=0; i<profile_wp.length; i++) {
230 profile_wp[i] = parseFloat(profile_wp[i]);
231 profile_wp_round[i] = profile_wp[i].accuracy(2)
232 };
233 profile_wp_xy = jsapi.math.color.XYZ2xyY(profile_wp[0], profile_wp[1], profile_wp[2]);
234 profile_wp_xy_round[0] = profile_wp_xy[0].accuracy(4);
235 profile_wp_xy_round[1] = profile_wp_xy[1].accuracy(4);
236 for (var i=0; i<profile_wp.length; i++) {
237 profile_wp_norm_1[i] = profile_wp[i] / profile_wp[1];
238 profile_wp_norm[i] = profile_wp_norm_1[i] * 100;
239 profile_wp_norm_round[i] = profile_wp_norm[i].accuracy(2)
240 };
241 profile_colortemp = Math.round(jsapi.math.color.XYZ2CorColorTemp(profile_wp_norm[0], profile_wp_norm[1], profile_wp_norm[2]));
242 }
243
244 if (bp.length == 3) {
245 for (var i=0; i<bp.length; i++) {
246 bp[i] = parseFloat(bp[i]);
247 };
248 }
249
250 if (wp.length == 3) {
251 for (var i=0; i<wp.length; i++) {
252 wp[i] = parseFloat(wp[i]);
253 wp_round[i] = wp[i].accuracy(2)
254 };
255 wp_xy = jsapi.math.color.XYZ2xyY(wp[0], wp[1], wp[2]);
256 wp_xy_round[0] = wp_xy[0].accuracy(4);
257 wp_xy_round[1] = wp_xy[1].accuracy(4);
258 for (var i=0; i<wp.length; i++) {
259 wp_norm_1[i] = wp[i] / wp[1];
260 wp_norm[i] = wp_norm_1[i] * 100;
261 wp_norm_round[i] = wp_norm[i].accuracy(2)
262 };
263 colortemp = Math.round(jsapi.math.color.XYZ2CorColorTemp(wp_norm[0], wp_norm[1], wp_norm[2]));
264 if (colortemp >= 1667 && colortemp < 2500) {
265 f['F_out'].elements['FF_planckian'].checked = planckian = true;
266 f['F_out'].elements['FF_planckian'].disabled = true;
267 }
268 colortemp_assumed = Math.round(colortemp / 100) * 100;
269 if (planckian)
270 wp_assumed = jsapi.math.color.planckianCT2XYZ(colortemp_assumed);
271 else
272 wp_assumed = jsapi.math.color.CIEDCorColorTemp2XYZ(colortemp_assumed);
273 for (var i=0; i<wp_assumed.length; i++) {
274 wp_assumed[i] = wp_assumed[i] * 100;
275 wp_assumed_round[i] = wp_assumed[i].accuracy(2);
276 }
277 wp_assumed_xy = jsapi.math.color.XYZ2xyY(wp_assumed[0], wp_assumed[1], wp_assumed[2]);
278 wp_assumed_xy_round[0] = wp_assumed_xy[0].accuracy(4);
279 wp_assumed_xy_round[1] = wp_assumed_xy[1].accuracy(4);
280 }
281
282 var ICtCp_lumi_target_scale = (profile_wp || wp)[1] / 10000,
283 ICtCp_lumi_scale = wp[1] / 10000;
284
285 this.report_html = [
286 ' <div class="info"><h3 class="toggle" onclick="toggle(this)">Basic Information</h3>',
287 ' <table cellspacing="0" id="info">',
288 ' <tr>',
289 ' <th>Device:</th>',
290 ' <td>' + e['FF_display'].value + '</td>',
291 ' </tr>',
292 ' <tr>',
293 ' <th>Instrument:</th>',
294 ' <td>' + e['FF_instrument'].value + '</td>',
295 ' </tr>',
296 (e['FF_correction_matrix'].value ? '<tr><th>Correction:</th><td>' + e['FF_correction_matrix'].value + '</td></tr>' : ''),
297 ' <tr>',
298 ' <th>Display profile:</th>',
299 ' <td>' + e['FF_profile'].value + '</td>',
300 ' </tr>'
301 ];
302 if (profile_wp[1] != 100) this.report_html = this.report_html.concat([
303 ' <tr>',
304 ' <th>Display profile luminance:</th>',
305 ' <td>' + profile_wp[1].accuracy(1) + ' cd/m²</td>',
306 ' </tr>'
307 ]);
308 if (profile_wp.length == 3) this.report_html = this.report_html.concat([
309 ' <tr>',
310 ' <th>Display profile whitepoint:</th>',
311 ' <td>' + 'xy ' + profile_wp_xy_round.join(' ') + ' (XYZ ' + profile_wp_norm_round.join(' ') + '), CCT ' + profile_colortemp + 'K</td>',
312 ' </tr>'
313 ]);
314 if (wp.length == 3) this.report_html = this.report_html.concat([
315 ' <tr>',
316 ' <th>Measured luminance:</th>',
317 ' <td>' + wp[1].accuracy(1) + ' cd/m²</td>',
318 ' </tr>',
319 ' <tr>',
320 ' <th>Measured whitepoint:</th>',
321 ' <td>' + 'xy ' + wp_xy_round.join(' ') + ' (XYZ ' + wp_norm_round.join(' ') + '), CCT ' + colortemp + 'K</td>',
322 ' </tr>',
323 ' <tr>',
324 ' <th>Assumed target whitepoint:</th>',
325 ' <td>' + colortemp_assumed + 'K ' + (planckian ? 'blackbody' : 'daylight') + ', xy ' + wp_assumed_xy_round.join(' ') + ' (XYZ ' + wp_assumed_round.join(' ') + ')</td>'
326 ]);
327 if (bp.length == 3 && bp[0] > -1 && bp[1] > -1 && bp[2] > -1) this.report_html = this.report_html.concat([
328 ' <tr>',
329 ' <th>Measured black luminance:</th>',
330 ' <td>' + bp[1].accuracy(4) + ' cd/m²</td>',
331 ' </tr>',
332 ' <tr>',
333 ' <th>Contrast:</th>',
334 ' <td>' + (wp[1] / bp[1]).accuracy(1) + ':1</td>',
335 ' </tr>'
336 ]);
337 this.report_html = this.report_html.concat([
338 ' </tr>',
339 ' <tr>',
340 ' <th>Testchart:</th>',
341 ' <td>' + this.testchart + '</td>',
342 ' </tr>',
343 ' <tr>',
344 ' <th>Simulation profile:</th>',
345 ' <td>' + (SIMULATION_PROFILE || 'None') + '</td>',
346 ' </tr>',
347 ' <tr>',
348 ' <th>Gamma mapping:</th>',
349 ' <td>' + (TRC_GAMMA ? (TRC ? TRC : TRC + ' ' + TRC_GAMMA.toFixed(2) + ' ' + {"b": "relative",
350 "B": "absolute"}[TRC_GAMMA_TYPE] + ', black output offset ' + (TRC_OUTPUT_OFFSET * 100).toFixed(0) + '%') : (SIMULATION_PROFILE ? 'No' : 'N/A')) + '</td>',
351 ' </tr>',
352 ' <tr>',
353 ' <th>Whitepoint simulation:</th>',
354 ' <td>' + (WHITEPOINT_SIMULATION ? 'Yes' + (WHITEPOINT_SIMULATION_RELATIVE ? ', relative to display profile whitepoint' : '') : (!DEVICELINK_PROFILE && SIMULATION_PROFILE ? 'No' : 'N/A')) + '</td>',
355 ' </tr>',
356 ' <tr>',
357 ' <th>Chromatic adaptation:</th>',
358 ' <td>' + e['FF_adaption'].value + '</td>',
359 ' </tr>',
360 ' <tr>',
361 ' <th>Devicelink profile:</th>',
362 ' <td>' + (DEVICELINK_PROFILE || 'None') + '</td>',
363 ' </tr>',
364 ' <tr>',
365 ' <th>Evaluation criteria:</th>',
366 ' <td>' + criteria.name + '</td>',
367 ' </tr>',
368 ' <tr>',
369 ' <th>Date:</th>',
370 ' <td>' + e['FF_datetime'].value + '</td>',
371 ' </tr>',
372 ' </table></div>'
373 ]);
374 // Warn when the profile white point differs significantly from the measured
375 // display white point (> 300 K). This typically means the profile was built
376 // from uncalibrated measurements, e.g. the calibration video LUT was not
377 // active during profiling or no colorimeter correction file was applied.
378 if (profile_colortemp && colortemp && Math.abs(profile_colortemp - colortemp) > 300) {
379 this.report_html.push(
380 '<p class="warning-banner">Warning: The profile white point (' + profile_colortemp + ' K) ' +
381 'differs significantly from the measured display white point (' + colortemp + ' K). ' +
382 'The display profile was likely built from uncalibrated measurements. ' +
383 'Common causes: the calibration video LUT was not active during profiling, ' +
384 'or no colorimeter correction file was applied. ' +
385 'Re-calibrating and re-profiling the display should fix this.</p>'
386 );
387 }
388 var result_start = this.report_html.length;
389 this.report_html = this.report_html.concat([
390 ' <div class="summary">',
391 ' <h3 class="toggle" onclick="toggle(this)">Summary</h3>',
392 ' <div id="summary">',
393 ' <table cellspacing="0">',
394 ' <tr>',
395 ' <th class="first-column">Criteria</th><th>Nominal</th><th>Recommended</th><th>#</th><th colspan="2">&#160;</th><th>Actual</th><th>&#160;</th><th>Result</th>',
396 ' </tr>'
397 ]);
398 var seen = [];
399 for (var j=0; j<rules.length; j++) {
400 result[j] = {
401 E: [],
402 L: [],
403 C: [],
404 H: [],
405 a: [],
406 b: [],
407 Ch: [],
408 g: [],
409 matches: [],
410 sum: null
411 };
412 if (rules[j][1].length == 1) {
413 switch (rules[j][1][0]) {
414 case 'CAL_REDLEVELS':
415 if (window.CAL_RGBLEVELS) {
416 result[j].sum = (window.CAL_RGBLEVELS[0] / CAL_ENTRYCOUNT * 100).accuracy(1);
417 result[j].htmlsum = result[j].sum + '%<br />(' + window.CAL_RGBLEVELS[0] + '/' + CAL_ENTRYCOUNT + ')';
418 }
419 else {
420 rules[j][3] = null;
421 rules[j][4] = null;
422 continue;
423 }
424 break;
425 case 'CAL_GREENLEVELS':
426 if (window.CAL_RGBLEVELS) {
427 result[j].sum = (window.CAL_RGBLEVELS[1] / CAL_ENTRYCOUNT * 100).accuracy(1);
428 result[j].htmlsum = result[j].sum + '%<br />(' + window.CAL_RGBLEVELS[1] + '/' + CAL_ENTRYCOUNT + ')';
429 }
430 else {
431 rules[j][3] = null;
432 rules[j][4] = null;
433 continue;
434 }
435 break;
436 case 'CAL_BLUELEVELS':
437 if (window.CAL_RGBLEVELS) {
438 result[j].sum = (window.CAL_RGBLEVELS[2] / CAL_ENTRYCOUNT * 100).accuracy(1);
439 result[j].htmlsum = result[j].sum + '%<br />(' + window.CAL_RGBLEVELS[2] + '/' + CAL_ENTRYCOUNT + ')';
440 }
441 else {
442 rules[j][3] = null;
443 rules[j][4] = null;
444 continue;
445 }
446 break;
447 case 'CAL_GRAYLEVELS':
448 if (window.CAL_RGBLEVELS) {
449 var cal_graylevels = Math.min(CAL_RGBLEVELS[0], CAL_RGBLEVELS[1], CAL_RGBLEVELS[2]);
450 result[j].sum = (cal_graylevels / CAL_ENTRYCOUNT * 100).accuracy(1);
451 result[j].htmlsum = result[j].sum + '%<br />(' + cal_graylevels + '/' + CAL_ENTRYCOUNT + ')';
452 }
453 else {
454 rules[j][3] = null;
455 rules[j][4] = null;
456 continue;
457 }
458 break;
459 case 'WHITEPOINT_MvsA': // Measured vs. assumed
460 if (wp.length == 3) {
461 target_Lab = [100, 0, 0];
462 actual_Lab = jsapi.math.color.XYZ2Lab(wp_norm[0], wp_norm[1], wp_norm[2], [wp_assumed[0], wp_assumed[1], wp_assumed[2]]);
463 // alert(rules[j] + '\ntarget_Lab: ' + target_Lab + '\nactual_Lab: ' + actual_Lab);
464 delta = jsapi.math.color.delta(target_Lab[0], target_Lab[1], target_Lab[2], actual_Lab[0], actual_Lab[1], actual_Lab[2], rules[j][5], null, null, null, [wp_assumed[0] / 100, wp_assumed[1] / 100, wp_assumed[2] / 100], (profile_wp || wp)[1], wp[1], cat);
465 result[j].E.push(delta.E);
466 result[j].L.push(delta.Lw);
467 result[j].C.push(delta.Cw);
468 result[j].H.push(delta.Hw);
469 result[j].a.push(delta.a);
470 result[j].b.push(delta.b);
471 result[j].Ch.push(delta.Ch);
472 }
473 else {
474 rules[j][3] = null;
475 rules[j][4] = null;
476 continue;
477 }
478 break;
479 case 'WHITEPOINT_MvsP': // Profile vs. measured
480 if (wp.length == 3 && profile_wp.length == 3) {
481 target_Lab = [100, 0, 0];
482 actual_Lab = jsapi.math.color.XYZ2Lab(wp_norm[0], wp_norm[1], wp_norm[2], [profile_wp_norm[0], profile_wp_norm[1], profile_wp_norm[2]]);
483 // alert(rules[j] + '\ntarget_Lab: ' + target_Lab + '\nactual_Lab: ' + actual_Lab);
484 delta = jsapi.math.color.delta(target_Lab[0], target_Lab[1], target_Lab[2], actual_Lab[0], actual_Lab[1], actual_Lab[2], rules[j][5], null, null, null, profile_wp_norm_1, (profile_wp || wp)[1], wp[1], cat);
485 result[j].E.push(delta.E);
486 result[j].L.push(delta.Lw);
487 result[j].C.push(delta.Cw);
488 result[j].H.push(delta.Hw);
489 result[j].a.push(delta.a);
490 result[j].b.push(delta.b);
491 result[j].Ch.push(delta.Ch);
492 }
493 else {
494 rules[j][3] = null;
495 rules[j][4] = null;
496 continue;
497 }
498 break;
499 }
500 };
501 this.report_html.push(' <tr' + (!(rules[j][3] || rules[j][4]) || !rules[j][5] || (!rules[j][6] && rules[j][5].substr(3) != delta_calc_method.substr(3)) ? ' class="statonly' + (verbosestats ? '' : ' verbose') + '"' : '' ) + '>');
502 this.report_html.push(' <td class="first-column">' + rules[j][0] + '</td><td>' + (rules[j][3] ? (rules[j][2] ? '&lt;= ' + rules[j][3] : '&gt;= ' + rules[j][3] + '%') : '&#160;') + '</td><td class="statonly">' + (rules[j][4] ? (rules[j][2] ? '&lt;= ' + rules[j][4] : '&gt;= ' + rules[j][4] + '%'): '&#160;') + '</td><td class="sample_id">');
503 patch_number_html = [];
504 actual_rgb_html = [];
505 target_rgb_html = [];
506 var haspatchid = false;
507 if (rules[j][2].indexOf("_MAX") < 0 && rules[j][2].indexOf("_MIN") < 0) {
508 for (var k=0; k<rules[j][1].length; k++) if (rules[j][1].length > 1 && seen.indexOf(rules[j][1].join(',')) < 0 && (rules[j][6] || rules[j][5].substr(3) == delta_calc_method.substr(3))) {
509 patch_number_html.push('<div class="sample_id">&#160;</div>');
510 haspatchid = true;
511 if (rules[j][1][k].length == 4) // Assume CMYK
512 target_rgb = jsapi.math.color.CMYK2RGB(rules[j][1][k][0] / 100, rules[j][1][k][1] / 100, rules[j][1][k][2] / 100, rules[j][1][k][3] / 100, 255);
513 else
514 // XXX Note that round(50 * 2.55) = 127, but
515 // round(50 / 100 * 255) = 128 (the latter is what we want)!
516 target_rgb = [rules[j][1][k][0] / 100.0 * 255, rules[j][1][k][1] / 100.0 * 255, rules[j][1][k][2] / 100.0 * 255];
517 target_rgb_html.push('<div class="patch" style="background-color: rgb(' + Math.round(target_rgb[0]) + ', ' + Math.round(target_rgb[1]) + ', ' + Math.round(target_rgb[2]) + ');">&#160;</div>');
518 actual_rgb_html.push('<div class="patch" style="color: red; position: relative;"><span style="position: absolute;">\u2716</span>&#160;</div>');
519 }
520 };
521 if (rules[j][1].length) {
522 for (var k=0; k<rules[j][1].length; k++) {
523 for (var l=0; l<rules[j][1][k].length; l++) if (!isNaN(rules[j][1][k][l])) rules[j][1][k][l] = rules[j][1][k][l].accuracy(2);
524 }
525 };
526 var silent = false;
527 for (var i=0, n=0; i<this.data.length; i++) {
528 this.data[i].actual_DE = null;
529 this.data[i].tolerance_DE = null;
530 this.data[i].actual_DL = null;
531 this.data[i].tolerance_DL = null;
532 this.data[i].actual_Da = null;
533 this.data[i].tolerance_Da = null;
534 this.data[i].actual_Db = null;
535 this.data[i].tolerance_Db = null;
536 this.data[i].actual_DC = null;
537 this.data[i].tolerance_DC = null;
538 this.data[i].actual_DH = null;
539 this.data[i].tolerance_DH = null;
540 n++;
541 target = data_ref.data[i];
542 actual = this.data[i];
543 matched = false;
544 var colors = get_colors(target, actual, o, no_Lab, no_XYZ, gray_balance_cal_only, false, profile_wp_norm, wp_norm, absolute, cat, use_profile_wp_as_ref);
545 target_Lab = colors.target_Lab;
546 actual_Lab = colors.actual_Lab;
547 current_rgb = colors.current_rgb;
548 current_cmyk = colors.current_cmyk;
549 if (rules[j][1].length) {
550 for (var k=0; k<rules[j][1].length; k++) {
551 if ((rules[j][1][k].length == 3 && current_rgb.join(',') == rules[j][1][k].join(',')) || (rules[j][1][k].length == 4 && current_cmyk.join(',') == rules[j][1][k].join(','))) {
552 // if (silent || !confirm('rules[j]: ' + rules[j] + '\nrules[j][1][k]: ' + rules[j][1][k] + '\nthis.data[' + i + ']: ' + this.data[i] + '\ncurrent_rgb: ' + current_rgb + '\ncurrent_cmyk: ' + current_cmyk)) silent = true;
553 if (rules[j][2].indexOf("_MAX") < 0 && rules[j][2].indexOf("_MIN") < 0 && seen.indexOf(rules[j][1].join(',')) < 0 && (rules[j][6] || rules[j][5].substr(3) == delta_calc_method.substr(3))) {
554 if (rules[j][1].length) {
555 patch_number_html[k] = ('<div class="sample_id">' + n.fill(String(number_of_sets).length) + '</div>');
556 haspatchid = true;
557 }
558 target_rgb = jsapi.math.color.Lab2RGB(target_Lab[0], target_Lab[1], target_Lab[2], target_Lab2RGB_wp_1, target_Lab2RGB_src_wp_1, 255, true, cat);
559 actual_rgb = jsapi.math.color.Lab2RGB(actual_Lab[0], actual_Lab[1], actual_Lab[2], actual_Lab2RGB_wp_1, actual_Lab2RGB_src_wp_1, 255, true, cat);
560 target_rgb_html[k] = ('<div class="patch" style="background-color: rgb(' + target_rgb[0] + ', ' + target_rgb[1] + ', ' + target_rgb[2] + ');">&#160;</div>');
561 actual_rgb_html[k] = ('<div class="patch" style="background-color: rgb(' + actual_rgb[0] + ', ' + actual_rgb[1] + ', ' + actual_rgb[2] + ');">&#160;</div>');
562 };
563 matched = true
564 }
565 }
566 }
567 else matched = true;
568 if (matched) {
569 delta = jsapi.math.color.delta(target_Lab[0], target_Lab[1], target_Lab[2], actual_Lab[0], actual_Lab[1], actual_Lab[2], rules[j][5], null, null, null, absolute && (use_profile_wp_as_ref ? profile_wp_norm_1 : 'D50'), (profile_wp || wp)[1], wp[1], cat);
570 result[j].E.push(delta.E);
571 result[j].L.push(delta.Lw);
572 result[j].C.push(delta.Cw);
573 result[j].H.push(delta.Hw);
574 result[j].a.push(delta.a);
575 result[j].b.push(delta.b);
576 result[j].Ch.push(delta.Ch);
577 if (actual.gamma) result[j].g.push(actual.gamma);
578 if ((rules[j][1].length || rules[j][2].indexOf('_MAX') > -1 || rules[j][2].indexOf('_MIN') > -1) && (rules[j][2].indexOf('GAMMA') < 0 || actual.gamma)) result[j].matches.push([i, i, n])
579 }
580 };
581 this.report_html = this.report_html.concat(patch_number_html);
582 var number_of_sets = n;
583 if (!rules[j][1].length || ((rules[j][1][0] == 'WHITEPOINT_MvsA' || (rules[j][1][0] == 'WHITEPOINT_MvsP' && profile_wp.length == 3)) && wp.length == 3) || result[j].matches.length >= rules[j][1].length) switch (rules[j][2]) {
584 case DELTA_A_MAX:
585 result[j].sum = jsapi.math.absmax(result[j].a);
586 break;
587 case DELTA_A_AVG:
588 result[j].sum = jsapi.math.avgabs(result[j].a);
589 break;
590 case DELTA_A_MED:
591 result[j].sum = jsapi.math.median(result[j].a);
592 break;
593 case DELTA_A_MAD:
594 result[j].sum = jsapi.math.mad(result[j].a);
595 break;
596 case DELTA_A_PERCENTILE_95:
597 result[j].sum = jsapi.math.percentile(result[j].a, 0.95);
598 break;
599 case DELTA_A_PERCENTILE_99:
600 result[j].sum = jsapi.math.percentile(result[j].a, 0.99);
601 break;
602 case DELTA_A_RANGE:
603 result[j].sum = jsapi.math.max(result[j].a) - jsapi.math.min(result[j].a);
604 break;
605 case DELTA_A_STDDEV:
606 result[j].sum = jsapi.math.stddev(result[j].a);
607 break;
608
609 case DELTA_A_B_RANGE:
610 var ab = result[j].a.concat(result[j].b);
611 result[j].sum = jsapi.math.max(ab) - jsapi.math.min(ab);
612 break;
613
614 case DELTA_CH_MAX:
615 result[j].sum = jsapi.math.max(result[j].Ch);
616 break;
617 case DELTA_CH_AVG:
618 result[j].sum = jsapi.math.avg(result[j].Ch);
619 break;
620
621 case DELTA_B_MAX:
622 result[j].sum = jsapi.math.absmax(result[j].b);
623 break;
624 case DELTA_B_AVG:
625 result[j].sum = jsapi.math.avgabs(result[j].b);
626 break;
627 case DELTA_B_MED:
628 result[j].sum = jsapi.math.median(result[j].b);
629 break;
630 case DELTA_B_MAD:
631 result[j].sum = jsapi.math.mad(result[j].b);
632 break;
633 case DELTA_B_PERCENTILE_95:
634 result[j].sum = jsapi.math.percentile(result[j].B, 0.95);
635 break;
636 case DELTA_B_PERCENTILE_99:
637 result[j].sum = jsapi.math.percentile(result[j].B, 0.99);
638 break;
639 case DELTA_B_RANGE:
640 result[j].sum = jsapi.math.max(result[j].b) - jsapi.math.min(result[j].b);
641 break;
642 case DELTA_B_STDDEV:
643 result[j].sum = jsapi.math.stddev(result[j].b);
644 break;
645
646 case DELTA_E_MAX:
647 result[j].sum = jsapi.math.absmax(result[j].E);
648 break;
649 case DELTA_E_AVG:
650 result[j].sum = jsapi.math.avg(result[j].E);
651 break;
652 case DELTA_E_MED:
653 result[j].sum = jsapi.math.median(result[j].E);
654 break;
655 case DELTA_E_MAD:
656 result[j].sum = jsapi.math.mad(result[j].E);
657 break;
658 case DELTA_E_PERCENTILE_95:
659 result[j].sum = jsapi.math.percentile(result[j].E, 0.95);
660 break;
661 case DELTA_E_PERCENTILE_99:
662 result[j].sum = jsapi.math.percentile(result[j].E, 0.99);
663 break;
664 case DELTA_E_RANGE:
665 result[j].sum = jsapi.math.max(result[j].E) - jsapi.math.min(result[j].E);
666 break;
667 case DELTA_E_STDDEV:
668 result[j].sum = jsapi.math.stddev(result[j].E);
669 break;
670
671 case DELTA_L_MAX:
672 result[j].sum = jsapi.math.absmax(result[j].L);
673 break;
674 case DELTA_L_AVG:
675 result[j].sum = jsapi.math.avgabs(result[j].L);
676 break;
677 case DELTA_L_MED:
678 result[j].sum = jsapi.math.median(result[j].L);
679 break;
680 case DELTA_L_MAD:
681 result[j].sum = jsapi.math.mad(result[j].L);
682 break;
683 case DELTA_L_PERCENTILE_95:
684 result[j].sum = jsapi.math.percentile(result[j].L, 0.95);
685 break;
686 case DELTA_L_PERCENTILE_99:
687 result[j].sum = jsapi.math.percentile(result[j].L, 0.99);
688 break;
689 case DELTA_L_RANGE:
690 result[j].sum = jsapi.math.max(result[j].L) - jsapi.math.min(result[j].L);
691 break;
692 case DELTA_L_STDDEV:
693 result[j].sum = jsapi.math.stddev(result[j].L);
694 break;
695
696 case DELTA_C_MAX:
697 result[j].sum = jsapi.math.absmax(result[j].C);
698 break;
699 case DELTA_C_AVG:
700 result[j].sum = jsapi.math.avgabs(result[j].C);
701 break;
702 case DELTA_C_MED:
703 result[j].sum = jsapi.math.median(result[j].C);
704 break;
705 case DELTA_C_MAD:
706 result[j].sum = jsapi.math.mad(result[j].C);
707 break;
708 case DELTA_C_PERCENTILE_95:
709 result[j].sum = jsapi.math.percentile(result[j].C, 0.95);
710 break;
711 case DELTA_C_PERCENTILE_99:
712 result[j].sum = jsapi.math.percentile(result[j].C, 0.99);
713 break;
714 case DELTA_C_RANGE:
715 result[j].sum = jsapi.math.max(result[j].C) - jsapi.math.min(result[j].C);
716 break;
717 case DELTA_C_STDDEV:
718 result[j].sum = jsapi.math.stddev(result[j].C);
719 break;
720
721 case DELTA_H_MAX:
722 result[j].sum = jsapi.math.absmax(result[j].H);
723 break;
724 case DELTA_H_AVG:
725 result[j].sum = jsapi.math.avgabs(result[j].H);
726 break;
727 case DELTA_H_MED:
728 result[j].sum = jsapi.math.median(result[j].H);
729 break;
730 case DELTA_H_MAD:
731 result[j].sum = jsapi.math.mad(result[j].H);
732 break;
733 case DELTA_H_PERCENTILE_95:
734 result[j].sum = jsapi.math.percentile(result[j].H, 0.95);
735 break;
736 case DELTA_H_PERCENTILE_99:
737 result[j].sum = jsapi.math.percentile(result[j].H, 0.99);
738 break;
739 case DELTA_H_RANGE:
740 result[j].sum = jsapi.math.max(result[j].H) - jsapi.math.min(result[j].H);
741 break;
742 case DELTA_H_STDDEV:
743 result[j].sum = jsapi.math.stddev(result[j].H);
744 break;
745
746 case GAMMA_MAX:
747 if (result[j].g.length) result[j].sum = jsapi.math.max(result[j].g);
748 break;
749 case GAMMA_MIN:
750 if (result[j].g.length) result[j].sum = jsapi.math.min(result[j].g);
751 break;
752 case GAMMA_AVG:
753 if (result[j].g.length) result[j].sum = jsapi.math.avg(result[j].g);
754 break;
755 case GAMMA_MED:
756 if (result[j].g.length) result[j].sum = jsapi.math.median(result[j].g);
757 break;
758 case GAMMA_MAD:
759 if (result[j].g.length) result[j].sum = jsapi.math.mad(result[j].g);
760 break;
761 case GAMMA_PERCENTILE_95:
762 if (result[j].g.length) result[j].sum = jsapi.math.percentile(result[j].g, 0.95);
763 break;
764 case GAMMA_PERCENTILE_99:
765 if (result[j].g.length) result[j].sum = jsapi.math.percentile(result[j].g, 0.99);
766 break;
767 case GAMMA_RANGE:
768 if (result[j].g.length) result[j].sum = jsapi.math.max(result[j].g) - jsapi.math.min(result[j].g);
769 break;
770 case GAMMA_STDDEV:
771 if (result[j].g.length) result[j].sum = jsapi.math.stddev(result[j].g);
772 break;
773 }
774 else if (!rules[j][1].length || (rules[j][1][0] + '').indexOf('LEVELS') < 0) missing_data = true;
775 if (result[j].matches.length) {
776 matched = false;
777 for (var k=0; k<result[j].matches.length; k++) {
778 target = data_ref.data[result[j].matches[k][0]];
779 actual = this.data[result[j].matches[k][1]];
780 switch (rules[j][2]) {
781 case DELTA_E_MAX:
782 if (result[j].E[k] == result[j].sum) matched = true;
783 break;
784 case DELTA_L_MAX:
785 if (result[j].L[k] == result[j].sum) matched = true;
786 break;
787 case DELTA_A_MAX:
788 if (result[j].a[k] == result[j].sum) matched = true;
789 break;
790 case DELTA_B_MAX:
791 if (result[j].b[k] == result[j].sum) matched = true;
792 break;
793 case DELTA_CH_MAX:
794 if (result[j].Ch[k] == result[j].sum) matched = true;
795 break;
796 case DELTA_C_MAX:
797 if (result[j].C[k] == result[j].sum) matched = true;
798 break;
799 case DELTA_H_MAX:
800 if (result[j].H[k] == result[j].sum) matched = true;
801 break;
802 case GAMMA_MAX:
803 if (result[j].g[k] == result[j].sum) matched = true;
804 break;
805 case GAMMA_MIN:
806 if (result[j].g[k] == result[j].sum) matched = true;
807 break;
808 };
809 if (matched) {
810 result[j].finalmatch = result[j].matches[k];
811 break;
812 };
813 };
814 if (matched) {
815 this.report_html.push('<div class="sample_id">' + result[j].finalmatch[2].fill(String(number_of_sets).length) + '</div>');
816 haspatchid = true;
817 var colors = get_colors(target, actual, o, no_Lab, no_XYZ, gray_balance_cal_only, true, profile_wp_norm, wp_norm, absolute, cat, use_profile_wp_as_ref);
818 target_Lab = colors.target_Lab;
819 actual_Lab = colors.actual_Lab;
820 target_rgb = jsapi.math.color.Lab2RGB(target_Lab[0], target_Lab[1], target_Lab[2], target_Lab2RGB_wp_1, target_Lab2RGB_src_wp_1, 255, true, cat);
821 actual_rgb = jsapi.math.color.Lab2RGB(actual_Lab[0], actual_Lab[1], actual_Lab[2], actual_Lab2RGB_wp_1, actual_Lab2RGB_src_wp_1, 255, true, cat);
822 target_rgb_html.push('<div class="patch" style="background-color: rgb(' + target_rgb[0] + ', ' + target_rgb[1] + ', ' + target_rgb[2] + ');">&#160;</div>');
823 actual_rgb_html.push('<div class="patch" style="background-color: rgb(' + actual_rgb[0] + ', ' + actual_rgb[1] + ', ' + actual_rgb[2] + ');">&#160;</div>');
824 };
825 }
826 if (!target_rgb_html.length) {
827 target_rgb_html.push('&#160;');
828 actual_rgb_html.push('&#160;');
829 };
830 if (!haspatchid) this.report_html.push('<div class="sample_id">&#160;</div>');
831 this.report_html.push(' </td>');
832 this.report_html.push(' <td class="patch">' + target_rgb_html.join('') + '</td>');
833 this.report_html.push(' <td class="patch">' + actual_rgb_html.join('') + '</td>');
834 var bar_html = [];
835 if (result[j].sum != null && rules[j][2] && rules[j][2].indexOf("GAMMA") < 0) {
836 if (!rules[j][3] || (!rules[j][6] && rules[j][5] && rules[j][5].substr(3) != delta_calc_method.substr(3))) rgb = [204, 204, 204];
837 else {
838 var rgb = [0, 255, 0],
839 step = 255 / (rules[j][3] + rules[j][3] / 2);
840 if (Math.abs(result[j].sum) <= rules[j][3]) {
841 rgb[0] += Math.min(step * Math.abs(result[j].sum), 255);
842 rgb[1] -= Math.min(step * Math.abs(result[j].sum), 255);
843 var maxrg = Math.max(rgb[0], rgb[1]);
844 rgb[0] *= (255 / maxrg);
845 rgb[1] *= (255 / maxrg);
846 rgb[0] = Math.round(rgb[0]);
847 rgb[1] = Math.round(rgb[1]);
848 }
849 else rgb = [255, 0, 0];
850 };
851 for (var l = 0; l < actual_rgb_html.length; l ++) {
852 bar_html.push(Math.abs(result[j].sum).accuracy(2) > 0 ? '<span style="display: block; width: ' + Math.round(10 * Math.abs(result[j].sum).accuracy(2)) + 'px; background-color: rgb(' + rgb.join(', ') + '); border: 1px solid silver; border-top: none; border-bottom: none; padding: .125em 0 .125em 0; overflow: hidden;">&#160;</span>' : '&#160;');
853 };
854 };
855 this.report_html.push(' <td><span class="' + (result[j].sum != null && rules[j][3] && (rules[j][6] || !rules[j][5] || rules[j][5].substr(3) == delta_calc_method.substr(3)) ? ((rules[j][2] ? Math.abs(result[j].sum).accuracy(2) < rules[j][3] : Math.abs(result[j].sum).accuracy(2) > rules[j][3]) ? 'ok' : (Math.abs(result[j].sum).accuracy(2) == rules[j][3] ? 'warn' : 'ko')) : 'statonly') + '">' + (result[j].sum != null ? result[j].htmlsum || result[j].sum.accuracy(2) : '&#160;') + '</span></td><td class="bar">' + (bar_html.join('') || '&#160;') + '</td><td class="' + (result[j].sum != null && (!rules[j][3] || (rules[j][2] ? Math.abs(result[j].sum) <= rules[j][3] : Math.abs(result[j].sum) >= rules[j][3])) ? (((rules[j][2] ? Math.abs(result[j].sum).accuracy(2) < rules[j][3] : Math.abs(result[j].sum).accuracy(2) > rules[j][3]) ? 'ok">OK <span class="checkmark">✔</span>' : (result[j].sum != null && rules[j][3] ? 'warn">OK \u26a0' : 'statonly">')) + '<span class="' + (rules[j][4] && (rules[j][2] ? Math.abs(result[j].sum) <= rules[j][4] : Math.abs(result[j].sum) >= rules[j][4]) ? 'checkmark' : 'hidden') + (rules[j][3] && rules[j][4] ? '">✔' : '">&#160;')) : 'ko">' + (result[j].sum != null ? 'NOT OK' : '') + ' <span class="checkmark">\u2716') + '</span></td>');
856 this.report_html.push(' </tr>');
857 if (rules[j][1] && rules[j][1].length > 1 && (rules[j][6] || rules[j][5].substr(3) == delta_calc_method.substr(3))) seen.push(rules[j][1].join(','));
858 };
859 this.report_html.push(' </table>');
860
861 var pass, overachieve;
862 for (var j=0; j<result.length; j++) {
863 if (rules[j][6] || !rules[j][5] || rules[j][5].substr(3) == delta_calc_method.substr(3)) {
864 if (!rules[j][3]) continue;
865 if (missing_data || isNaN(result[j].sum) || (rules[j][2] ? Math.abs(result[j].sum) > rules[j][3] : Math.abs(result[j].sum) < rules[j][3])) pass = false;
866 if (!rules[j][4]) continue;
867 if (missing_data || isNaN(result[j].sum) || (rules[j][2] ? Math.abs(result[j].sum) > rules[j][4] : Math.abs(result[j].sum) < rules[j][4])) overachieve = false;
868 }
869 if (rules[j][5] && rules[j][5].substr(3) == delta_calc_method.substr(3)) for (var k=0; k<result[j].matches.length; k++) {
870 if (rules[j][2].indexOf('_E_') > -1) {
871 this.data[result[j].matches[k][1]].actual_DE = Math.abs(rules[j][2].indexOf('_MAX') < 0 ? result[j].sum : result[j].E[k]);
872 this.data[result[j].matches[k][1]].tolerance_DE = rules[j][3];
873 }
874 else if (rules[j][2].indexOf('_L_') > -1) {
875 this.data[result[j].matches[k][1]].actual_DL = Math.abs(rules[j][2].indexOf('_MAX') < 0 ? result[j].sum : result[j].L[k]);
876 this.data[result[j].matches[k][1]].tolerance_DL = rules[j][3];
877 }
878 else if (rules[j][2].indexOf('_A_') > -1) {
879 this.data[result[j].matches[k][1]].actual_Da = Math.abs(rules[j][2].indexOf('_MAX') < 0 ? result[j].sum : result[j].a[k]);
880 this.data[result[j].matches[k][1]].tolerance_Da = rules[j][3];
881 }
882 else if (rules[j][2].indexOf('_B_') > -1) {
883 this.data[result[j].matches[k][1]].actual_Db = Math.abs(rules[j][2].indexOf('_MAX') < 0 ? result[j].sum : result[j].b[k]);
884 this.data[result[j].matches[k][1]].tolerance_Db = rules[j][3];
885 }
886 else if (rules[j][2].indexOf('_C_') > -1) {
887 this.data[result[j].matches[k][1]].actual_DC = Math.abs(rules[j][2].indexOf('_MAX') < 0 ? result[j].sum : result[j].C[k]);
888 this.data[result[j].matches[k][1]].tolerance_DC = rules[j][3];
889 }
890 else if (rules[j][2].indexOf('_H_') > -1) {
891 this.data[result[j].matches[k][1]].actual_DH = Math.abs(rules[j][2].indexOf('_MAX') < 0 ? result[j].sum : result[j].H[k]);
892 this.data[result[j].matches[k][1]].tolerance_DH = rules[j][3];
893 }
894 };
895 };
896 this.report_html.push('<div class="footer"><p><span class="' + (pass !== false ? 'ok"><span class="checkmark">✔</span> ' + criteria.passtext : 'ko"><span class="checkmark">\u2716</span> ' + (missing_data ? 'MISSING DATA' : criteria.failtext)) + '</span>' + ((overachieve !== false && criteria.passrecommendedtext) || (overachieve === false && criteria.failrecommendedtext) ? '<br /><span class="' + (overachieve !== false ? 'ok"><span class="checkmark">✔</span> ' + criteria.passrecommendedtext : 'info"><span class="checkmark">✘</span> ' + criteria.failrecommendedtext) + '</span>' : '') + '</p></div>');
897
898 this.result_html = this.report_html.slice(result_start);
899 this.report_html.push(' </div></div>');
900
901 this.report_html.push(' <div class="overview">');
902 this.report_html.push(' <h3 class="toggle" onclick="toggle(this)">Overview</h3>');
903 this.report_html.push(' <table cellspacing="0" id="overview">');
904 this.report_html.push(' <tr>');
905 var device_labels = fields_match.slice(devstart, devend + 1),
906 device_channels = device_labels.join('').replace(/(?:CMYK|RGB)_/g, '');
907 this.report_html.push(' <th>#</th><th colspan="' + device_labels.length + '">Device Values</th><th colspan="' + (criteria.fields_match.join(',').indexOf('CMYK') < 0 ? '4' : '3') + '">Nominal Values</th><th colspan="2">&#160;</th><th colspan="' + (criteria.fields_match.join(',').indexOf('CMYK') < 0 ? '4' : '3') + '">Measured Values</th><th colspan="4">Color distance</th><th>&#160;</th>');
908 this.report_html.push(' </tr>');
909 this.report_html.push(' <tr>');
910 if (mode == 'Lab')
911 labels = 'L*,a*,b*';
912 else if (mode == 'XYZ')
913 labels = 'X,Y,Z';
914 else if (mode == 'xyY')
915 labels = 'x,y,Y';
916 else if (mode == "Lu'v'")
917 labels = "L*,u',v'";
918 else if (mode == "ICtCp")
919 labels = "I,Ct,Cp";
920 this.report_html.push(' <th>&#160;</th><th>' + device_labels.join('</th><th>').replace(/\w+_/g, '') + '</th><th>' + labels.split(',').join('</th><th>') + '</th>' + (criteria.fields_match.join(',').indexOf('CMYK') < 0 ? '<th>γ</th>' : '') + '<th>&#160;</th><th>&#160;</th><th>' + labels.split(',').join('</th><th>') + '</th>' + (criteria.fields_match.join(',').indexOf('CMYK') < 0 ? '<th>γ</th>' : '') + '<th>Δ' + delta_L_desc + '</th>' + /* '<th>Δa</th><th>Δb</th>' + */ '<th>Δ' + delta_C_desc + '</th><th>Δ' + delta_H_desc + '</th><th>Δ' + delta_E_desc + '</th><th>&#160;</th>');
921 this.report_html.push(' </tr>');
922 var grayscale_values = [], gamut_values = [];
923 for (var i=0, n=0; i<this.data.length; i++) {
924 n++;
925 target = data_ref.data[i];
926 actual = this.data[i];
927 var colors = get_colors(target, actual, o, no_Lab, no_XYZ, gray_balance_cal_only, true, profile_wp_norm, wp_norm, absolute, cat, use_profile_wp_as_ref);
928 target_Lab = colors.target_Lab;
929 actual_Lab = colors.actual_Lab;
930 current_rgb = colors.current_rgb;
931 current_cmyk = colors.current_cmyk;
932 target_rgb = jsapi.math.color.Lab2RGB(target_Lab[0], target_Lab[1], target_Lab[2], target_Lab2RGB_wp_1, target_Lab2RGB_src_wp_1, 255, true, cat);
933 actual_rgb = jsapi.math.color.Lab2RGB(actual_Lab[0], actual_Lab[1], actual_Lab[2], actual_Lab2RGB_wp_1, actual_Lab2RGB_src_wp_1, 255, true, cat);
934 delta = jsapi.math.color.delta(target_Lab[0], target_Lab[1], target_Lab[2], actual_Lab[0], actual_Lab[1], actual_Lab[2], delta_calc_method, null, null, null, absolute && (use_profile_wp_as_ref ? profile_wp_norm_1 : 'D50'), (profile_wp || wp)[1], wp[1], cat);
935 if (mode == 'Lab') {
936 target_color = target_Lab;
937 actual_color = actual_Lab;
938 accuracy = 2;
939 }
940 else if (mode == 'XYZ' || mode == 'xyY' || mode == "Lu'v'" || mode == "ICtCp") {
941 target_color = jsapi.math.color.Lab2XYZ(target_Lab[0], target_Lab[1], target_Lab[2], absolute && use_profile_wp_as_ref && profile_wp_norm_1);
942 actual_color = jsapi.math.color.Lab2XYZ(actual_Lab[0], actual_Lab[1], actual_Lab[2], absolute && use_profile_wp_as_ref && profile_wp_norm_1);
943 if (mode != "ICtCp") {
944 target_color = [target_color[0] * 100, target_color[1] * 100, target_color[2] * 100];
945 actual_color = [actual_color[0] * 100, actual_color[1] * 100, actual_color[2] * 100];
946 }
947 accuracy = 4;
948 if (mode == 'xyY') {
949 target_color = jsapi.math.color.XYZ2xyY(target_color[0], target_color[1], target_color[2], absolute && profile_wp_norm_1);
950 actual_color = jsapi.math.color.XYZ2xyY(actual_color[0], actual_color[1], actual_color[2], absolute && wp_norm_1);
951 }
952 else if (mode == "Lu'v'") {
953 target_color = jsapi.math.color.XYZ2Lu_v_(target_color[0], target_color[1], target_color[2], absolute && profile_wp_norm);
954 actual_color = jsapi.math.color.XYZ2Lu_v_(actual_color[0], actual_color[1], actual_color[2], absolute && wp_norm);
955 }
956 if (mode == "ICtCp") {
957 if (!absolute || use_profile_wp_as_ref) {
958 target_color = jsapi.math.color.adapt(target_color[0], target_color[1], target_color[2], (absolute && use_profile_wp_as_ref) ? profile_wp_norm_1 : [0.9642, 1, 0.8249], "D65", cat);
959 actual_color = jsapi.math.color.adapt(actual_color[0], actual_color[1], actual_color[2], (absolute && use_profile_wp_as_ref) ? profile_wp_norm_1 : [0.9642, 1, 0.8249], "D65", cat);
960 }
961 target_color = jsapi.math.color.XYZ2ICtCp(target_color[0] * ICtCp_lumi_target_scale, target_color[1] * ICtCp_lumi_target_scale, target_color[2] * ICtCp_lumi_target_scale);
962 actual_color = jsapi.math.color.XYZ2ICtCp(actual_color[0] * ICtCp_lumi_scale, actual_color[1] * ICtCp_lumi_scale, actual_color[2] * ICtCp_lumi_scale);
963 }
964 }
965 this.report_html.push(' <tr' + (i == this.data.length - 1 ? ' class="last-row"' : '') + '>');
966 var bar_html = [], rgb;
967 if (actual.tolerance_DE == null)
968 actual.tolerance_DE = warn_deviation;
969 if (actual.actual_DE == null)
970 actual.actual_DE = delta.E;
971 if (actual.delta == null)
972 actual.delta = delta;
973 if (warn_deviation != null) {
974 rgb = [0, 255, 0];
975 var step = 255 / (actual.tolerance_DE + actual.tolerance_DE / 2);
976 if (actual.actual_DE <= actual.tolerance_DE) {
977 rgb[0] += Math.min(step * actual.actual_DE, 255);
978 rgb[1] -= Math.min(step * actual.actual_DE, 255);
979 var maxrg = Math.max(rgb[0], rgb[1]);
980 rgb[0] *= (255 / maxrg);
981 rgb[1] *= (255 / maxrg);
982 rgb[0] = Math.round(rgb[0]);
983 rgb[1] = Math.round(rgb[1]);
984 }
985 else rgb = [255, 0, 0];
986 }
987 else rgb = [204, 204, 204];
988 bar_html.push(actual.actual_DE.accuracy(2) > 0 ? '<span style="display: block; width: ' + Math.round(10 * actual.actual_DE.accuracy(2)) + 'px; background-color: rgb(' + rgb.join(', ') + '); border: 1px solid silver; border-top: none; border-bottom: none; padding: .125em 0 .125em 0; overflow: hidden;">&#160;</span>' : '&#160;');
989 if (criteria.fields_match.join(',').indexOf('CMYK') > -1)
990 var device = current_cmyk;
991 else {
992 var device = current_rgb;
993 // XXX Note that round(50 * 2.55) = 127, but
994 // round(50 / 100 * 255) = 128 (the latter is what we want)!
995 for (var j=0; j<device.length; j++) device[j] = Math.round(device[j] / 100.0 * 255);
996 }
997 if ((target.gamma && actual.gamma) ||
998 (current_rgb[0] == 0 && current_rgb[1] == 0 && current_rgb[2] == 0) ||
999 (current_rgb[0] == 255 && current_rgb[1] == 255 && current_rgb[2] == 255)) {
1000 grayscale_values.push([current_rgb, target, actual, target_Lab, actual_Lab, target_rgb, actual_rgb]);
1001 }
1002 gamut_values.push([n, device_channels, device, target_color, actual_Lab, actual_color, target_rgb, actual_rgb, delta_calc_method, delta.E]);
1003 this.report_html.push(' <td>' + n.fill(String(number_of_sets).length) + '</td><td>' + device.join('</td><td>') + '</td><td>' + target_color[0].accuracy(accuracy) + '</td><td>' + target_color[1].accuracy(accuracy) + '</td><td>' + target_color[2].accuracy(accuracy) + '</td>' + (criteria.fields_match.join(',').indexOf('CMYK') < 0 ? '<td>' + (target.gamma ? target.gamma.accuracy(2) : '&#160;') + '</td>' : '') + '<td class="patch" style="background-color: rgb(' + target_rgb[0] + ', ' + target_rgb[1] + ', ' + target_rgb[2] + ');"><div class="patch">&#160;</div></td><td class="patch" style="background-color: rgb(' + actual_rgb[0] + ', ' + actual_rgb[1] + ', ' + actual_rgb[2] + ');"><div class="patch">&#160;</div></td><td>' + actual_color[0].accuracy(accuracy) + '</td><td>' + actual_color[1].accuracy(accuracy) + '</td><td>' + actual_color[2].accuracy(accuracy) + '</td>' + (criteria.fields_match.join(',').indexOf('CMYK') < 0 ? '<td>' + (actual.gamma ? actual.gamma.accuracy(2) : '&#160;') + '</td>' : '') + '<td class="' + (actual.actual_DL != null ? (actual.actual_DL.accuracy(2) < actual.tolerance_DL ? 'ok' : (actual.actual_DL.accuracy(2) == actual.tolerance_DL ? 'warn' : 'ko')) : 'info') + '">' + delta.Lw.accuracy(2) + '</td>' + /* '<td class="' + (actual.actual_Da != null ? (actual.actual_Da.accuracy(2) < actual.tolerance_Da ? 'ok' : (actual.actual_Da.accuracy(2) == actual.tolerance_Da ? 'warn' : 'ko')) : 'info') + '">' + delta.a.accuracy(2) + '</td><td class="' + (actual.actual_Db != null ? (actual.actual_Db.accuracy(2) < actual.tolerance_Db ? 'ok' : (actual.actual_Db.accuracy(2) == actual.tolerance_Db ? 'warn' : 'ko')) : 'info') + '">' + delta.b.accuracy(2) + '</td>' + */ '<td class="' + (actual.actual_DC != null ? (actual.actual_DC.accuracy(2) < actual.tolerance_DC ? 'ok' : (actual.actual_DC.accuracy(2) == actual.tolerance_DC ? 'warn' : 'ko')) : 'info') + '">' + delta.Cw.accuracy(2) + '</td><td class="' + (actual.actual_DH != null ? (actual.actual_DH.accuracy(2) < actual.tolerance_DH ? 'ok' : (actual.actual_DH.accuracy(2) == actual.tolerance_DH ? 'warn' : 'ko')) : 'info') + '">' + delta.Hw.accuracy(2) + '</td><td class="' + (actual.actual_DE != null && actual.tolerance_DE != null ? (actual.actual_DE.accuracy(2) < actual.tolerance_DE ? 'ok' : (actual.actual_DE.accuracy(2) == actual.tolerance_DE ? 'warn' : 'ko')) : (!warn_deviation || delta.E < warn_deviation ? 'info' : 'warn')) + '">' + delta.E.accuracy(2) + '</td><td class="bar">' + bar_html.join('') + '</td>');
1004 this.report_html.push(' </tr>');
1005 };
1006 this.report_html.push(' </table>');
1007 this.report_html.push(' </div>');
1008
1009 if (grayscale_values.length) {
1010 grayscale_values.sort(function(a, b) {
1011 // Compare signal level
1012 if (a[0][0] < b[0][0]) return -1;
1013 if (a[0][0] > b[0][0]) return 1;
1014 // If same signal level, compare target L*
1015 if (a[3][0] < b[3][0]) return -1;
1016 if (a[3][0] > b[3][0]) return 1;
1017 return 0;
1018 });
1019
1020 // CCT
1021 var CCT = [], hwidth = 100 / 18, width = (100 - hwidth) / grayscale_values.length, rows = 17, start = 10500, end = 2500, rstep = (start - end) / (rows - 1), rowh = 30;
1022 CCT.push(' <div class="CCT graph">');
1023 CCT.push(' <h3 class="toggle" onclick="toggle(this)">Correlated Color Temperature</h3>');
1024 CCT.push(' <table cellspacing="0" id="CCT" style="' + bggridlines(rowh) + 'height: ' + rowh * (rows + 1) + 'px;">');
1025 CCT.push('<tr><th style="width: ' + hwidth + '%; height: ' + rowh + 'px">' + start + 'K</th>');
1026 debug && window.console && console.log('CCT');
1027 for (var i = 0; i < grayscale_values.length; i ++) {
1028 var target_XYZ = jsapi.math.color.Lab2XYZ(grayscale_values[i][3][0], grayscale_values[i][3][1], grayscale_values[i][3][2], absolute && use_profile_wp_as_ref && profile_wp_norm, 100.0),
1029 actual_XYZ = jsapi.math.color.Lab2XYZ(grayscale_values[i][4][0], grayscale_values[i][4][1], grayscale_values[i][4][2], absolute && use_profile_wp_as_ref && profile_wp_norm, 100.0);
1030 if (!absolute) {
1031 // Make absolute
1032 target_XYZ = jsapi.math.color.adapt(target_XYZ[0], target_XYZ[1], target_XYZ[2], [96.42, 100, 82.49], profile_wp_norm, cat);
1033 actual_XYZ = jsapi.math.color.adapt(actual_XYZ[0], actual_XYZ[1], actual_XYZ[2], [96.42, 100, 82.49], wp_norm, cat);
1034 }
1035 debug && window.console && console.log('Target XYZ', target_XYZ.join(', '), 'Actual XYZ', actual_XYZ.join(', '));
1036 var target_CCT = jsapi.math.color.XYZ2CorColorTemp(target_XYZ[0], target_XYZ[1], target_XYZ[2]),
1037 actual_CCT = jsapi.math.color.XYZ2CorColorTemp(actual_XYZ[0], actual_XYZ[1], actual_XYZ[2]),
1038 target_Lab = jsapi.math.color.XYZ2Lab(target_XYZ[0], target_XYZ[1], target_XYZ[2], absolute && use_profile_wp_as_ref && profile_wp_norm),
1039 actual_Lab = jsapi.math.color.XYZ2Lab(actual_XYZ[0], actual_XYZ[1], actual_XYZ[2], absolute && use_profile_wp_as_ref && profile_wp_norm),
1040 delta = jsapi.math.color.delta(target_Lab[0], target_Lab[1], target_Lab[2], actual_Lab[0], actual_Lab[1], actual_Lab[2], delta_calc_method, null, null, null, (absolute && use_profile_wp_as_ref && profile_wp_norm_1) || 'D50', (profile_wp || wp)[1], wp[1], cat),
1041 delta_CH = Math.sqrt(Math.pow(delta.Cw, 2) + Math.pow(delta.Hw, 2));
1042 var rgb = jsapi.math.color.XYZ2RGB(actual_XYZ[0] / actual_XYZ[1] * 0.75, actual_XYZ[1] / actual_XYZ[1] * 0.75, actual_XYZ[2] / actual_XYZ[1] * 0.75, null, 255), brgb = [];
1043 for (var j = 0; j < 3; j ++)
1044 brgb[j] = Math.round(rgb[j] * .8);
1045 CCT.push('<td rowspan="' + rows + '" style="width: ' + width + '%;" data-title="Level: ' + (grayscale_values[i][0][0] / 255 * 100).accuracy(0) + '%\nNominal: ' + (target_CCT > -1 ? target_CCT.accuracy(0) + 'K' : 'Cannot compute CCT (XYZ out of range)') + '\nMeasured: ' + (actual_CCT > -1 ? actual_CCT.accuracy(0) + 'K' : 'Cannot compute CCT (XYZ out of range)') + '\nΔ' + strip_tags(delta_C_desc) + ': ' + delta.Cw.accuracy(2) + '\nΔ' + strip_tags(delta_H_desc) + ': ' + delta.Hw.accuracy(2) + '"><div class="col" style="height: ' + rowh * rows + 'px;"><div class="ref" style="bottom: ' + Math.min((target_CCT - end) / rstep * rowh + rowh / 2, rowh * rows) + 'px;"></div><div class="act" style="background-color: rgb(' + rgb.join(', ') + '); border-color: rgb(' + brgb.join(', ') + '); bottom: ' + Math.min((actual_CCT - end) / rstep * rowh + rowh / 2, rowh * rows) + 'px;"></div></div></td>');
1046 }
1047 CCT.push('</tr>');
1048 for (var i = start - rstep; i >= end; i -= rstep) {
1049 CCT.push('<tr><th style="height: ' + rowh + 'px">' + i + 'K</th></tr>');
1050 }
1051 CCT.push('<tr class="x"><th style="height: ' + rowh + 'px">%</th>');
1052 for (var i = 0; i < grayscale_values.length; i ++) {
1053 CCT.push('<td>' + (grayscale_values[i][0][0] / 255 * 100).accuracy(0) + '</td>');
1054 }
1055 CCT.push('</tr></table></div>');
1056 //var idx = this.report_html.indexOf(' <div class="overview">');
1057 //this.report_html.splice(idx, 0, CCT.join('\n'));
1058 this.report_html = this.report_html.concat(CCT);
1059
1060 // Gamma tracking
1061 var numgamma = 0, gamma_max = 3, gamma_min = 1.4;
1062 for (var i = 0; i < grayscale_values.length; i ++) {
1063 if (grayscale_values[i][1].gamma && grayscale_values[i][2].gamma) {
1064 numgamma ++;
1065 gamma_max = Math.max(gamma_max, grayscale_values[i][1].gammaR, grayscale_values[i][2].gammaR, grayscale_values[i][1].gammaG, grayscale_values[i][2].gammaG, grayscale_values[i][1].gammaB, grayscale_values[i][2].gammaB);
1066 gamma_min = Math.min(gamma_min, grayscale_values[i][1].gammaR, grayscale_values[i][2].gammaR, grayscale_values[i][1].gammaG, grayscale_values[i][2].gammaG, grayscale_values[i][1].gammaB, grayscale_values[i][2].gammaB);
1067 }
1068 }
1069 if (numgamma > 0) {
1070 var gamma_tracking = [], hwidth = 100 / 31, width = (100 - hwidth) / numgamma, start = Math.ceil(gamma_max * 10), end = Math.floor(gamma_min * 10), rows = start - end + 1, rstep = (start - end) / (rows - 1), rowh = 30;
1071 gamma_tracking.push(' <div class="gamma_tracking graph">');
1072 gamma_tracking.push(' <h3 class="toggle" onclick="toggle(this)">Gamma</h3>');
1073 gamma_tracking.push(' <table cellspacing="0" id="gamma_tracking" style="' + bggridlines(rowh) + 'height: ' + rowh * (rows + 1) + 'px;">');
1074 gamma_tracking.push('<tr><th style="width: ' + hwidth + '%; height: ' + rowh + 'px">' + (start / 10).toFixed(1) + '</th>');
1075 for (var i = 0; i < grayscale_values.length; i ++) {
1076 if (!grayscale_values[i][1].gamma || !grayscale_values[i][2].gamma) continue;
1077 var target_Lab = grayscale_values[i][3],
1078 actual_Lab = grayscale_values[i][4],
1079 target_gamma = grayscale_values[i][1].gamma,
1080 actual_gamma = grayscale_values[i][2].gamma,
1081 gamma = 2.2 + target_gamma - actual_gamma,
1082 Eprime = Math.pow(Math.pow(0.75, 2.2), (1 / gamma)),
1083 rgb = [],
1084 brgb = [],
1085 delta = jsapi.math.color.delta(target_Lab[0], target_Lab[1], target_Lab[2], actual_Lab[0], actual_Lab[1], actual_Lab[2], delta_calc_method, null, null, null, absolute && (use_profile_wp_as_ref ? profile_wp_norm_1 : 'D50'), (profile_wp || wp)[1], wp[1], cat);
1086 for (var j = 0; j < 3; j ++) {
1087 rgb.push(Math.round(Eprime * 255));
1088 brgb.push(Math.round(Eprime * 204));
1089 }
1090 gamma_tracking.push('<td rowspan="' + rows + '" style="width: ' + width + '%;" data-title="Level: ' + (grayscale_values[i][0][0] / 255 * 100).accuracy(0) + '%\nNominal: Gamma ' + grayscale_values[i][1].gamma.accuracy(2) + '\nMeasured: Gamma ' + grayscale_values[i][2].gamma.accuracy(2) + (get_gammaRGB ? '\nR: ' + grayscale_values[i][2].gammaR.accuracy(2) + '\nG: ' + grayscale_values[i][2].gammaG.accuracy(2) + '\nB: ' + grayscale_values[i][2].gammaB.accuracy(2) : '') + '\nΔ' + strip_tags(delta_L_desc) + ': ' + delta.Lw.accuracy(2) + '"><div class="col" style="height: ' + rowh * rows + 'px;"><div class="ref" style="bottom: ' + ((grayscale_values[i][1].gamma * 10 - end) / rstep * rowh + rowh / 2) + 'px;"></div><div class="act" style="bottom: ' + ((grayscale_values[i][2].gamma * 10 - end) / rstep * rowh + rowh / 2) + 'px; background-color: rgb(' + rgb.join(', ') + '); border-color: rgb(' + brgb.join(', ') + ');"></div>' + (get_gammaRGB ? '<div class="act" style="bottom: ' + ((grayscale_values[i][2].gammaR * 10 - end) / rstep * rowh + rowh / 2) + 'px; background-color: #f00; border-color: #c00;"></div><div class="act" style="bottom: ' + ((grayscale_values[i][2].gammaG * 10 - end) / rstep * rowh + rowh / 2) + 'px; background-color: #0f0; border-color: #0c0;"></div><div class="act" style="bottom: ' + ((grayscale_values[i][2].gammaB * 10 - end) / rstep * rowh + rowh / 2) + 'px; background-color: #00a0ff; border-color: #0080ff;"></div>' : '') + '</div></td>');
1091 }
1092 gamma_tracking.push('</tr>');
1093 for (var i = start - rstep; i >= end; i -= rstep) {
1094 gamma_tracking.push('<tr><th style="height: ' + rowh + 'px">' + (i / 10).toFixed(1) + '</th></tr>');
1095 }
1096 gamma_tracking.push('<tr class="x"><th>%</th>');
1097 for (var i = 0; i < grayscale_values.length; i ++) {
1098 if (!grayscale_values[i][1].gamma || !grayscale_values[i][2].gamma) continue;
1099 gamma_tracking.push('<td>' + (grayscale_values[i][0][0] / 255 * 100).accuracy(0) + '</td>');
1100 }
1101 gamma_tracking.push('</tr></table></div>');
1102 //var idx = this.report_html.indexOf(' <div class="overview">');
1103 //this.report_html.splice(idx, 0, gamma_tracking.join('\n'));
1104 this.report_html = this.report_html.concat(gamma_tracking);
1105 } // numgamma > 0
1106
1107 // RGB Balance
1108 var rgb_balance = [], hwidth = 100 / 21, width = (100 - hwidth) / grayscale_values.length, rows = 17, start = 40, end = -40, rstep = (start - end) / (rows - 1), rowh = 30, actual_white_Y = jsapi.math.color.Lab2XYZ(grayscale_values[grayscale_values.length - 1][4][0], 0, 0)[1];
1109 rgb_balance.push(' <div class="rgb_balance graph">');
1110 rgb_balance.push(' <h3 class="toggle" onclick="toggle(this)">RGB Gray Balance</h3>');
1111 rgb_balance.push(' <table cellspacing="0" id="rgb_balance" style="' + bggridlines(rowh) + 'height: ' + rowh * (rows + 1) + 'px;">');
1112 rgb_balance.push('<tr><th style="width: ' + hwidth + '%; height: ' + rowh + 'px">+' + start + '%</th>');
1113 debug && window.console && console.log('RGB Gray Balance');
1114 for (var i = 0; i < grayscale_values.length; i ++) {
1115 var target_Lab = grayscale_values[i][3],
1116 actual_Lab = grayscale_values[i][4],
1117 target_XYZ = jsapi.math.color.Lab2XYZ(target_Lab[0], target_Lab[1], target_Lab[2], absolute && use_profile_wp_as_ref && profile_wp_norm, 100.0),
1118 actual_XYZ = jsapi.math.color.Lab2XYZ(actual_Lab[0], actual_Lab[1], actual_Lab[2], absolute && use_profile_wp_as_ref && profile_wp_norm, 100.0),
1119 target_rgb = [target_XYZ[0] / target_XYZ[1], target_XYZ[1] / target_XYZ[1], target_XYZ[2] / target_XYZ[1]],
1120 //target_rgb = jsapi.math.color.XYZ2RGB(target_rgb[0], target_rgb[1], target_rgb[2], absolute && wp_norm_1, 1, false, false),
1121 target_rgb = jsapi.math.color.xyz_to_rgb_matrix(0.6400, 0.3300, 0.3000, 0.6000, 0.1500, 0.0600, (absolute && wp_norm_1) || "D65", 1.0).multiply(target_rgb),
1122 fact = 1,
1123 actual_xyY = jsapi.math.color.XYZ2xyY(actual_XYZ[0], actual_XYZ[1], actual_XYZ[2]),
1124 actual_rgb = [actual_xyY[0] / actual_xyY[1] * fact, fact, (1 - (actual_xyY[0] + actual_xyY[1])) / actual_xyY[1] * fact],
1125 //actual_rgb = jsapi.math.color.XYZ2RGB(actual_rgb[0], actual_rgb[1], actual_rgb[2], absolute && wp_norm_1, 1, false, false),
1126 actual_rgb = jsapi.math.color.xyz_to_rgb_matrix(0.6400, 0.3300, 0.3000, 0.6000, 0.1500, 0.0600, (absolute && wp_norm_1) || "D65", 1.0).multiply(actual_rgb),
1127 delta = jsapi.math.color.delta(target_Lab[0], target_Lab[1], target_Lab[2], actual_Lab[0], actual_Lab[1], actual_Lab[2], delta_calc_method, null, null, null, absolute && (use_profile_wp_as_ref ? profile_wp_norm_1 : 'D50'), (profile_wp || wp)[1], wp[1], cat);
1128 debug && window.console && console.log('Target XYZ', target_XYZ.join(', '), 'Actual XYZ', actual_XYZ.join(', '));
1129 debug && window.console && console.log('Target RGB', target_rgb.join(', '), 'Actual RGB', actual_rgb.join(', '));
1130 if (isNaN(jsapi.math.min(target_rgb)) || isNaN(jsapi.math.min(actual_rgb))) {
1131 rgb_balance.push('<td rowspan="' + rows + '" style="width: ' + width + '%;" data-title="Level: ' + (grayscale_values[i][0][0] / 255 * 100).accuracy(0) + '%\nΔ' + strip_tags(delta_C_desc) + ': ' + delta.Cw.accuracy(2) + '\nΔ' + strip_tags(delta_H_desc) + ': ' + delta.Hw.accuracy(2) + '"></td>');
1132 continue;
1133 }
1134 rgb_balance.push('<td rowspan="' + rows + '" style="width: ' + width + '%;" data-title="Level: ' + (grayscale_values[i][0][0] / 255 * 100).accuracy(0) + '%\nR: ' + (actual_rgb[0] - target_rgb[0] > 0 ? '+' : '') + ((actual_rgb[0] - target_rgb[0]) * 100).accuracy(2) + '%\nG: ' + (actual_rgb[1] - target_rgb[1] > 0 ? '+' : '') + ((actual_rgb[1] - target_rgb[1]) * 100).accuracy(2) + '%\nB: ' + (actual_rgb[2] - target_rgb[2] > 0 ? '+' : '') + ((actual_rgb[2] - target_rgb[2]) * 100).accuracy(2) + '%\nΔ' + strip_tags(delta_C_desc) + ': ' + delta.Cw.accuracy(2) + '\nΔ' + strip_tags(delta_H_desc) + ': ' + delta.Hw.accuracy(2) + '"><div class="col" style="height: ' + rowh * rows + 'px;"><div class="ref" style="bottom: ' + rowh * rows / 2 + 'px;"></div><div class="act" style="bottom: ' + (rowh * rows / 2 + (actual_rgb[0] - target_rgb[0]) * 100 * rowh / rstep) + 'px; background-color: #f00; border-color: #c00;"></div><div class="act" style="bottom: ' + (rowh * rows / 2 + (actual_rgb[1] - target_rgb[1]) * 100 * rowh / rstep) + 'px; background-color: #0f0; border-color: #0c0;"></div><div class="act" style="bottom: ' + (rowh * rows / 2 + (actual_rgb[2] - target_rgb[2]) * 100 * rowh / rstep) + 'px; background-color: #00a0ff; border-color: #0080ff;"></div></div></td>');
1135 }
1136 rgb_balance.push('</tr>');
1137 for (var i = start - rstep; i >= end; i -= rstep) {
1138 rgb_balance.push('<tr><th style="height: ' + rowh + 'px">' + (i > 0 ? '+' : '') + i + '%</th></tr>');
1139 }
1140 rgb_balance.push('<tr class="x"><th>%</th>');
1141 for (var i = 0; i < grayscale_values.length; i ++) {
1142 rgb_balance.push('<td>' + (grayscale_values[i][0][0] / 255 * 100).accuracy(0) + '</td>');
1143 }
1144 rgb_balance.push('</tr></table></div>');
1145 //var idx = this.report_html.indexOf(' <div class="overview">');
1146 //this.report_html.splice(idx, 0, rgb_balance.join('\n'));
1147 this.report_html = this.report_html.concat(rgb_balance);
1148 }
1149
1150 if (gamut_values.length) {
1151 var accuracy, offset, multiplier;
1152 switch (mode) {
1153 case "Lu'v'":
1154 xy = "u'v'";
1155 accuracy = 4;
1156 offset = [10, 95];
1157 multiplier = 1200;
1158 break;
1159 case 'XYZ':
1160 xy = 'XZ';
1161 accuracy = 2;
1162 offset = [5, 95];
1163 multiplier = 8;
1164 break;
1165 case 'xyY':
1166 xy = 'xy';
1167 accuracy = 4;
1168 offset = [10, 95];
1169 multiplier = 1000;
1170 break;
1171 case "ICtCp":
1172 xy = 'CtCp';
1173 accuracy = 4;
1174 offset = [50, 50];
1175 multiplier = 1000;
1176 break;
1177 default:
1178 xy = 'a*b*';
1179 accuracy = 2;
1180 offset = [50, 50];
1181 multiplier = 3;
1182 }
1183 this.report_html.push(' <div class="gamut graph">');
1184 this.report_html.push(' <h3 class="toggle" onclick="toggle(this)">Gamut ' + xy + '</h3>');
1185 this.report_html.push(' <div class="canvas" id="gamut" style="height: 900px;"><div class="inner" style="left: ' + offset[0] + '%; top: ' + offset[1] + '%;"><div class="overlay" style="left: -' + offset[0] * 9 + 'em; top: -' + offset[1] * 9 + 'em;"></div>');
1186 // Sort by L*
1187 gamut_values.sort(function (a, b) {
1188 if (a[4][0] < b[4][0]) return -1;
1189 if (a[4][0] > b[4][0]) return 1;
1190 return 0;
1191 });
1192 for (var i = 0; i < gamut_values.length; i ++) {
1193 var n = gamut_values[i][0],
1194 device_channels = gamut_values[i][1],
1195 device = gamut_values[i][2],
1196 target_color = gamut_values[i][3],
1197 target_xy,
1198 actual_color = gamut_values[i][5],
1199 actual_xy,
1200 target_rgb = gamut_values[i][6],
1201 actual_rgb = gamut_values[i][7],
1202 delta_calc_method = gamut_values[i][8],
1203 deltaE = gamut_values[i][9];
1204 switch (mode) {
1205 case 'XYZ':
1206 target_xy = [target_color[2], target_color[0]];
1207 actual_xy = [actual_color[2], actual_color[0]];
1208 break;
1209 case 'xyY':
1210 target_xy = target_color;
1211 actual_xy = actual_color;
1212 break;
1213 default:
1214 target_xy = target_color.slice(1);
1215 actual_xy = actual_color.slice(1);
1216 }
1217 this.report_html.push('<div class="wrap" style="left: ' + (target_xy[0] * multiplier).accuracy(8) + 'em; bottom: ' + (target_xy[1] * multiplier).accuracy(8) + 'em;" data-title="#' + n.fill(String(number_of_sets).length) + ' ' + device_channels + ': ' + device.join(' ') + '\nNominal ' + labels.split(',').join('') + ': ' + [target_color[0].accuracy(accuracy), target_color[1].accuracy(accuracy), target_color[2].accuracy(accuracy)].join(' ') + '\n(Measured ' + labels.split(',').join('') + ': ' + [actual_color[0].accuracy(accuracy), actual_color[1].accuracy(accuracy), actual_color[2].accuracy(accuracy)].join(' ') + ')\nΔ' + strip_tags(delta_E_desc) + ': ' + deltaE.accuracy(2) + '"><div class="ref patch-' + i + '" data-index="' + i + '" data-bgcolor="rgb(' + target_rgb.join(', ') + ')" data-bordercolor="rgb(' + [Math.round(target_rgb[0] * .8), Math.round(target_rgb[1] * .8), Math.round(target_rgb[2] * .8)].join(', ') + ')"></div></div><div class="wrap wrap-act" style="left: ' + (actual_xy[0] * multiplier).accuracy(8) + 'em; bottom: ' + (actual_xy[1] * multiplier).accuracy(8) + 'em;" data-title="#' + n.fill(String(number_of_sets).length) + ' ' + device_channels + ': ' + device.join(' ') + '\nMeasured ' + labels.split(',').join('') + ': ' + [actual_color[0].accuracy(accuracy), actual_color[1].accuracy(accuracy), actual_color[2].accuracy(accuracy)].join(' ') + '\n(Nominal ' + labels.split(',').join('') + ': ' + [target_color[0].accuracy(accuracy), target_color[1].accuracy(accuracy), target_color[2].accuracy(accuracy)].join(' ') + ')\nΔ' + strip_tags(delta_E_desc) + ': ' + deltaE.accuracy(2) + '"><div class="act patch-' + i + '" data-index="' + i + '" style="background-color: rgb(' + actual_rgb.join(', ') + '); border-color: rgb(' + [Math.round(actual_rgb[0] * .8), Math.round(actual_rgb[1] * .8), Math.round(actual_rgb[2] * .8)].join(', ') + ');"></div></div>');
1218 }
1219 this.report_html.push(' </div></div>');
1220 }
1221
1222 return this.report_html.join('\n')
1223 };
1224
1225 function bggridlines(rowh) {
1226 return window.btoa ? 'background-image: url(data:image/svg+xml;base64,' + btoa('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="10px" height="' + rowh + 'px" viewBox="0 0 10 ' + rowh + '"><line opacity="0.5" stroke="#999999" x1="0" y1="' + rowh / 2 + '" x2="10" y2="' + rowh / 2 + '"/></svg>') + ');' : '';
1227 };
1228
1229 function trim(txt) {
1230 return txt.replace(/^\s+|\s+$/g, "")
1231 };
1232
1233 function lf2cr(txt) {
1234 return txt.replace(/\r\n/g, "\r").replace(/\n/g, "\r")
1235 };
1236
1237 function cr2lf(txt) {
1238 // CR LF = Windows
1239 // CR = Mac OS 9
1240 // LF = Unix/Linux/Mac OS X
1241 return txt.replace(/\r\n/g, "\n").replace(/\r/g, "\n")
1242 };
1243
1244 function compact(txt, collapse_whitespace) {
1245 txt = trim(txt).replace(/\n\s+|\s+\n/g, "\n");
1246 return collapse_whitespace?txt.replace(/\s+/g, " "):txt
1247 };
1248
1249 function comma2point(txt) {
1250 return decimal(txt)
1251 };
1252
1253 function decimal(txt, sr, re) {
1254 if (!sr) sr = "\\,";
1255 if (!re) re = ".";
1256 return txt.replace(new RegExp("((^|\\s)\\-?\\d+)"+sr+"(\\d+(\\s|$))", "g"), "$1"+re+"$3")
1257 };
1258
1259 function toarray(txt, level) {
1260 txt=comma2point(compact(cr2lf(txt)));
1261 if (!txt) return [];
1262 if (level) {
1263 txt=txt.split(/\s/)
1264 }
1265 else {
1266 txt=txt.split("\n");
1267 for (var i=0; i<txt.length; i++) {
1268 txt[i]=txt[i].split(/\s+/);
1269 for (var j=0; j<txt[i].length; j++) {
1270 parsed=parseFloat(txt[i][j]);
1271 if (!isNaN(parsed)) txt[i][j]=parsed;
1272 }
1273 }
1274 };
1275 return txt
1276 };
1277
1278 function fromarray(array, level) {
1279 array = array.clone();
1280 if (level) return array.join("\t");
1281 for (var i=0; i<array.length; i++) array[i]=array[i].join("\t");
1282 return array.join("\n")
1283 };
1284
1285 function analyze(which) {
1286 var f=document.forms,
1287 e=f['F_out'].elements,fv,i,j,v,s;
1288
1289 if (!trim(f["F_data"].elements["FF_data_in"].value) || !trim(f["F_data"].elements["FF_data_ref"].value)) return;
1290
1291 if (!get_data(which)) {
1292 if (which == "r" || !which) {
1293 if (trim(f['F_data'].elements['FF_data_ref'].value)) {
1294 if (!data_ref.data_format.length) set_status("Reference data: No or invalid data format.");
1295 else if (!data_ref.data.length) set_status("Reference data: No or invalid values.")
1296 };
1297 };
1298 if (which == "i" || !which) {
1299 if (trim(f['F_data'].elements['FF_data_in'].value)) {
1300 if (!data_in.data_format.length) set_status("Measurement data: No or invalid data format.");
1301 else if (!data_in.data.length) set_status("Measurement data: No or invalid values.")
1302 };
1303 }
1304 };
1305
1306 var _criteria = [];
1307 for (var id in comparison_criteria) {
1308 if (comparison_criteria[id] && comparison_criteria[id].name && _criteria.indexOf(comparison_criteria[id]) < 0) {
1309 for (var i=0; i<comparison_criteria[id].fields_match.length; i++) {
1310 if (data_ref.data_format.indexOf(comparison_criteria[id].fields_match[i]) < 0)
1311 break;
1312 else if (fields_match.indexOf(comparison_criteria[id].fields_match[i]) < 0)
1313 fields_match.push(comparison_criteria[id].fields_match[i]);
1314 };
1315 if (i == comparison_criteria[id].fields_match.length) {
1316 _criteria.push(comparison_criteria[id])
1317 }
1318 }
1319 };
1320 for (var i=0; i<_criteria.length; i++) {
1321 e['FF_criteria'].options[i] = new Option(_criteria[i].name, _criteria[i].id); //, data_ref.id == _criteria[i].id, data_ref.id == _criteria[i].id);
1322 if (data_ref.id == _criteria[i].id) e['FF_criteria'].selectedIndex = i;
1323 };
1324
1325 var criteria = comparison_criteria[e['FF_criteria'].value],
1326 fields_extract_r = fields_match.slice().concat(criteria.fields_compare),
1327 fields_extract_i = fields_match.slice().concat(criteria.fields_compare);
1328
1329 for (i=0; i<fields_extract_i.length; i++) {
1330 for (j=0; j<data_in.data_format.length; j++) {
1331 if (data_in.data_format[j]==fields_extract_i[i]) {
1332 fields_extract_indexes_i.push(j);
1333 break
1334 }
1335 }
1336 };
1337 for (i=0; i<fields_extract_r.length; i++) {
1338 for (j=0; j<data_ref.data_format.length; j++) {
1339 if (data_ref.data_format[j]==fields_extract_r[i]) {
1340 fields_extract_indexes_r.push(j);
1341 break
1342 }
1343 }
1344 };
1345
1346 if (data_in.data.length && data_ref.data.length && data_in.data.length != data_ref.data.length) {
1347 alert("Different amount of sets in measurements and reference data.");
1348 return false
1349 };
1350 var data_in_format_missing_fields = [], data_ref_format_missing_fields = [], errortxt = "";
1351 for (i = 0; i < fields_extract_i.length; i ++) {
1352 if (data_in.data_format.indexOf(fields_extract_i[i]) < 0) data_in_format_missing_fields.push(fields_extract_i[i]);
1353 if (data_ref.data_format.indexOf(fields_extract_i[i]) < 0) data_ref_format_missing_fields.push(fields_extract_i[i]);
1354 };
1355 if (data_in_format_missing_fields.length) {
1356 errortxt += "Measurement data is missing the following fields: " + data_in_format_missing_fields.join(", ") + ".\n"
1357 }
1358 if (data_ref_format_missing_fields.length) {
1359 errortxt += "Reference data is missing the following fields: " + data_ref_format_missing_fields.join(", ") + ".\n"
1360 };
1361 if (errortxt) {
1362 alert(errortxt + "Measurements and reference data must contain atleast: " + fields_extract_i.join(", "));
1363 return
1364 };
1365
1366 if (data_ref.data_format.length && data_ref.data.length && data_in.data_format.length && data_in.data.length) {
1367 compare();
1368 };
1369 };
1370
1371 function get_colors(target, actual, o, no_Lab, no_XYZ, gray_balance_cal_only, skip_gamma, profile_wp_norm, wp_norm, absolute, cat, use_profile_wp_as_ref) {
1372 var target_Lab, actual_Lab, target_XYZ, actual_XYZ, current_rgb, current_cmyk = [];
1373 target_Lab = [target[fields_extract_indexes_r[o + 1]], target[fields_extract_indexes_r[o + 2]], target[fields_extract_indexes_r[o + 3]]];
1374 actual_Lab = [actual[fields_extract_indexes_i[o + 1]], actual[fields_extract_indexes_i[o + 2]], actual[fields_extract_indexes_i[o + 3]]];
1375 if (no_Lab && !no_XYZ) {
1376 target_XYZ = jsapi.math.color.adapt(target_Lab[0], target_Lab[1], target_Lab[2], profile_wp_norm, [96.42, 100, 82.49], cat);
1377 actual_XYZ = jsapi.math.color.adapt(actual_Lab[0], actual_Lab[1], actual_Lab[2], wp_norm, [96.42, 100, 82.49], cat);
1378 target_Lab = jsapi.math.color.XYZ2Lab(target_XYZ[0], target_XYZ[1], target_XYZ[2]);
1379 actual_Lab = jsapi.math.color.XYZ2Lab(actual_XYZ[0], actual_XYZ[1], actual_XYZ[2]);
1380 }
1381 if (fields_match.join(',').indexOf('RGB') == 0) {
1382 current_rgb = [actual[fields_extract_indexes_i[0]], actual[fields_extract_indexes_i[1]], actual[fields_extract_indexes_i[2]]];
1383 if (fields_match.join(',').indexOf('CMYK') > -1)
1384 current_cmyk = [actual[fields_extract_indexes_i[3]], actual[fields_extract_indexes_i[4]], actual[fields_extract_indexes_i[5]], actual[fields_extract_indexes_i[6]]];
1385 }
1386 else {
1387 current_rgb = [actual[fields_extract_indexes_i[4]], actual[fields_extract_indexes_i[5]], actual[fields_extract_indexes_i[6]]];
1388 if (fields_match.join(',').indexOf('CMYK') > -1)
1389 current_cmyk = [actual[fields_extract_indexes_i[0]], actual[fields_extract_indexes_i[1]], actual[fields_extract_indexes_i[2]], actual[fields_extract_indexes_i[3]]];
1390 }
1391 for (var l=0; l<current_rgb.length; l++) current_rgb[l] = current_rgb[l].accuracy(2);
1392 for (var l=0; l<current_cmyk.length; l++) current_cmyk[l] = current_cmyk[l].accuracy(2);
1393 if (current_rgb[0] == current_rgb[1] && current_rgb[1] == current_rgb[2]) {
1394 if (gray_balance_cal_only) {
1395 target_Lab[0] = actual_Lab[0]; // set L to measured value
1396 target_Lab[1] = target_Lab[2] = 0; // set a=b=0
1397 }
1398 }
1399 if (absolute) {
1400 target_XYZ = jsapi.math.color.Lab2XYZ(target_Lab[0], target_Lab[1], target_Lab[2], null, 100.0);
1401 target_XYZ = jsapi.math.color.adapt(target_XYZ[0], target_XYZ[1], target_XYZ[2], [96.42, 100, 82.49], profile_wp_norm, cat);
1402 target_Lab = jsapi.math.color.XYZ2Lab(target_XYZ[0], target_XYZ[1], target_XYZ[2], use_profile_wp_as_ref && profile_wp_norm);
1403 actual_XYZ = jsapi.math.color.Lab2XYZ(actual_Lab[0], actual_Lab[1], actual_Lab[2], null, 100.0);
1404 actual_XYZ = jsapi.math.color.adapt(actual_XYZ[0], actual_XYZ[1], actual_XYZ[2], [96.42, 100, 82.49], wp_norm, cat);
1405 actual_Lab = jsapi.math.color.XYZ2Lab(actual_XYZ[0], actual_XYZ[1], actual_XYZ[2], use_profile_wp_as_ref && profile_wp_norm);
1406 }
1407 if (current_rgb[0] == current_rgb[1] && current_rgb[1] == current_rgb[2]) {
1408 if (!skip_gamma && !current_cmyk.length && current_rgb[0] > 0 && current_rgb[0] < 100 && target_Lab[0] > 0 && actual_Lab[0] > 0) {
1409 if (!absolute) {
1410 target_XYZ = jsapi.math.color.Lab2XYZ(target_Lab[0], target_Lab[1], target_Lab[2], null, 100.0);
1411 actual_XYZ = jsapi.math.color.Lab2XYZ(actual_Lab[0], actual_Lab[1], actual_Lab[2], null, 100.0);
1412 }
1413 target.gamma = Math.log(target_XYZ[1] / 100) / Math.log(current_rgb[0] / 100);
1414 actual.gamma = Math.log(actual_XYZ[1] / 100) / Math.log(current_rgb[0] / 100);
1415 if (get_gammaRGB) {
1416 var profile_wp_norm_1 = [profile_wp_norm[0] / 100.0, profile_wp_norm[1] / 100.0, profile_wp_norm[2] / 100.0],
1417 wp_norm_1 = [wp_norm[0] / 100.0, wp_norm[1] / 100.0, wp_norm[2] / 100.0],
1418 target_RGB = jsapi.math.color.xyz_to_rgb_matrix(0.6400, 0.3300, 0.3000, 0.6000, 0.1500, 0.0600, (absolute && profile_wp_norm_1) || "D50", 1.0).multiply(target_XYZ),
1419 actual_RGB = jsapi.math.color.xyz_to_rgb_matrix(0.6400, 0.3300, 0.3000, 0.6000, 0.1500, 0.0600, (absolute && wp_norm_1) || "D50", 1.0).multiply(actual_XYZ);
1420 target.gammaR = Math.log(target_RGB[0] / 100) / Math.log(current_rgb[0] / 100);
1421 target.gammaG = Math.log(target_RGB[1] / 100) / Math.log(current_rgb[0] / 100);
1422 target.gammaB = Math.log(target_RGB[2] / 100) / Math.log(current_rgb[0] / 100);
1423 actual.gammaR = Math.log(actual_RGB[0] / 100) / Math.log(current_rgb[0] / 100);
1424 actual.gammaG = Math.log(actual_RGB[1] / 100) / Math.log(current_rgb[0] / 100);
1425 actual.gammaB = Math.log(actual_RGB[2] / 100) / Math.log(current_rgb[0] / 100);
1426 }
1427 else {
1428 target.gammaR = target.gamma;
1429 target.gammaG = target.gamma;
1430 target.gammaB = target.gamma;
1431 actual.gammaR = actual.gamma;
1432 actual.gammaG = actual.gamma;
1433 actual.gammaB = actual.gamma;
1434 }
1435 }
1436 }
1437 return {target_Lab: target_Lab,
1438 actual_Lab: actual_Lab,
1439 current_rgb: current_rgb,
1440 current_cmyk: current_cmyk,
1441 target_XYZ: target_XYZ,
1442 actual_XYZ: actual_XYZ};
1443 };
1444
1445 function get_data(which) {
1446 var f=document.forms;
1447
1448 if (which == "r" || !which) {
1449 data_ref=new dataset(f["F_data"].elements["FF_data_ref"].value)
1450 };
1451 if (which == "i" || !which) {
1452 data_in=new dataset(f["F_data"].elements["FF_data_in"].value)
1453 };
1454
1455 if (which == "r" || !which) {
1456 if (!data_ref.data_format.length) return false;
1457 if (!data_ref.data.length) return false
1458 };
1459 if (which == "i" || !which) {
1460 if (!data_in.data_format.length) return false;
1461 if (!data_in.data.length) return false
1462 };
1463
1464 return true
1465 };
1466
1467 function compare(set_delta_calc_method) {
1468 form_elements_set_disabled(null, true);
1469 var fe = document.forms["F_out"].elements, fe2 = document.forms["F_data"].elements;
1470 if (fe2["FF_variables"]) try {
1471 eval(fe2["FF_variables"].value);
1472 window.comparison_criteria = comparison_criteria;
1473 if (debug) alert("Comparsion criteria: " + (comparison_criteria.toSource ? comparison_criteria.toSource() : comparison_criteria))
1474 }
1475 catch (e) {
1476 alert("Error parsing variable:\n" + e + "\nUsing default values.")
1477 };
1478 var report = data_in.generate_report(set_delta_calc_method),
1479 criteria = comparison_criteria[fe['FF_criteria'].value];
1480 document.getElementById('result').innerHTML = report;
1481 layout();
1482 document.getElementById('reporttitle').style.visibility = "visible";
1483 document.getElementById('report').style.visibility = "visible";
1484 form_elements_set_disabled(null, false);
1485 form_element_set_disabled(fe['FF_absolute'], !!criteria.lock_use_absolute_values);
1486 form_element_set_disabled(fe['FF_use_profile_wp_as_ref'], !fe['FF_absolute'].checked);
1487 if (document.getElementsByClassName) {
1488 var canvas = document.getElementsByClassName('canvas'),
1489 inner_coords, mouse_is_down, mouse_down_coords;
1490 document.addEventListener('mouseup', function (e) {
1491 for (var i = 0; i < canvas.length; i ++) {
1492 jsapi.dom.attributeRemoveWord(canvas[i], 'class', 'dragging');
1493 }
1494 mouse_is_down = false;
1495 });
1496 for (var i = 0; i < canvas.length; i ++) {
1497 var act = Array.prototype.slice.apply(canvas[i].getElementsByClassName('act')),
1498 ref = Array.prototype.slice.apply(canvas[i].getElementsByClassName('ref')),
1499 pts = act.concat(ref);
1500 for (var j = 0; j < pts.length; j ++) {
1501 pts[j].addEventListener('mouseenter', function (e) {
1502 var linked = this.parentNode.parentNode.getElementsByClassName('patch-' + jsapi.dom.attr(this, 'data-index'));
1503 jsapi.dom.attributeAddWord(this.parentNode.parentNode, 'class', 'hover');
1504 for (var k = 0; k < linked.length; k ++) {
1505 jsapi.dom.attributeAddWord(linked[k].parentNode, 'class', 'hover');
1506 if (jsapi.dom.attributeHasWord(linked[k], 'class', 'ref')) {
1507 linked[k].style.backgroundColor = jsapi.dom.attr(linked[k], 'data-bgcolor');
1508 linked[k].style.borderColor = jsapi.dom.attr(linked[k], 'data-bordercolor');
1509 }
1510 }
1511 });
1512 pts[j].addEventListener('mouseleave', function (e) {
1513 var linked = this.parentNode.parentNode.getElementsByClassName('patch-' + jsapi.dom.attr(this, 'data-index'));
1514 jsapi.dom.attributeRemoveWord(this.parentNode.parentNode, 'class', 'hover');
1515 for (var k = 0; k < linked.length; k ++) {
1516 jsapi.dom.attributeRemoveWord(linked[k].parentNode, 'class', 'hover');
1517 if (jsapi.dom.attributeHasWord(linked[k], 'class', 'ref')) {
1518 linked[k].style.backgroundColor = '';
1519 linked[k].style.borderColor = '';
1520 }
1521 }
1522 });
1523 }
1524 // Reset viewport
1525 canvas[i].addEventListener('dblclick', function () {
1526 var inner = this.getElementsByClassName('inner')[0];
1527 this.style.fontSize = '1px';
1528 inner.style.marginLeft = '';
1529 inner.style.marginTop = '';
1530 });
1531 // Click drag viewport
1532 canvas[i].addEventListener('mousedown', function (e) {
1533 var inner = this.getElementsByClassName('inner')[0];
1534 inner_coords = [parseFloat(inner.style.marginLeft) || 0, parseFloat(inner.style.marginTop) || 0];
1535 jsapi.dom.attributeAddWord(this, 'class', 'dragging');
1536 mouse_is_down = true;
1537 mouse_down_coords = [e.pageX, e.pageY];
1538 e.preventDefault();
1539 });
1540 canvas[i].addEventListener('mousemove', function (e) {
1541 if (mouse_is_down) {
1542 var fontSize = parseFloat(this.style.fontSize) || 1,
1543 inner = this.getElementsByClassName('inner')[0];
1544 inner.style.marginLeft = inner_coords[0] + (e.pageX - mouse_down_coords[0]) / fontSize + 'em';
1545 inner.style.marginTop = inner_coords[1] + (e.pageY - mouse_down_coords[1]) / fontSize + 'em';
1546 }
1547 });
1548 // Mousewheel zoom
1549 canvas[i].addEventListener('wheel', function (e) {
1550 var fontSize = parseFloat(this.style.fontSize) || 1;
1551 if ((e.deltaY < 0 && fontSize < 1000) || (e.deltaY > 0 && fontSize > 1)) {
1552 if (e.deltaY < 0) fontSize += fontSize / 4;
1553 else fontSize = Math.max(fontSize - fontSize / 4, 1);
1554 this.style.fontSize = fontSize + 'px';
1555 e.preventDefault();
1556 }
1557 });
1558 }
1559 }
1560 return true
1561 };
1562
1563 function layout() {
1564 var padding = 0, borderwidth = 0, margin = 20,
1565 maxwidth = (document.getElementById("report").offsetWidth || 900) - padding * 2 - borderwidth * 2,
1566 tables = document.getElementsByTagName("table");
1567 for (var i = 0; i < tables.length; i ++) {
1568 if (tables[i].offsetWidth > maxwidth) {
1569 maxwidth = tables[i].offsetWidth;
1570 document.body.style.width = (maxwidth + padding * 2 + borderwidth * 2) + 'px';
1571 }
1572 }
1573 for (var i = 0; i < tables.length; i ++) tables[i].style.width = maxwidth + 'px';
1574 }
1575
1576 function form_element_set_disabled(form_element, disabled) {
1577 if (!form_element || form_element.readOnly || form_element.type == "hidden" || form_element.type == "file" || jsapi.dom.attributeHasWord(form_element, "class", "fakefile") || jsapi.dom.attributeHasWord(form_element, "class", "save") || jsapi.dom.attributeHasWord(form_element, "class", "delete")) return;
1578 if (form_element.name == "FF_delta_calc_method") disabled = form_element.disabled;
1579 disabled = disabled ? "disabled" : "";
1580 form_element.disabled = disabled;
1581 if (disabled && !jsapi.dom.attributeHasWord(form_element, "class", "disabled")) jsapi.dom.attributeAddWord(form_element, "class", "disabled");
1582 else if (!disabled && jsapi.dom.attributeHasWord(form_element, "class", "disabled")) jsapi.dom.attributeRemoveWord(form_element, "class", "disabled");
1583 var labels = document.getElementsByTagName("label");
1584 for (var i=0; i<labels.length; i++) if (jsapi.dom.attribute(labels[i], "for") == form_element.id) {
1585 if (jsapi.dom.attribute(labels[i], "for") == "FF_gray_balance_cal_only") labels[i].style.display = document.getElementById(jsapi.dom.attribute(labels[i], "for")).style.display = window.CRITERIA_GRAYSCALE ? "inline" : "none";
1586 labels[i].className = disabled;
1587 labels[i].disabled = disabled;
1588 }
1589 };
1590
1591 function form_elements_set_disabled(form, disabled) {
1592 disabled = disabled ? "disabled" : "";
1593 if (form) for (var j=0; j<form.elements.length; j++) form_element_set_disabled(form.elements[j], disabled);
1594 else {
1595 for (var i=0; i<document.forms.length; i++) {
1596 for (var j=0; j<document.forms[i].elements.length; j++) {
1597 if (document.forms[i].elements[j].name == "FF_gray_balance_cal_only") form_element_set_disabled(document.forms[i].elements[j], disabled || !window.CRITERIA_GRAYSCALE);
1598 else form_element_set_disabled(document.forms[i].elements[j], disabled);
1599 }
1600 }
1601 }
1602 };
1603
1604 function toggle(e) {
1605 var target = document.getElementById(jsapi.dom.attr(e.parentNode, 'class').split(/\s+/)[0]);
1606 if (jsapi.dom.attributeHasWord(e.parentNode, 'class', 'collapsed')) {
1607 jsapi.dom.attributeRemoveWord(e.parentNode, 'class', 'collapsed');
1608 jsapi.dom.attributeRemoveWord(target, 'class', 'collapsed');
1609 }
1610 else {
1611 jsapi.dom.attributeAddWord(e.parentNode, 'class', 'collapsed');
1612 jsapi.dom.attributeAddWord(target, 'class', 'collapsed');
1613 }
1614 };
1615
1616 function togglestats() {
1617 var verbosestats = document.forms['F_out'].elements['FF_verbosestats'].checked,
1618 summary = document.getElementById("summary"),
1619 trs = summary.getElementsByTagName("tr");
1620 for (var i = 0; i < trs.length; i ++) {
1621 if (jsapi.dom.attributeHasWord(trs[i], "class", "statonly")) (jsapi.dom.attributeHasWord(trs[i], "class", "verbose") ? jsapi.dom.attributeRemoveWord : jsapi.dom.attributeAddWord)(trs[i], "class", "verbose");
1622 }
1623 layout();
1624 };
1625
1626 function set_status(str, append) {
1627 if (append) window.status += str;
1628 else window.status = str
1629 };
1630
1631 function set_progress(str, cur_num, max_num) {
1632 var p = Math.ceil(100 / max_num * cur_num);
1633 set_status(str + p + "% " + "|".repeat(p / 2))
1634 };
1635
1636 function basename(path) {
1637 return path.split(/[\/\\]/).pop()
1638 };
1639
1640 function splitext(path) {
1641 var test = path.match(/(^.+)(\.\w+)$/);
1642 return test ? test.slice(1) : [path, null]
1643 };
1644
1645 function strip_tags(str) {
1646 return str.replace(/<[^<]+>/g, '').replace(/CTCP/g, ' CtCp');
1647 };
1648
1649 function plaintext(which) {
1650 var e = document.forms['F_data'].elements;
1651 if (which == 'ref')
1652 var f = 'FF_data_ref';
1653 else
1654 var f = 'FF_data_in';
1655 var win = window.open();
1656 win.document.write('<pre>' + e[f].value);
1657 win.document.close();
1658 };