@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
|
@@ -27,183 +27,158 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Original work. No code from any other barcode implementation.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
30
|
/** MicroPDF417 encoder. @module micropdf417/encoder */
|
|
32
|
-
|
|
33
31
|
import { BitMatrix } from '../core/bit-matrix.js';
|
|
34
32
|
import { EncodeError } from '../core/errors.js';
|
|
35
33
|
import { pdf417PatternForCodeword } from '../pdf417/tables.js';
|
|
36
34
|
import { compactMicroPDF417 } from './compaction.js';
|
|
37
35
|
import { microPdf417ErrorCorrection } from './error-correction.js';
|
|
38
|
-
import {
|
|
39
|
-
MICROPDF417_VARIANTS,
|
|
40
|
-
microPdf417RapSequence,
|
|
41
|
-
microPdf417RowAddress,
|
|
42
|
-
microPdf417VariantByNumber,
|
|
43
|
-
microPdf417VariantForCapacity,
|
|
44
|
-
} from './tables.js';
|
|
45
|
-
|
|
36
|
+
import { MICROPDF417_VARIANTS, microPdf417RapSequence, microPdf417RowAddress, microPdf417VariantByNumber, microPdf417VariantForCapacity, } from './tables.js';
|
|
46
37
|
function appendWidths(matrix, y, x, sequence, height) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
let dark = true;
|
|
39
|
+
for (const digit of sequence) {
|
|
40
|
+
const width = digit.charCodeAt(0) - 48;
|
|
41
|
+
if (!Number.isInteger(width) || width < 1 || width > 6) {
|
|
42
|
+
throw new EncodeError('MicroPDF417: invalid module-width sequence');
|
|
43
|
+
}
|
|
44
|
+
if (dark)
|
|
45
|
+
matrix.setRegion(x, y, width, height);
|
|
46
|
+
x += width;
|
|
47
|
+
dark = !dark;
|
|
52
48
|
}
|
|
53
|
-
|
|
54
|
-
x += width;
|
|
55
|
-
dark = !dark;
|
|
56
|
-
}
|
|
57
|
-
return x;
|
|
49
|
+
return x;
|
|
58
50
|
}
|
|
59
|
-
|
|
60
51
|
function codewordSequence(codeword, cluster) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
return pdf417PatternForCodeword(codeword, cluster)
|
|
53
|
+
.toString(2)
|
|
54
|
+
.padStart(17, '0')
|
|
55
|
+
.replace(/0+|1+/g, (run) => String(run.length));
|
|
65
56
|
}
|
|
66
|
-
|
|
67
57
|
function symbolWidth(columns) {
|
|
68
|
-
|
|
58
|
+
return 21 + columns * 17 + (columns > 2 ? 10 : 0);
|
|
69
59
|
}
|
|
70
|
-
|
|
71
60
|
function validateOptions(options) {
|
|
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
|
-
|
|
61
|
+
const rowHeight = options.rowHeight ?? 2;
|
|
62
|
+
if (!Number.isInteger(rowHeight) || rowHeight < 2) {
|
|
63
|
+
throw new EncodeError('MicroPDF417: rowHeight must be an integer of at least 2');
|
|
64
|
+
}
|
|
65
|
+
if (options.columns !== undefined &&
|
|
66
|
+
(!Number.isInteger(options.columns) || options.columns < 1 || options.columns > 4)) {
|
|
67
|
+
throw new EncodeError('MicroPDF417: columns must be an integer in 1..4');
|
|
68
|
+
}
|
|
69
|
+
if (options.variant !== undefined &&
|
|
70
|
+
(!Number.isInteger(options.variant) || options.variant < 1 || options.variant > 34)) {
|
|
71
|
+
throw new EncodeError('MicroPDF417: variant must be an integer in 1..34');
|
|
72
|
+
}
|
|
73
|
+
if (options.aspectRatio !== undefined &&
|
|
74
|
+
(!Number.isFinite(options.aspectRatio) || options.aspectRatio <= 0)) {
|
|
75
|
+
throw new EncodeError('MicroPDF417: aspectRatio must be positive');
|
|
76
|
+
}
|
|
77
|
+
if (options.rows !== undefined) {
|
|
78
|
+
throw new EncodeError('MicroPDF417: rows are fixed by the selected variant');
|
|
79
|
+
}
|
|
80
|
+
if (options.eccLevel !== undefined) {
|
|
81
|
+
throw new EncodeError('MicroPDF417: error correction is fixed by the selected variant');
|
|
82
|
+
}
|
|
83
|
+
for (const feature of [
|
|
84
|
+
'structuredAppend', 'macro', 'macroPdf417', 'macroControlBlock',
|
|
85
|
+
'readerInit', 'gs1', 'hibc', 'linkage',
|
|
86
|
+
]) {
|
|
87
|
+
if (options[feature] !== undefined) {
|
|
88
|
+
throw new EncodeError(`MicroPDF417: ${feature} is not implemented`);
|
|
89
|
+
}
|
|
100
90
|
}
|
|
101
|
-
|
|
102
|
-
return rowHeight;
|
|
91
|
+
return rowHeight;
|
|
103
92
|
}
|
|
104
|
-
|
|
105
93
|
function chooseVariant(codewordCount, rowHeight, options) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
94
|
+
if (options.variant !== undefined) {
|
|
95
|
+
const variant = microPdf417VariantByNumber(options.variant);
|
|
96
|
+
if (!variant)
|
|
97
|
+
throw new EncodeError(`MicroPDF417: unknown variant ${options.variant}`);
|
|
98
|
+
if (options.columns !== undefined && variant.columns !== options.columns) {
|
|
99
|
+
throw new EncodeError(`MicroPDF417: variant ${variant.id} has ${variant.columns} columns`);
|
|
100
|
+
}
|
|
101
|
+
if (codewordCount > variant.dataCodewords) {
|
|
102
|
+
throw new EncodeError(`MicroPDF417: payload requires ${codewordCount} data codewords, variant ${variant.id} holds ${variant.dataCodewords}`);
|
|
103
|
+
}
|
|
104
|
+
return variant;
|
|
111
105
|
}
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
if (options.columns === undefined && options.aspectRatio === undefined) {
|
|
107
|
+
try {
|
|
108
|
+
return microPdf417VariantForCapacity(codewordCount);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (!(error instanceof RangeError))
|
|
112
|
+
throw error;
|
|
113
|
+
throw new EncodeError(`MicroPDF417: payload requires ${codewordCount} data codewords and exceeds every variant`);
|
|
114
|
+
}
|
|
116
115
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return microPdf417VariantForCapacity(codewordCount);
|
|
123
|
-
} catch (error) {
|
|
124
|
-
if (!(error instanceof RangeError)) throw error;
|
|
125
|
-
throw new EncodeError(`MicroPDF417: payload requires ${codewordCount} data codewords and exceeds every variant`);
|
|
116
|
+
const candidates = MICROPDF417_VARIANTS.filter((variant) => variant.dataCodewords >= codewordCount &&
|
|
117
|
+
(options.columns === undefined || variant.columns === options.columns));
|
|
118
|
+
if (!candidates.length) {
|
|
119
|
+
const columnText = options.columns === undefined ? '' : ` with ${options.columns} columns`;
|
|
120
|
+
throw new EncodeError(`MicroPDF417: payload does not fit any supported variant${columnText}`);
|
|
126
121
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
variant.dataCodewords < best.dataCodewords ||
|
|
140
|
-
(variant.dataCodewords === best.dataCodewords && variant.totalCodewords < best.totalCodewords)
|
|
141
|
-
? variant : best
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const target = options.aspectRatio;
|
|
146
|
-
return candidates.reduce((best, variant) => {
|
|
147
|
-
const ratio = symbolWidth(variant.columns) / (variant.rows * rowHeight);
|
|
148
|
-
const score = Math.abs(Math.log(ratio / target)) +
|
|
149
|
-
(variant.dataCodewords - codewordCount) / 10000;
|
|
150
|
-
return !best || score < best.score ? { variant, score } : best;
|
|
151
|
-
}, null).variant;
|
|
122
|
+
if (options.aspectRatio === undefined) {
|
|
123
|
+
return candidates.reduce((best, variant) => variant.dataCodewords < best.dataCodewords ||
|
|
124
|
+
(variant.dataCodewords === best.dataCodewords && variant.totalCodewords < best.totalCodewords)
|
|
125
|
+
? variant : best);
|
|
126
|
+
}
|
|
127
|
+
const target = options.aspectRatio;
|
|
128
|
+
return candidates.reduce((best, variant) => {
|
|
129
|
+
const ratio = symbolWidth(variant.columns) / (variant.rows * rowHeight);
|
|
130
|
+
const score = Math.abs(Math.log(ratio / target)) +
|
|
131
|
+
(variant.dataCodewords - codewordCount) / 10000;
|
|
132
|
+
return !best || score < best.score ? { variant, score } : best;
|
|
133
|
+
}, null).variant;
|
|
152
134
|
}
|
|
153
|
-
|
|
154
135
|
/** Encode a value as one of the 34 fixed MicroPDF417 variants. */
|
|
155
136
|
export function encodeMicroPDF417(value, options = {}) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (hasCentralRap) {
|
|
186
|
-
if (address.center === null) {
|
|
187
|
-
throw new EncodeError('MicroPDF417: selected variant is missing its centre row address');
|
|
137
|
+
const rowHeight = validateOptions(options);
|
|
138
|
+
const payload = compactMicroPDF417(value, options);
|
|
139
|
+
const variant = chooseVariant(payload.length, rowHeight, options);
|
|
140
|
+
const data = payload.slice();
|
|
141
|
+
while (data.length < variant.dataCodewords)
|
|
142
|
+
data.push(900);
|
|
143
|
+
const ecc = microPdf417ErrorCorrection(data, variant);
|
|
144
|
+
if (ecc.length !== variant.eccCodewords) {
|
|
145
|
+
throw new EncodeError('MicroPDF417: error-correction length does not match the selected variant');
|
|
146
|
+
}
|
|
147
|
+
const codewords = data.concat(ecc);
|
|
148
|
+
if (codewords.length !== variant.totalCodewords || codewords.length !== variant.rows * variant.columns) {
|
|
149
|
+
throw new EncodeError('MicroPDF417: selected variant has inconsistent codeword dimensions');
|
|
150
|
+
}
|
|
151
|
+
const matrix = new BitMatrix(symbolWidth(variant.columns), variant.rows * rowHeight);
|
|
152
|
+
for (let row = 0; row < variant.rows; row++) {
|
|
153
|
+
const y = row * rowHeight;
|
|
154
|
+
const address = microPdf417RowAddress(variant, row);
|
|
155
|
+
let x = appendWidths(matrix, y, 0, microPdf417RapSequence(address.left, 'side'), rowHeight);
|
|
156
|
+
for (let column = 0; column < variant.columns; column++) {
|
|
157
|
+
x = appendWidths(matrix, y, x, codewordSequence(codewords[row * variant.columns + column], address.cluster), rowHeight);
|
|
158
|
+
const hasCentralRap = (variant.columns === 3 && column === 0) ||
|
|
159
|
+
(variant.columns === 4 && column === 1);
|
|
160
|
+
if (hasCentralRap) {
|
|
161
|
+
if (address.center === null) {
|
|
162
|
+
throw new EncodeError('MicroPDF417: selected variant is missing its centre row address');
|
|
163
|
+
}
|
|
164
|
+
x = appendWidths(matrix, y, x, microPdf417RapSequence(address.center, 'center'), rowHeight);
|
|
165
|
+
}
|
|
188
166
|
}
|
|
189
|
-
x = appendWidths(matrix, y, x, microPdf417RapSequence(address.
|
|
190
|
-
|
|
167
|
+
x = appendWidths(matrix, y, x, microPdf417RapSequence(address.right, 'side'), rowHeight);
|
|
168
|
+
matrix.setRegion(x, y, 1, rowHeight);
|
|
169
|
+
x++;
|
|
170
|
+
if (x !== matrix.width)
|
|
171
|
+
throw new EncodeError('MicroPDF417: row width does not match the selected variant');
|
|
191
172
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
rowHeight,
|
|
204
|
-
payloadCodewords: payload.length,
|
|
205
|
-
dataCodewords: data,
|
|
206
|
-
codewords,
|
|
207
|
-
};
|
|
208
|
-
return matrix;
|
|
173
|
+
matrix.micropdf417 = {
|
|
174
|
+
variant: variant.id,
|
|
175
|
+
rows: variant.rows,
|
|
176
|
+
columns: variant.columns,
|
|
177
|
+
eccCodewords: variant.eccCodewords,
|
|
178
|
+
rowHeight,
|
|
179
|
+
payloadCodewords: payload.length,
|
|
180
|
+
dataCodewords: data,
|
|
181
|
+
codewords,
|
|
182
|
+
};
|
|
183
|
+
return matrix;
|
|
209
184
|
}
|
|
@@ -27,29 +27,24 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Original work. No code from any other barcode implementation.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
30
|
/** MicroPDF417 error correction over the existing GF(929) core. @module micropdf417/error-correction */
|
|
32
|
-
|
|
33
31
|
import { EncodeError } from '../core/errors.js';
|
|
34
32
|
import { GF929 } from '../core/galois-field.js';
|
|
35
33
|
import { generatorPoly, rsDecode, rsEncode } from '../core/reed-solomon.js';
|
|
36
|
-
|
|
37
34
|
function eccLength(entry) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
if (!entry || !Number.isInteger(entry.eccCodewords))
|
|
36
|
+
throw new EncodeError('MicroPDF417: a variant with an ECC length is required');
|
|
37
|
+
if (entry.eccCodewords < 1 || entry.eccCodewords >= GF929.size)
|
|
38
|
+
throw new EncodeError('MicroPDF417: ECC length is outside GF(929) bounds');
|
|
39
|
+
return entry.eccCodewords;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
41
|
/** Return the fixed number of parity codewords for a MicroPDF417 variant. */
|
|
44
42
|
export function microPdf417EccLength(entry) { return eccLength(entry); }
|
|
45
|
-
|
|
46
43
|
/** Build the MicroPDF417 generator polynomial for a variant's fixed ECC length. */
|
|
47
44
|
export function microPdf417Generator(entry) { return generatorPoly(eccLength(entry), GF929, 1); }
|
|
48
|
-
|
|
49
45
|
/** Compute systematic MicroPDF417 parity codewords. `data` must already include padding. */
|
|
50
46
|
export function microPdf417ErrorCorrection(data, entry) { return rsEncode(data, eccLength(entry), GF929, 1); }
|
|
51
|
-
|
|
52
47
|
/** Correct a complete MicroPDF417 codeword stream, optionally marking erasures. */
|
|
53
48
|
export function microPdf417CorrectErrors(codewords, entry, erasures = []) {
|
|
54
|
-
|
|
49
|
+
return rsDecode(codewords, eccLength(entry), GF929, 1, erasures);
|
|
55
50
|
}
|
|
@@ -27,22 +27,8 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Original work. No code from any other barcode implementation.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
MICROPDF417_VARIANTS,
|
|
33
|
-
microPdf417NextRap,
|
|
34
|
-
microPdf417VariantByNumber,
|
|
35
|
-
microPdf417VariantForCapacity,
|
|
36
|
-
microPdf417RapSequence,
|
|
37
|
-
microPdf417RowAddress,
|
|
38
|
-
validateMicroPdf417Tables,
|
|
39
|
-
} from './tables.js';
|
|
40
|
-
export {
|
|
41
|
-
microPdf417EccLength,
|
|
42
|
-
microPdf417Generator,
|
|
43
|
-
microPdf417ErrorCorrection,
|
|
44
|
-
microPdf417CorrectErrors,
|
|
45
|
-
} from './error-correction.js';
|
|
30
|
+
export { MICROPDF417_VARIANTS, microPdf417NextRap, microPdf417VariantByNumber, microPdf417VariantForCapacity, microPdf417RapSequence, microPdf417RowAddress, validateMicroPdf417Tables, } from './tables.js';
|
|
31
|
+
export { microPdf417EccLength, microPdf417Generator, microPdf417ErrorCorrection, microPdf417CorrectErrors, } from './error-correction.js';
|
|
46
32
|
export { compactMicroPDF417 } from './compaction.js';
|
|
47
33
|
export { encodeMicroPDF417 } from './encoder.js';
|
|
48
34
|
export { decodeMicroPDF417 } from './decoder.js';
|