forked from dlbeer/quirc
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathquircjs.cpp
More file actions
111 lines (97 loc) · 1.87 KB
/
quircjs.cpp
File metadata and controls
111 lines (97 loc) · 1.87 KB
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
extern "C" {
#include <emscripten.h>
#include <quirc.h>
struct quirc *qr;
uint8_t *image;
void setup() {
qr = quirc_new();
if (!qr) {
perror("Failed to allocate memory");
}
}
void teardown() {
quirc_destroy(qr);
}
void resize(int width, int height) {
if (quirc_resize(qr, width, height) < 0) {
perror("Failed to allocate video memory");
}
}
void fill() {
image = quirc_begin(qr, NULL, NULL);
}
void filled() {
quirc_end(qr);
}
void process() {
int num_codes;
int i;
num_codes = quirc_count(qr);
EM_ASM_({
if (window.counted) counted($0);
}, num_codes);
for (i = 0; i < num_codes; i++) {
struct quirc_code code;
struct quirc_data data;
quirc_decode_error_t err;
quirc_extract(qr, i, &code);
/* Decoding stage */
err = quirc_decode(&code, &data);
if (err)
printf("DECODE FAILED: %s\n", quirc_strerror(err));
else {
// printf("Data: %s\n", data.payload);
EM_ASM_({
var a = arguments;
var $i = 0;
if (window.decoded) decoded(
a[$i++], // i
a[$i++], // version
a[$i++], // ecc
a[$i++], // mask
a[$i++], // data type
a[$i++], // payload
a[$i++], // payload len
a[$i++], // corners
a[$i++],
a[$i++],
a[$i++],
a[$i++],
a[$i++],
a[$i++],
a[$i++]
);
},
i,
data.version,
data.ecc_level,
data.mask,
data.data_type,
data.payload,
data.payload_len,
code.corners[0].x,
code.corners[0].y,
code.corners[1].x,
code.corners[1].y,
code.corners[2].x,
code.corners[2].y,
code.corners[3].x,
code.corners[3].y
);
}
}
}
long xsetup(int width, int height) {
setup();
resize(width, height);
fill();
// return pointer to image
return (long) image;
}
long xprocess() {
filled();
process();
fill();
return (long) image;
}
}