zedbar 0.3.1 → 0.4.1

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
@@ -113,6 +113,30 @@ const results = scanImageBytes(imageBytes, { symbologies: ['QR-Code'] });
113
113
  - `symbolType` (`string`) - Barcode format (e.g., `"QR-Code"`, `"EAN-13"`)
114
114
  - `data` (`Uint8Array`) - Raw decoded bytes
115
115
  - `text` (`string | undefined`) - Decoded data as UTF-8 string, or `undefined` if not valid UTF-8
116
+ - `points` (`Point[]`) - Position points in image coordinates. For QR codes, the four corners of the QR's bounding rectangle (in implementation-defined order). For linear barcodes, one or more touchpoints accumulated as the symbol was scanned. Empty if no points were recorded.
117
+ - `bounds` (`Bounds | undefined`) - Axis-aligned bounding rectangle of `points`, or `undefined` if no points were recorded.
118
+
119
+ ### `Point`
120
+
121
+ - `x` (`number`)
122
+ - `y` (`number`)
123
+
124
+ ### `Bounds`
125
+
126
+ - `x`, `y` (`number`) - Top-left corner in image coordinates.
127
+ - `width`, `height` (`number`) - Reported as `max - min` of the recorded points (the horizontal and vertical extent between the outermost points), not as a pixel count.
128
+
129
+ ```javascript
130
+ for (const result of scanImageBytes(imageBytes)) {
131
+ for (const { x, y } of result.points) {
132
+ console.log(` point at (${x}, ${y})`);
133
+ }
134
+ if (result.bounds) {
135
+ const { x, y, width, height } = result.bounds;
136
+ console.log(` bounds: ${width}×${height} at (${x}, ${y})`);
137
+ }
138
+ }
139
+ ```
116
140
 
117
141
  ## Supported Formats
118
142
 
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.3.1",
4
+ "version": "0.4.1",
5
5
  "license": "LGPL-3.0-or-later",
