-
Notifications
You must be signed in to change notification settings - Fork 0
/
opencv_wasm.js
10961 lines (10442 loc) · 580 KB
/
opencv_wasm.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(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(function() {
return (root.cv = factory());
});
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else if (typeof window === 'object') {
// Browser globals
root.cv = factory();
} else if (typeof importScripts === 'function') {
// Web worker
root.cv = factory();
} else {
// Other shells, e.g. d8
root.cv = factory();
}
}(this, function() {
var cv = (function() {
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
return (
function(cv) {
cv = cv || {};
var Module = typeof cv !== "undefined" ? cv : {};
var moduleOverrides = {};
var key;
for (key in Module) {
if (Module.hasOwnProperty(key)) {
moduleOverrides[key] = Module[key]
}
}
var arguments_ = [];
var thisProgram = "./this.program";
var quit_ = function(status, toThrow) {
throw toThrow
};
var ENVIRONMENT_IS_WEB = true;
var ENVIRONMENT_IS_WORKER = false;
var ENVIRONMENT_IS_NODE = false;
if (Module["ENVIRONMENT"]) {
throw new Error("Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -s ENVIRONMENT=web or -s ENVIRONMENT=node)")
}
var scriptDirectory = "";
function locateFile(path) {
if (Module["locateFile"]) {
return Module["locateFile"](path, scriptDirectory)
}
return scriptDirectory + path
}
var read_, readAsync, readBinary, setWindowTitle;
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = self.location.href
} else if (document.currentScript) {
scriptDirectory = document.currentScript.src
}
if (_scriptDir) {
scriptDirectory = _scriptDir
}
if (scriptDirectory.indexOf("blob:") !== 0) {
scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf("/") + 1)
} else {
scriptDirectory = ""
}
if (!(typeof window === "object" || typeof importScripts === "function")) throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");
{
read_ = function shell_read(url) {
var xhr = new XMLHttpRequest;
xhr.open("GET", url, false);
xhr.send(null);
return xhr.responseText
};
if (ENVIRONMENT_IS_WORKER) {
readBinary = function readBinary(url) {
var xhr = new XMLHttpRequest;
xhr.open("GET", url, false);
xhr.responseType = "arraybuffer";
xhr.send(null);
return new Uint8Array(xhr.response)
}
}
readAsync = function readAsync(url, onload, onerror) {
var xhr = new XMLHttpRequest;
xhr.open("GET", url, true);
xhr.responseType = "arraybuffer";
xhr.onload = function xhr_onload() {
if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
onload(xhr.response);
return
}
onerror()
};
xhr.onerror = onerror;
xhr.send(null)
}
}
setWindowTitle = function(title) {
document.title = title
}
} else {
throw new Error("environment detection error")
}
var out = Module["print"] || console.log.bind(console);
var err = Module["printErr"] || console.warn.bind(console);
for (key in moduleOverrides) {
if (moduleOverrides.hasOwnProperty(key)) {
Module[key] = moduleOverrides[key]
}
}
moduleOverrides = null;
if (Module["arguments"]) arguments_ = Module["arguments"];
if (!Object.getOwnPropertyDescriptor(Module, "arguments")) Object.defineProperty(Module, "arguments", {
configurable: true,
get: function() {
abort("Module.arguments has been replaced with plain arguments_")
}
});
if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
if (!Object.getOwnPropertyDescriptor(Module, "thisProgram")) Object.defineProperty(Module, "thisProgram", {
configurable: true,
get: function() {
abort("Module.thisProgram has been replaced with plain thisProgram")
}
});
if (Module["quit"]) quit_ = Module["quit"];
if (!Object.getOwnPropertyDescriptor(Module, "quit")) Object.defineProperty(Module, "quit", {
configurable: true,
get: function() {
abort("Module.quit has been replaced with plain quit_")
}
});
assert(typeof Module["memoryInitializerPrefixURL"] === "undefined", "Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead");
assert(typeof Module["pthreadMainPrefixURL"] === "undefined", "Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead");
assert(typeof Module["cdInitializerPrefixURL"] === "undefined", "Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead");
assert(typeof Module["filePackagePrefixURL"] === "undefined", "Module.filePackagePrefixURL option was removed, use Module.locateFile instead");
assert(typeof Module["read"] === "undefined", "Module.read option was removed (modify read_ in JS)");
assert(typeof Module["readAsync"] === "undefined", "Module.readAsync option was removed (modify readAsync in JS)");
assert(typeof Module["readBinary"] === "undefined", "Module.readBinary option was removed (modify readBinary in JS)");
assert(typeof Module["setWindowTitle"] === "undefined", "Module.setWindowTitle option was removed (modify setWindowTitle in JS)");
if (!Object.getOwnPropertyDescriptor(Module, "read")) Object.defineProperty(Module, "read", {
configurable: true,
get: function() {
abort("Module.read has been replaced with plain read_")
}
});
if (!Object.getOwnPropertyDescriptor(Module, "readAsync")) Object.defineProperty(Module, "readAsync", {
configurable: true,
get: function() {
abort("Module.readAsync has been replaced with plain readAsync")
}
});
if (!Object.getOwnPropertyDescriptor(Module, "readBinary")) Object.defineProperty(Module, "readBinary", {
configurable: true,
get: function() {
abort("Module.readBinary has been replaced with plain readBinary")
}
});
var STACK_ALIGN = 16;
stackSave = stackRestore = stackAlloc = function() {
abort("cannot use the stack before compiled code is ready to run, and has provided stack access")
};
function dynamicAlloc(size) {
assert(DYNAMICTOP_PTR);
var ret = HEAP32[DYNAMICTOP_PTR >> 2];
var end = ret + size + 15 & -16;
if (end > _emscripten_get_heap_size()) {
abort("failure to dynamicAlloc - memory growth etc. is not supported there, call malloc/sbrk directly")
}
HEAP32[DYNAMICTOP_PTR >> 2] = end;
return ret
}
function getNativeTypeSize(type) {
switch (type) {
case "i1":
case "i8":
return 1;
case "i16":
return 2;
case "i32":
return 4;
case "i64":
return 8;
case "float":
return 4;
case "double":
return 8;
default: {
if (type[type.length - 1] === "*") {
return 4
} else if (type[0] === "i") {
var bits = parseInt(type.substr(1));
assert(bits % 8 === 0, "getNativeTypeSize invalid bits " + bits + ", type " + type);
return bits / 8
} else {
return 0
}
}
}
}
function warnOnce(text) {
if (!warnOnce.shown) warnOnce.shown = {};
if (!warnOnce.shown[text]) {
warnOnce.shown[text] = 1;
err(text)
}
}
var asm2wasmImports = {
"f64-rem": function(x, y) {
return x % y
},
"debugger": function() {
debugger
}
};
var jsCallStartIndex = 1;
var functionPointers = new Array(0);
function convertJsFunctionToWasm(func, sig) {
if (typeof WebAssembly.Function === "function") {
var typeNames = {
"i": "i32",
"j": "i64",
"f": "f32",
"d": "f64"
};
var type = {
parameters: [],
results: sig[0] == "v" ? [] : [typeNames[sig[0]]]
};
for (var i = 1; i < sig.length; ++i) {
type.parameters.push(typeNames[sig[i]])
}
return new WebAssembly.Function(type, func)
}
var typeSection = [1, 0, 1, 96];
var sigRet = sig.slice(0, 1);
var sigParam = sig.slice(1);
var typeCodes = {
"i": 127,
"j": 126,
"f": 125,
"d": 124
};
typeSection.push(sigParam.length);
for (var i = 0; i < sigParam.length; ++i) {
typeSection.push(typeCodes[sigParam[i]])
}
if (sigRet == "v") {
typeSection.push(0)
} else {
typeSection = typeSection.concat([1, typeCodes[sigRet]])
}
typeSection[1] = typeSection.length - 2;
var bytes = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0].concat(typeSection, [2, 7, 1, 1, 101, 1, 102, 0, 0, 7, 5, 1, 1, 102, 0, 0]));
var module = new WebAssembly.Module(bytes);
var instance = new WebAssembly.Instance(module, {
"e": {
"f": func
}
});
var wrappedFunc = instance.exports["f"];
return wrappedFunc
}
var funcWrappers = {};
function dynCall(sig, ptr, args) {
if (args && args.length) {
assert(args.length == sig.length - 1);
assert("dynCall_" + sig in Module, "bad function pointer type - no table for sig '" + sig + "'");
return Module["dynCall_" + sig].apply(null, [ptr].concat(args))
} else {
assert(sig.length == 1);
assert("dynCall_" + sig in Module, "bad function pointer type - no table for sig '" + sig + "'");
return Module["dynCall_" + sig].call(null, ptr)
}
}
var tempRet0 = 0;
var setTempRet0 = function(value) {
tempRet0 = value
};
var getTempRet0 = function() {
return tempRet0
};
var wasmBinary;
if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
if (!Object.getOwnPropertyDescriptor(Module, "wasmBinary")) Object.defineProperty(Module, "wasmBinary", {
configurable: true,
get: function() {
abort("Module.wasmBinary has been replaced with plain wasmBinary")
}
});
var noExitRuntime;
if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"];
if (!Object.getOwnPropertyDescriptor(Module, "noExitRuntime")) Object.defineProperty(Module, "noExitRuntime", {
configurable: true,
get: function() {
abort("Module.noExitRuntime has been replaced with plain noExitRuntime")
}
});
if (typeof WebAssembly !== "object") {
abort("No WebAssembly support found. Build with -s WASM=0 to target JavaScript instead.")
}
function setValue(ptr, value, type, noSafe) {
type = type || "i8";
if (type.charAt(type.length - 1) === "*") type = "i32";
switch (type) {
case "i1":
HEAP8[ptr >> 0] = value;
break;
case "i8":
HEAP8[ptr >> 0] = value;
break;
case "i16":
HEAP16[ptr >> 1] = value;
break;
case "i32":
HEAP32[ptr >> 2] = value;
break;
case "i64":
tempI64 = [value >>> 0, (tempDouble = value, +Math_abs(tempDouble) >= 1 ? tempDouble > 0 ? (Math_min(+Math_floor(tempDouble / 4294967296), 4294967295) | 0) >>> 0 : ~~+Math_ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0)], HEAP32[ptr >> 2] = tempI64[0], HEAP32[ptr + 4 >> 2] = tempI64[1];
break;
case "float":
HEAPF32[ptr >> 2] = value;
break;
case "double":
HEAPF64[ptr >> 3] = value;
break;
default:
abort("invalid type for setValue: " + type)
}
}
var wasmMemory;
var wasmTable = new WebAssembly.Table({
"initial": 14737,
"maximum": 14737,
"element": "anyfunc"
});
var ABORT = false;
var EXITSTATUS = 0;
function assert(condition, text) {
if (!condition) {
abort("Assertion failed: " + text)
}
}
function getCFunc(ident) {
var func = Module["_" + ident];
assert(func, "Cannot call unknown function " + ident + ", make sure it is exported");
return func
}
function ccall(ident, returnType, argTypes, args, opts) {
var toC = {
"string": function(str) {
var ret = 0;
if (str !== null && str !== undefined && str !== 0) {
var len = (str.length << 2) + 1;
ret = stackAlloc(len);
stringToUTF8(str, ret, len)
}
return ret
},
"array": function(arr) {
var ret = stackAlloc(arr.length);
writeArrayToMemory(arr, ret);
return ret
}
};
function convertReturnValue(ret) {
if (returnType === "string") return UTF8ToString(ret);
if (returnType === "boolean") return Boolean(ret);
return ret
}
var func = getCFunc(ident);
var cArgs = [];
var stack = 0;
assert(returnType !== "array", 'Return type should not be "array".');
if (args) {
for (var i = 0; i < args.length; i++) {
var converter = toC[argTypes[i]];
if (converter) {
if (stack === 0) stack = stackSave();
cArgs[i] = converter(args[i])
} else {
cArgs[i] = args[i]
}
}
}
var ret = func.apply(null, cArgs);
ret = convertReturnValue(ret);
if (stack !== 0) stackRestore(stack);
return ret
}
var ALLOC_NONE = 3;
function allocate(slab, types, allocator, ptr) {
var zeroinit, size;
if (typeof slab === "number") {
zeroinit = true;
size = slab
} else {
zeroinit = false;
size = slab.length
}
var singleType = typeof types === "string" ? types : null;
var ret;
if (allocator == ALLOC_NONE) {
ret = ptr
} else {
ret = [_malloc, stackAlloc, dynamicAlloc][allocator](Math.max(size, singleType ? 1 : types.length))
}
if (zeroinit) {
var stop;
ptr = ret;
assert((ret & 3) == 0);
stop = ret + (size & ~3);
for (; ptr < stop; ptr += 4) {
HEAP32[ptr >> 2] = 0
}
stop = ret + size;
while (ptr < stop) {
HEAP8[ptr++ >> 0] = 0
}
return ret
}
if (singleType === "i8") {
if (slab.subarray || slab.slice) {
HEAPU8.set(slab, ret)
} else {
HEAPU8.set(new Uint8Array(slab), ret)
}
return ret
}
var i = 0,
type, typeSize, previousType;
while (i < size) {
var curr = slab[i];
type = singleType || types[i];
if (type === 0) {
i++;
continue
}
assert(type, "Must know what type to store in allocate!");
if (type == "i64") type = "i32";
setValue(ret + i, curr, type);
if (previousType !== type) {
typeSize = getNativeTypeSize(type);
previousType = type
}
i += typeSize
}
return ret
}
function getMemory(size) {
if (!runtimeInitialized) return dynamicAlloc(size);
return _malloc(size)
}
var UTF8Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf8") : undefined;
function UTF8ArrayToString(u8Array, idx, maxBytesToRead) {
var endIdx = idx + maxBytesToRead;
var endPtr = idx;
while (u8Array[endPtr] && !(endPtr >= endIdx)) ++endPtr;
if (endPtr - idx > 16 && u8Array.subarray && UTF8Decoder) {
return UTF8Decoder.decode(u8Array.subarray(idx, endPtr))
} else {
var str = "";
while (idx < endPtr) {
var u0 = u8Array[idx++];
if (!(u0 & 128)) {
str += String.fromCharCode(u0);
continue
}
var u1 = u8Array[idx++] & 63;
if ((u0 & 224) == 192) {
str += String.fromCharCode((u0 & 31) << 6 | u1);
continue
}
var u2 = u8Array[idx++] & 63;
if ((u0 & 240) == 224) {
u0 = (u0 & 15) << 12 | u1 << 6 | u2
} else {
if ((u0 & 248) != 240) warnOnce("Invalid UTF-8 leading byte 0x" + u0.toString(16) + " encountered when deserializing a UTF-8 string on the asm.js/wasm heap to a JS string!");
u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | u8Array[idx++] & 63
}
if (u0 < 65536) {
str += String.fromCharCode(u0)
} else {
var ch = u0 - 65536;
str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023)
}
}
}
return str
}
function UTF8ToString(ptr, maxBytesToRead) {
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : ""
}
function stringToUTF8Array(str, outU8Array, outIdx, maxBytesToWrite) {
if (!(maxBytesToWrite > 0)) return 0;
var startIdx = outIdx;
var endIdx = outIdx + maxBytesToWrite - 1;
for (var i = 0; i < str.length; ++i) {
var u = str.charCodeAt(i);
if (u >= 55296 && u <= 57343) {
var u1 = str.charCodeAt(++i);
u = 65536 + ((u & 1023) << 10) | u1 & 1023
}
if (u <= 127) {
if (outIdx >= endIdx) break;
outU8Array[outIdx++] = u
} else if (u <= 2047) {
if (outIdx + 1 >= endIdx) break;
outU8Array[outIdx++] = 192 | u >> 6;
outU8Array[outIdx++] = 128 | u & 63
} else if (u <= 65535) {
if (outIdx + 2 >= endIdx) break;
outU8Array[outIdx++] = 224 | u >> 12;
outU8Array[outIdx++] = 128 | u >> 6 & 63;
outU8Array[outIdx++] = 128 | u & 63
} else {
if (outIdx + 3 >= endIdx) break;
if (u >= 2097152) warnOnce("Invalid Unicode code point 0x" + u.toString(16) + " encountered when serializing a JS string to an UTF-8 string on the asm.js/wasm heap! (Valid unicode code points should be in range 0-0x1FFFFF).");
outU8Array[outIdx++] = 240 | u >> 18;
outU8Array[outIdx++] = 128 | u >> 12 & 63;
outU8Array[outIdx++] = 128 | u >> 6 & 63;
outU8Array[outIdx++] = 128 | u & 63
}
}
outU8Array[outIdx] = 0;
return outIdx - startIdx
}
function stringToUTF8(str, outPtr, maxBytesToWrite) {
assert(typeof maxBytesToWrite == "number", "stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!");
return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite)
}
function lengthBytesUTF8(str) {
var len = 0;
for (var i = 0; i < str.length; ++i) {
var u = str.charCodeAt(i);
if (u >= 55296 && u <= 57343) u = 65536 + ((u & 1023) << 10) | str.charCodeAt(++i) & 1023;
if (u <= 127) ++len;
else if (u <= 2047) len += 2;
else if (u <= 65535) len += 3;
else len += 4
}
return len
}
var UTF16Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-16le") : undefined;
function allocateUTF8(str) {
var size = lengthBytesUTF8(str) + 1;
var ret = _malloc(size);
if (ret) stringToUTF8Array(str, HEAP8, ret, size);
return ret
}
function writeArrayToMemory(array, buffer) {
assert(array.length >= 0, "writeArrayToMemory array must have a length (should be an array or typed array)");
HEAP8.set(array, buffer)
}
function writeAsciiToMemory(str, buffer, dontAddNull) {
for (var i = 0; i < str.length; ++i) {
assert(str.charCodeAt(i) === str.charCodeAt(i) & 255);
HEAP8[buffer++ >> 0] = str.charCodeAt(i)
}
if (!dontAddNull) HEAP8[buffer >> 0] = 0
}
var PAGE_SIZE = 16384;
var WASM_PAGE_SIZE = 65536;
function alignUp(x, multiple) {
if (x % multiple > 0) {
x += multiple - x % multiple
}
return x
}
var buffer, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
function updateGlobalBufferAndViews(buf) {
buffer = buf;
Module["HEAP8"] = HEAP8 = new Int8Array(buf);
Module["HEAP16"] = HEAP16 = new Int16Array(buf);
Module["HEAP32"] = HEAP32 = new Int32Array(buf);
Module["HEAPU8"] = HEAPU8 = new Uint8Array(buf);
Module["HEAPU16"] = HEAPU16 = new Uint16Array(buf);
Module["HEAPU32"] = HEAPU32 = new Uint32Array(buf);
Module["HEAPF32"] = HEAPF32 = new Float32Array(buf);
Module["HEAPF64"] = HEAPF64 = new Float64Array(buf)
}
var STACK_BASE = 1578304,
STACK_MAX = 6821184,
DYNAMIC_BASE = 6821184,
DYNAMICTOP_PTR = 1578112;
assert(STACK_BASE % 16 === 0, "stack must start aligned");
assert(DYNAMIC_BASE % 16 === 0, "heap must start aligned");
var TOTAL_STACK = 5242880;
if (Module["TOTAL_STACK"]) assert(TOTAL_STACK === Module["TOTAL_STACK"], "the stack size can no longer be determined at runtime");
var INITIAL_TOTAL_MEMORY = Module["TOTAL_MEMORY"] || 134217728;
if (!Object.getOwnPropertyDescriptor(Module, "TOTAL_MEMORY")) Object.defineProperty(Module, "TOTAL_MEMORY", {
configurable: true,
get: function() {
abort("Module.TOTAL_MEMORY has been replaced with plain INITIAL_TOTAL_MEMORY")
}
});
assert(INITIAL_TOTAL_MEMORY >= TOTAL_STACK, "TOTAL_MEMORY should be larger than TOTAL_STACK, was " + INITIAL_TOTAL_MEMORY + "! (TOTAL_STACK=" + TOTAL_STACK + ")");
assert(typeof Int32Array !== "undefined" && typeof Float64Array !== "undefined" && Int32Array.prototype.subarray !== undefined && Int32Array.prototype.set !== undefined, "JS engine does not provide full typed array support");
if (Module["wasmMemory"]) {
wasmMemory = Module["wasmMemory"]
} else {
wasmMemory = new WebAssembly.Memory({
"initial": INITIAL_TOTAL_MEMORY / WASM_PAGE_SIZE,
"maximum": 1073741824 / WASM_PAGE_SIZE
})
}
if (wasmMemory) {
buffer = wasmMemory.buffer
}
INITIAL_TOTAL_MEMORY = buffer.byteLength;
assert(INITIAL_TOTAL_MEMORY % WASM_PAGE_SIZE === 0);
assert(65536 % WASM_PAGE_SIZE === 0);
updateGlobalBufferAndViews(buffer);
HEAP32[DYNAMICTOP_PTR >> 2] = DYNAMIC_BASE;
function writeStackCookie() {
assert((STACK_MAX & 3) == 0);
HEAPU32[(STACK_MAX >> 2) - 1] = 34821223;
HEAPU32[(STACK_MAX >> 2) - 2] = 2310721022;
HEAP32[0] = 1668509029
}
function checkStackCookie() {
var cookie1 = HEAPU32[(STACK_MAX >> 2) - 1];
var cookie2 = HEAPU32[(STACK_MAX >> 2) - 2];
if (cookie1 != 34821223 || cookie2 != 2310721022) {
abort("Stack overflow! Stack cookie has been overwritten, expected hex dwords 0x89BACDFE and 0x02135467, but received 0x" + cookie2.toString(16) + " " + cookie1.toString(16))
}
if (HEAP32[0] !== 1668509029) abort("Runtime error: The application has corrupted its heap memory area (address zero)!")
}
function abortStackOverflow(allocSize) {
abort("Stack overflow! Attempted to allocate " + allocSize + " bytes on the stack, but stack has only " + (STACK_MAX - stackSave() + allocSize) + " bytes available!")
}(function() {
var h16 = new Int16Array(1);
var h8 = new Int8Array(h16.buffer);
h16[0] = 25459;
if (h8[0] !== 115 || h8[1] !== 99) throw "Runtime error: expected the system to be little-endian!"
})();
function abortFnPtrError(ptr, sig) {
abort("Invalid function pointer " + ptr + " called with signature '" + sig + "'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this). Build with ASSERTIONS=2 for more info.")
}
function callRuntimeCallbacks(callbacks) {
while (callbacks.length > 0) {
var callback = callbacks.shift();
if (typeof callback == "function") {
callback();
continue
}
var func = callback.func;
if (typeof func === "number") {
if (callback.arg === undefined) {
Module["dynCall_v"](func)
} else {
Module["dynCall_vi"](func, callback.arg)
}
} else {
func(callback.arg === undefined ? null : callback.arg)
}
}
}
var __ATPRERUN__ = [];
var __ATINIT__ = [];
var __ATMAIN__ = [];
var __ATPOSTRUN__ = [];
var runtimeInitialized = false;
var runtimeExited = false;
function preRun() {
if (Module["preRun"]) {
if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]];
while (Module["preRun"].length) {
addOnPreRun(Module["preRun"].shift())
}
}
callRuntimeCallbacks(__ATPRERUN__)
}
function initRuntime() {
checkStackCookie();
assert(!runtimeInitialized);
runtimeInitialized = true;
if (!Module["noFSInit"] && !FS.init.initialized) FS.init();
TTY.init();
callRuntimeCallbacks(__ATINIT__)
}
function preMain() {
checkStackCookie();
FS.ignorePermissions = false;
callRuntimeCallbacks(__ATMAIN__)
}
function exitRuntime() {
checkStackCookie();
runtimeExited = true
}
function postRun() {
checkStackCookie();
if (Module["postRun"]) {
if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]];
while (Module["postRun"].length) {
addOnPostRun(Module["postRun"].shift())
}
}
callRuntimeCallbacks(__ATPOSTRUN__)
}
function addOnPreRun(cb) {
__ATPRERUN__.unshift(cb)
}
function addOnPostRun(cb) {
__ATPOSTRUN__.unshift(cb)
}
assert(Math.imul, "This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill");
assert(Math.fround, "This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill");
assert(Math.clz32, "This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill");
assert(Math.trunc, "This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill");
var Math_abs = Math.abs;
var Math_ceil = Math.ceil;
var Math_floor = Math.floor;
var Math_min = Math.min;
var runDependencies = 0;
var runDependencyWatcher = null;
var dependenciesFulfilled = null;
var runDependencyTracking = {};
function getUniqueRunDependency(id) {
var orig = id;
while (1) {
if (!runDependencyTracking[id]) return id;
id = orig + Math.random()
}
return id
}
function addRunDependency(id) {
runDependencies++;
if (Module["monitorRunDependencies"]) {
Module["monitorRunDependencies"](runDependencies)
}
if (id) {
assert(!runDependencyTracking[id]);
runDependencyTracking[id] = 1;
if (runDependencyWatcher === null && typeof setInterval !== "undefined") {
runDependencyWatcher = setInterval(function() {
if (ABORT) {
clearInterval(runDependencyWatcher);
runDependencyWatcher = null;
return
}
var shown = false;
for (var dep in runDependencyTracking) {
if (!shown) {
shown = true;
err("still waiting on run dependencies:")
}
err("dependency: " + dep)
}
if (shown) {
err("(end of list)")
}
}, 1e4)
}
} else {
err("warning: run dependency added without ID")
}
}
function removeRunDependency(id) {
runDependencies--;
if (Module["monitorRunDependencies"]) {
Module["monitorRunDependencies"](runDependencies)
}
if (id) {
assert(runDependencyTracking[id]);
delete runDependencyTracking[id]
} else {
err("warning: run dependency removed without ID")
}
if (runDependencies == 0) {
if (runDependencyWatcher !== null) {
clearInterval(runDependencyWatcher);
runDependencyWatcher = null
}
if (dependenciesFulfilled) {
var callback = dependenciesFulfilled;
dependenciesFulfilled = null;
callback()
}
}
}
Module["preloadedImages"] = {};
Module["preloadedAudios"] = {};
function abort(what) {
if (Module["onAbort"]) {
Module["onAbort"](what)
}
what += "";
out(what);
err(what);
ABORT = true;
EXITSTATUS = 1;
var output = "abort(" + what + ") at " + stackTrace();
what = output;
throw new WebAssembly.RuntimeError(what)
}
var dataURIPrefix = "data:application/octet-stream;base64,";
function isDataURI(filename) {
return String.prototype.startsWith ? filename.startsWith(dataURIPrefix) : filename.indexOf(dataURIPrefix) === 0
}
var wasmBinaryFile = "opencv_js.wasm";
if (!isDataURI(wasmBinaryFile)) {
wasmBinaryFile = locateFile(wasmBinaryFile)
}
function getBinary() {
try {
if (wasmBinary) {
return new Uint8Array(wasmBinary)
}
if (readBinary) {
return readBinary(wasmBinaryFile)
} else {
throw "both async and sync fetching of the wasm failed"
}
} catch (err) {
abort(err)
}
}
function getBinaryPromise() {
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === "function") {
return fetch(wasmBinaryFile, {
credentials: "same-origin"
}).then(function(response) {
if (!response["ok"]) {
throw "failed to load wasm binary file at '" + wasmBinaryFile + "'"
}
return response["arrayBuffer"]()
}).catch(function() {
return getBinary()
})
}
return new Promise(function(resolve, reject) {
resolve(getBinary())
})
}
function createWasm() {
var info = {
"env": asmLibraryArg,
"wasi_unstable": asmLibraryArg,
"global": {
"NaN": NaN,
Infinity: Infinity
},
"global.Math": Math,
"asm2wasm": asm2wasmImports
};
function receiveInstance(instance, module) {
var exports = instance.exports;
Module["asm"] = exports;
removeRunDependency("wasm-instantiate")
}
addRunDependency("wasm-instantiate");
var trueModule = Module;
function receiveInstantiatedSource(output) {
assert(Module === trueModule, "the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?");
trueModule = null;
receiveInstance(output["instance"])
}
function instantiateArrayBuffer(receiver) {
return getBinaryPromise().then(function(binary) {
return WebAssembly.instantiate(binary, info)
}).then(receiver, function(reason) {
err("failed to asynchronously prepare wasm: " + reason);
abort(reason)
})
}
function instantiateAsync() {
if (!wasmBinary && typeof WebAssembly.instantiateStreaming === "function" && !isDataURI(wasmBinaryFile) && typeof fetch === "function") {
fetch(wasmBinaryFile, {
credentials: "same-origin"
}).then(function(response) {
var result = WebAssembly.instantiateStreaming(response, info);
return result.then(receiveInstantiatedSource, function(reason) {
err("wasm streaming compile failed: " + reason);
err("falling back to ArrayBuffer instantiation");
instantiateArrayBuffer(receiveInstantiatedSource)
})
})
} else {
return instantiateArrayBuffer(receiveInstantiatedSource)
}
}
if (Module["instantiateWasm"]) {
try {
var exports = Module["instantiateWasm"](info, receiveInstance);
return exports
} catch (e) {
err("Module.instantiateWasm callback failed with error: " + e);
return false
}
}
instantiateAsync();
return {}
}
Module["asm"] = createWasm;
var tempDouble;
var tempI64;
__ATINIT__.push({
func: function() {
globalCtors()
}
});
var tempDoublePtr = 1578288;
assert(tempDoublePtr % 8 == 0);
function _emscripten_set_main_loop_timing(mode, value) {
Browser.mainLoop.timingMode = mode;
Browser.mainLoop.timingValue = value;
if (!Browser.mainLoop.func) {
console.error("emscripten_set_main_loop_timing: Cannot set timing mode for main loop since a main loop does not exist! Call emscripten_set_main_loop first to set one up.");
return 1
}
if (mode == 0) {
Browser.mainLoop.scheduler = function Browser_mainLoop_scheduler_setTimeout() {
var timeUntilNextTick = Math.max(0, Browser.mainLoop.tickStartTime + value - _emscripten_get_now()) | 0;
setTimeout(Browser.mainLoop.runner, timeUntilNextTick)
};
Browser.mainLoop.method = "timeout"
} else if (mode == 1) {
Browser.mainLoop.scheduler = function Browser_mainLoop_scheduler_rAF() {
Browser.requestAnimationFrame(Browser.mainLoop.runner)
};
Browser.mainLoop.method = "rAF"
} else if (mode == 2) {
if (typeof setImmediate === "undefined") {
var setImmediates = [];
var emscriptenMainLoopMessageId = "setimmediate";
var Browser_setImmediate_messageHandler = function(event) {
if (event.data === emscriptenMainLoopMessageId || event.data.target === emscriptenMainLoopMessageId) {
event.stopPropagation();
setImmediates.shift()()
}
};
addEventListener("message", Browser_setImmediate_messageHandler, true);
setImmediate = function Browser_emulated_setImmediate(func) {
setImmediates.push(func);
if (ENVIRONMENT_IS_WORKER) {
if (Module["setImmediates"] === undefined) Module["setImmediates"] = [];
Module["setImmediates"].push(func);
postMessage({
target: emscriptenMainLoopMessageId
})
} else postMessage(emscriptenMainLoopMessageId, "*")
}
}
Browser.mainLoop.scheduler = function Browser_mainLoop_scheduler_setImmediate() {
setImmediate(Browser.mainLoop.runner)