Skip to content

Commit

Permalink
schmich#74 - Update the scanner.js file to reuse function pointers in…
Browse files Browse the repository at this point in the history
…stead of adding new ones.
  • Loading branch information
adammcfadden committed Oct 31, 2017
1 parent b0f9519 commit 1682a11
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/scanner.js
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

0 comments on commit 1682a11

Please sign in to comment.