-
Notifications
You must be signed in to change notification settings - Fork 166
/
infragram.js
2244 lines (1908 loc) · 78.1 KB
/
infragram.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
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return _sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }
(function () {
function r(e, n, t) {
function o(i, f) {
if (!n[i]) {
if (!e[i]) {
var c = "function" == typeof require && require;
if (!f && c) return c(i, !0);
if (u) return u(i, !0);
var a = new Error("Cannot find module '" + i + "'");
throw a.code = "MODULE_NOT_FOUND", a;
}
var p = n[i] = {
exports: {}
};
e[i][0].call(p.exports, function (r) {
var n = e[i][1][r];
return o(n || r);
}, p, p.exports, r, e, n, t);
}
return n[i].exports;
}
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) {
o(t[i]);
}
return o;
}
return r;
})()({
1: [function (require, module, exports) {
function urlHash() {
function getUrlHashParameter(param) {
var params = getUrlHashParameters();
return params[param];
}
function getUrlHashParameters() {
var sPageURL = window.location.hash;
if (sPageURL) sPageURL = sPageURL.split('#')[1];
var pairs = sPageURL.split('&');
var object = {};
pairs.forEach(function (pair, i) {
pair = pair.split('=');
if (pair[0] != '') object[pair[0]] = pair[1];
});
return object;
} // accepts an object like { paramName: value, paramName1: value }
// and transforms to: url.com#paramName=value¶mName1=value
function setUrlHashParameters(params) {
var keys = Object.keys(params);
var values = Object.values(params);
var pairs = [];
keys.forEach(function (key, i) {
if (key != '') pairs.push(keys[i] + '=' + values[i]);
});
var hash = pairs.join('&');
window.location.hash = hash;
}
function setUrlHashParameter(param, value) {
var params = getUrlHashParameters();
params[param] = value;
setUrlHashParameters(params);
}
return {
getUrlHashParameter: getUrlHashParameter,
getUrlHashParameters: getUrlHashParameters,
setUrlHashParameter: setUrlHashParameter,
setUrlHashParameters: setUrlHashParameters
};
}
module.exports = urlHash;
}, {}],
2: [function (require, module, exports) {
window.Infragram = function Infragram(options) {
options = options || {};
options.uploader = options.uploader || false;
options.processor = options.processor || 'javascript';
options.camera = require('./io/camera')(options);
options.colorized = options.colorized || false;
options.mode = options.mode || "raw", options.video_live = options.video_live || false, options.webGlSupported = options.webGlSupported || false; // move into processor
options.processors = {
'webgl': require('./processors/webgl'),
'javascript': require('./processors/javascript')
};
options.processor = options.processors[options.processor](options);
options.file = require('./io/file')(options, options.processor);
options.logger = require('./logger')(options);
var Interface = require('./ui/interface')(options); // this can change processor based on URL hash
//options.processor.initialize(options); // double initialize after end of processor code?
console.log('processor:', options.processor.type);
options.colorize = function colorize(map) {
options.processor.colorize(map);
}; // this should accept an object with parameters r,g,b,h,s,v,m and mode
options.run = function run(mode) {
options.logger.save_log();
return options.processor.run(mode);
}; // split into processor.video() methods
options.video = function video() {
options.camera.initialize();
var interval;
if (options.processor.type == "webgl") interval = 15;else interval = 150;
setInterval(function () {
if (image) options.run(options.mode);
options.camera.getSnapshot(); //if (options.colorized) return options.colorize();
}, interval);
}; // TODO: this doesn't work; it just downloads the unmodified image.
// probably a timing issue?
function download() {
//options.run(options.mode);
//if (options.colorized) return options.colorize();
options.file.downloadImage();
}
return {
Camera: options.camera,
Interface: Interface,
logger: options.logger,
run: options.run,
colorize: options.colorize,
processors: options.processors,
download: download,
options: options
};
};
module.exports = Infragram;
}, {
"./io/camera": 7,
"./io/file": 8,
"./logger": 9,
"./processors/javascript": 10,
"./processors/webgl": 11,
"./ui/interface": 15
}],
3: [function (require, module, exports) {
module.exports = function segmented_colormap(segments) {
return function (x) {
var i, l, len, m, ref, result, x0, x1, xstart, y0, y1;
y0 = 0;
y1 = 0;
var _ref = [segments[0][0], 1];
x0 = _ref[0];
x1 = _ref[1];
if (x < x0) {
return y0;
}
for (i = l = 0, len = segments.length; l < len; i = ++l) {
var _segments$i = _slicedToArray(segments[i], 3);
xstart = _segments$i[0];
y0 = _segments$i[1];
y1 = _segments$i[2];
x0 = xstart;
if (i === segments.length - 1) {
x1 = 1;
break;
}
x1 = segments[i + 1][0];
if (xstart <= x && x < x1) {
break;
}
}
result = [];
for (i = m = 0, ref = y0.length; 0 <= ref ? m < ref : m > ref; i = 0 <= ref ? ++m : --m) {
result[i] = (x - x0) / (x1 - x0) * (y1[i] - y0[i]) + y0[i];
}
return result;
};
};
}, {}],
4: [function (require, module, exports) {
module.exports = {
"greyscale": {
"author": "publiclab",
"description": "A simple linear greyscale colormap, black to white.",
"url": "https://publiclab.org/colormaps#greyscale",
"colormapRanges": [[0, [0, 0, 0], [255, 255, 255]], [1, [255, 255, 255], [255, 255, 255]]]
},
"default": {
"author": "publiclab",
"description": "A full-colorwheel colormap, covering the colors in the spectrum.",
"url": "https://publiclab.org/colormaps#default",
"colormapRanges": [[0, [45, 1, 121], [25, 1, 137]], [0.125, [25, 1, 137], [0, 6, 156]], [0.1875, [0, 6, 156], [7, 41, 172]], [0.25, [7, 41, 172], [22, 84, 187]], [0.3125, [22, 84, 187], [25, 125, 194]], [0.375, [25, 125, 194], [26, 177, 197]], [0.4375, [26, 177, 197], [23, 199, 193]], [0.47, [23, 199, 193], [25, 200, 170]], [0.50, [25, 200, 170], [21, 209, 27]], [0.5625, [21, 209, 27], [108, 215, 18]], [0.625, [108, 215, 18], [166, 218, 19]], [0.6875, [166, 218, 19], [206, 221, 20]], [0.75, [206, 221, 20], [222, 213, 19]], [0.7813, [222, 213, 19], [222, 191, 19]], [0.8125, [222, 191, 19], [227, 133, 17]], [0.875, [227, 133, 17], [231, 83, 16]], [0.9375, [231, 83, 16], [220, 61, 48]]]
},
"stretched": {
"author": "publiclab",
"description": "A simple colormap from blue to red, with no purple overlap.",
"url": "https://publiclab.org/colormaps#stretched",
"colormapRanges": [[0, [0, 0, 255], [0, 0, 255]], [0.1, [0, 0, 255], [38, 195, 195]], [0.5, [0, 150, 0], [255, 255, 0]], [0.7, [255, 255, 0], [255, 50, 50]], [0.9, [255, 50, 50], [255, 50, 50]]]
},
"bluwhtgrngis": {
"author": "MaggPi",
"description": "A colormap from blue to white to green to....",
"url": "https://publiclab.org/colormaps#bluwhtgrngis",
"colormapRanges": [[0, [6, 23, 86], [6, 25, 84]], [0.0625, [6, 25, 84], [6, 25, 84]], [0.125, [6, 25, 84], [6, 25, 84]], [0.1875, [6, 25, 84], [6, 25, 84]], [0.25, [6, 25, 84], [6, 25, 84]], [0.3125, [6, 25, 84], [9, 24, 84]], [0.3438, [9, 24, 84], [119, 120, 162]], [0.375, [119, 129, 162], [249, 250, 251]], [0.406, [249, 250, 251], [255, 255, 255]], [0.4375, [255, 255, 255], [255, 255, 255]], [0.50, [255, 255, 255], [214, 205, 191]], [0.52, [214, 205, 191], [178, 175, 96]], [0.5625, [178, 175, 96], [151, 176, 53]], [0.593, [151, 176, 53], [146, 188, 12]], [0.625, [146, 188, 12], [96, 161, 1]], [0.6875, [96, 161, 1], [30, 127, 3]], [0.75, [30, 127, 3], [0, 99, 1]], [0.8125, [0, 99, 1], [0, 74, 1]], [0.875, [0, 74, 1], [0, 52, 0]], [0.9375, [0, 52, 0], [0, 34, 0]], [0.968, [0, 34, 0], [68, 70, 67]]]
},
"brntogrn": {
"author": "MaggPi",
"description": "A colormap from brown to green.",
"url": "https://publiclab.org/colormaps#brntogrn",
"colormapRanges": [[0, [110, 12, 3], [118, 6, 1]], [0.0625, [118, 6, 1], [141, 19, 6]], [0.125, [141, 19, 6], [165, 35, 13]], [0.1875, [165, 35, 13], [177, 59, 25]], [0.2188, [177, 59, 25], [192, 91, 36]], [0.25, [192, 91, 36], [214, 145, 76]], [0.3125, [214, 145, 76], [230, 183, 134]], [0.375, [230, 183, 134], [243, 224, 194]], [0.4375, [243, 224, 194], [250, 252, 229]], [0.50, [250, 252, 229], [217, 235, 185]], [0.5625, [217, 235, 185], [184, 218, 143]], [0.625, [184, 218, 143], [141, 202, 89]], [0.6875, [141, 202, 89], [80, 176, 61]], [0.75, [80, 176, 61], [0, 147, 32]], [0.8125, [0, 147, 32], [1, 122, 22]], [0.875, [1, 122, 22], [0, 114, 19]], [0.90, [0, 114, 19], [0, 105, 18]], [0.9375, [0, 105, 18], [7, 70, 14]]]
},
"blutoredjet": {
"author": "MaggPi",
"description": "A colormap from blue to red.",
"url": "https://publiclab.org/colormaps#blutoredjet",
"colormapRanges": [[0, [0, 0, 140], [1, 1, 186]], [0.0625, [1, 1, 186], [0, 1, 248]], [0.125, [0, 1, 248], [0, 70, 254]], [0.1875, [0, 70, 254], [0, 130, 255]], [0.25, [0, 130, 255], [2, 160, 255]], [0.2813, [2, 160, 255], [0, 187, 255]], [0.3125, [0, 187, 255], [6, 250, 255]], [0.348, [0, 218, 255], [8, 252, 251]], [0.375, [8, 252, 251], [27, 254, 228]], [0.406, [27, 254, 228], [70, 255, 187]], [0.4375, [70, 255, 187], [104, 254, 151]], [0.47, [104, 254, 151], [132, 255, 19]], [0.50, [132, 255, 19], [195, 255, 60]], [0.5625, [195, 255, 60], [231, 254, 25]], [0.5976, [231, 254, 25], [253, 246, 1]], [0.625, [253, 246, 1], [252, 210, 1]], [0.657, [252, 210, 1], [255, 183, 0]], [0.6875, [255, 183, 0], [255, 125, 2]], [0.75, [255, 125, 2], [255, 65, 1]], [0.8125, [255, 65, 1], [247, 1, 1]], [0.875, [247, 1, 1], [200, 1, 3]], [0.9375, [200, 1, 3], [122, 3, 2]]]
},
"colors16": {
"author": "publiclab",
"description": "A segmented colormap of the full color spectrum, divided into 16 colors.",
"url": "https://publiclab.org/colormaps#colors16",
"colormapRanges": [[0, [0, 0, 0], [0, 0, 0]], [0.0625, [3, 1, 172], [3, 1, 172]], [0.125, [3, 1, 222], [3, 1, 222]], [0.1875, [0, 111, 255], [0, 111, 255]], [0.25, [3, 172, 255], [3, 172, 255]], [0.3125, [1, 226, 255], [1, 226, 255]], [0.375, [2, 255, 0], [2, 255, 0]], [0.4375, [198, 254, 0], [190, 254, 0]], [0.50, [252, 255, 0], [252, 255, 0]], [0.5625, [255, 223, 3], [255, 223, 3]], [0.625, [255, 143, 3], [255, 143, 3]], [0.6875, [255, 95, 3], [255, 95, 3]], [0.75, [242, 0, 1], [242, 0, 1]], [0.8125, [245, 0, 170], [245, 0, 170]], [0.875, [223, 180, 225], [223, 180, 225]], [0.9375, [255, 255, 255], [255, 255, 255]]]
},
"fastie": {
"author": "cfastie",
"description": "A colormap for highlighting NDVI values over 0 on a scale from -1 to 1; in this scale, values from 0-0.5 are greyscale, while those over 0.5 are color.",
"url": "https://publiclab.org/colormaps#fastie",
"colormapRanges": [[0, [255, 255, 255], [0, 0, 0]], [0.167, [0, 0, 0], [255, 255, 255]], [0.33, [255, 255, 255], [0, 0, 0]], [0.5, [0, 0, 0], [140, 140, 255]], [0.55, [140, 140, 255], [0, 255, 0]], [0.63, [0, 255, 0], [255, 255, 0]], [0.75, [255, 255, 0], [255, 0, 0]], [0.95, [255, 0, 0], [255, 0, 255]]]
}
};
}, {}],
5: [function (require, module, exports) {
// This file was adapted from infragram-js:
// http://github.com/p-v-o-s/infragram-js.
module.exports = function Colormaps(options) {
// see https://github.com/publiclab/image-sequencer/tree/main/src/modules/Colormap/
var colormapFunctionGenerator = require('./colormapFunctionGenerator.js');
var colormaps = require('./colormaps.json');
Object.keys(colormaps).forEach(function (key) {
// make a function from the colormap, which we can't easily do in JSON
colormaps[key].fn = colormapFunctionGenerator(colormaps[key].colormapRanges);
});
var JsImage = require('../util/JsImage.js');
function colorify(jsImage, colormap) {
var b, data, g, i, j, l, n, r, ref;
$('#btn-colorize').addClass('active');
n = jsImage.width * jsImage.height;
data = new Uint8ClampedArray(4 * n);
j = 0;
for (i = l = 0, ref = n; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) {
var _colormap = colormap(jsImage.data[i]);
var _colormap2 = _slicedToArray(_colormap, 3);
r = _colormap2[0];
g = _colormap2[1];
b = _colormap2[2];
data[j++] = r;
data[j++] = g;
data[j++] = b;
data[j++] = 255;
}
return new JsImage(data, jsImage.width, jsImage.height, 4);
}
return {
colorify: colorify,
colormap1: colormaps['default'].fn,
colormap2: colormaps['stretched'].fn,
greyscale_colormap: colormaps['greyscale'].fn,
segmented_colormap: colormapFunctionGenerator
};
};
}, {
"../util/JsImage.js": 17,
"./colormapFunctionGenerator.js": 3,
"./colormaps.json": 4
}],
6: [function (require, module, exports) {
// This file was adapted from infragram-js:
// http://github.com/p-v-o-s/infragram-js.
module.exports = window.Converters = {
// modified from:
// http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c
hsv2rgb: function hsv2rgb(h, s, v) {
var data, f, i, p, q, rgb, t;
data = [];
if (s === 0) {
rgb = [v, v, v];
} else {
i = Math.floor(h * 6);
f = h * 6 - i;
p = v * (1 - s);
q = v * (1 - f * s);
t = v * (1 - (1 - f) * s);
data = [v * (1 - s), v * (1 - s * (h - i)), v * (1 - s * (1 - (h - i)))];
switch (i) {
case 0:
rgb = [v, t, p];
break;
case 1:
rgb = [q, v, p];
break;
case 2:
rgb = [p, v, t];
break;
case 3:
rgb = [p, q, v];
break;
case 4:
rgb = [t, p, v];
break;
default:
rgb = [v, p, q];
}
}
return rgb;
},
rgb2hsv: function rgb2hsv(r, g, b) {
var d, h, max, min, s, v;
max = Math.max(r, g, b);
min = Math.min(r, g, b);
h = s = v = max;
d = max - min;
s = max === 0 ? 0 : d / max;
if (max === min) {
h = 0; // achromatic
} else {
switch (max) {
case r:
h = (g - b) / d + (g < b ? 6 : 0);
break;
case g:
h = (b - r) / d + 2;
break;
case b:
h = (r - g) / d + 4;
}
h /= 6;
}
return [h, s, v];
}
};
}, {}],
7: [function (require, module, exports) {
// This file was adapted from infragram-js:
// http://github.com/p-v-o-s/infragram-js.
module.exports = function Camera(options) {
var canvas, ctx; // Initialize getUserMedia with options
function initialize() {
getUserMedia(webRtcOptions, success, deviceError); // iOS Safari 11 compatibility: https://github.com/webrtc/adapter/issues/685
webRtcOptions.videoEl.setAttribute('id', 'webCamVideoEl');
var webCamVideoEl = document.getElementById('webCamVideoEl');
webCamVideoEl.setAttribute('autoplay', 'autoplay');
webCamVideoEl.setAttribute('playsinline', 'playsinline');
window.webcam = webRtcOptions; // this is weird but maybe used for flash fallback?
canvas = options.canvas || document.getElementById("image");
ctx = canvas.getContext("2d"); // Trigger a snapshot w/ button
// -- move this to interface.js?
$("#snapshot").show();
$("#live-video").show();
$("#webcam").show();
} // webRtcOptions contains the configuration information for the shim
// it allows us to specify the width and height of the video
// output we"re working with, the location of the fallback swf,
// events that are triggered onCapture and onSave (for the fallback)
// and so on.
var webRtcOptions = options.webRtcOptions || {
"audio": false,
"video": true,
// the element (by id) you wish to use for
// displaying the stream from a camera
el: "webcam",
extern: null,
append: true,
// height and width of the output stream
// container
width: 640,
height: 480,
// the recommended mode to be used is
// "callback " where a callback is executed
// once data is available
mode: "callback",
// a debugger callback is available if needed
debug: function debug() {},
// callback for capturing the fallback stream
onCapture: function onWebRtcCapture() {
return window.webcam.save();
},
// callback for saving the stream, useful for
// relaying data further.
onSave: onSaveGetUserMedia,
onLoad: function onLoadGetUserMedia() {}
};
function onSaveGetUserMedia(data) {
var col,
h,
i,
img,
j,
ref,
tmp,
w,
pos = 0;
col = data.split("");
img = camera.image;
tmp = null;
w = webRtcOptions.width;
h = webRtcOptions.height;
for (i = j = 0, ref = w - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
tmp = parseInt(col[i], 10);
img.data[pos + 0] = tmp >> 16 & 0xff;
img.data[pos + 1] = tmp >> 8 & 0xff;
img.data[pos + 2] = tmp & 0xff;
img.data[pos + 3] = 0xff;
pos += 4;
}
if (pos >= 4 * w * h) {
ctx.putImageData(img, 0, 0);
return pos = 0;
}
}
function success(stream) {
var video;
window.localStream = stream;
isCamera = true;
if (webRtcOptions.context === "webrtc") {
video = document.getElementById("webCamVideoEl");
if (navigator.mozGetUserMedia) {
video.mozSrcObject = stream;
} else {
video.srcObject = stream;
}
return video.onerror = function (e) {
return stream.stop();
};
} else {}
}
function deviceError(error) {
alert("No camera available.");
console.log(error);
return console.error("An error occurred: [CODE " + error.code + "]");
} // not doing anything now... for copying to a 2nd canvas
function getSnapshot() {
var video; // If the current context is WebRTC/getUserMedia (something
// passed back from the shim to avoid doing further feature
// detection), we handle getting video/images for our canvas
// from our HTML5 <video> element.
if (webRtcOptions.context === "webrtc") {
video = document.getElementsByTagName("video")[0];
options.processor.updateImage(video);
return $("#webcam").hide(); // Otherwise, if the context is Flash, we ask the shim to
// directly call window.webcam, where our shim is located
// and ask it to capture for us.
} else if (webRtcOptions.context === "flash") {
return window.webcam.capture();
} else {
console.log("No context was supplied to getSnapshot()");
}
}
return {
getSnapshot: getSnapshot,
initialize: initialize,
onSaveGetUserMedia: onSaveGetUserMedia,
webRtcOptions: webRtcOptions
};
};
}, {}],
8: [function (require, module, exports) {
// This file was adapted from infragram-js:
// http://github.com/p-v-o-s/infragram-js.
module.exports = function File(options, processor) {
function downloadImage() {
var event, format, lnk; // create an "off-screen" anchor tag
lnk = document.createElement("a"); // the key here is to set the download attribute of the a tag
lnk.href = processor.getCurrentImage();
if (lnk.href.match('image/jpeg')) {
format = "jpg";
} else {
format = "png";
}
lnk.download = new Date().toISOString().replace(/:/g, "_") + "." + format; // create a "fake" click-event to trigger the download
if (document.createEvent) {
event = document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
lnk.dispatchEvent(event);
} else if (lnk.fireEvent) {
lnk.fireEvent("onclick");
}
return true;
} // from a local URL (remote may be against js security rules)
function fetchImage(src, mode) {
var img;
$("#save-modal-btn").show();
$("#save-zone").show();
img = new Image();
if (options.uploader) {
img.onload = function () {
var filename;
filename = src.split('/');
filename = filename[filename.length - 1];
FileUpload.setFilename(filename);
if (mode) {
if (mode.substring(0, 5) === "infra") {
$("#modeSwitcher").val(mode).change();
} else {
$("button#" + mode).button("toggle");
$("button#" + mode).click(); // this should be via a direct call, not a click; the show.jade page should not require buttons!
}
}
options.save_infragrammar_expressions(params);
if (mode === "ndvi") {
options.save_infragrammar_expressions({
'm': '(R-B)/(R+B)'
});
mode = "infragrammar_mono";
} else if (mode === "nir") {
options.save_infragrammar_expressions({
'm': 'R'
});
mode = "infragrammar_mono";
} else if (mode === "raw") {
options.save_infragrammar_expressions({
'r': 'R',
'g': 'G',
'b': 'B'
});
mode = "infragrammar";
}
processor.updateImage(this);
if (params['color'] === "true" || params['c'] === "true") {
options.colorized = true; // before run_infrag, so it gets logged
}
run_infragrammar(mode); // this sets colorized to false!
if (params['color'] === "true" || params['c'] === "true") {
options.colorized = true; // again, so it gets run
}
if (options.colorized) {
$("button#color").button("toggle");
return run_colorize();
}
};
}
return img.src = src;
}
return {
fetchImage: fetchImage,
downloadImage: downloadImage
};
};
}, {}],
9: [function (require, module, exports) {
// refactor to access state, not dom
module.exports = function Logger(options) {
var log = []; // a record of previous commands run
function log_mono() {
var logEntry;
logEntry = "mode=infragrammar_mono";
logEntry += $("#m_exp").val() ? "&m=" + $("#m_exp").val() : "";
logEntry += options.colorized ? "&c=true" : ""; // no way to succinctly store the colormap... just offer range of colorizations at view-time?
return log.push(logEntry);
}
function log_hsv() {
var logEntry;
logEntry = "mode=infragrammar_hsv";
logEntry += $("#h_exp").val() ? "&h=" + $("#h_exp").val() : "";
logEntry += $("#s_exp").val() ? "&s=" + $("#s_exp").val() : "";
logEntry += $("#v_exp").val() ? "&v=" + $("#v_exp").val() : "";
return log.push(logEntry);
}
function log_rgb() {
var logEntry;
logEntry = "mode=infragrammar";
logEntry += $("#r_exp").val() ? "&r=" + $("#r_exp").val() : "";
logEntry += $("#g_exp").val() ? "&g=" + $("#g_exp").val() : "";
logEntry += $("#b_exp").val() ? "&b=" + $("#b_exp").val() : "";
return log.push(logEntry);
}
function save_log() {
if (options.mode === "infragrammar_mono") {
return log_mono();
} else if (options.mode === "infragrammar_hsv") {
return log_hsv();
} else if (options.mode === "infragrammar") {
return log_rgb();
}
}
return {
log: log,
log_hsv: log_hsv,
log_mono: log_mono,
log_rgb: log_rgb,
save_log: save_log
};
};
}, {}],
10: [function (require, module, exports) {
// This file was adapted from infragram-js:
// http://github.com/p-v-o-s/infragram-js.
// not currently being used -- will replace with Image Sequencer perhaps?
// https://github.com/publiclab/image-sequencer
module.exports = function javascriptProcessor() {
var b_exp = "",
g_exp = "",
get_channels,
Colormaps = require('../color/colormaps')(JsImage),
colormap = Colormaps.colormap1,
converters = require('../color/converters'),
image = null,
mode = "raw",
ndvi,
r_exp = "",
set_mode,
update_colorbar;
var JsImage = require('../util/JsImage.js');
function get_channels(jsImage) {
var b, g, i, l, mkImage, n, r, ref;
n = jsImage.width * jsImage.height;
r = new Float32Array(n);
g = new Float32Array(n);
b = new Float32Array(n);
for (i = l = 0, ref = n; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) {
r[i] = jsImage.data[4 * i + 0];
g[i] = jsImage.data[4 * i + 1];
b[i] = jsImage.data[4 * i + 2];
}
function mkImage(d) {
return new JsImage(d, jsImage.width, jsImage.height, 1);
}
return [mkImage(r), mkImage(g), mkImage(b)];
} // replace with infragrammar expression
function ndvi(nirJsImg, visJsImg) {
var d, i, l, n, ref;
n = nirJsImg.width * nirJsImg.height;
d = new Float64Array(n);
for (i = l = 0, ref = n; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) {
d[i] = (nirJsImg.data[i] - visJsImg.data[i]) / (nirJsImg.data[i] + visJsImg.data[i]);
}
return new JsImage(d, nirJsImg.width, nirJsImg.height, 1);
}
function infragrammar(jsImage) {
var b, g, i, l, n, o, r, ref;
$('#btn-colorize').removeClass('active');
n = jsImage.width * jsImage.height;
r = new Float32Array(n);
g = new Float32Array(n);
b = new Float32Array(n);
o = new Float32Array(4 * n);
for (i = l = 0, ref = n; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) {
r[i] = jsImage.data[4 * i + 0] / 255;
g[i] = jsImage.data[4 * i + 1] / 255;
b[i] = jsImage.data[4 * i + 2] / 255;
o[4 * i + 0] = 255 * r_exp(r[i], g[i], b[i]);
o[4 * i + 1] = 255 * g_exp(r[i], g[i], b[i]);
o[4 * i + 2] = 255 * b_exp(r[i], g[i], b[i]);
o[4 * i + 3] = 255;
}
return new JsImage(o, jsImage.width, jsImage.height, 4);
}
function infragrammar_mono(jsImage) {
var b, g, i, l, n, o, r, ref;
n = jsImage.width * jsImage.height;
r = new Float32Array(n);
g = new Float32Array(n);
b = new Float32Array(n);
o = new Float32Array(n);
for (i = l = 0, ref = n; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) {
r[i] = jsImage.data[4 * i + 0] / 255.0;
g[i] = jsImage.data[4 * i + 1] / 255.0;
b[i] = jsImage.data[4 * i + 2] / 255.0;
o[i] = r_exp(r[i], g[i], b[i]);
}
return new JsImage(o, jsImage.width, jsImage.height, 1);
}
function render(jsImage) {
var ctx, d, e;
e = $("#image")[0];
e.width = jsImage.width;
e.height = jsImage.height;
ctx = e.getContext("2d");
d = ctx.getImageData(0, 0, jsImage.width, jsImage.height);
jsImage.copyToImageData(d);
return ctx.putImageData(d, 0, 0);
}
function colorize() {
var imageData = getImageData();
render(Colormaps.colorify(infragrammar_mono(imageData), function (x) {
return colormap((x + 1) / 2);
}));
return true;
}
update_colorbar = function update_colorbar(min, max) {
var b, ctx, d, e, g, i, j, k, l, m, r, ref, ref1;
$('#colorbar-container')[0].style.display = 'inline-block';
e = $('#colorbar')[0];
ctx = e.getContext("2d");
d = ctx.getImageData(0, 0, e.width, e.height);
for (i = l = 0, ref = e.width; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) {
for (j = m = 0, ref1 = e.height; 0 <= ref1 ? m < ref1 : m > ref1; j = 0 <= ref1 ? ++m : --m) {
var _colormap3 = colormap(i / e.width);
var _colormap4 = _slicedToArray(_colormap3, 3);
r = _colormap4[0];
g = _colormap4[1];
b = _colormap4[2];
k = 4 * (i + j * e.width);
d.data[k + 0] = r;
d.data[k + 1] = g;
d.data[k + 2] = b;
d.data[k + 3] = 255;
}
}
ctx.putImageData(d, 0, 0);
$("#colorbar-min")[0].textContent = min.toFixed(2);
return $("#colorbar-max")[0].textContent = max.toFixed(2);
};
function update(image) {
var b, g, max, min, ndvi_jsImg, normalize, r, resultJsImage;
$('#colorbar-container')[0].style.display = 'none';
if (mode === "ndvi") {
var _normalize = function _normalize(x) {
return (x - min) / (max - min);
};
var _get_channels = get_channels(image);
var _get_channels2 = _slicedToArray(_get_channels, 3);
r = _get_channels2[0];
g = _get_channels2[1];
b = _get_channels2[2];
ndvi_jsImg = ndvi(r, b); // this isn't correct for NDVI; we want values from -1 to 1:
// [[min],[max]] = ndvi_img.extrema()
min = -1;
max = 1;
;
resultJsImage = Colormaps.colorify(ndvi_jsImg, function (x) {
return colormap(_normalize(x));
});
update_colorbar(min, max);
} else if (mode === "raw") {
resultJsImage = new JsImage(image.data, image.width, image.height, 4);
} else if (mode === "nir") {
var _get_channels3 = get_channels(image);
var _get_channels4 = _slicedToArray(_get_channels3, 3);
r = _get_channels4[0];
g = _get_channels4[1];
b = _get_channels4[2];
resultJsImage = Colormaps.colorify(r, function (x) {
return [x, x, x];
});
} else {
resultJsImage = infragrammar(image);
}
return render(resultJsImage);
}
function save_expressions(r, g, b) {
if (r === "") {
r = "R";
}
if (g === "") {
g = "G";
}
if (b === "") {
b = "B";
}
eval("r_exp = function(R,G,B){var r=R,g=G,b=B;return " + r + ";}");
eval("g_exp = function(R,G,B){var r=R,g=G,b=B;return " + g + ";}");
return eval("b_exp = function(R,G,B){var r=R,g=G,b=B;return " + b + ";}");
}
;
function save_expressions_hsv(h, s, v) {
if (h === "") {
h = "H";
}
if (s === "") {
s = "S";
}
if (v === "") {
v = "V";
}
eval("r_exp = function(R,G,B){var h=H,s=S,v=V,hsv = converters.rgb2hsv(R, G, B), H = hsv[0], S = hsv[1], V = hsv[2]; return converters.hsv2rgb(" + h + "," + s + "," + v + ")[0];}");
eval("g_exp = function(R,G,B){var h=H,s=S,v=V,hsv = converters.rgb2hsv(R, G, B), H = hsv[0], S = hsv[1], V = hsv[2]; return converters.hsv2rgb(" + h + "," + s + "," + v + ")[1];}");
return eval("b_exp = function(R,G,B){var h=H,s=S,v=V,hsv = converters.rgb2hsv(R, G, B), H = hsv[0], S = hsv[1], V = hsv[2]; return converters.hsv2rgb(" + h + "," + s + "," + v + ")[2];}");
}
function getImageData() {
var ctx = $('#image')[0].getContext("2d"); // risks being circular def of width/height
var width = $('#image').width();
var height = $('#image').height(); // this now just defaults to file-scoped 'image' which we want to avoid
return image || ctx.getImageData(0, 0, width, height);
}
function getJsImage() {
var imageData = getImageData();
return new JsImage(imageData.data, imageData.width, imageData.height, 1);
}
function set_mode(new_mode) {
mode = new_mode;
update(getImageData());
if (mode === "ndvi") {
// TODO: move this into interface code:
return $("#colormaps-group")[0].style.display = "inline-block";
} else {
if ($("#colormaps-group").length > 0) {
return $("#colormaps-group")[0].style.display = "none";
}
}
} // img should be a native JavaScript image obj
function updateImage(img) {
var ctx, height, imgCanvas, width;
imgCanvas = document.getElementById("image");
ctx = imgCanvas.getContext("2d");
width = img.videoWidth || img.width;
height = img.videoHeight || img.height;
ctx.drawImage(img, 0, 0, width, height, 0, 0, imgCanvas.width, imgCanvas.height);
image = ctx.getImageData(0, 0, imgCanvas.width, imgCanvas.height);
return set_mode(mode);
}
function run(mode) {
return set_mode(mode);
}
function getCurrentImage() {
var ctx, e;
e = $("#image")[0];
ctx = e.getContext("2d");
return ctx.canvas.toDataURL("image/jpeg");
}
return {
type: 'javascript',
colormap: colormap,
getCurrentImage: getCurrentImage,
getImageData: getImageData,
getJsImage: getJsImage,
infragrammar_mono: infragrammar_mono,
infragrammar: infragrammar,
render: render,
run: run,
save_expressions: save_expressions,
save_expressions_hsv: save_expressions_hsv,
update: update,
updateImage: updateImage,
colorize: colorize,
initialize: function initialize() {}
};
};
}, {
"../color/colormaps": 5,
"../color/converters": 6,
"../util/JsImage.js": 17
}],
11: [function (require, module, exports) {
// Generated by CoffeeScript 2.1.0
// This file was adapted from infragram-js:
// http://github.com/p-v-o-s/infragram-js.
module.exports = function webglProcessor(options) {
var imgContext = null,
mapContext = null,
inputImage,
// the pre-processed image
vertices = [-1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0],
waitForShadersToLoad = 0,
webglUtils = require('../util/webgl-utils')(),
colorized = false,