zedbar 0.2.1 → 0.2.3

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/README.md CHANGED
@@ -74,17 +74,18 @@ for (const { symbolType, text } of scanGrayscale(data, width, height)) {
74
74
 
75
75
  ## API
76
76
 
77
- ### `scanImageBytes(bytes)`
77
+ ### `scanImageBytes(bytes, options?)`
78
78
 
79
79
  Scans an encoded image (PNG, JPEG, WebP, BMP) for barcodes and QR codes.
80
80
 
81
81
  **Parameters:**
82
82
 
83
83
  - `bytes` (`Uint8Array` or `Buffer`) - Raw bytes of an image file
84
+ - `options` (`ScanOptions`, optional) - Scanning options
84
85
 
85
86
  **Returns:** `DecodeResult[]` - Array of decoded barcodes
86
87
 
87
- ### `scanGrayscale(data, width, height)`
88
+ ### `scanGrayscale(data, width, height, options?)`
88
89
 
89
90
  Scans grayscale image data for barcodes and QR codes.
90
91
 
@@ -93,9 +94,14 @@ Scans grayscale image data for barcodes and QR codes.
93
94
  - `data` (`Uint8Array`) - Grayscale pixel data, 1 byte per pixel, row-major order
94
95
  - `width` (`number`) - Image width in pixels
95
96
  - `height` (`number`) - Image height in pixels
97
+ - `options` (`ScanOptions`, optional) - Scanning options
96
98
 
97
99
  **Returns:** `DecodeResult[]` - Array of decoded barcodes
98
100
 
101
+ ### `ScanOptions`
102
+
103
+ - `retryUndecodedRegions` (`boolean`, default: `true`) - Automatically retry undecoded QR finder regions by cropping and upscaling. Disable to skip the retry and reduce processing time for images that are known to have sufficient resolution.
104
+
99
105
  ### `DecodeResult`
100
106
 
101
107
  - `symbolType` (`string`) - Barcode format (e.g., `"QR-Code"`, `"EAN-13"`)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zedbar",
3
3
  "description": "Fast QR code and barcode scanner for Node.js, powered by WebAssembly",
4
- "version": "0.2.1",
4
+ "version": "0.2.3",
5
5
  "license": "LGPL-3.0-or-later",
6
6
  "repository": {
7
7
  "type": "git",
package/zedbar.d.ts CHANGED
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * Returns an array of `DecodeResult` objects.
13
13
  */
14
- export function scanImageBytes(bytes: Uint8Array): DecodeResult[];
14
+ export function scanImageBytes(bytes: Uint8Array, options?: ScanOptions | null): DecodeResult[];
15
15
  /**
16
16
  * Scan grayscale image data for barcodes and QR codes.
17
17
  *
@@ -20,7 +20,7 @@ export function scanImageBytes(bytes: Uint8Array): DecodeResult[];
20
20
  *
21
21
  * Returns an array of `DecodeResult` objects.
22
22
  */
23
- export function scanGrayscale(data: Uint8Array, width: number, height: number): DecodeResult[];
23
+ export function scanGrayscale(data: Uint8Array, width: number, height: number, options?: ScanOptions | null): DecodeResult[];
24
24
  /**
25
25
  * A decoded barcode/QR code result.
26
26
  */
@@ -34,10 +34,43 @@ export class DecodeResult {
34
34
  readonly symbolType: string;
35
35
  /**
36
36
  * Raw decoded bytes.
37
+ *
38
+ * For 2D codes (QR, SQ), these are the original bytes as encoded
39
+ * in the barcode, before any text encoding or base64 conversion.
37
40
  */
38
41
  readonly data: Uint8Array;
39
42
  /**
40
- * Decoded data as UTF-8 text, or null if not valid UTF-8.
43
+ * Decoded data as text, or null if not decodable as text.
44
+ *
45
+ * For 2D codes, the text is produced by detecting the encoding (UTF-8,
46
+ * Shift-JIS, Windows-1252, etc.) and converting to a UTF-8 string.
47
+ * For linear barcodes, the data is always ASCII text.
41
48
  */
42
49
  readonly text: string | undefined;
43
50
  }
51
+ /**
52
+ * Options for barcode scanning.
53
+ *
54
+ * All fields are optional and default to sensible values when omitted.
55
+ *
56
+ * ```js
57
+ * // Use defaults (retry enabled):
58
+ * const results = scanGrayscale(data, width, height);
59
+ *
60
+ * // Disable automatic retry of small QR codes:
61
+ * const results = scanGrayscale(data, width, height, { retryUndecodedRegions: false });
62
+ * ```
63
+ */
64
+ export class ScanOptions {
65
+ free(): void;
66
+ [Symbol.dispose](): void;
67
+ /**
68
+ * Create a new options object with defaults.
69
+ */
70
+ constructor();
71
+ /**
72
+ * Whether to automatically retry undecoded QR finder regions by
73
+ * cropping and upscaling them. Default: `true`.
74
+ */
75
+ set retryUndecodedRegions(value: boolean);
76
+ }
package/zedbar.js CHANGED
@@ -38,6 +38,16 @@ function passArray8ToWasm0(arg, malloc) {
38
38
  return ptr;
39
39
  }
40
40
 
41
+ function isLikeNone(x) {
42
+ return x === undefined || x === null;
43
+ }
44
+
45
+ function _assertClass(instance, klass) {
46
+ if (!(instance instanceof klass)) {
47
+ throw new Error(`expected instance of ${klass.name}`);
48
+ }
49
+ }
50
+
41
51
  function takeFromExternrefTable0(idx) {
42
52
  const value = wasm.__wbindgen_export_0.get(idx);
43
53
  wasm.__externref_table_dealloc(idx);
@@ -74,18 +84,24 @@ function getArrayJsValueFromWasm0(ptr, len) {
74
84
  *
75
85
  * Returns an array of `DecodeResult` objects.
76
86
  * @param {Uint8Array} bytes
87
+ * @param {ScanOptions | null} [options]
77
88
  * @returns {DecodeResult[]}
78
89
  */
79
- exports.scanImageBytes = function(bytes) {
90
+ exports.scanImageBytes = function(bytes, options) {
80
91
  const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
81
92
  const len0 = WASM_VECTOR_LEN;
82
- const ret = wasm.scanImageBytes(ptr0, len0);
93
+ let ptr1 = 0;
94
+ if (!isLikeNone(options)) {
95
+ _assertClass(options, ScanOptions);
96
+ ptr1 = options.__destroy_into_raw();
97
+ }
98
+ const ret = wasm.scanImageBytes(ptr0, len0, ptr1);
83
99
  if (ret[3]) {
84
100
  throw takeFromExternrefTable0(ret[2]);
85
101
  }
86
- var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
102
+ var v3 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
87
103
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
88
- return v2;
104
+ return v3;
89
105
  };
90
106
 
91
107
  /**
@@ -98,18 +114,24 @@ exports.scanImageBytes = function(bytes) {
98
114
  * @param {Uint8Array} data
99
115
  * @param {number} width
100
116
  * @param {number} height
117
+ * @param {ScanOptions | null} [options]
101
118
  * @returns {DecodeResult[]}
102
119
  */
103
- exports.scanGrayscale = function(data, width, height) {
120
+ exports.scanGrayscale = function(data, width, height, options) {
104
121
  const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
105
122
  const len0 = WASM_VECTOR_LEN;
106
- const ret = wasm.scanGrayscale(ptr0, len0, width, height);
123
+ let ptr1 = 0;
124
+ if (!isLikeNone(options)) {
125
+ _assertClass(options, ScanOptions);
126
+ ptr1 = options.__destroy_into_raw();
127
+ }
128
+ const ret = wasm.scanGrayscale(ptr0, len0, width, height, ptr1);
107
129
  if (ret[3]) {
108
130
  throw takeFromExternrefTable0(ret[2]);
109
131
  }
110
- var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
132
+ var v3 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
111
133
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
112
- return v2;
134
+ return v3;
113
135
  };
114
136
 
115
137
  const DecodeResultFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -157,6 +179,9 @@ class DecodeResult {
157
179
  }
158
180
  /**
159
181
  * Raw decoded bytes.
182
+ *
183
+ * For 2D codes (QR, SQ), these are the original bytes as encoded
184
+ * in the barcode, before any text encoding or base64 conversion.
160
185
  * @returns {Uint8Array}
161
186
  */
162
187
  get data() {
@@ -166,7 +191,11 @@ class DecodeResult {
166
191
  return v1;
167
192
  }
168
193
  /**
169
- * Decoded data as UTF-8 text, or null if not valid UTF-8.
194
+ * Decoded data as text, or null if not decodable as text.
195
+ *
196
+ * For 2D codes, the text is produced by detecting the encoding (UTF-8,
197
+ * Shift-JIS, Windows-1252, etc.) and converting to a UTF-8 string.
198
+ * For linear barcodes, the data is always ASCII text.
170
199
  * @returns {string | undefined}
171
200
  */
172
201
  get text() {
@@ -183,6 +212,57 @@ if (Symbol.dispose) DecodeResult.prototype[Symbol.dispose] = DecodeResult.protot
183
212
 
184
213
  exports.DecodeResult = DecodeResult;
185
214
 
215
+ const ScanOptionsFinalization = (typeof FinalizationRegistry === 'undefined')
216
+ ? { register: () => {}, unregister: () => {} }
217
+ : new FinalizationRegistry(ptr => wasm.__wbg_scanoptions_free(ptr >>> 0, 1));
218
+ /**
219
+ * Options for barcode scanning.
220
+ *
221
+ * All fields are optional and default to sensible values when omitted.
222
+ *
223
+ * ```js
224
+ * // Use defaults (retry enabled):
225
+ * const results = scanGrayscale(data, width, height);
226
+ *
227
+ * // Disable automatic retry of small QR codes:
228
+ * const results = scanGrayscale(data, width, height, { retryUndecodedRegions: false });
229
+ * ```
230
+ */
231
+ class ScanOptions {
232
+
233
+ __destroy_into_raw() {
234
+ const ptr = this.__wbg_ptr;
235
+ this.__wbg_ptr = 0;
236
+ ScanOptionsFinalization.unregister(this);
237
+ return ptr;
238
+ }
239
+
240
+ free() {
241
+ const ptr = this.__destroy_into_raw();
242
+ wasm.__wbg_scanoptions_free(ptr, 0);
243
+ }
244
+ /**
245
+ * Whether to automatically retry undecoded QR finder regions by
246
+ * cropping and upscaling them. Default: `true`.
247
+ * @param {boolean} value
248
+ */
249
+ set retryUndecodedRegions(value) {
250
+ wasm.scanoptions_set_retryUndecodedRegions(this.__wbg_ptr, value);
251
+ }
252
+ /**
253
+ * Create a new options object with defaults.
254
+ */
255
+ constructor() {
256
+ const ret = wasm.scanoptions_new();
257
+ this.__wbg_ptr = ret >>> 0;
258
+ ScanOptionsFinalization.register(this, this.__wbg_ptr, this);
259
+ return this;
260
+ }
261
+ }
262
+ if (Symbol.dispose) ScanOptions.prototype[Symbol.dispose] = ScanOptions.prototype.free;
263
+
264
+ exports.ScanOptions = ScanOptions;
265
+
186
266
  exports.__wbg_decoderesult_new = function(arg0) {
187
267
  const ret = DecodeResult.__wrap(arg0);
188
268
  return ret;
package/zedbar_bg.wasm CHANGED
Binary file