6
6
  "repository": {
7
7
  "type": "git",
package/zedbar.d.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ /**
4
+ * Scan grayscale image data for barcodes and QR codes.
5
+ *
6
+ * `data` must be an array of 8-bit grayscale pixel values,
7
+ * row-major, with dimensions `width` x `height`.
8
+ *
9
+ * Returns an array of `DecodeResult` objects.
10
+ */
11
+ export function scanGrayscale(data: Uint8Array, width: number, height: number, options?: ScanOptions | null): DecodeResult[];
3
12
  /**
4
13
  * Scan an encoded image (PNG, JPEG, BMP, WebP) for barcodes and QR codes.
5
14
  *
@@ -13,14 +22,20 @@
13
22
  */
14
23
  export function scanImageBytes(bytes: Uint8Array, options?: ScanOptions | null): DecodeResult[];
15
24
  /**
16
- * Scan grayscale image data for barcodes and QR codes.
17
- *
18
- * `data` must be an array of 8-bit grayscale pixel values,
19
- * row-major, with dimensions `width` x `height`.
20
- *
21
- * Returns an array of `DecodeResult` objects.
25
+ * Axis-aligned bounding rectangle of a decoded symbol in image
26
+ * coordinates. `width` and `height` are reported as `max - min` of the
27
+ * recorded points (i.e. the horizontal and vertical extent between the
28
+ * outermost points), not as a pixel count.
22
29
  */
23
- export function scanGrayscale(data: Uint8Array, width: number, height: number, options?: ScanOptions | null): DecodeResult[];
30
+ export class Bounds {
31
+ private constructor();
32
+ free(): void;
33
+ [Symbol.dispose](): void;
34
+ readonly x: number;
35
+ readonly y: number;
36
+ readonly width: number;
37
+ readonly height: number;
38
+ }
24
39
  /**
25
40
  * A decoded barcode/QR code result.
26
41
  */
@@ -47,6 +62,30 @@ export class DecodeResult {
47
62
  * For linear barcodes, the data is always ASCII text.
48
63
  */
49
64
  readonly text: string | undefined;
65
+ /**
66
+ * The axis-aligned bounding rectangle of this symbol's recorded
67
+ * points, or `null` if no points were recorded.
68
+ */
69
+ readonly bounds: Bounds | undefined;
70
+ /**
71
+ * The recorded position points of this symbol in image coordinates.
72
+ *
73
+ * For QR codes, this is the four corner points of the QR's bounding
74
+ * rectangle (in implementation-defined order). For linear barcodes,
75
+ * this is one or more touchpoints accumulated as the symbol was
76
+ * scanned. Empty if no points were recorded.
77
+ */
78
+ readonly points: Point[];
79
+ }
80
+ /**
81
+ * A 2D pixel coordinate in image space.
82
+ */
83
+ export class Point {
84
+ private constructor();
85
+ free(): void;
86
+ [Symbol.dispose](): void;
87
+ readonly x: number;
88
+ readonly y: number;
50
89
  }
51
90
  /**
52
91
  * Options for barcode scanning.
package/zedbar.js CHANGED
@@ -112,6 +112,17 @@ function getArrayU8FromWasm0(ptr, len) {
112
112
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
113
113
  }
114
114
 
115
+ function getArrayJsValueFromWasm0(ptr, len) {
116
+ ptr = ptr >>> 0;
117
+ const mem = getDataViewMemory0();
118
+ const result = [];
119
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
120
+ result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true)));
121
+ }
122
+ wasm.__externref_drop_slice(ptr, len);
123
+ return result;
124
+ }
125
+
115
126
  function passArray8ToWasm0(arg, malloc) {
116
127
  const ptr = malloc(arg.length * 1, 1) >>> 0;
117
128
  getUint8ArrayMemory0().set(arg, ptr / 1);
@@ -130,40 +141,28 @@ function takeFromExternrefTable0(idx) {
130
141
  wasm.__externref_table_dealloc(idx);
131
142
  return value;
132
143
  }
133
-
134
- function getArrayJsValueFromWasm0(ptr, len) {
135
- ptr = ptr >>> 0;
136
- const mem = getDataViewMemory0();
137
- const result = [];
138
- for (let i = ptr; i < ptr + 4 * len; i += 4) {
139
- result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true)));
140
- }
141
- wasm.__externref_drop_slice(ptr, len);
142
- return result;
143
- }
144
144
  /**
145
- * Scan an encoded image (PNG, JPEG, BMP, WebP) for barcodes and QR codes.
146
- *
147
- * `bytes` should contain the raw bytes of an image file in one of the
148
- * supported formats: PNG, JPEG, BMP, or WebP.
145
+ * Scan grayscale image data for barcodes and QR codes.
149
146
  *
150
- * The image will be automatically decoded and converted to grayscale
151
- * before scanning.
147
+ * `data` must be an array of 8-bit grayscale pixel values,
148
+ * row-major, with dimensions `width` x `height`.
152
149
  *
153
150
  * Returns an array of `DecodeResult` objects.
154
- * @param {Uint8Array} bytes
151
+ * @param {Uint8Array} data
152
+ * @param {number} width
153
+ * @param {number} height
155
154
  * @param {ScanOptions | null} [options]
156
155
  * @returns {DecodeResult[]}
157
156
  */
158
- exports.scanImageBytes = function(bytes, options) {
159
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
157
+ exports.scanGrayscale = function(data, width, height, options) {
158
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
160
159
  const len0 = WASM_VECTOR_LEN;
161
160
  let ptr1 = 0;
162
161
  if (!isLikeNone(options)) {
163
162
  _assertClass(options, ScanOptions);
164
163
  ptr1 = options.__destroy_into_raw();
165
164
  }
166
- const ret = wasm.scanImageBytes(ptr0, len0, ptr1);
165
+ const ret = wasm.scanGrayscale(ptr0, len0, width, height, ptr1);
167
166
  if (ret[3]) {
168
167
  throw takeFromExternrefTable0(ret[2]);
169
168
  }
@@ -173,27 +172,28 @@ exports.scanImageBytes = function(bytes, options) {
173
172
  };
174
173
 
175
174
  /**
176
- * Scan grayscale image data for barcodes and QR codes.
175
+ * Scan an encoded image (PNG, JPEG, BMP, WebP) for barcodes and QR codes.
177
176
  *
178
- * `data` must be an array of 8-bit grayscale pixel values,
179
- * row-major, with dimensions `width` x `height`.
177
+ * `bytes` should contain the raw bytes of an image file in one of the
178
+ * supported formats: PNG, JPEG, BMP, or WebP.
179
+ *
180
+ * The image will be automatically decoded and converted to grayscale
181
+ * before scanning.
180
182
  *
181
183
  * Returns an array of `DecodeResult` objects.
182
- * @param {Uint8Array} data
183
- * @param {number} width
184
- * @param {number} height
184
+ * @param {Uint8Array} bytes
185
185
  * @param {ScanOptions | null} [options]
186
186
  * @returns {DecodeResult[]}
187
187
  */
188
- exports.scanGrayscale = function(data, width, height, options) {
189
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
188
+ exports.scanImageBytes = function(bytes, options) {
189
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
190
190
  const len0 = WASM_VECTOR_LEN;
191
191
  let ptr1 = 0;
192
192
  if (!isLikeNone(options)) {
193
193
  _assertClass(options, ScanOptions);
194
194
  ptr1 = options.__destroy_into_raw();
195
195
  }
196
- const ret = wasm.scanGrayscale(ptr0, len0, width, height, ptr1);
196
+ const ret = wasm.scanImageBytes(ptr0, len0, ptr1);
197
197
  if (ret[3]) {
198
198
  throw takeFromExternrefTable0(ret[2]);
199
199
  }
@@ -202,6 +202,69 @@ exports.scanGrayscale = function(data, width, height, options) {
202
202
  return v3;
203
203
  };
204
204
 
205
+ const BoundsFinalization = (typeof FinalizationRegistry === 'undefined')
206
+ ? { register: () => {}, unregister: () => {} }
207
+ : new FinalizationRegistry(ptr => wasm.__wbg_bounds_free(ptr >>> 0, 1));
208
+ /**
209
+ * Axis-aligned bounding rectangle of a decoded symbol in image
210
+ * coordinates. `width` and `height` are reported as `max - min` of the
211
+ * recorded points (i.e. the horizontal and vertical extent between the
212
+ * outermost points), not as a pixel count.
213
+ */
214
+ class Bounds {
215
+
216
+ static __wrap(ptr) {
217
+ ptr = ptr >>> 0;
218
+ const obj = Object.create(Bounds.prototype);
219
+ obj.__wbg_ptr = ptr;
220
+ BoundsFinalization.register(obj, obj.__wbg_ptr, obj);
221
+ return obj;
222
+ }
223
+
224
+ __destroy_into_raw() {
225
+ const ptr = this.__wbg_ptr;
226
+ this.__wbg_ptr = 0;
227
+ BoundsFinalization.unregister(this);
228
+ return ptr;
229
+ }
230
+
231
+ free() {
232
+ const ptr = this.__destroy_into_raw();
233
+ wasm.__wbg_bounds_free(ptr, 0);
234
+ }
235
+ /**
236
+ * @returns {number}
237
+ */
238
+ get x() {
239
+ const ret = wasm.bounds_x(this.__wbg_ptr);
240
+ return ret;
241
+ }
242
+ /**
243
+ * @returns {number}
244
+ */
245
+ get y() {
246
+ const ret = wasm.bounds_y(this.__wbg_ptr);
247
+ return ret;
248
+ }
249
+ /**
250
+ * @returns {number}
251
+ */
252
+ get width() {
253
+ const ret = wasm.bounds_width(this.__wbg_ptr);
254
+ return ret >>> 0;
255
+ }
256
+ /**
257
+ * @returns {number}
258
+ */
259
+ get height() {
260
+ const ret = wasm.bounds_height(this.__wbg_ptr);
261
+ return ret >>> 0;
262
+ }
263
+ }
264
+ if (Symbol.dispose) Bounds.prototype[Symbol.dispose] = Bounds.prototype.free;
265
+
266
+ exports.Bounds = Bounds;
267
+
205
268
  const DecodeResultFinalization = (typeof FinalizationRegistry === 'undefined')
206
269
  ? { register: () => {}, unregister: () => {} }
207
270
  : new FinalizationRegistry(ptr => wasm.__wbg_decoderesult_free(ptr >>> 0, 1));
@@ -275,11 +338,81 @@ class DecodeResult {
275
338
  }
276
339
  return v1;
277
340
  }
341
+ /**
342
+ * The axis-aligned bounding rectangle of this symbol's recorded
343
+ * points, or `null` if no points were recorded.
344
+ * @returns {Bounds | undefined}
345
+ */
346
+ get bounds() {
347
+ const ret = wasm.decoderesult_bounds(this.__wbg_ptr);
348
+ return ret === 0 ? undefined : Bounds.__wrap(ret);
349
+ }
350
+ /**
351
+ * The recorded position points of this symbol in image coordinates.
352
+ *
353
+ * For QR codes, this is the four corner points of the QR's bounding
354
+ * rectangle (in implementation-defined order). For linear barcodes,
355
+ * this is one or more touchpoints accumulated as the symbol was
356
+ * scanned. Empty if no points were recorded.
357
+ * @returns {Point[]}
358
+ */
359
+ get points() {
360
+ const ret = wasm.decoderesult_points(this.__wbg_ptr);
361
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
362
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
363
+ return v1;
364
+ }
278
365
  }
279
366
  if (Symbol.dispose) DecodeResult.prototype[Symbol.dispose] = DecodeResult.prototype.free;
280
367
 
281
368
  exports.DecodeResult = DecodeResult;
282
369
 
370
+ const PointFinalization = (typeof FinalizationRegistry === 'undefined')
371
+ ? { register: () => {}, unregister: () => {} }
372
+ : new FinalizationRegistry(ptr => wasm.__wbg_point_free(ptr >>> 0, 1));
373
+ /**
374
+ * A 2D pixel coordinate in image space.
375
+ */
376
+ class Point {
377
+
378
+ static __wrap(ptr) {
379
+ ptr = ptr >>> 0;
380
+ const obj = Object.create(Point.prototype);
381
+ obj.__wbg_ptr = ptr;
382
+ PointFinalization.register(obj, obj.__wbg_ptr, obj);
383
+ return obj;
384
+ }
385
+
386
+ __destroy_into_raw() {
387
+ const ptr = this.__wbg_ptr;
388
+ this.__wbg_ptr = 0;
389
+ PointFinalization.unregister(this);
390
+ return ptr;
391
+ }
392
+
393
+ free() {
394
+ const ptr = this.__destroy_into_raw();
395
+ wasm.__wbg_point_free(ptr, 0);
396
+ }
397
+ /**
398
+ * @returns {number}
399
+ */
400
+ get x() {
401
+ const ret = wasm.bounds_x(this.__wbg_ptr);
402
+ return ret;
403
+ }
404
+ /**
405
+ * @returns {number}
406
+ */
407
+ get y() {
408
+ const ret = wasm.bounds_y(this.__wbg_ptr);
409
+ return ret;
410
+ }
411
+ }
412
+ if (Symbol.dispose) Point.prototype[Symbol.dispose] = Point.prototype.free;
413
+
414
+ exports.Point = Point;
415
+
283
416
  const ScanOptionsFinalization = (typeof FinalizationRegistry === 'undefined')
284
417
  ? { register: () => {}, unregister: () => {} }
285
418
  : new FinalizationRegistry(ptr => wasm.__wbg_scanoptions_free(ptr >>> 0, 1));
@@ -355,6 +488,11 @@ exports.__wbg_decoderesult_new = function(arg0) {
355
488
  return ret;
356
489
  };
357
490
 
491
+ exports.__wbg_point_new = function(arg0) {
492
+ const ret = Point.__wrap(arg0);
493
+ return ret;
494
+ };
495
+
358
496
  exports.__wbg_wbindgenstringget_0f16a6ddddef376f = function(arg0, arg1) {
359
497
  const obj = arg1;
360
498
  const ret = typeof(obj) === 'string' ? obj : undefined;
package/zedbar_bg.wasm CHANGED
Binary file