zedbar 0.2.1 → 0.2.2
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 +8 -2
- package/package.json +1 -1
- package/zedbar.d.ts +36 -10
- package/zedbar.js +96 -23
- package/zedbar_bg.wasm +0 -0
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
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
|
*
|
|
@@ -11,16 +20,7 @@
|
|
|
11
20
|
*
|
|
12
21
|
* Returns an array of `DecodeResult` objects.
|
|
13
22
|
*/
|
|
14
|
-
export function scanImageBytes(bytes: Uint8Array): DecodeResult[];
|
|
15
|
-
/**
|
|
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.
|
|
22
|
-
*/
|
|
23
|
-
export function scanGrayscale(data: Uint8Array, width: number, height: number): DecodeResult[];
|
|
23
|
+
export function scanImageBytes(bytes: Uint8Array, options?: ScanOptions | null): DecodeResult[];
|
|
24
24
|
/**
|
|
25
25
|
* A decoded barcode/QR code result.
|
|
26
26
|
*/
|
|
@@ -41,3 +41,29 @@ export class DecodeResult {
|
|
|
41
41
|
*/
|
|
42
42
|
readonly text: string | undefined;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Options for barcode scanning.
|
|
46
|
+
*
|
|
47
|
+
* All fields are optional and default to sensible values when omitted.
|
|
48
|
+
*
|
|
49
|
+
* ```js
|
|
50
|
+
* // Use defaults (retry enabled):
|
|
51
|
+
* const results = scanGrayscale(data, width, height);
|
|
52
|
+
*
|
|
53
|
+
* // Disable automatic retry of small QR codes:
|
|
54
|
+
* const results = scanGrayscale(data, width, height, { retryUndecodedRegions: false });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export class ScanOptions {
|
|
58
|
+
free(): void;
|
|
59
|
+
[Symbol.dispose](): void;
|
|
60
|
+
/**
|
|
61
|
+
* Create a new options object with defaults.
|
|
62
|
+
*/
|
|
63
|
+
constructor();
|
|
64
|
+
/**
|
|
65
|
+
* Whether to automatically retry undecoded QR finder regions by
|
|
66
|
+
* cropping and upscaling them. Default: `true`.
|
|
67
|
+
*/
|
|
68
|
+
set retryUndecodedRegions(value: boolean);
|
|
69
|
+
}
|
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);
|
|
@@ -64,52 +74,64 @@ function getArrayJsValueFromWasm0(ptr, len) {
|
|
|
64
74
|
return result;
|
|
65
75
|
}
|
|
66
76
|
/**
|
|
67
|
-
* Scan
|
|
68
|
-
*
|
|
69
|
-
* `bytes` should contain the raw bytes of an image file in one of the
|
|
70
|
-
* supported formats: PNG, JPEG, BMP, or WebP.
|
|
77
|
+
* Scan grayscale image data for barcodes and QR codes.
|
|
71
78
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
79
|
+
* `data` must be an array of 8-bit grayscale pixel values,
|
|
80
|
+
* row-major, with dimensions `width` x `height`.
|
|
74
81
|
*
|
|
75
82
|
* Returns an array of `DecodeResult` objects.
|
|
76
|
-
* @param {Uint8Array}
|
|
83
|
+
* @param {Uint8Array} data
|
|
84
|
+
* @param {number} width
|
|
85
|
+
* @param {number} height
|
|
86
|
+
* @param {ScanOptions | null} [options]
|
|
77
87
|
* @returns {DecodeResult[]}
|
|
78
88
|
*/
|
|
79
|
-
exports.
|
|
80
|
-
const ptr0 = passArray8ToWasm0(
|
|
89
|
+
exports.scanGrayscale = function(data, width, height, options) {
|
|
90
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
81
91
|
const len0 = WASM_VECTOR_LEN;
|
|
82
|
-
|
|
92
|
+
let ptr1 = 0;
|
|
93
|
+
if (!isLikeNone(options)) {
|
|
94
|
+
_assertClass(options, ScanOptions);
|
|
95
|
+
ptr1 = options.__destroy_into_raw();
|
|
96
|
+
}
|
|
97
|
+
const ret = wasm.scanGrayscale(ptr0, len0, width, height, ptr1);
|
|
83
98
|
if (ret[3]) {
|
|
84
99
|
throw takeFromExternrefTable0(ret[2]);
|
|
85
100
|
}
|
|
86
|
-
var
|
|
101
|
+
var v3 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
87
102
|
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
88
|
-
return
|
|
103
|
+
return v3;
|
|
89
104
|
};
|
|
90
105
|
|
|
91
106
|
/**
|
|
92
|
-
* Scan
|
|
107
|
+
* Scan an encoded image (PNG, JPEG, BMP, WebP) for barcodes and QR codes.
|
|
93
108
|
*
|
|
94
|
-
* `
|
|
95
|
-
*
|
|
109
|
+
* `bytes` should contain the raw bytes of an image file in one of the
|
|
110
|
+
* supported formats: PNG, JPEG, BMP, or WebP.
|
|
111
|
+
*
|
|
112
|
+
* The image will be automatically decoded and converted to grayscale
|
|
113
|
+
* before scanning.
|
|
96
114
|
*
|
|
97
115
|
* Returns an array of `DecodeResult` objects.
|
|
98
|
-
* @param {Uint8Array}
|
|
99
|
-
* @param {
|
|
100
|
-
* @param {number} height
|
|
116
|
+
* @param {Uint8Array} bytes
|
|
117
|
+
* @param {ScanOptions | null} [options]
|
|
101
118
|
* @returns {DecodeResult[]}
|
|
102
119
|
*/
|
|
103
|
-
exports.
|
|
104
|
-
const ptr0 = passArray8ToWasm0(
|
|
120
|
+
exports.scanImageBytes = function(bytes, options) {
|
|
121
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
105
122
|
const len0 = WASM_VECTOR_LEN;
|
|
106
|
-
|
|
123
|
+
let ptr1 = 0;
|
|
124
|
+
if (!isLikeNone(options)) {
|
|
125
|
+
_assertClass(options, ScanOptions);
|
|
126
|
+
ptr1 = options.__destroy_into_raw();
|
|
127
|
+
}
|
|
128
|
+
const ret = wasm.scanImageBytes(ptr0, len0, ptr1);
|
|
107
129
|
if (ret[3]) {
|
|
108
130
|
throw takeFromExternrefTable0(ret[2]);
|
|
109
131
|
}
|
|
110
|
-
var
|
|
132
|
+
var v3 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
111
133
|
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
112
|
-
return
|
|
134
|
+
return v3;
|
|
113
135
|
};
|
|
114
136
|
|
|
115
137
|
const DecodeResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
@@ -183,6 +205,57 @@ if (Symbol.dispose) DecodeResult.prototype[Symbol.dispose] = DecodeResult.protot
|
|
|
183
205
|
|
|
184
206
|
exports.DecodeResult = DecodeResult;
|
|
185
207
|
|
|
208
|
+
const ScanOptionsFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
209
|
+
? { register: () => {}, unregister: () => {} }
|
|
210
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_scanoptions_free(ptr >>> 0, 1));
|
|
211
|
+
/**
|
|
212
|
+
* Options for barcode scanning.
|
|
213
|
+
*
|
|
214
|
+
* All fields are optional and default to sensible values when omitted.
|
|
215
|
+
*
|
|
216
|
+
* ```js
|
|
217
|
+
* // Use defaults (retry enabled):
|
|
218
|
+
* const results = scanGrayscale(data, width, height);
|
|
219
|
+
*
|
|
220
|
+
* // Disable automatic retry of small QR codes:
|
|
221
|
+
* const results = scanGrayscale(data, width, height, { retryUndecodedRegions: false });
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
class ScanOptions {
|
|
225
|
+
|
|
226
|
+
__destroy_into_raw() {
|
|
227
|
+
const ptr = this.__wbg_ptr;
|
|
228
|
+
this.__wbg_ptr = 0;
|
|
229
|
+
ScanOptionsFinalization.unregister(this);
|
|
230
|
+
return ptr;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
free() {
|
|
234
|
+
const ptr = this.__destroy_into_raw();
|
|
235
|
+
wasm.__wbg_scanoptions_free(ptr, 0);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Whether to automatically retry undecoded QR finder regions by
|
|
239
|
+
* cropping and upscaling them. Default: `true`.
|
|
240
|
+
* @param {boolean} value
|
|
241
|
+
*/
|
|
242
|
+
set retryUndecodedRegions(value) {
|
|
243
|
+
wasm.scanoptions_set_retryUndecodedRegions(this.__wbg_ptr, value);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Create a new options object with defaults.
|
|
247
|
+
*/
|
|
248
|
+
constructor() {
|
|
249
|
+
const ret = wasm.scanoptions_new();
|
|
250
|
+
this.__wbg_ptr = ret >>> 0;
|
|
251
|
+
ScanOptionsFinalization.register(this, this.__wbg_ptr, this);
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (Symbol.dispose) ScanOptions.prototype[Symbol.dispose] = ScanOptions.prototype.free;
|
|
256
|
+
|
|
257
|
+
exports.ScanOptions = ScanOptions;
|
|
258
|
+
|
|
186
259
|
exports.__wbg_decoderesult_new = function(arg0) {
|
|
187
260
|
const ret = DecodeResult.__wrap(arg0);
|
|
188
261
|
return ret;
|
package/zedbar_bg.wasm
CHANGED
|
Binary file
|