@sythos/js_barcode_universal 1.5.8 → 1.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +5 -4
- package/NOTICE.md +2 -2
- package/README.md +61 -13
- package/bundle/sythos-barcode.esm.js +11658 -11244
- package/bundle/sythos-barcode.js +11658 -11244
- package/package.json +10 -3
- package/src/index.d.ts +1 -1
- package/src/index.js +508 -516
- package/src/js/aztec/decoder.js +208 -199
- package/src/js/aztec/detector.js +153 -126
- package/src/js/aztec/encoder.js +172 -153
- package/src/js/aztec/high-level.js +106 -101
- package/src/js/aztec/index.js +1 -12
- package/src/js/aztec/tables.js +106 -120
- package/src/js/aztecrune/decoder.js +76 -85
- package/src/js/aztecrune/detector.js +107 -93
- package/src/js/aztecrune/encoder.js +50 -68
- package/src/js/aztecrune/index.js +1 -16
- package/src/js/aztecrune/tables.js +59 -54
- package/src/js/compactpdf417/decoder.js +69 -74
- package/src/js/compactpdf417/detector.js +74 -75
- package/src/js/compactpdf417/encoder.js +68 -81
- package/src/js/compactpdf417/index.js +1 -13
- package/src/js/compactpdf417/tables.js +71 -80
- package/src/js/core/bit-buffer.js +106 -122
- package/src/js/core/bit-matrix.js +196 -194
- package/src/js/core/errors.js +13 -15
- package/src/js/core/galois-field.js +119 -133
- package/src/js/core/index.js +2 -19
- package/src/js/core/reed-solomon.js +195 -204
- package/src/js/databar/codec.js +93 -108
- package/src/js/databar/decoder.js +149 -140
- package/src/js/databar/encoder.js +47 -55
- package/src/js/databar/gs1.js +122 -123
- package/src/js/databar/index.js +4 -36
- package/src/js/databar/patterns.js +81 -85
- package/src/js/databar/tables.js +51 -52
- package/src/js/datamatrix/decoder.js +216 -182
- package/src/js/datamatrix/detector.js +161 -132
- package/src/js/datamatrix/encoder.js +192 -133
- package/src/js/datamatrix/index.js +1 -9
- package/src/js/datamatrix/tables.js +68 -69
- package/src/js/frameqr/decoder.js +102 -125
- package/src/js/frameqr/detector.js +101 -94
- package/src/js/frameqr/encoder.js +67 -80
- package/src/js/frameqr/index.js +1 -10
- package/src/js/frameqr/tables.js +145 -163
- package/src/js/image/binarizer.js +146 -162
- package/src/js/image/grid-sampler.js +63 -79
- package/src/js/image/index.js +0 -2
- package/src/js/image/luminance.js +129 -140
- package/src/js/image/perspective.js +112 -149
- package/src/js/micropdf417/compaction.js +64 -65
- package/src/js/micropdf417/decoder.js +106 -109
- package/src/js/micropdf417/detector.js +73 -70
- package/src/js/micropdf417/encoder.js +129 -154
- package/src/js/micropdf417/error-correction.js +6 -11
- package/src/js/micropdf417/index.js +2 -16
- package/src/js/micropdf417/tables.js +112 -99
- package/src/js/microqr/decoder.js +177 -182
- package/src/js/microqr/detector.js +240 -256
- package/src/js/microqr/encoder.js +239 -194
- package/src/js/microqr/index.js +0 -2
- package/src/js/microqr/tables.js +208 -200
- package/src/js/oned/addons.js +167 -191
- package/src/js/oned/index.js +27 -58
- package/src/js/oned/patterns.js +194 -213
- package/src/js/oned/reader.js +1003 -984
- package/src/js/oned/writers.js +411 -466
- package/src/js/pdf417/compaction.js +315 -222
- package/src/js/pdf417/decoder.js +71 -36
- package/src/js/pdf417/detector.js +377 -361
- package/src/js/pdf417/encoder.js +57 -46
- package/src/js/pdf417/error-correction.js +5 -8
- package/src/js/pdf417/tables.js +248 -250
- package/src/js/qr/decoder.js +311 -347
- package/src/js/qr/detector.js +378 -395
- package/src/js/qr/encoder.js +514 -599
- package/src/js/qr/index.js +0 -2
- package/src/js/qr/tables.js +375 -422
- package/src/js/render/image-data.js +57 -62
- package/src/js/render/index.js +21 -23
- package/src/js/render/options.js +82 -90
- package/src/js/render/png.js +144 -169
- package/src/js/render/svg.js +41 -44
- package/src/js/render/webgl.js +103 -109
- package/src/js/render/webgpu.js +205 -217
- package/src/js/rmqr/decoder.js +161 -53
- package/src/js/rmqr/detector.js +73 -41
- package/src/js/rmqr/encoder.js +253 -104
- package/src/js/rmqr/index.js +1 -5
- package/src/js/rmqr/tables.js +108 -85
- package/src/ts/aztec/decoder.ts +317 -0
- package/src/ts/aztec/detector.ts +224 -0
- package/src/ts/aztec/encoder.ts +257 -0
- package/src/ts/aztec/high-level.ts +211 -0
- package/src/ts/aztec/index.ts +45 -0
- package/src/ts/aztec/tables.ts +210 -0
- package/src/ts/aztecrune/decoder.ts +155 -0
- package/src/ts/aztecrune/detector.ts +166 -0
- package/src/ts/aztecrune/encoder.ts +121 -0
- package/src/ts/aztecrune/index.ts +49 -0
- package/src/ts/aztecrune/tables.ts +137 -0
- package/src/ts/compactpdf417/decoder.ts +128 -0
- package/src/ts/compactpdf417/detector.ts +139 -0
- package/src/ts/compactpdf417/encoder.ts +140 -0
- package/src/ts/compactpdf417/index.ts +17 -0
- package/src/ts/compactpdf417/tables.ts +173 -0
- package/src/ts/core/bit-buffer.ts +174 -0
- package/src/ts/core/bit-matrix.ts +241 -0
- package/src/ts/core/errors.ts +61 -0
- package/src/ts/core/galois-field.ts +207 -0
- package/src/ts/core/index.ts +56 -0
- package/src/ts/core/reed-solomon.ts +327 -0
- package/src/ts/databar/codec.ts +181 -0
- package/src/ts/databar/decoder.ts +215 -0
- package/src/ts/databar/encoder.ts +96 -0
- package/src/ts/databar/gs1.ts +177 -0
- package/src/ts/databar/index.ts +68 -0
- package/src/ts/databar/patterns.ts +143 -0
- package/src/ts/databar/tables.ts +124 -0
- package/src/ts/datamatrix/decoder.ts +262 -0
- package/src/ts/datamatrix/detector.ts +225 -0
- package/src/ts/datamatrix/encoder.ts +191 -0
- package/src/ts/datamatrix/index.ts +42 -0
- package/src/ts/datamatrix/tables.ts +123 -0
- package/src/ts/frameqr/decoder.ts +239 -0
- package/src/ts/frameqr/detector.ts +192 -0
- package/src/ts/frameqr/encoder.ts +156 -0
- package/src/ts/frameqr/index.ts +42 -0
- package/src/ts/frameqr/tables.ts +270 -0
- package/src/ts/image/binarizer.ts +270 -0
- package/src/ts/image/grid-sampler.ts +164 -0
- package/src/ts/image/index.ts +40 -0
- package/src/ts/image/luminance.ts +196 -0
- package/src/ts/image/perspective.ts +195 -0
- package/src/ts/index.d.ts +1 -1
- package/src/ts/index.ts +790 -0
- package/src/ts/micropdf417/compaction.ts +116 -0
- package/src/ts/micropdf417/decoder.ts +183 -0
- package/src/ts/micropdf417/detector.ts +149 -0
- package/src/ts/micropdf417/encoder.ts +209 -0
- package/src/ts/micropdf417/error-correction.ts +55 -0
- package/src/ts/micropdf417/index.ts +49 -0
- package/src/ts/micropdf417/tables.ts +184 -0
- package/src/ts/microqr/decoder.ts +245 -0
- package/src/ts/microqr/detector.ts +355 -0
- package/src/ts/microqr/encoder.ts +269 -0
- package/src/ts/microqr/index.ts +36 -0
- package/src/ts/microqr/tables.ts +316 -0
- package/src/ts/oned/addons.ts +420 -0
- package/src/ts/oned/index.ts +106 -0
- package/src/ts/oned/patterns.ts +384 -0
- package/src/ts/oned/reader.ts +1364 -0
- package/src/ts/oned/writers.ts +746 -0
- package/src/ts/pdf417/compaction.ts +298 -0
- package/src/ts/pdf417/decoder.ts +75 -0
- package/src/ts/pdf417/detector.ts +468 -0
- package/src/ts/pdf417/encoder.ts +91 -0
- package/src/ts/pdf417/error-correction.ts +47 -0
- package/src/ts/pdf417/index.ts +6 -0
- package/src/ts/pdf417/tables.ts +317 -0
- package/src/ts/qr/decoder.ts +575 -0
- package/src/ts/qr/detector.ts +630 -0
- package/src/ts/qr/encoder.ts +958 -0
- package/src/ts/qr/index.ts +44 -0
- package/src/ts/qr/tables.ts +737 -0
- package/src/ts/render/image-data.ts +125 -0
- package/src/ts/render/index.ts +130 -0
- package/src/ts/render/options.ts +160 -0
- package/src/ts/render/png.ts +295 -0
- package/src/ts/render/svg.ts +120 -0
- package/src/ts/render/webgl.ts +206 -0
- package/src/ts/render/webgpu.ts +369 -0
- package/src/ts/rmqr/decoder.ts +101 -0
- package/src/ts/rmqr/detector.ts +90 -0
- package/src/ts/rmqr/encoder.ts +172 -0
- package/src/ts/rmqr/index.ts +37 -0
- package/src/ts/rmqr/tables.ts +154 -0
package/src/js/aztec/detector.js
CHANGED
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Original work. No code from any other barcode implementation.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
30
|
/**
|
|
32
31
|
* Aztec image detection.
|
|
33
32
|
*
|
|
@@ -47,109 +46,118 @@
|
|
|
47
46
|
*
|
|
48
47
|
* @module aztec/detector
|
|
49
48
|
*/
|
|
50
|
-
|
|
51
49
|
import { NotFoundError } from '../core/errors.js';
|
|
52
50
|
import { sampleQuad } from '../image/grid-sampler.js';
|
|
53
51
|
import { decodeAztec } from './decoder.js';
|
|
54
|
-
|
|
55
52
|
/** @typedef {{x:number, y:number}} Point */
|
|
56
53
|
/** @typedef {{corners: Point[], dimension: number, compact: boolean, moduleSize: number, matrix: import('../core/bit-matrix.js').BitMatrix}} Detection */
|
|
57
|
-
|
|
58
54
|
// Compact: 11 + 4 layers. Full symbols add reference-grid rows/columns every
|
|
59
55
|
// 15 modules measured from their central 14-module base, not every 15 layers.
|
|
60
56
|
const DIMENSIONS = [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
...[1, 2, 3, 4].map((layers) => ({ compact: true, dimension: 11 + 4 * layers })),
|
|
58
|
+
...Array.from({ length: 32 }, (_, index) => {
|
|
59
|
+
const layers = index + 1;
|
|
60
|
+
return { compact: false, dimension: 15 + 4 * layers + 2 * Math.floor((2 * layers + 6) / 15) };
|
|
61
|
+
}),
|
|
66
62
|
];
|
|
67
|
-
|
|
68
63
|
function pixel(image, x, y) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
const ix = Math.round(x);
|
|
65
|
+
const iy = Math.round(y);
|
|
66
|
+
return ix >= 0 && iy >= 0 && ix < image.width && iy < image.height && image.get(ix, iy);
|
|
72
67
|
}
|
|
73
|
-
|
|
74
68
|
/** Connected components of either polarity, retaining only plausible modules. */
|
|
75
69
|
function components(image, value) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
70
|
+
const seen = new Uint8Array(image.width * image.height);
|
|
71
|
+
const out = [];
|
|
72
|
+
const maximumArea = Math.max(4, Math.floor(image.width * image.height * 0.08));
|
|
73
|
+
for (let y = 0; y < image.height; y++)
|
|
74
|
+
for (let x = 0; x < image.width; x++) {
|
|
75
|
+
const start = y * image.width + x;
|
|
76
|
+
if (seen[start] || image.get(x, y) !== value)
|
|
77
|
+
continue;
|
|
78
|
+
const xs = [x];
|
|
79
|
+
const ys = [y];
|
|
80
|
+
seen[start] = 1;
|
|
81
|
+
let head = 0;
|
|
82
|
+
let minX = x;
|
|
83
|
+
let maxX = x;
|
|
84
|
+
let minY = y;
|
|
85
|
+
let maxY = y;
|
|
86
|
+
while (head < xs.length) {
|
|
87
|
+
const px = xs[head];
|
|
88
|
+
const py = ys[head++];
|
|
89
|
+
if (px < minX)
|
|
90
|
+
minX = px;
|
|
91
|
+
if (px > maxX)
|
|
92
|
+
maxX = px;
|
|
93
|
+
if (py < minY)
|
|
94
|
+
minY = py;
|
|
95
|
+
if (py > maxY)
|
|
96
|
+
maxY = py;
|
|
97
|
+
for (const [nx, ny] of [[px - 1, py], [px + 1, py], [px, py - 1], [px, py + 1]]) {
|
|
98
|
+
if (nx < 0 || ny < 0 || nx >= image.width || ny >= image.height)
|
|
99
|
+
continue;
|
|
100
|
+
const at = ny * image.width + nx;
|
|
101
|
+
if (!seen[at] && image.get(nx, ny) === value) {
|
|
102
|
+
seen[at] = 1;
|
|
103
|
+
xs.push(nx);
|
|
104
|
+
ys.push(ny);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const width = maxX - minX + 1;
|
|
109
|
+
const height = maxY - minY + 1;
|
|
110
|
+
const area = width * height;
|
|
111
|
+
// The central module is solid and approximately square. This filter is
|
|
112
|
+
// intentionally permissive because a rotated raster module is diamond-ish.
|
|
113
|
+
if (xs.length <= maximumArea && Math.abs(width - height) <= Math.max(1, Math.ceil(Math.max(width, height) * 0.35)) &&
|
|
114
|
+
xs.length >= area * 0.45) {
|
|
115
|
+
out.push({ x: (minX + maxX) / 2, y: (minY + maxY) / 2, width, height, pixels: xs.length });
|
|
116
|
+
}
|
|
96
117
|
}
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
const width = maxX - minX + 1;
|
|
100
|
-
const height = maxY - minY + 1;
|
|
101
|
-
const area = width * height;
|
|
102
|
-
// The central module is solid and approximately square. This filter is
|
|
103
|
-
// intentionally permissive because a rotated raster module is diamond-ish.
|
|
104
|
-
if (xs.length <= maximumArea && Math.abs(width - height) <= Math.max(1, Math.ceil(Math.max(width, height) * 0.35)) &&
|
|
105
|
-
xs.length >= area * 0.45) {
|
|
106
|
-
out.push({ x: (minX + maxX) / 2, y: (minY + maxY) / 2, width, height, pixels: xs.length });
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return out.sort((a, b) => b.pixels - a.pixels).slice(0, 2000);
|
|
118
|
+
return out.sort((a, b) => b.pixels - a.pixels).slice(0, 2000);
|
|
110
119
|
}
|
|
111
|
-
|
|
112
120
|
function expectedDark(ring, inverted) {
|
|
113
|
-
|
|
121
|
+
return inverted ? (ring & 1) === 1 : (ring & 1) === 0;
|
|
114
122
|
}
|
|
115
|
-
|
|
116
123
|
/** Score one square bull's-eye at an angle and a candidate module pitch. */
|
|
117
124
|
function ringScore(image, centre, pitch, angle, inverted, rings) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
const cos = Math.cos(angle);
|
|
126
|
+
const sin = Math.sin(angle);
|
|
127
|
+
let correct = 0;
|
|
128
|
+
let total = 0;
|
|
129
|
+
for (let ring = 0; ring < rings; ring++) {
|
|
130
|
+
const wanted = expectedDark(ring, inverted);
|
|
131
|
+
for (let j = -ring; j <= ring; j++)
|
|
132
|
+
for (let i = -ring; i <= ring; i++) {
|
|
133
|
+
if (ring && Math.abs(i) !== ring && Math.abs(j) !== ring)
|
|
134
|
+
continue;
|
|
135
|
+
const x = centre.x + (i * cos - j * sin) * pitch;
|
|
136
|
+
const y = centre.y + (i * sin + j * cos) * pitch;
|
|
137
|
+
if (pixel(image, x, y) === wanted)
|
|
138
|
+
correct++;
|
|
139
|
+
total++;
|
|
140
|
+
}
|
|
130
141
|
}
|
|
131
|
-
|
|
132
|
-
return correct / total;
|
|
142
|
+
return correct / total;
|
|
133
143
|
}
|
|
134
|
-
|
|
135
144
|
function rotateCorners(corners, turn) {
|
|
136
|
-
|
|
145
|
+
return corners.slice(turn).concat(corners.slice(0, turn));
|
|
137
146
|
}
|
|
138
|
-
|
|
139
147
|
function invert(matrix) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
const out = matrix.clone();
|
|
149
|
+
for (let y = 0; y < out.height; y++)
|
|
150
|
+
for (let x = 0; x < out.width; x++)
|
|
151
|
+
out.flip(x, y);
|
|
152
|
+
return out;
|
|
143
153
|
}
|
|
144
|
-
|
|
145
154
|
function cornersFor(centre, pitch, angle, dimension) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
155
|
+
const half = dimension * pitch / 2;
|
|
156
|
+
const cos = Math.cos(angle);
|
|
157
|
+
const sin = Math.sin(angle);
|
|
158
|
+
const point = (x, y) => ({ x: centre.x + x * cos - y * sin, y: centre.y + x * sin + y * cos });
|
|
159
|
+
return [point(-half, -half), point(half, -half), point(half, half), point(-half, half)];
|
|
151
160
|
}
|
|
152
|
-
|
|
153
161
|
/**
|
|
154
162
|
* Find an Aztec symbol in a binarized image.
|
|
155
163
|
*
|
|
@@ -161,53 +169,62 @@ function cornersFor(centre, pitch, angle, dimension) {
|
|
|
161
169
|
* @returns {Detection | null}
|
|
162
170
|
*/
|
|
163
171
|
export function detectAztec(binaryImage) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
172
|
+
if (!binaryImage || !binaryImage.width || !binaryImage.height) {
|
|
173
|
+
throw new NotFoundError('detectAztec: no image supplied');
|
|
174
|
+
}
|
|
175
|
+
const candidates = [];
|
|
176
|
+
for (const inverted of [false, true]) {
|
|
177
|
+
for (const core of components(binaryImage, !inverted)) {
|
|
178
|
+
// A non-rotated one-module component directly gives its pitch. For
|
|
179
|
+
// rotated modules its bounding box grows by |sin| + |cos|, compensated
|
|
180
|
+
// below for every tested angle.
|
|
181
|
+
for (let degrees = 0; degrees < 180; degrees += 4) {
|
|
182
|
+
const angle = degrees * Math.PI / 180;
|
|
183
|
+
const scale = Math.abs(Math.cos(angle)) + Math.abs(Math.sin(angle));
|
|
184
|
+
const pitch = ((core.width + core.height) / 2) / scale;
|
|
185
|
+
if (pitch < 0.8)
|
|
186
|
+
continue;
|
|
187
|
+
// Test Full first: its seven rings also exclude Compact candidates.
|
|
188
|
+
const fullScore = ringScore(binaryImage, core, pitch, angle, inverted, 7);
|
|
189
|
+
const rings = fullScore >= 0.88 ? 7 : 5;
|
|
190
|
+
const score = rings === 7 ? fullScore : ringScore(binaryImage, core, pitch, angle, inverted, 5);
|
|
191
|
+
if (score < 0.91)
|
|
192
|
+
continue;
|
|
193
|
+
const symbolKinds = rings === 7 ? DIMENSIONS.filter((item) => !item.compact) : DIMENSIONS.filter((item) => item.compact);
|
|
194
|
+
for (const kind of symbolKinds) {
|
|
195
|
+
const baseCorners = cornersFor(core, pitch, angle, kind.dimension);
|
|
196
|
+
for (let turn = 0; turn < 4; turn++) {
|
|
197
|
+
const corners = rotateCorners(baseCorners, turn);
|
|
198
|
+
let matrix;
|
|
199
|
+
try {
|
|
200
|
+
matrix = sampleQuad(binaryImage, kind.dimension, corners);
|
|
201
|
+
}
|
|
202
|
+
catch (e) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (inverted)
|
|
206
|
+
matrix = invert(matrix);
|
|
207
|
+
try {
|
|
208
|
+
// The decoder verifies the mode-message ECC and exact geometry.
|
|
209
|
+
// We do not expose its result here so callers can use pure
|
|
210
|
+
// detection without treating payload decoding as an API contract.
|
|
211
|
+
decodeAztec(matrix);
|
|
212
|
+
candidates.push({ corners, dimension: kind.dimension, compact: kind.compact,
|
|
213
|
+
moduleSize: pitch, matrix, score });
|
|
214
|
+
}
|
|
215
|
+
catch (e) { /* Not an Aztec mode message at this dimension. */ }
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
200
219
|
}
|
|
201
|
-
}
|
|
202
220
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
221
|
+
candidates.sort((a, b) => b.score - a.score || b.moduleSize - a.moduleSize);
|
|
222
|
+
const best = candidates[0];
|
|
223
|
+
if (!best)
|
|
224
|
+
return null;
|
|
225
|
+
delete best.score;
|
|
226
|
+
return best;
|
|
209
227
|
}
|
|
210
|
-
|
|
211
228
|
/**
|
|
212
229
|
* Detect then decode an Aztec symbol. Detection failure is a normal result for
|
|
213
230
|
* images without an Aztec code, therefore invalid candidates return null.
|
|
@@ -216,9 +233,19 @@ export function detectAztec(binaryImage) {
|
|
|
216
233
|
* @returns {(import('./decoder.js').DecodeResult & {corners: Point[]}) | null}
|
|
217
234
|
*/
|
|
218
235
|
export function detectAndDecodeAztec(binaryImage) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
236
|
+
let detection;
|
|
237
|
+
try {
|
|
238
|
+
detection = detectAztec(binaryImage);
|
|
239
|
+
}
|
|
240
|
+
catch (e) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
if (!detection)
|
|
244
|
+
return null;
|
|
245
|
+
try {
|
|
246
|
+
return Object.assign({ corners: detection.corners }, decodeAztec(detection.matrix));
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
224
251
|
}
|