zedbar 0.1.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/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # zedbar
2
+
3
+ Fast QR code and barcode scanner for Node.js, powered by WebAssembly.
4
+
5
+ A port of the [ZBar](http://zbar.sourceforge.net/) barcode scanning library from C to Rust, compiled to WebAssembly for use in Node.js.
6
+
7
+ ## Features
8
+
9
+ - **Fast**: Native-speed scanning via WebAssembly
10
+ - **No native dependencies**: Works on any platform Node.js supports
11
+ - **Multiple formats**: QR Code, EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 93, Code 39, Codabar, Interleaved 2 of 5, DataBar, SQ Code
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install zedbar
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```javascript
22
+ import { scanGrayscale } from 'zedbar';
23
+ import sharp from 'sharp';
24
+
25
+ // Load image and convert to grayscale
26
+ const { data, info } = await sharp('barcode.png')
27
+ .grayscale()
28
+ .raw()
29
+ .toBuffer({ resolveWithObject: true });
30
+
31
+ // Scan for barcodes
32
+ for (const { symbolType, text } of scanGrayscale(data, info.width, info.height)) {
33
+ console.log(`${symbolType}: ${text}`);
34
+ }
35
+ ```
36
+
37
+ ## API
38
+
39
+ ### `scanGrayscale(data, width, height)`
40
+
41
+ Scans grayscale image data for barcodes and QR codes.
42
+
43
+ **Parameters:**
44
+ - `data` (`Uint8Array`) - Grayscale pixel data, 1 byte per pixel, row-major order
45
+ - `width` (`number`) - Image width in pixels
46
+ - `height` (`number`) - Image height in pixels
47
+
48
+ **Returns:** `DecodeResult[]` - Array of decoded barcodes
49
+
50
+ ### `DecodeResult`
51
+
52
+ - `symbolType` (`string`) - Barcode format (e.g., `"QR-Code"`, `"EAN-13"`)
53
+ - `data` (`Uint8Array`) - Raw decoded bytes
54
+ - `text` (`string | undefined`) - Decoded data as UTF-8 string, or `undefined` if not valid UTF-8
55
+
56
+ ## Supported Formats
57
+
58
+ | Format | `symbolType` |
59
+ |--------|-------------|
60
+ | QR Code | `QR-Code` |
61
+ | EAN-13 | `EAN-13` |
62
+ | EAN-8 | `EAN-8` |
63
+ | UPC-A | `UPC-A` |
64
+ | UPC-E | `UPC-E` |
65
+ | Code 128 | `CODE-128` |
66
+ | Code 93 | `CODE-93` |
67
+ | Code 39 | `CODE-39` |
68
+ | Codabar | `Codabar` |
69
+ | Interleaved 2 of 5 | `I2/5` |
70
+ | DataBar | `DataBar` |
71
+ | SQ Code | `SQ-Code` |
72
+
73
+ ## License
74
+
75
+ LGPL-3.0-or-later
76
+
77
+ Based on the [ZBar](http://zbar.sourceforge.net/) library. See [GitHub](https://github.com/eventualbuddha/zedbar) for source code.
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "zedbar",
3
+ "description": "Fast QR code and barcode scanner for Node.js, powered by WebAssembly",
4
+ "version": "0.1.0",
5
+ "license": "LGPL-3.0-or-later",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/eventualbuddha/zedbar.git"
9
+ },
10
+ "files": [
11
+ "zedbar_bg.wasm",
12
+ "zedbar.js",
13
+ "zedbar.d.ts"
14
+ ],
15
+ "main": "zedbar.js",
16
+ "types": "zedbar.d.ts",
17
+ "keywords": [
18
+ "qrcode",
19
+ "qr-code",
20
+ "barcode",
21
+ "scanner",
22
+ "decoder",
23
+ "wasm",
24
+ "webassembly",
25
+ "ean",
26
+ "code128",
27
+ "code39"
28
+ ],
29
+ "author": "eventualbuddha",
30
+ "homepage": "https://github.com/eventualbuddha/zedbar",
31
+ "bugs": {
32
+ "url": "https://github.com/eventualbuddha/zedbar/issues"
33
+ },
34
+ "engines": {
35
+ "node": ">=16.0.0"
36
+ }
37
+ }
package/zedbar.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ /* tslint:disable */
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): DecodeResult[];
12
+ /**
13
+ * A decoded barcode/QR code result.
14
+ */
15
+ export class DecodeResult {
16
+ private constructor();
17
+ free(): void;
18
+ [Symbol.dispose](): void;
19
+ /**
20
+ * The barcode format name (e.g. "QR-Code", "EAN-13").
21
+ */
22
+ readonly symbolType: string;
23
+ /**
24
+ * Raw decoded bytes.
25
+ */
26
+ readonly data: Uint8Array;
27
+ /**
28
+ * Decoded data as UTF-8 text, or null if not valid UTF-8.
29
+ */
30
+ readonly text: string | undefined;
31
+ }
package/zedbar.js ADDED
@@ -0,0 +1,193 @@
1
+
2
+ let imports = {};
3
+ imports['__wbindgen_placeholder__'] = module.exports;
4
+
5
+ let cachedUint8ArrayMemory0 = null;
6
+
7
+ function getUint8ArrayMemory0() {
8
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
9
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
10
+ }
11
+ return cachedUint8ArrayMemory0;
12
+ }
13
+
14
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
15
+
16
+ cachedTextDecoder.decode();
17
+
18
+ function decodeText(ptr, len) {
19
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
20
+ }
21
+
22
+ function getStringFromWasm0(ptr, len) {
23
+ ptr = ptr >>> 0;
24
+ return decodeText(ptr, len);
25
+ }
26
+
27
+ function getArrayU8FromWasm0(ptr, len) {
28
+ ptr = ptr >>> 0;
29
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
30
+ }
31
+
32
+ let WASM_VECTOR_LEN = 0;
33
+
34
+ function passArray8ToWasm0(arg, malloc) {
35
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
36
+ getUint8ArrayMemory0().set(arg, ptr / 1);
37
+ WASM_VECTOR_LEN = arg.length;
38
+ return ptr;
39
+ }
40
+
41
+ function takeFromExternrefTable0(idx) {
42
+ const value = wasm.__wbindgen_export_0.get(idx);
43
+ wasm.__externref_table_dealloc(idx);
44
+ return value;
45
+ }
46
+
47
+ let cachedDataViewMemory0 = null;
48
+
49
+ function getDataViewMemory0() {
50
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
51
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
52
+ }
53
+ return cachedDataViewMemory0;
54
+ }
55
+
56
+ function getArrayJsValueFromWasm0(ptr, len) {
57
+ ptr = ptr >>> 0;
58
+ const mem = getDataViewMemory0();
59
+ const result = [];
60
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
61
+ result.push(wasm.__wbindgen_export_0.get(mem.getUint32(i, true)));
62
+ }
63
+ wasm.__externref_drop_slice(ptr, len);
64
+ return result;
65
+ }
66
+ /**
67
+ * Scan grayscale image data for barcodes and QR codes.
68
+ *
69
+ * `data` must be an array of 8-bit grayscale pixel values,
70
+ * row-major, with dimensions `width` x `height`.
71
+ *
72
+ * Returns an array of `DecodeResult` objects.
73
+ * @param {Uint8Array} data
74
+ * @param {number} width
75
+ * @param {number} height
76
+ * @returns {DecodeResult[]}
77
+ */
78
+ exports.scanGrayscale = function(data, width, height) {
79
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
80
+ const len0 = WASM_VECTOR_LEN;
81
+ const ret = wasm.scanGrayscale(ptr0, len0, width, height);
82
+ if (ret[3]) {
83
+ throw takeFromExternrefTable0(ret[2]);
84
+ }
85
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
86
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
87
+ return v2;
88
+ };
89
+
90
+ const DecodeResultFinalization = (typeof FinalizationRegistry === 'undefined')
91
+ ? { register: () => {}, unregister: () => {} }
92
+ : new FinalizationRegistry(ptr => wasm.__wbg_decoderesult_free(ptr >>> 0, 1));
93
+ /**
94
+ * A decoded barcode/QR code result.
95
+ */
96
+ class DecodeResult {
97
+
98
+ static __wrap(ptr) {
99
+ ptr = ptr >>> 0;
100
+ const obj = Object.create(DecodeResult.prototype);
101
+ obj.__wbg_ptr = ptr;
102
+ DecodeResultFinalization.register(obj, obj.__wbg_ptr, obj);
103
+ return obj;
104
+ }
105
+
106
+ __destroy_into_raw() {
107
+ const ptr = this.__wbg_ptr;
108
+ this.__wbg_ptr = 0;
109
+ DecodeResultFinalization.unregister(this);
110
+ return ptr;
111
+ }
112
+
113
+ free() {
114
+ const ptr = this.__destroy_into_raw();
115
+ wasm.__wbg_decoderesult_free(ptr, 0);
116
+ }
117
+ /**
118
+ * The barcode format name (e.g. "QR-Code", "EAN-13").
119
+ * @returns {string}
120
+ */
121
+ get symbolType() {
122
+ let deferred1_0;
123
+ let deferred1_1;
124
+ try {
125
+ const ret = wasm.decoderesult_symbolType(this.__wbg_ptr);
126
+ deferred1_0 = ret[0];
127
+ deferred1_1 = ret[1];
128
+ return getStringFromWasm0(ret[0], ret[1]);
129
+ } finally {
130
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
131
+ }
132
+ }
133
+ /**
134
+ * Raw decoded bytes.
135
+ * @returns {Uint8Array}
136
+ */
137
+ get data() {
138
+ const ret = wasm.decoderesult_data(this.__wbg_ptr);
139
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
140
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
141
+ return v1;
142
+ }
143
+ /**
144
+ * Decoded data as UTF-8 text, or null if not valid UTF-8.
145
+ * @returns {string | undefined}
146
+ */
147
+ get text() {
148
+ const ret = wasm.decoderesult_text(this.__wbg_ptr);
149
+ let v1;
150
+ if (ret[0] !== 0) {
151
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
152
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
153
+ }
154
+ return v1;
155
+ }
156
+ }
157
+ if (Symbol.dispose) DecodeResult.prototype[Symbol.dispose] = DecodeResult.prototype.free;
158
+
159
+ exports.DecodeResult = DecodeResult;
160
+
161
+ exports.__wbg_decoderesult_new = function(arg0) {
162
+ const ret = DecodeResult.__wrap(arg0);
163
+ return ret;
164
+ };
165
+
166
+ exports.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
167
+ throw new Error(getStringFromWasm0(arg0, arg1));
168
+ };
169
+
170
+ exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
171
+ // Cast intrinsic for `Ref(String) -> Externref`.
172
+ const ret = getStringFromWasm0(arg0, arg1);
173
+ return ret;
174
+ };
175
+
176
+ exports.__wbindgen_init_externref_table = function() {
177
+ const table = wasm.__wbindgen_export_0;
178
+ const offset = table.grow(4);
179
+ table.set(0, undefined);
180
+ table.set(offset + 0, undefined);
181
+ table.set(offset + 1, null);
182
+ table.set(offset + 2, true);
183
+ table.set(offset + 3, false);
184
+ ;
185
+ };
186
+
187
+ const wasmPath = `${__dirname}/zedbar_bg.wasm`;
188
+ const wasmBytes = require('fs').readFileSync(wasmPath);
189
+ const wasmModule = new WebAssembly.Module(wasmBytes);
190
+ const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;
191
+
192
+ wasm.__wbindgen_start();
193
+
package/zedbar_bg.wasm ADDED
Binary file