@sythos/js_barcode_universal 1.5.8 → 1.5.9
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 +17 -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
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Sythos Barcode Suite
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2026 Sythos
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* SPDX-License-Identifier: MIT
|
|
27
|
+
*
|
|
28
|
+
* Original work. No code from any other barcode implementation.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Aztec Rune encoder.
|
|
33
|
+
*
|
|
34
|
+
* A Rune carries exactly one byte. Numeric strings are accepted for convenient
|
|
35
|
+
* human-readable input and are normalized to the canonical three-digit text;
|
|
36
|
+
* binary callers can pass one byte in an ArrayBuffer or typed-array view.
|
|
37
|
+
*
|
|
38
|
+
* @module aztecrune/encoder
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
import { BitMatrix } from '../core/bit-matrix.js';
|
|
42
|
+
import { EncodeError } from '../core/errors.js';
|
|
43
|
+
import { rsEncode } from '../core/reed-solomon.js';
|
|
44
|
+
import {
|
|
45
|
+
AZTEC_RUNE_DATA_POSITIONS,
|
|
46
|
+
AZTEC_RUNE_ECC_CODEWORDS,
|
|
47
|
+
AZTEC_RUNE_MASK,
|
|
48
|
+
AZTEC_RUNE_SIZE,
|
|
49
|
+
aztecRuneField,
|
|
50
|
+
buildAztecRuneStructure,
|
|
51
|
+
} from './tables.js';
|
|
52
|
+
|
|
53
|
+
/** @param {unknown} value @returns {number} */
|
|
54
|
+
export function normalizeAztecRuneValue(value) {
|
|
55
|
+
if (typeof value === 'number') {
|
|
56
|
+
if (Number.isInteger(value) && value >= 0 && value <= 255) return value;
|
|
57
|
+
throw new EncodeError('Aztec Rune: numeric value must be an integer from 0 to 255');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (typeof value === 'string') {
|
|
61
|
+
if (!/^\d{1,3}$/.test(value)) throw new EncodeError('Aztec Rune: text input must contain one to three decimal digits');
|
|
62
|
+
const numeric = Number(value);
|
|
63
|
+
if (numeric > 255) throw new EncodeError('Aztec Rune: decimal value must be from 000 to 255');
|
|
64
|
+
return numeric;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let bytes = null;
|
|
68
|
+
if (value instanceof ArrayBuffer) bytes = new Uint8Array(value);
|
|
69
|
+
else if (ArrayBuffer.isView(value)) bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
70
|
+
if (bytes) {
|
|
71
|
+
if (bytes.length !== 1) throw new EncodeError('Aztec Rune: binary input must contain exactly one byte');
|
|
72
|
+
return bytes[0];
|
|
73
|
+
}
|
|
74
|
+
throw new EncodeError('Aztec Rune: expected a number, decimal string or one-byte binary value');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @param {number} value @returns {number[]} */
|
|
78
|
+
function codewordsForValue(value) {
|
|
79
|
+
const data = [value >>> 4, value & 0x0f];
|
|
80
|
+
const parity = rsEncode(data, AZTEC_RUNE_ECC_CODEWORDS, aztecRuneField(), 1);
|
|
81
|
+
return data.concat(parity).map((word) => word ^ AZTEC_RUNE_MASK);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @param {BitMatrix} matrix @param {number[]} codewords */
|
|
85
|
+
function writeDataRing(matrix, codewords) {
|
|
86
|
+
for (let word = 0; word < codewords.length; word++) {
|
|
87
|
+
for (let bit = 0; bit < 4; bit++) {
|
|
88
|
+
const at = word * 4 + bit;
|
|
89
|
+
const [x, y] = AZTEC_RUNE_DATA_POSITIONS[at];
|
|
90
|
+
matrix.setValue(x, y, ((codewords[word] >>> (3 - bit)) & 1) !== 0);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Encode one byte as an Aztec Rune.
|
|
97
|
+
*
|
|
98
|
+
* @param {number|string|ArrayBuffer|ArrayBufferView} value
|
|
99
|
+
* @param {{inverted?: boolean}} [options]
|
|
100
|
+
* @returns {import('../core/bit-matrix.js').BitMatrix & {
|
|
101
|
+
* format: 'aztecrune', value: number, inverted: boolean
|
|
102
|
+
* }}
|
|
103
|
+
*/
|
|
104
|
+
export function encodeAztecRune(value, options = {}) {
|
|
105
|
+
const numeric = normalizeAztecRuneValue(value);
|
|
106
|
+
if (options.inverted !== undefined && typeof options.inverted !== 'boolean') {
|
|
107
|
+
throw new EncodeError('Aztec Rune: inverted must be boolean');
|
|
108
|
+
}
|
|
109
|
+
const inverted = options.inverted === true;
|
|
110
|
+
const matrix = buildAztecRuneStructure();
|
|
111
|
+
writeDataRing(matrix, codewordsForValue(numeric));
|
|
112
|
+
if (inverted) {
|
|
113
|
+
for (let y = 0; y < AZTEC_RUNE_SIZE; y++) for (let x = 0; x < AZTEC_RUNE_SIZE; x++) matrix.flip(x, y);
|
|
114
|
+
}
|
|
115
|
+
matrix.format = 'aztecrune';
|
|
116
|
+
matrix.value = numeric;
|
|
117
|
+
matrix.inverted = inverted;
|
|
118
|
+
return matrix;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { codewordsForValue };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Sythos Barcode Suite
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2026 Sythos
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* SPDX-License-Identifier: MIT
|
|
27
|
+
*
|
|
28
|
+
* Original work. No code from any other barcode implementation.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** Aztec Rune entry points. @module aztecrune */
|
|
32
|
+
|
|
33
|
+
export { encodeAztecRune, normalizeAztecRuneValue } from './encoder.js';
|
|
34
|
+
export { decodeAztecRune } from './decoder.js';
|
|
35
|
+
export { detectAztecRune, detectAndDecodeAztecRune } from './detector.js';
|
|
36
|
+
export {
|
|
37
|
+
AZTEC_RUNE_SIZE,
|
|
38
|
+
AZTEC_RUNE_DATA_BITS,
|
|
39
|
+
AZTEC_RUNE_WORD_SIZE,
|
|
40
|
+
AZTEC_RUNE_DATA_CODEWORDS,
|
|
41
|
+
AZTEC_RUNE_ECC_CODEWORDS,
|
|
42
|
+
AZTEC_RUNE_TOTAL_CODEWORDS,
|
|
43
|
+
AZTEC_RUNE_MASK,
|
|
44
|
+
AZTEC_RUNE_DATA_POSITIONS,
|
|
45
|
+
aztecRuneStructuralValue,
|
|
46
|
+
buildAztecRuneStructure,
|
|
47
|
+
aztecRuneField,
|
|
48
|
+
validateAztecRuneTables,
|
|
49
|
+
} from './tables.js';
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Sythos Barcode Suite
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2026 Sythos
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* SPDX-License-Identifier: MIT
|
|
27
|
+
*
|
|
28
|
+
* Original work. No code from any other barcode implementation.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Aztec Rune geometry.
|
|
33
|
+
*
|
|
34
|
+
* Aztec Rune is the 11x11, one-byte member of the Aztec family. Two 4-bit
|
|
35
|
+
* data words and five 4-bit Reed-Solomon check words are XORed with the fixed
|
|
36
|
+
* Aztec Rune mask and written clockwise on the outer data ring. The finder and
|
|
37
|
+
* corner orientation marks are independent of the value.
|
|
38
|
+
*
|
|
39
|
+
* The constants below are derived from the public Aztec Code specification and
|
|
40
|
+
* are kept separate from the general Aztec implementation so a normal Aztec
|
|
41
|
+
* decoder can never accidentally treat an 11x11 Rune as a regular symbol.
|
|
42
|
+
*
|
|
43
|
+
* @module aztecrune/tables
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
import { BitMatrix } from '../core/bit-matrix.js';
|
|
47
|
+
import { fieldForWordSize } from '../aztec/tables.js';
|
|
48
|
+
|
|
49
|
+
export const AZTEC_RUNE_SIZE = 11;
|
|
50
|
+
export const AZTEC_RUNE_DATA_BITS = 8;
|
|
51
|
+
export const AZTEC_RUNE_WORD_SIZE = 4;
|
|
52
|
+
export const AZTEC_RUNE_DATA_CODEWORDS = 2;
|
|
53
|
+
export const AZTEC_RUNE_ECC_CODEWORDS = 5;
|
|
54
|
+
export const AZTEC_RUNE_TOTAL_CODEWORDS = AZTEC_RUNE_DATA_CODEWORDS + AZTEC_RUNE_ECC_CODEWORDS;
|
|
55
|
+
export const AZTEC_RUNE_MASK = 0b1010;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Data-module coordinates in wire order: clockwise, starting at the top.
|
|
59
|
+
* Every side contributes seven modules, for 28 bits in total.
|
|
60
|
+
*/
|
|
61
|
+
export const AZTEC_RUNE_DATA_POSITIONS = Object.freeze([
|
|
62
|
+
...Array.from({ length: 7 }, (_, i) => [i + 2, 0]),
|
|
63
|
+
...Array.from({ length: 7 }, (_, i) => [10, i + 2]),
|
|
64
|
+
...Array.from({ length: 7 }, (_, i) => [8 - i, 10]),
|
|
65
|
+
...Array.from({ length: 7 }, (_, i) => [0, 8 - i]),
|
|
66
|
+
].map(([x, y]) => Object.freeze([x, y])));
|
|
67
|
+
|
|
68
|
+
const DATA_KEYS = new Set(AZTEC_RUNE_DATA_POSITIONS.map(([x, y]) => `${x},${y}`));
|
|
69
|
+
|
|
70
|
+
/** @param {number} x @param {number} y @returns {boolean} */
|
|
71
|
+
export function isAztecRuneDataPosition(x, y) {
|
|
72
|
+
return DATA_KEYS.has(`${x},${y}`);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Return the value of a structural module. Data positions return `null`.
|
|
76
|
+
* The bull's-eye has five square rings including its one-module centre; its
|
|
77
|
+
* even-radius rings are dark. The four corner groups are the orientation marks
|
|
78
|
+
* described by the Aztec Rune specification.
|
|
79
|
+
*
|
|
80
|
+
* @param {number} x @param {number} y
|
|
81
|
+
* @returns {boolean|null}
|
|
82
|
+
*/
|
|
83
|
+
export function aztecRuneStructuralValue(x, y) {
|
|
84
|
+
if (!Number.isInteger(x) || !Number.isInteger(y) || x < 0 || y < 0 || x >= AZTEC_RUNE_SIZE || y >= AZTEC_RUNE_SIZE) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (isAztecRuneDataPosition(x, y)) return null;
|
|
88
|
+
|
|
89
|
+
const distance = Math.max(Math.abs(x - 5), Math.abs(y - 5));
|
|
90
|
+
if (distance <= 4) return (distance & 1) === 0;
|
|
91
|
+
|
|
92
|
+
// Corner orientation groups, clockwise from the upper-left corner:
|
|
93
|
+
// three dark, white-dark-dark, dark-white-white, three white.
|
|
94
|
+
if ((x === 0 && y <= 1) || (y === 0 && x <= 1)) return true;
|
|
95
|
+
if ((x === 10 && y <= 1) || (y === 0 && x === 10)) return true;
|
|
96
|
+
if (x === 9 && y === 0) return false;
|
|
97
|
+
if (x === 10 && y === 10) return false;
|
|
98
|
+
if (y === 10 && x >= 0 && x <= 1) return false;
|
|
99
|
+
if (x === 0 && y >= 9) return false;
|
|
100
|
+
if (x === 10 && y === 9) return true;
|
|
101
|
+
|
|
102
|
+
// All non-data cells are covered by the bull's-eye or the four corners.
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Build only the fixed finder/orientation structure. */
|
|
107
|
+
export function buildAztecRuneStructure() {
|
|
108
|
+
const matrix = new BitMatrix(AZTEC_RUNE_SIZE);
|
|
109
|
+
for (let y = 0; y < AZTEC_RUNE_SIZE; y++) {
|
|
110
|
+
for (let x = 0; x < AZTEC_RUNE_SIZE; x++) {
|
|
111
|
+
const value = aztecRuneStructuralValue(x, y);
|
|
112
|
+
if (value === true) matrix.set(x, y);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return matrix;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Return the field used by Rune data/check words. */
|
|
119
|
+
export function aztecRuneField() {
|
|
120
|
+
return fieldForWordSize(AZTEC_RUNE_WORD_SIZE);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Validate the fixed Rune contract and coordinate layout. */
|
|
124
|
+
export function validateAztecRuneTables() {
|
|
125
|
+
const problems = [];
|
|
126
|
+
if (AZTEC_RUNE_SIZE !== 11) problems.push('Rune symbol size must be 11');
|
|
127
|
+
if (AZTEC_RUNE_TOTAL_CODEWORDS * AZTEC_RUNE_WORD_SIZE !== 28) problems.push('Rune outer ring must carry 28 bits');
|
|
128
|
+
if (AZTEC_RUNE_DATA_POSITIONS.length !== 28) problems.push('Rune data ring must contain 28 modules');
|
|
129
|
+
if (new Set(AZTEC_RUNE_DATA_POSITIONS.map(([x, y]) => `${x},${y}`)).size !== 28) problems.push('Rune data coordinates must be unique');
|
|
130
|
+
const structure = buildAztecRuneStructure();
|
|
131
|
+
for (let y = 0; y < AZTEC_RUNE_SIZE; y++) for (let x = 0; x < AZTEC_RUNE_SIZE; x++) {
|
|
132
|
+
if (isAztecRuneDataPosition(x, y)) continue;
|
|
133
|
+
const expected = aztecRuneStructuralValue(x, y) === true;
|
|
134
|
+
if (structure.get(x, y) !== expected) problems.push(`Rune structure mismatch at ${x},${y}`);
|
|
135
|
+
}
|
|
136
|
+
return problems;
|
|
137
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Sythos Barcode Suite
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2026 Sythos
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* SPDX-License-Identifier: MIT
|
|
27
|
+
*
|
|
28
|
+
* Original work. No code from any other barcode implementation.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** Compact PDF417 decoder. @module compactpdf417/decoder */
|
|
32
|
+
|
|
33
|
+
import { FormatError } from '../core/errors.js';
|
|
34
|
+
import { decodePdf417CompactionDetailed } from '../pdf417/compaction.js';
|
|
35
|
+
import { pdf417CorrectErrors, pdf417EccLength } from '../pdf417/error-correction.js';
|
|
36
|
+
import { pdf417CodewordForPattern } from '../pdf417/tables.js';
|
|
37
|
+
import {
|
|
38
|
+
COMPACT_PDF417_START_BITS,
|
|
39
|
+
compactPdf417Geometry,
|
|
40
|
+
compactPdf417Indicators,
|
|
41
|
+
compactPdf417MatchingLevels,
|
|
42
|
+
} from './tables.js';
|
|
43
|
+
|
|
44
|
+
function bits(matrix, y, x, width) {
|
|
45
|
+
let value = 0;
|
|
46
|
+
for (let index = 0; index < width; index++) value = (value << 1) | (matrix.get(x + index, y) ? 1 : 0);
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function patternString(matrix, y, x, width) {
|
|
51
|
+
return bits(matrix, y, x, width).toString(2).padStart(width, '0');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Decode a compact/truncated PDF417 module matrix.
|
|
56
|
+
*
|
|
57
|
+
* The high-level payload uses the normal PDF417 Text/Byte/Numeric compaction
|
|
58
|
+
* rules. This function only changes the physical row parser: no right row
|
|
59
|
+
* indicator is expected and the final module of each row must be dark.
|
|
60
|
+
*
|
|
61
|
+
* @param {import('../core/bit-matrix.js').BitMatrix} matrix
|
|
62
|
+
* @param {object} [options]
|
|
63
|
+
* @param {number} [options.rowHeight]
|
|
64
|
+
*/
|
|
65
|
+
export function decodeCompactPDF417(matrix, options = {}) {
|
|
66
|
+
if (!matrix?.width || !matrix?.height) throw new FormatError('Compact PDF417: no matrix supplied');
|
|
67
|
+
const rowHeight = options.rowHeight ?? matrix.compactPdf417?.rowHeight ?? 3;
|
|
68
|
+
let geometry;
|
|
69
|
+
try { geometry = compactPdf417Geometry(matrix.width, matrix.height, rowHeight); }
|
|
70
|
+
catch (error) { throw new FormatError(error.message); }
|
|
71
|
+
|
|
72
|
+
const { rows, columns } = geometry;
|
|
73
|
+
const all = [];
|
|
74
|
+
const erasures = [];
|
|
75
|
+
const leftIndicators = [];
|
|
76
|
+
|
|
77
|
+
for (let row = 0; row < rows; row++) {
|
|
78
|
+
const y = row * rowHeight;
|
|
79
|
+
if (patternString(matrix, y, 0, 17) !== COMPACT_PDF417_START_BITS) {
|
|
80
|
+
throw new FormatError('Compact PDF417: missing start pattern');
|
|
81
|
+
}
|
|
82
|
+
const cluster = (row % 3) * 3;
|
|
83
|
+
const leftDecoded = pdf417CodewordForPattern(bits(matrix, y, 17, 17));
|
|
84
|
+
if (!leftDecoded || leftDecoded.cluster !== cluster) {
|
|
85
|
+
throw new FormatError('Compact PDF417: invalid left row indicator');
|
|
86
|
+
}
|
|
87
|
+
leftIndicators.push(leftDecoded.codeword);
|
|
88
|
+
|
|
89
|
+
const dataStart = 34;
|
|
90
|
+
const stopX = dataStart + columns * 17;
|
|
91
|
+
if (!matrix.get(stopX, y)) throw new FormatError('Compact PDF417: missing reduced stop module');
|
|
92
|
+
for (let column = 0; column < columns; column++) {
|
|
93
|
+
const decoded = pdf417CodewordForPattern(bits(matrix, y, dataStart + column * 17, 17));
|
|
94
|
+
if (!decoded || decoded.cluster !== cluster) {
|
|
95
|
+
erasures.push(all.length);
|
|
96
|
+
all.push(0);
|
|
97
|
+
} else {
|
|
98
|
+
all.push(decoded.codeword);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const levels = compactPdf417MatchingLevels(leftIndicators, rows, columns);
|
|
104
|
+
if (levels.length !== 1) throw new FormatError('Compact PDF417: row indicator mismatch');
|
|
105
|
+
const level = levels[0];
|
|
106
|
+
const eccLength = pdf417EccLength(level);
|
|
107
|
+
if (all.length <= eccLength) throw new FormatError('Compact PDF417: insufficient codewords for ECC');
|
|
108
|
+
|
|
109
|
+
const corrected = all.slice();
|
|
110
|
+
const corrections = pdf417CorrectErrors(corrected, level, erasures);
|
|
111
|
+
const length = corrected[0];
|
|
112
|
+
if (length < 1 || length > corrected.length - eccLength) {
|
|
113
|
+
throw new FormatError('Compact PDF417: invalid symbol length descriptor');
|
|
114
|
+
}
|
|
115
|
+
const payload = corrected.slice(1, length);
|
|
116
|
+
const decoded = decodePdf417CompactionDetailed(payload);
|
|
117
|
+
return {
|
|
118
|
+
...decoded,
|
|
119
|
+
format: 'compact-pdf417',
|
|
120
|
+
compact: true,
|
|
121
|
+
codewords: corrected,
|
|
122
|
+
rows,
|
|
123
|
+
columns,
|
|
124
|
+
eccLevel: level,
|
|
125
|
+
rowHeight,
|
|
126
|
+
corrections,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Sythos Barcode Suite
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2026 Sythos
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* SPDX-License-Identifier: MIT
|
|
27
|
+
*
|
|
28
|
+
* Original work. No code from any other barcode implementation.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** Compact PDF417 detector for clean, integer-scaled rasters. @module compactpdf417/detector */
|
|
32
|
+
|
|
33
|
+
import { BitMatrix } from '../core/bit-matrix.js';
|
|
34
|
+
import { compactPdf417Width } from './tables.js';
|
|
35
|
+
import { decodeCompactPDF417 } from './decoder.js';
|
|
36
|
+
|
|
37
|
+
function rotateClockwise(source) {
|
|
38
|
+
const out = new BitMatrix(source.height, source.width);
|
|
39
|
+
for (let y = 0; y < source.height; y++) {
|
|
40
|
+
for (let x = 0; x < source.width; x++) {
|
|
41
|
+
if (source.get(x, y)) out.set(source.height - 1 - y, x);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
function cropAndDownsample(source, box, width, height, scale) {
|
|
47
|
+
const out = new BitMatrix(width, height);
|
|
48
|
+
for (let y = 0; y < height; y++) {
|
|
49
|
+
for (let x = 0; x < width; x++) {
|
|
50
|
+
let dark = 0;
|
|
51
|
+
for (let dy = 0; dy < scale; dy++) {
|
|
52
|
+
for (let dx = 0; dx < scale; dx++) {
|
|
53
|
+
if (source.get(box.x + x * scale + dx, box.y + y * scale + dy)) dark++;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (dark * 2 >= scale * scale) out.set(x, y);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function cornersFor(box) {
|
|
63
|
+
return [
|
|
64
|
+
{ x: box.x, y: box.y },
|
|
65
|
+
{ x: box.x + box.width, y: box.y },
|
|
66
|
+
{ x: box.x + box.width, y: box.y + box.height },
|
|
67
|
+
{ x: box.x, y: box.y + box.height },
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function mapCorners(corners, toOriginal) {
|
|
72
|
+
return corners.map((point) => toOriginal(point));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Detect one Compact PDF417 symbol in a binarized raster.
|
|
77
|
+
*
|
|
78
|
+
* The clean-raster detector uses the dark bounding box and enumerates legal
|
|
79
|
+
* compact widths, integer module scales, row counts and row heights. It is
|
|
80
|
+
* deliberately conservative: arbitrary perspective, non-integer resampling,
|
|
81
|
+
* grayscale thresholding and damaged stop bars belong to a future photo
|
|
82
|
+
* detector and are not claimed here.
|
|
83
|
+
*
|
|
84
|
+
* @param {import('../core/bit-matrix.js').BitMatrix} binaryImage
|
|
85
|
+
* @param {object} [options]
|
|
86
|
+
* @param {number} [options.rowHeight] Restrict the row-height search.
|
|
87
|
+
* @returns {object|null}
|
|
88
|
+
*/
|
|
89
|
+
export function detectCompactPDF417(binaryImage, options = {}) {
|
|
90
|
+
if (!binaryImage?.width || !binaryImage?.height || typeof binaryImage.get !== 'function') return null;
|
|
91
|
+
|
|
92
|
+
let oriented = binaryImage;
|
|
93
|
+
let toOriginal = (point) => ({ x: point.x, y: point.y });
|
|
94
|
+
for (let rotation = 0; rotation < 4; rotation++) {
|
|
95
|
+
const bounds = oriented.getBounds();
|
|
96
|
+
if (bounds) {
|
|
97
|
+
for (let columns = 1; columns <= 30; columns++) {
|
|
98
|
+
const width = compactPdf417Width(columns);
|
|
99
|
+
const scale = bounds.width / width;
|
|
100
|
+
if (!Number.isInteger(scale) || scale < 1) continue;
|
|
101
|
+
const baseHeight = bounds.height / scale;
|
|
102
|
+
const rowHeights = Number.isInteger(options.rowHeight)
|
|
103
|
+
? [options.rowHeight]
|
|
104
|
+
: Array.from({ length: 18 }, (_, index) => index + 3);
|
|
105
|
+
for (const rowHeight of rowHeights) {
|
|
106
|
+
if (!Number.isInteger(baseHeight / rowHeight)) continue;
|
|
107
|
+
const rows = baseHeight / rowHeight;
|
|
108
|
+
if (rows < 3 || rows > 90) continue;
|
|
109
|
+
const matrix = cropAndDownsample(oriented, bounds, width, baseHeight, scale);
|
|
110
|
+
try {
|
|
111
|
+
const result = decodeCompactPDF417(matrix, { rowHeight });
|
|
112
|
+
const corners = mapCorners(cornersFor(bounds), toOriginal);
|
|
113
|
+
return {
|
|
114
|
+
...result,
|
|
115
|
+
matrix,
|
|
116
|
+
corners,
|
|
117
|
+
rotation: rotation * 90,
|
|
118
|
+
moduleSize: scale,
|
|
119
|
+
compact: true,
|
|
120
|
+
};
|
|
121
|
+
} catch {
|
|
122
|
+
// Try another geometry; a standard PDF417 or random artwork should
|
|
123
|
+
// never be accepted unless the compact decoder validates every row.
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const previous = oriented;
|
|
130
|
+
const previousToOriginal = toOriginal;
|
|
131
|
+
oriented = rotateClockwise(previous);
|
|
132
|
+
toOriginal = (point) => previousToOriginal({ x: point.y, y: previous.height - point.x });
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function detectAndDecodeCompactPDF417(binaryImage, options = {}) {
|
|
138
|
+
return detectCompactPDF417(binaryImage, options);
|
|
139
|
+
}
|