-
Notifications
You must be signed in to change notification settings - Fork 55
/
lutmessage.js
1109 lines (1106 loc) · 32.4 KB
/
lutmessage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* lutmessage.js
* messaging object between UI and calculations / web workers for LUTCalc Web App.
* 28th December 2014
*
* LUTCalc generates 1D and 3D Lookup Tables (LUTs) for video cameras that shoot log gammas,
* principally the Sony CineAlta line.
*
* By Ben Turley, http://turley.tv
* First License: GPLv2
* Github: https://github.com/cameramanben/LUTCalc
*/
function LUTMessage(inputs) {
this.inputs = inputs;
this.ui = []; // Links to UI objects for function returns
this.p = 0;
this.ui[0] = this;
this.go = false;
// 0 - LUTMessage
// 1 - camerabox
// 2 - gammabox
// 3 - tweaksbox
// 4 - lutbox
// 5 - generatebox
// 6 - infobox
// 7 - LUTAnalyst
// 8 - preview
// 9 - twkHG
// 10 - twkLA
// 11 - formats
// 12 - twkWHITE
// 13 - twkCS
// 14 - twkMulti
// 15 - twkSampler
// 16 - mobile
// 17 - twkDisplay
if (typeof this.inputs.blobWorkers !== 'undefined') {
this.blobWorkers = this.inputs.blobWorkers;
} else {
this.blobWorkers = false;
}
// this.blobWorkers = false;
this.gas = []; // Array of gamma web workers
this.gaT = 2; // Gamma threads
this.gaN = 0; // Next web worker to send data to
this.gaV = 0; // Counter keeping tabs on 'freshness' of returned data
this.gaU = 0; // Counter keeping tabs on how many of the threads are up-to-date
this.gaL = 0;
this.gaPQ = 0;
this.startGaThreads();
this.gts = []; // Array of gamma web workers
this.gtT = 2; // Gamut threads
this.gtN = 0; // Next web worker to send data to
this.gtV = 0; // Counter keeping tabs on 'freshness' of returned data
this.gtU = 0; // Counter keeping tabs on how many of the threads are up-to-date
this.gtL = 0;
this.startGtThreads();
this.precision = 8;
this.gaReady = false;
this.gtReady = false;
this.gagtReady = false;
}
LUTMessage.prototype.addUI = function(code,ui) {
this.ui[code] = ui;
};
LUTMessage.prototype.getGammaThreads = function() {
return this.gaT;
};
LUTMessage.prototype.getGamutThreads = function() {
return this.gtT;
};
LUTMessage.prototype.getWorker = function() {
return this.gas[0];
};
LUTMessage.prototype.setReady = function() {
this.go = true;
};
// Gamma Message Handling
LUTMessage.prototype.startGaThreads = function() {
var max = this.gaT;
var windowURL,workerString,gammaWorkerBlob;
if (this.blobWorkers) {
windowURL = window.URL || window.webkitURL;
workerString = (workerLUTString + workerGammaString).replace('"use strict";', '');
gammaWorkerBlob = new Blob([ workerString ], { type: 'text/javascript' } );
}
for (var i=0; i<max; i++) {
var _this = this;
if (this.blobWorkers) {
try {
var blobURL = windowURL.createObjectURL(gammaWorkerBlob);
this.gas[i] = new Worker(blobURL);
// URL.revokeObjectURL(blobURL);
} catch (e) { // Fallback for - IE10 and 11
console.log('No Inline Web Workers');
this.blobWorkers = false;
this.gas[i] = new Worker('gammaworker.js');
}
} else {
this.gas[i] = new Worker('gammaworker.js');
}
this.gas[i].onmessage = function(e) {
_this.gaRx(e.data);
};
}
};
LUTMessage.prototype.stopGaThreads = function() {
var max = this.gas.length;
for (var i=0; i<max; i++) {
this.gas[i].terminate();
}
this.gas = [];
};
LUTMessage.prototype.changeGaThreads = function(T) {
if (typeof T==='number' && (T%1)===0) {
this.gaT = T;
var max = this.gas.length;
if (T > max) {
var windowURL,workerString,gammaWorkerBlob;
if (this.blobWorkers) {
windowURL = window.URL || window.webkitURL;
workerString = (workerLUTString + workerGammaString).replace('"use strict";', '');
gammaWorkerBlob = new Blob([ workerString ], { type: 'text/javascript' } );
}
for (var i=max; i<T; i++) {
var _this = this;
if (this.blobWorkers) {
try {
var blobURL = windowURL.createObjectURL(gammaWorkerBlob);
this.gas[i] = new Worker(blobURL);
// URL.revokeObjectURL(blobURL);
} catch (e) { // Fallback for - IE10 and 11
this.blobWorkers = false;
console.log('No Inline Web Workers');
this.gas[i] = new Worker('gammaworker.js');
}
} else {
this.gas[i] = new Worker('gammaworker.js');
}
this.gas[i].onmessage = function(e) {
_this.gaRx(e.data);
};
}
} else if (T < max) {
for (var i=T-1; i<max; i++) {
this.gas[i].terminate();
}
this.gas = this.gas.slice(0,T);
this.gaN = 0;
this.gaU = 0;
}
}
};
LUTMessage.prototype.gaSetParams = function() {
if (this.go) {
this.gaV++;
var d = {
v: this.gaV,
inGamma: parseInt(this.inputs.inGamma.options[this.inputs.inGamma.options.selectedIndex].value),
inLinGamma: parseInt(this.inputs.inLinGamma.options[this.inputs.inLinGamma.options.selectedIndex].value),
outGamma: parseInt(this.inputs.outGamma.options[this.inputs.outGamma.options.selectedIndex].value),
outLinGamma: parseInt(this.inputs.outLinGamma.options[this.inputs.outLinGamma.options.selectedIndex].value),
contrast: {
rec: parseInt(this.inputs.inConGamma.options[this.inputs.inConGamma.options.selectedIndex].value),
out: parseInt(this.inputs.outConGamma.options[this.inputs.outConGamma.options.selectedIndex].value),
},
pqLwIn: parseFloat(this.inputs.inPQLw.value),
pqLwOut: parseFloat(this.inputs.outPQLw.value),
pqEOTFLwIn: parseFloat(this.inputs.inPQEOTFLw.value),
pqEOTFLwOut: parseFloat(this.inputs.outPQEOTFLw.value),
hlgLwIn: parseFloat(this.inputs.inHLGLw.value),
hlgLwOut: parseFloat(this.inputs.outHLGLw.value),
hlgBBCIn: this.inputs.hlgBBCScaleIn[1].checked,
hlgBBCOut: this.inputs.hlgBBCScaleOut[1].checked,
defGamma: this.inputs.defGammaIn,
newISO: parseFloat(this.inputs.cineEI.value),
natISO: parseFloat(this.inputs.nativeISO.innerHTML),
camType: parseInt(this.inputs.cameraType.value),
stopShift: parseFloat(this.inputs.stopShift.value),
camClip: Math.pow(2,parseFloat(this.inputs.wclip)+parseFloat(this.inputs.stopShift.value))*0.18,
// clip: this.inputs.clipCheck.checked,
clipSelect: parseInt(this.inputs.clipSelect.options[this.inputs.clipSelect.selectedIndex].value),
clipLegal: this.inputs.clipLegalCheck.checked,
isTrans: this.inputs.isTrans
};
if (this.inputs.inRange[0].checked) {
d.inL = true;
} else {
d.inL = false;
}
if (this.inputs.outRange[0].checked) {
d.outL = true;
} else {
d.outL = false;
}
if (typeof this.inputs.bClip !== 'undefined') {
d.bClip = this.inputs.bClip;
d.wClip = this.inputs.wClip;
}
if (typeof this.inputs.scaleCheck !== 'undefined' && this.inputs.scaleCheck && typeof this.inputs.scaleMin.value !== 'undefined') {
d.scaleMin = parseFloat(this.inputs.scaleMin.value);
d.scaleMax = parseFloat(this.inputs.scaleMax.value);
if (d.scaleMin !== 0.0 || d.scaleMax !== 1.0) {
d.scaleCheck = true;
} else {
d.scaleCheck = false;
}
} else {
d.scaleCheck = false;
}
this.ui[3].getTFParams(d);
var max = this.gas.length;
for (var i=0; i<max; i++) {
this.gas[i].postMessage({t: 0, d: d});
}
}
};
LUTMessage.prototype.gaTx = function(p,t,d) { // parent (sender), type, data
if (typeof p !== 'undefined') {
if (this.inputs.isTrans && d !== null && typeof d.to !== 'undefined') {
var max = d.to.length;
var objArray = [];
for (var j=0; j < max; j++) {
objArray.push(d[d.to[j]]);
}
this.gas[this.gaN].postMessage({p: p, t: t, v: this.gaV, d: d},objArray);
this.gaN = (this.gaN + 1) % this.gaT;
} else {
this.gas[this.gaN].postMessage({p: p, t: t, v: this.gaV, d: d});
this.gaN = (this.gaN + 1) % this.gaT;
}
}
};
LUTMessage.prototype.gaTxAll = function(p,t,d) { // parent (sender), type, data
if (typeof p !== 'undefined') {
if (this.inputs.isTrans && d !== null && typeof d.to !== 'undefined') {
var max = d.to.length;
var objArray = [];
for (var j=0; j < max; j++) {
objArray.push(d[d.to[j]]);
}
max = this.gas.length;
for (var j=0; j<max; j++) {
this.gas[j].postMessage({p: p, t: t, v: this.gaV, d: d}, objArray);
}
} else {
var max = this.gas.length;
for (var j=0; j<max; j++) {
this.gas[j].postMessage({p: p, t: t, v: this.gaV, d: d});
}
}
}
};
LUTMessage.prototype.gaRx = function(d) {
if (d.msg) {
console.log(d.details);
} else if (d.err) {
console.log(d.details);
} else if (d.resend) {
console.log('Resending gamma - ' + d.t + ' to ' + d.p);
this.gaTx(d.p,d.t,d.d);
} else if (d.v === this.gaV) {
switch(d.t) {
case 20: // Set Parameters
this.gammaParamsSet(d);
break;
case 21: // 1D input to output
this.ui[5].got1D(d);
break;
case 22: // LUTAnalyst SL3 input to linear
this.ui[d.p].setCSInputData(d.o,d.natTF,d.legIn);
this.gtTx(d.p,2,{
p:d.p,
t:d.t,
v:d.v,
dim:d.dim,
gamma:d.gamma,
gamut:d.gamut
});
break;
case 23: // RGB input to linear
this.gtTx(d.p,1,d);
break;
case 24: // RGB linear to output
this.ui[5].got3D(d);
break;
case 25: // Get lists of gammas
this.gotGammaLists(d);
break;
case 26: // Set LA LUT
this.gaL++;
if (this.gaL === this.gaT) {
this.gaL = 0;
this.ui[10].doneStuff();
this.ui[6].updateGamma();
}
break;
case 27: // Set LA Title
break;
case 28: // LUTAnalyst SLog3 data value from given transfer function
this.ui[d.p].gotInputVals(d.o,d.dim);
break;
case 29: // LUTAnalyst Slog3/S-Gamut3.cine values to LUT input colourspace
this.ui[d.p].gotInputVals(d.o,d.dim);
break;
case 30: // Get IRE values for output from a list of linear values
this.gotIOGammaNames(d);
break;
case 31: // Get IRE values for output from a list of linear values
this.gotChartVals(d);
break;
case 32: // Get 8-bit corrected values for preview image
this.ui[d.p].gotLine(d);
break;
case 34: // Get linear / S-Gamut3.cine value for preview image
this.gtTx(d.p,14,d);
break;
case 35: // Get primaries of current colour space for preview
this.ui[d.p].updatePrimaries(d.o);
break;
case 36: // Get PSST-CDL colours
this.ui[3].psstColours(d);
if (this.inputs.isMobile) {
this.ui[16].updateUI();
}
break;
case 37: // Get Multi Colours
this.ui[3].multiColours(d);
break;
case 38: // Get LUT in to LUT out values for primaries
this.ui[6].updateRGBChart(d);
break;
case 39: // Update PQ LMax level
this.gaPQ++;
if (this.gaPQ === this.gaT) {
this.gaPQ = 0;
this.gaSetParams();
}
break;
}
}
};
LUTMessage.prototype.showArray = function(o,dim) {
var temp = new Float64Array(o);
var max = Math.round(temp.length/3);
var R = new Float64Array(max);
var G = new Float64Array(max);
var B = new Float64Array(max);
for (var j=0; j<max; j++) {
R[j] = temp[j*3];
G[j] = temp[(j*3)+1];
B[j] = temp[(j*3)+2];
}
console.log(max);
console.log(R);
console.log(G);
console.log(B);
};
LUTMessage.prototype.gammaParamsSet = function(d) {
this.gaU++;
if (this.gaU === this.gaT) {
this.gaU = 0;
this.gtTx(3,16,{});
this.gtTx(8,15,{});
this.ui[3].setParams(d);
this.ui[6].updateGamma();
this.ui[8].isChanged(d.eiMult);
if (this.inputs.isMobile) {
this.ui[16].updateUI();
}
if (!this.gagtReady) {
this.gaReady = true;
if (this.gtReady) {
this.gagtReady = true;
if (this.inputs.appleApp) {
var data = { version: this.inputs.versionNum }
window.webkit.messageHandlers.appReady.postMessage(JSON.stringify(data));
}
}
}
}
};
LUTMessage.prototype.gotGammaLists = function(d) {
this.inputs.addInput('gammaLA',d.LA);
this.inputs.addInput('gammaPQ',d.PQ);
this.inputs.addInput('gammaHLG',d.HLG);
this.inputs.addInput('gammaPQOOTF',d.PQOOTF);
this.inputs.addInput('gammaPQEOTF',d.PQEOTF);
this.inputs.addInput('gammaHLGOOTF',d.HLGOOTF);
this.inputs.addInput('gammaDLogM',d.DLogM);
this.inputs.addInput('gammaInList',d.inList);
this.inputs.addInput('gammaOutList',d.outList);
this.inputs.addInput('gammaLinList',d.linList);
this.inputs.addInput('gammaCatList',d.catList);
this.inputs.addInput('gammaDisList',d.disList);
this.inputs.addInput('gammaDisBaseGamuts',d.baseDisGamuts);
this.inputs.addInput('gammaBaseGamuts',d.baseGamuts);
this.inputs.addInput('gammaSubNames',d.subNames);
this.inputs.addInput('gammaDataLevel',d.gammaDat);
this.inputs.addInput('gammaExt',d.gammaExt);
var subLists = [];
var m = d.subNames.length;
var allIdx = m-1;
for (var j=0; j<m; j++) {
subLists[j] = [];
if (d.subNames[j] === 'All') {
allIdx = j;
}
}
m = d.subList.length;
var m2;
for (var j=0; j<m; j++) {
m2 = d.subList[j].length;
for (var k=0; k<m2; k++) {
subLists[d.subList[j][k]].push(j);
}
}
subLists[allIdx].length = 0;
for (var j=0; j<m; j++) {
subLists[allIdx].push(j);
}
this.inputs.addInput('gammaSubLists',subLists);
this.ui[2].gotGammaLists(); // Gamma Box
this.ui[3].gotGammaLists(); // Tweaks Box
this.ui[4].gotGammaLists(); // LUT Box
this.gaSetParams();
};
LUTMessage.prototype.gotBaseIRE = function(d) {
this.ui[3].gotBaseIRE(d.o); // Tweaks Box
this.ui[5].gotBaseIRE(d.o); // Generate Box
};
LUTMessage.prototype.gotIREs = function(d) {
this.ui[d.p].gotIREs(d.i,d.o);
};
LUTMessage.prototype.gotIOGammaNames = function(d) {
this.ui[d.p].gotIOGammaNames(d.o);
};
LUTMessage.prototype.gotChartVals = function(d) {
// this.gtTx(d.p,11,{ colIn:d.colIn, colOut:d.colOut, eiMult:d.eiMult, to:['colIn','colOut']});
this.ui[d.p].gotChartVals(d);
};
LUTMessage.prototype.gotHighLevelDefault = function(d) {
this.ui[3].gotHighLevelDefault(d.rec,d.map);
};
// Gamut Message Handling
LUTMessage.prototype.startGtThreads = function() {
var max = this.gtT;
var windowURL,workerString,csWorkerBlob;
if (this.blobWorkers) {
windowURL = window.URL || window.webkitURL;
workerString = (workerLUTString + workerRingString + workerBrentString + workerCSString).replace('"use strict";', '');
csWorkerBlob = new Blob([ workerString ], { type: 'text/javascript' } );
}
for (var i=0; i<max; i++) {
var _this = this;
if (this.blobWorkers) {
try {
var blobURL = windowURL.createObjectURL(csWorkerBlob);
this.gts[i] = new Worker(blobURL);
// URL.revokeObjectURL(blobURL);
} catch (e) { // Fallback for - IE10 and 11
console.log('No Inline Web Workers');
this.blobWorkers = false;
this.gts[i] = new Worker('colourspaceworker.js');
}
} else {
this.gts[i] = new Worker('colourspaceworker.js');
}
this.gts[i].onmessage = function(e) {
_this.gtRx(e.data);
};
}
};
LUTMessage.prototype.stopGtThreads = function() {
var max = this.gts.length;
for (var i=0; i<max; i++) {
this.gts[i].terminate();
}
this.gts = [];
};
LUTMessage.prototype.changeGtThreads = function(T) {
if (typeof T==='number' && (T%1)===0) {
this.gtT = T;
var max = this.gts.length;
if (T > max) {
var windowURL,workerString,csWorkerBlob;
if (this.blobWorkers) {
windowURL = window.URL || window.webkitURL;
workerString = (workerLUTString + workerRingString + workerBrentString + workerCSString).replace('"use strict";', '');
csWorkerBlob = new Blob([ workerString ], { type: 'text/javascript' } );
}
for (var i=max; i<T; i++) {
var _this = this;
if (this.blobWorkers) {
try {
var blobURL = windowURL.createObjectURL(csWorkerBlob);
this.gts[i] = new Worker(blobURL);
// URL.revokeObjectURL(blobURL);
} catch (e) { // Fallback for - IE10 and 11
this.blobWorkers = false;
this.gts[i] = new Worker('colourspaceworker.js');
}
} else {
this.gts[i] = new Worker('colourspaceworker.js');
}
this.gts[i].onmessage = function(e) {
_this.gtRx(e.data);
};
}
} else if (T < max) {
for (var i=T-1; i<max; i++) {
this.gts[i].terminate();
}
this.gts = this.gts.slice(0,T);
this.gtN = 0;
this.gtU = 0;
}
}
};
LUTMessage.prototype.gtSetParams = function() {
if (this.go) {
this.gtV++;
var d = {
v: this.gtV,
inGamut: parseInt(this.inputs.inGamut.options[this.inputs.inGamut.selectedIndex].value),
outGamut: parseInt(this.inputs.outGamut.options[this.inputs.outGamut.selectedIndex].value),
isTrans: this.inputs.isTrans
};
this.ui[3].getCSParams(d);
var max = this.gts.length;
for (var i=0; i<max; i++) {
this.gts[i].postMessage({t: 0, d: d});
}
}
};
LUTMessage.prototype.gtTx = function(p,t,d) { // parent (sender), type, data
if (typeof p !== 'undefined') {
if (this.inputs.isTrans && d !== null && typeof d.to !== 'undefined') {
var max = d.to.length;
var objArray = [];
for (var j=0; j < max; j++) {
objArray.push(d[d.to[j]]);
}
this.gts[this.gtN].postMessage({p: p, t: t, v: this.gtV, d: d}, objArray);
this.gtN = (this.gtN + 1) % this.gtT;
} else {
this.gts[this.gtN].postMessage({p: p, t: t, v: this.gtV, d: d});
this.gtN = (this.gtN + 1) % this.gtT;
}
}
};
LUTMessage.prototype.gtTxAll = function(p,t,d) { // parent (sender), type, data
if (typeof p !== 'undefined') {
if (this.inputs.isTrans && d !== null && typeof d.to !== 'undefined') {
var max = d.to.length;
var objArray = [];
for (var j=0; j < max; j++) {
objArray.push(d[d.to[j]]);
}
max = this.gts.length;
for (var j=0; j<max; j++) {
this.gts[j].postMessage({p: p, t: t, v: this.gtV, d: d}, objArray);
}
} else {
var max = this.gts.length;
for (var j=0; j<max; j++) {
this.gts[j].postMessage({p: p, t: t, v: this.gtV, d: d});
}
}
}
};
LUTMessage.prototype.gtRx = function(d) {
if (d.msg) {
console.log(d.details);
} else if (d.err) {
console.log(d.details);
} else if (d.resend) {
console.log('Resending gamut - ' + d.t + ' to ' + d.p);
if (d.t === 1) {
this.gaTx(d.p,d.t,{R:d.d.R,G:d.d.G,B:d.d.B,vals:d.d.vals,dim:d.d.dim,to:d.d.to});
} else {
this.gtTx(d.p,d.t,d.d);
}
} else if (d.v === this.gtV || d.t === 37) {
switch(d.t) {
case 20: // Set params
this.gamutParamsSet(d);
break;
case 21: // RGB input to output
this.gaTx(5,4,d);
break;
case 22: // RGB S-Gamut3.cine to LA input gamut
// console.log(new Float64Array(d.inputMatrix));
// this.gaTx(d.p,9,d);
this.ui[d.p].gotInputVals(d.inputMatrix,d.dim);
break;
case 23: // Recalculated custom matrix for changed colourspace
this.ui[d.p].recalcMatrix(d.idx,d.wcs,d.matrix);
break;
case 24: // Send Default LUT-based Gamuts from file to Worker
splashProg(5);
break;
case 25: // Get lists of gamuts
this.loadGamutLUTs();
this.gotGamutLists(d);
break;
case 26: // Set LA LUT
this.gtL++;
if (this.gtL === this.gtT) {
this.gtL = 0;
this.ui[8].isChanged();
}
break;
case 27: // Set LA Title
break;
case 28: // Get Colour Square
this.ui[d.p].gotColSqr(d.o,d.tIdx);
break;
case 29: // Get Multi Colours
if (d.doGamutLim) {
if (typeof d.og !== 'undefined') {
this.gaTx(d.p,17,{o: d.o, hs: d.hs, cb:d.cb, doGamutLim: true, og: d.og, gLimY: d.gLimY, gLimL: d.gLimL, gLimB: d.gLimB, to:['o','hs','og']});
} else {
this.gaTx(d.p,17,{o: d.o, hs: d.hs, cb:d.cb, doGamutLim: true, gLimY: d.gLimY, gLimL: d.gLimL, to:['o','hs']});
}
} else {
this.gaTx(d.p,17,{ o: d.o, hs: d.hs, cb:d.cb, doGamutLim: false, to:['o','hs']});
}
break;
case 30: //
this.gotIOGamutNames(d);
break;
case 31: // Get LUT In / LUT Out values for primaries
if (typeof d.rIn !== 'undefined') {
this.gaTx(d.p,18,{ rIn:d.rIn, gIn:d.gIn, bIn:d.bIn, rOut:d.rOut, gOut:d.gOut, bOut:d.bOut, cb:d.cb, to:['rIn', 'gIn', 'bIn','rOut','gOut','bOut']});
}
break;
case 32: // Get preview colour correction
this.gaTx(d.p,12,d);
break;
case 34: // Get linear / S-Gamut3.cine value for preview image
this.ui[d.p].preppedPreview(d.o);
break;
case 35: // Get primaries of current colour space for preview
this.gaTx(d.p,15,d);
break;
case 36: // Get PSST-CDL colours
this.gaTx(3,16,{b:d.b,a:d.a,cb:d.cb,to:['b','a']});
break;
case 37: // Get Chromatic Adaptation Transform options
this.ui[3].gotCATs(d.o);
break;
case 38: // Get CCT and Dxy for white point dropper
this.ui[12].gotPreCCTDuv(d);
break;
case 39: // Calculate primaries and white point for current output
this.ui[8].updateXY(d.xy);
break;
}
}
};
LUTMessage.prototype.gamutParamsSet = function(d) {
this.gtU++;
if (this.gtU === this.gtT) {
this.gtU = 0;
this.gtTx(3,16,{});
this.gtTx(8,15,{});
this.ui[3].setParams(d);
// this.ui[6].updateGamma();
this.ui[8].isChanged();
this.ui[8].testXY();
if (this.inputs.isMobile) {
this.ui[16].updateUI();
}
if (!this.gagtReady) {
this.gtReady = true;
if (this.gaReady) {
this.gagtReady = true;
if (this.inputs.appleApp) {
window.webkit.messageHandlers.appReady.postMessage("");
}
}
}
}
};
LUTMessage.prototype.gotGamutLists = function(d) {
this.inputs.addInput('gamutPass',d.pass);
this.inputs.addInput('gamutLA',d.LA);
this.inputs.addInput('gamutInList',d.inList);
this.inputs.addInput('gamutOutList',d.outList);
this.inputs.addInput('gamutLAList',d.laList);
this.inputs.addInput('gamutMatrixList',d.matList);
this.inputs.addInput('gamutCATList',d.CATList);
this.inputs.addInput('gamutSubNames',d.subNames);
var inSubs = [];
var outSubs = [];
var laSubs = [];
var m = d.subNames.length;
var allIdx = m-1;
for (var j=0; j<m; j++) {
inSubs[j] = [];
outSubs[j] = [];
laSubs[j] = [];
if (d.subNames[j] === 'All') {
allIdx = j;
}
}
m = d.inSub.length;
var m2;
for (var j=0; j<m; j++) {
m2 = d.inSub[j].length;
for (var k=0; k<m2; k++) {
inSubs[d.inSub[j][k]].push(j);
}
}
inSubs[allIdx].length = 0;
for (var j=0; j<m; j++) {
inSubs[allIdx].push(j);
}
m = d.outSub.length;
var m2;
for (var j=0; j<m; j++) {
m2 = d.outSub[j].length;
for (var k=0; k<m2; k++) {
outSubs[d.outSub[j][k]].push(j);
}
}
outSubs[allIdx].length = 0;
for (var j=0; j<m; j++) {
outSubs[allIdx].push(j);
}
m = d.laSub.length;
var m2;
for (var j=0; j<m; j++) {
m2 = d.laSub[j].length;
for (var k=0; k<m2; k++) {
laSubs[d.laSub[j][k]].push(j);
}
}
laSubs[allIdx].length = 0;
for (var j=0; j<m; j++) {
laSubs[allIdx].push(j);
}
this.inputs.addInput('gamutInSubLists',inSubs);
this.inputs.addInput('gamutOutSubLists',outSubs);
this.inputs.addInput('gamutLASubLists',laSubs);
this.ui[2].gotGamutLists(d.pass,d.LA); // Gamma Box
this.ui[3].gotGamutLists(); // Tweaks Box
this.gtSetParams();
};
LUTMessage.prototype.gotIOGamutNames = function(d) {
this.ui[d.p].gotIOGamutNames(d.inName,d.outName,d.hgName);
};
// Get Info For LUT Generation
LUTMessage.prototype.getInfo = function(info) {
info.version = this.inputs.version;
info.date = this.inputs.date;
this.ui[4].getInfo(info); // LUT Box (Dimensions, MLUTs, etc..)
this.ui[1].getInfo(info); // Camera Box (Stop Correction)
this.ui[2].getInfo(info); // Gamma Box (Gamma In / Out, Gamut In / Out)
this.ui[3].getInfo(info); // Tweaks Box - notes for in the LUT file
};
// Inter-object messages
LUTMessage.prototype.changeCamera = function() {
this.ui[2].defaultGam();
this.gaSetParams();
this.ui[4].changeGamma();
this.gtSetParams();
};
LUTMessage.prototype.updateGammaInList = function() {
this.ui[2].updateGammaInList(false);
};
LUTMessage.prototype.changeGamma = function() {
if (this.go) {
this.ui[4].changeGamma();
this.gaSetParams();
}
};
LUTMessage.prototype.updateGammaIn = function() {
if (this.go) {
this.ui[11].updateGammaIn();
}
}
LUTMessage.prototype.updateGammaOut = function() {
if (this.go) {
this.ui[11].updateGammaOut();
this.ui[17].updateGammaOut();
this.ui[3].updateGammaOut();
}
}
LUTMessage.prototype.changeGamut = function() {
if (this.go) {
this.ui[3].changeGamut();
this.gtSetParams();
this.ui[8].testXY();
}
};
LUTMessage.prototype.changeFormat = function() {
this.ui[2].oneOrThree();
this.ui[3].toggleTweaks();
// this.ui[8].testXY();
this.gaSetParams();
this.gtSetParams();
};
LUTMessage.prototype.oneOrThree = function() {
this.ui[11].oneOrThree();
this.ui[2].oneOrThree();
this.ui[3].toggleTweaks();
this.gtSetParams();
this.gaSetParams();
};
LUTMessage.prototype.showPreview = function() {
this.ui[3].toggleTweaks();
};
LUTMessage.prototype.getPreCCTDuv = function(xcoord,ycoord) {
var rgb = this.ui[8].getCanVal(xcoord, ycoord);
this.gtTx(12,18,{rgb: rgb.buffer, to:['rgb']});
};
LUTMessage.prototype.getSettings = function() {
var data = {};
data.version = this.inputs.version;
this.ui[1].getSettings(data);
this.ui[2].getSettings(data);
this.ui[3].getSettings(data);
this.ui[5].getSettings(data);
this.ui[11].getSettings(data);
this.ui[4].getSettings(data);
return JSON.stringify(data,null,"\t");
};
LUTMessage.prototype.setSettings = function() {
var data = JSON.parse(this.inputs.settingsData.text.join(''));
if (typeof data.lutBox !== 'undefined' && typeof data.lutBox.oneD === 'boolean') {
this.inputs.d[0].checked = data.oneD;
this.inputs.d[1].checked = !data.oneD;
}
this.ui[1].setSettings(data);
this.ui[2].setSettings(data);
this.ui[3].setSettings(data);
this.ui[5].setSettings(data);
this.ui[11].setSettings(data);
this.ui[4].setSettings(data);
this.gtSetParams();
this.gaSetParams();
};
LUTMessage.prototype.checkFormat = function() {
this.ui[11].updateGammaOut();
};
LUTMessage.prototype.isCustomGamma = function() {
return this.ui[3].isCustomGamma();
};
LUTMessage.prototype.isCustomGamut = function() {
return this.ui[3].isCustomGamut();
};
LUTMessage.prototype.displayCLC = function() {
this.ui[4].displayCLC();
};
LUTMessage.prototype.saved = function(source, success) {
switch (source) {
case 0: break; // LALutss or LABins - don't need a further response
case 1: this.ui[5].saved(success); // LUTs saved using the Generate buttons
break;
case 2: break; // RGB Sampler files - don't need a further response
case 3: break; // Settings files - don't need a further response
default: break;
}
};
LUTMessage.prototype.loadGamutLUTs = function() {
var fileNames = [
'LC709',
'LC709A',
's709',
'cpouttungsten',
'cpoutdaylight',
'Amira709',
'AlexaX2',
'V709',
'Cine709'
];
var m = fileNames.length;
var isLE;
if ((new Int8Array(new Int16Array([1]).buffer)[0]) > 0) {
isLE = true;
} else {
isLE = false;
}
for (var j=0; j<m; j++) {
var xhr = new XMLHttpRequest();
xhr.open('GET', fileNames[j] + '.labin', true);
xhr.responseType = 'arraybuffer';
xhr.onload = (function(here) {
return function(e) {
var buff = this.response;
var lutArr = new Uint8Array(buff);
if (!here.isLE) { // files are little endian, swap if system is big endian
// console.log('Gamut LUTs: Big Endian System');
var max = Math.round(lutArr.length / 4); // Float32s === 4 bytes
var i,b0,b1,b2,b3;
for (var j=0; j<max; j++) {
i = j*4;
b0=lutArr[ i ];
b1=lutArr[i+1];
b2=lutArr[i+2];
b3=lutArr[i+3];
lutArr[ i ] = b3;
lutArr[i+1] = b2;
lutArr[i+2] = b1;
lutArr[i+3] = b0;
}
}
var in32 = new Int32Array(buff);
var tfS = in32[0];
var dim = in32[1];
var csS = dim*dim*dim;
// Internal processing is Float64, files are scaled Int32
var C = [ new Float64Array(csS),
new Float64Array(csS),
new Float64Array(csS) ];
for (var j=0; j<csS; j++){
C[0][j] = parseFloat(in32[((2+tfS)) + j])/1073741824;
C[1][j] = parseFloat(in32[((2+tfS+csS)) + j])/1073741824;
C[2][j] = parseFloat(in32[((2+tfS+(2*csS))) + j])/1073741824;
}
var dataEnd = 2+tfS+(3*csS);
// get input matrix details (all zeros means no matrix defined)
var inputMatrix = new Float64Array(9);
var imM = false;
if (dataEnd < in32.length) {
for (var j=0; j<9; j++) {
if (in32[dataEnd+j] !== 0) {
imM = true;
inputMatrix[j] = parseFloat(in32[dataEnd+j])/107374182.4;
}
}
dataEnd += 9;
}
if (!imM) {
inputMatrix = false;
}
// look for input matrix, colourspace and transfer function info at the end of the file if present
var in1DTF = 'S-Log3'; // system default
var in3DTF = 'S-Log3'; // system default
var sysCS = 'Sony S-Gamut3.cine'; // system default
var in3DCS = 'Sony S-Gamut3.cine'; // system default
var in1DEX = true; // system default
var in3DEX = true; // system default
var in1DMin = [0,0,0];
var in1DMax = [1,1,1];
var in3DMin = [0,0,0];
var in3DMax = [1,1,1];
var interpolation = false;
var baseISO = false;
if (dataEnd < in32.length) {
dataEnd *= 4;
var fileEnd = lutArr.length;
var metaString = '';
for (var j=dataEnd; j<fileEnd; j++) {
metaString += String.fromCharCode(lutArr[j]).replace('^','γ');
}
if (metaString.search('|') >= 0) {
var meta = metaString.split('|');
var m = meta.length;
if (m > 2) {
for (var j=0; j<m; j +=2) {
switch (meta[j]) {
case '1DTF':
in1DTF = meta[j+1].trim();
break;
case '1DRG':
if (meta[j+1].toLowerCase() === '100') {
in1DEX = false;
}
break;
case '1DMIN':
in1DMin[0] = parseFloat(meta[j+1]);
if (isNaN(in1DMin[0])) {
in1DMin[0] = 0;
} else {
in1DMin[1] = in1DMin[0];
in1DMin[2] = in1DMin[0];
}
break;
case '1DMAX':
in1DMax[0] = parseFloat(meta[j+1]);
if (isNaN(in1DMax[0])) {
in1DMax[0] = 1;
} else {
in1DMax[1] = in1DMax[0];
in1DMax[2] = in1DMax[0];
}
break;
case 'SYSCS':
sysCS = meta[j+1].trim();
break;
case '3DTF':
in3DTF = meta[j+1].trim();
break;
case '3DCS':
in3DCS = meta[j+1].trim();