zedbar 0.3.1 → 0.4.0
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 +24 -0
- package/package.json +1 -1
- package/zedbar.d.ts +39 -0
- package/zedbar.js +149 -11
- package/zedbar_bg.wasm +0 -0
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
package/zedbar.d.ts
CHANGED
|
@@ -21,6 +21,21 @@ export function scanImageBytes(bytes: Uint8Array, options?: ScanOptions | null):
|
|
|
21
21
|
* Returns an array of `DecodeResult` objects.
|
|
22
22
|
*/
|
|
23
23
|
export function scanGrayscale(data: Uint8Array, width: number, height: number, options?: ScanOptions | null): DecodeResult[];
|
|
24
|
+
/**
|
|
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.
|
|
29
|
+
*/
|
|
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,17 +141,6 @@ 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
145
|
* Scan an encoded image (PNG, JPEG, BMP, WebP) for barcodes and QR codes.
|
|
146
146
|
*
|
|
@@ -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
|