Skip to content

Commit

Permalink
reuse Analyzer.decodeCallback for fix schmich#74
Browse files Browse the repository at this point in the history
  • Loading branch information
hsinlive committed Oct 16, 2019
1 parent b0f9519 commit 7e4d2d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,7 +1,7 @@
language: node_js
- '6'
install: npm install
script: gulp release
script: npx gulp release
env:
global:
- COMMIT_AUTHOR_NAME: "'Chris Schmich'"
Expand Down
21 changes: 11 additions & 10 deletions src/scanner.js
Expand Up @@ -95,15 +95,16 @@ class Analyzer {
this.canvas = document.createElement('canvas');
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 +143,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 7e4d2d6

Please sign in to comment.