Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ class Analyzer {
this.canvas.style.display = 'none';
this.canvasContext = null;

this.decodeCallback = ZXing.Runtime.addFunction(function (ptr, len, resultIndex, resultCount) {
let result = new Uint8Array(ZXing.HEAPU8.buffer, ptr, len);
let str = String.fromCharCode.apply(null, result);
if (resultIndex === 0) {
window.zxDecodeResult = '';
}
window.zxDecodeResult += str;
});
if(!Analyzer.decodeCallback) {
Analyzer.decodeCallback = ZXing.Runtime.addFunction(function (ptr, len, resultIndex, resultCount) {
let result = new Uint8Array(ZXing.HEAPU8.buffer, ptr, len);
let str = String.fromCharCode.apply(null, result);
if (resultIndex === 0) {
window.zxDecodeResult = '';
}
window.zxDecodeResult += str;
});
}
}

analyze() {
Expand Down Expand Up @@ -142,7 +144,7 @@ class Analyzer {
ZXing.HEAPU8[this.imageBuffer + j] = Math.trunc((r + g + b) / 3);
}

let err = ZXing._decode_qr(this.decodeCallback);
let err = ZXing._decode_qr(Analyzer.decodeCallback);
if (err) {
return null;
}
Expand Down