forked from zz85/quirc.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.html
89 lines (71 loc) · 1.99 KB
/
test.html
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
<html>
<body>
(decoded data will also be printed to web developer's console...)
<div id="decoded_data"></div>
<script src="quirc.js"></script>
<script>
var last = Date.now();
function log() {
var now = Date.now();
var args = Array.prototype.slice.call(arguments);
args.unshift('+' + (now - last) + 'ms');
console.log.apply(console, args);
last = now;
}
var data, image;
function gofill() {
/* Fill out the image buffer here.
* image is a pointer to a w*h bytes.
* One byte per pixel, w pixels per line, h lines in the buffer.
*/
log('gofill')
for (var i=0, j=0; i < data.length; i+=4, j++) {
Module.HEAPU8[image + j] = data[i];
}
log('writing');
var a = Module._xprocess();
log('quirc_end', a);
}
function decoded(i, version, ecc_level, mask, data_type, payload, payload_len) {
// console.log('decoded', arguments)
var buffer = read(payload, payload_len);
var str = String.fromCharCode.apply(null, buffer)
decoded_data.innerHTML = str;
log("Data:", str);
}
function read(offset, len) {
return new Uint8Array(Module.HEAPU8.buffer, offset, len);
}
function raw_quirc_apis() {
var quirc = {}
Object
.keys(Module)
.filter(function(f) { return f.startsWith('_quirc') })
.map(function(f) { return f.substring(7) })
.some(function(f) { quirc[f] = Module['_quirc_' + f] });
log('quirc', quirc);
}
var img = new Image;
img.src = 'qr.png';
img.onload = function() {
var width = this.width, height = this.height;
var canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext('2d');
ctx.drawImage(this, 0, 0);
var imageData = ctx.getImageData(0,0, width, height);
data = imageData.data;
document.body.appendChild(canvas);
log('start');
Module.onDecoded(decoded);
image = Module._xsetup(width, height);
log('_xsetup', image, 'pointer');
setInterval(function() {
gofill();
}, 1000)
// log('quirc_destroy', quirc.destroy(qr));
}
</script>
</body>
</html>