rxing-wasm 0.2.11 → 0.3.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 CHANGED
@@ -1,6 +1,10 @@
1
1
  # rxing-wasm
2
2
  WASM bindings for common rxing functions. The NPM link is [https://www.npmjs.com/package/rxing-wasm](https://www.npmjs.com/package/rxing-wasm) and the rust source is [https://github.com/rxing-core/rxing-wasm](https://github.com/hschimke/rxing-wasm).
3
3
 
4
+ ## Decode Multi Breaking Change with v0.3.0
5
+ Version `0.3.0` now returns `BarcodeResult` objects in a native javascript array. This fully deprecates the old method
6
+ which returned a custom object with internal state.
7
+
4
8
  ## Data
5
9
  The `convert_js_image_to_luma` function is used to convert canvas image data to the luma 8
6
10
  format that rxing expects. An example might look like to below.
@@ -99,7 +103,8 @@ pub fn decode_multi(
99
103
  width: u32,
100
104
  height: u32,
101
105
  hints: &mut decode_hints::DecodeHintDictionary,
102
- ) -> Result<MultiDecodeResult, String>;
106
+ filter_image: Option<bool>,
107
+ ) -> Result<Vec<BarcodeResult>, String>;
103
108
  ```
104
109
 
105
110
  ```rust
@@ -113,6 +118,4 @@ pub fn encode_barcode_with_hints(
113
118
  ```
114
119
 
115
120
  ## Beta Features
116
- `decode_multi` is currently in beta. The output may be unexpected, or undefined. Please use with caution. The interface may be unstable, and change.
117
-
118
121
  `encode_barcode_with_hints` is currently in alpha. The output and behaviour is unexpected and poorly documented. Use at your own risk, feature may change, unstable interface.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "rxing-wasm",
3
3
  "type": "module",
4
4
  "description": "wasm bindings for rxing to provide commong barcode operations (decode/encode)",
5
- "version": "0.2.11",
5
+ "version": "0.3.0",
6
6
  "license": "Apache 2.0",
7
7
  "repository": {
8
8
  "type": "git",
package/rxing_wasm.d.ts CHANGED
@@ -65,105 +65,10 @@ export function decode_barcode_with_hints(data: Uint8Array, width: number, heigh
65
65
  * @param {number} width
66
66
  * @param {number} height
67
67
  * @param {DecodeHintDictionary} hints
68
- * @returns {MultiDecodeResult}
69
- */
70
- export function decode_multi(data: Uint8Array, width: number, height: number, hints: DecodeHintDictionary): MultiDecodeResult;
71
- /**
72
- */
73
- export enum DecodeHintTypes {
74
- /**
75
- *
76
- * * Unspecified, application-specific hint. Maps to an unspecified {@link Object}.
77
- *
78
- */
79
- Other = 0,
80
- /**
81
- *
82
- * * Image is a pure monochrome image of a barcode. Doesn't matter what it maps to;
83
- * * use {@link Boolean#TRUE}.
84
- *
85
- */
86
- PureBarcode = 1,
87
- /**
88
- *
89
- * * Image is known to be of one of a few possible formats.
90
- * * Maps to a {@link List} of {@link BarcodeFormat}s.
91
- *
92
- */
93
- PossibleFormats = 2,
94
- /**
95
- *
96
- * * Spend more time to try to find a barcode; optimize for accuracy, not speed.
97
- * * Doesn't matter what it maps to; use {@link Boolean#TRUE}.
98
- *
99
- */
100
- TryHarder = 3,
101
- /**
102
- *
103
- * * Specifies what character encoding to use when decoding, where applicable (type String)
104
- *
105
- */
106
- CharacterSet = 4,
107
- /**
108
- *
109
- * * Allowed lengths of encoded data -- reject anything else. Maps to an {@code int[]}.
110
- *
111
- */
112
- AllowedLengths = 5,
113
- /**
114
- *
115
- * * Assume Code 39 codes employ a check digit. Doesn't matter what it maps to;
116
- * * use {@link Boolean#TRUE}.
117
- *
118
- */
119
- AssumeCode39CheckDigit = 6,
120
- /**
121
- *
122
- * * Assume the barcode is being processed as a GS1 barcode, and modify behavior as needed.
123
- * * For example this affects FNC1 handling for Code 128 (aka GS1-128). Doesn't matter what it maps to;
124
- * * use {@link Boolean#TRUE}.
125
- *
126
- */
127
- AssumeGs1 = 7,
128
- /**
129
- *
130
- * * If true, return the start and end digits in a Codabar barcode instead of stripping them. They
131
- * * are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them
132
- * * to not be. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
133
- *
134
- */
135
- ReturnCodabarStartEnd = 8,
136
- /**
137
- *
138
- * * The caller needs to be notified via callback when a possible {@link RXingResultPoint}
139
- * * is found. Maps to a {@link RXingResultPointCallback}.
140
- *
141
- */
142
- NeedResultPointCallback = 9,
143
- /**
144
- *
145
- * * Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this.
146
- * * Maps to an {@code int[]} of the allowed extension lengths, for example [2], [5], or [2, 5].
147
- * * If it is optional to have an extension, do not set this hint. If this is set,
148
- * * and a UPC or EAN barcode is found but an extension is not, then no result will be returned
149
- * * at all.
150
- *
151
- */
152
- AllowedEanExtensions = 10,
153
- /**
154
- *
155
- * * If true, also tries to decode as inverted image. All configured decoders are simply called a
156
- * * second time with an inverted image. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
157
- *
158
- */
159
- AlsoInverted = 11,
160
- /**
161
- *
162
- * * Translate the ASCII values parsed by the Telepen reader into the Telepen Numeric form; use {@link Boolean#TRUE}.
163
- *
68
+ * @param {boolean | undefined} [filter_image]
69
+ * @returns {(BarcodeResult)[]}
164
70
  */
165
- TelepenAsNumeric = 12,
166
- }
71
+ export function decode_multi(data: Uint8Array, width: number, height: number, hints: DecodeHintDictionary, filter_image?: boolean): (BarcodeResult)[];
167
72
  /**
168
73
  */
169
74
  export enum EncodeHintTypes {
@@ -415,6 +320,102 @@ export enum BarcodeFormat {
415
320
  }
416
321
  /**
417
322
  */
323
+ export enum DecodeHintTypes {
324
+ /**
325
+ *
326
+ * * Unspecified, application-specific hint. Maps to an unspecified {@link Object}.
327
+ *
328
+ */
329
+ Other = 0,
330
+ /**
331
+ *
332
+ * * Image is a pure monochrome image of a barcode. Doesn't matter what it maps to;
333
+ * * use {@link Boolean#TRUE}.
334
+ *
335
+ */
336
+ PureBarcode = 1,
337
+ /**
338
+ *
339
+ * * Image is known to be of one of a few possible formats.
340
+ * * Maps to a {@link List} of {@link BarcodeFormat}s.
341
+ *
342
+ */
343
+ PossibleFormats = 2,
344
+ /**
345
+ *
346
+ * * Spend more time to try to find a barcode; optimize for accuracy, not speed.
347
+ * * Doesn't matter what it maps to; use {@link Boolean#TRUE}.
348
+ *
349
+ */
350
+ TryHarder = 3,
351
+ /**
352
+ *
353
+ * * Specifies what character encoding to use when decoding, where applicable (type String)
354
+ *
355
+ */
356
+ CharacterSet = 4,
357
+ /**
358
+ *
359
+ * * Allowed lengths of encoded data -- reject anything else. Maps to an {@code int[]}.
360
+ *
361
+ */
362
+ AllowedLengths = 5,
363
+ /**
364
+ *
365
+ * * Assume Code 39 codes employ a check digit. Doesn't matter what it maps to;
366
+ * * use {@link Boolean#TRUE}.
367
+ *
368
+ */
369
+ AssumeCode39CheckDigit = 6,
370
+ /**
371
+ *
372
+ * * Assume the barcode is being processed as a GS1 barcode, and modify behavior as needed.
373
+ * * For example this affects FNC1 handling for Code 128 (aka GS1-128). Doesn't matter what it maps to;
374
+ * * use {@link Boolean#TRUE}.
375
+ *
376
+ */
377
+ AssumeGs1 = 7,
378
+ /**
379
+ *
380
+ * * If true, return the start and end digits in a Codabar barcode instead of stripping them. They
381
+ * * are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them
382
+ * * to not be. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
383
+ *
384
+ */
385
+ ReturnCodabarStartEnd = 8,
386
+ /**
387
+ *
388
+ * * The caller needs to be notified via callback when a possible {@link RXingResultPoint}
389
+ * * is found. Maps to a {@link RXingResultPointCallback}.
390
+ *
391
+ */
392
+ NeedResultPointCallback = 9,
393
+ /**
394
+ *
395
+ * * Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this.
396
+ * * Maps to an {@code int[]} of the allowed extension lengths, for example [2], [5], or [2, 5].
397
+ * * If it is optional to have an extension, do not set this hint. If this is set,
398
+ * * and a UPC or EAN barcode is found but an extension is not, then no result will be returned
399
+ * * at all.
400
+ *
401
+ */
402
+ AllowedEanExtensions = 10,
403
+ /**
404
+ *
405
+ * * If true, also tries to decode as inverted image. All configured decoders are simply called a
406
+ * * second time with an inverted image. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
407
+ *
408
+ */
409
+ AlsoInverted = 11,
410
+ /**
411
+ *
412
+ * * Translate the ASCII values parsed by the Telepen reader into the Telepen Numeric form; use {@link Boolean#TRUE}.
413
+ *
414
+ */
415
+ TelepenAsNumeric = 12,
416
+ }
417
+ /**
418
+ */
418
419
  export class BarcodeResult {
419
420
  free(): void;
420
421
  /**
@@ -495,15 +496,3 @@ export class EncodeHintDictionary {
495
496
  */
496
497
  remove_hint(hint: EncodeHintTypes): boolean;
497
498
  }
498
- /**
499
- */
500
- export class MultiDecodeResult {
501
- free(): void;
502
- /**
503
- */
504
- constructor();
505
- /**
506
- * @returns {BarcodeResult | undefined}
507
- */
508
- next(): BarcodeResult | undefined;
509
- }
package/rxing_wasm_bg.js CHANGED
@@ -349,127 +349,46 @@ export function decode_barcode_with_hints(data, width, height, hints, filter_ima
349
349
  }
350
350
  }
351
351
 
352
+ function getArrayJsValueFromWasm0(ptr, len) {
353
+ ptr = ptr >>> 0;
354
+ const mem = getUint32Memory0();
355
+ const slice = mem.subarray(ptr / 4, ptr / 4 + len);
356
+ const result = [];
357
+ for (let i = 0; i < slice.length; i++) {
358
+ result.push(takeObject(slice[i]));
359
+ }
360
+ return result;
361
+ }
352
362
  /**
353
363
  * @param {Uint8Array} data
354
364
  * @param {number} width
355
365
  * @param {number} height
356
366
  * @param {DecodeHintDictionary} hints
357
- * @returns {MultiDecodeResult}
367
+ * @param {boolean | undefined} [filter_image]
368
+ * @returns {(BarcodeResult)[]}
358
369
  */
359
- export function decode_multi(data, width, height, hints) {
370
+ export function decode_multi(data, width, height, hints, filter_image) {
360
371
  try {
361
372
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
362
373
  const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
363
374
  const len0 = WASM_VECTOR_LEN;
364
375
  _assertClass(hints, DecodeHintDictionary);
365
- wasm.decode_multi(retptr, ptr0, len0, width, height, hints.__wbg_ptr);
376
+ wasm.decode_multi(retptr, ptr0, len0, width, height, hints.__wbg_ptr, isLikeNone(filter_image) ? 0xFFFFFF : filter_image ? 1 : 0);
366
377
  var r0 = getInt32Memory0()[retptr / 4 + 0];
367
378
  var r1 = getInt32Memory0()[retptr / 4 + 1];
368
379
  var r2 = getInt32Memory0()[retptr / 4 + 2];
369
- if (r2) {
370
- throw takeObject(r1);
380
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
381
+ if (r3) {
382
+ throw takeObject(r2);
371
383
  }
372
- return MultiDecodeResult.__wrap(r0);
384
+ var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
385
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
386
+ return v2;
373
387
  } finally {
374
388
  wasm.__wbindgen_add_to_stack_pointer(16);
375
389
  }
376
390
  }
377
391
 
378
- /**
379
- */
380
- export const DecodeHintTypes = Object.freeze({
381
- /**
382
- *
383
- * * Unspecified, application-specific hint. Maps to an unspecified {@link Object}.
384
- *
385
- */
386
- Other:0,"0":"Other",
387
- /**
388
- *
389
- * * Image is a pure monochrome image of a barcode. Doesn't matter what it maps to;
390
- * * use {@link Boolean#TRUE}.
391
- *
392
- */
393
- PureBarcode:1,"1":"PureBarcode",
394
- /**
395
- *
396
- * * Image is known to be of one of a few possible formats.
397
- * * Maps to a {@link List} of {@link BarcodeFormat}s.
398
- *
399
- */
400
- PossibleFormats:2,"2":"PossibleFormats",
401
- /**
402
- *
403
- * * Spend more time to try to find a barcode; optimize for accuracy, not speed.
404
- * * Doesn't matter what it maps to; use {@link Boolean#TRUE}.
405
- *
406
- */
407
- TryHarder:3,"3":"TryHarder",
408
- /**
409
- *
410
- * * Specifies what character encoding to use when decoding, where applicable (type String)
411
- *
412
- */
413
- CharacterSet:4,"4":"CharacterSet",
414
- /**
415
- *
416
- * * Allowed lengths of encoded data -- reject anything else. Maps to an {@code int[]}.
417
- *
418
- */
419
- AllowedLengths:5,"5":"AllowedLengths",
420
- /**
421
- *
422
- * * Assume Code 39 codes employ a check digit. Doesn't matter what it maps to;
423
- * * use {@link Boolean#TRUE}.
424
- *
425
- */
426
- AssumeCode39CheckDigit:6,"6":"AssumeCode39CheckDigit",
427
- /**
428
- *
429
- * * Assume the barcode is being processed as a GS1 barcode, and modify behavior as needed.
430
- * * For example this affects FNC1 handling for Code 128 (aka GS1-128). Doesn't matter what it maps to;
431
- * * use {@link Boolean#TRUE}.
432
- *
433
- */
434
- AssumeGs1:7,"7":"AssumeGs1",
435
- /**
436
- *
437
- * * If true, return the start and end digits in a Codabar barcode instead of stripping them. They
438
- * * are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them
439
- * * to not be. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
440
- *
441
- */
442
- ReturnCodabarStartEnd:8,"8":"ReturnCodabarStartEnd",
443
- /**
444
- *
445
- * * The caller needs to be notified via callback when a possible {@link RXingResultPoint}
446
- * * is found. Maps to a {@link RXingResultPointCallback}.
447
- *
448
- */
449
- NeedResultPointCallback:9,"9":"NeedResultPointCallback",
450
- /**
451
- *
452
- * * Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this.
453
- * * Maps to an {@code int[]} of the allowed extension lengths, for example [2], [5], or [2, 5].
454
- * * If it is optional to have an extension, do not set this hint. If this is set,
455
- * * and a UPC or EAN barcode is found but an extension is not, then no result will be returned
456
- * * at all.
457
- *
458
- */
459
- AllowedEanExtensions:10,"10":"AllowedEanExtensions",
460
- /**
461
- *
462
- * * If true, also tries to decode as inverted image. All configured decoders are simply called a
463
- * * second time with an inverted image. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
464
- *
465
- */
466
- AlsoInverted:11,"11":"AlsoInverted",
467
- /**
468
- *
469
- * * Translate the ASCII values parsed by the Telepen reader into the Telepen Numeric form; use {@link Boolean#TRUE}.
470
- *
471
- */
472
- TelepenAsNumeric:12,"12":"TelepenAsNumeric", });
473
392
  /**
474
393
  */
475
394
  export const EncodeHintTypes = Object.freeze({
@@ -712,6 +631,101 @@ UpcE:15,"15":"UpcE",
712
631
  * UPC/EAN extension format. Not a stand-alone format.
713
632
  */
714
633
  UpcEanExtension:16,"16":"UpcEanExtension",MicroQR:17,"17":"MicroQR",Telepen:18,"18":"Telepen",RectangularMicroQR:19,"19":"RectangularMicroQR",UnsuportedFormat:20,"20":"UnsuportedFormat", });
634
+ /**
635
+ */
636
+ export const DecodeHintTypes = Object.freeze({
637
+ /**
638
+ *
639
+ * * Unspecified, application-specific hint. Maps to an unspecified {@link Object}.
640
+ *
641
+ */
642
+ Other:0,"0":"Other",
643
+ /**
644
+ *
645
+ * * Image is a pure monochrome image of a barcode. Doesn't matter what it maps to;
646
+ * * use {@link Boolean#TRUE}.
647
+ *
648
+ */
649
+ PureBarcode:1,"1":"PureBarcode",
650
+ /**
651
+ *
652
+ * * Image is known to be of one of a few possible formats.
653
+ * * Maps to a {@link List} of {@link BarcodeFormat}s.
654
+ *
655
+ */
656
+ PossibleFormats:2,"2":"PossibleFormats",
657
+ /**
658
+ *
659
+ * * Spend more time to try to find a barcode; optimize for accuracy, not speed.
660
+ * * Doesn't matter what it maps to; use {@link Boolean#TRUE}.
661
+ *
662
+ */
663
+ TryHarder:3,"3":"TryHarder",
664
+ /**
665
+ *
666
+ * * Specifies what character encoding to use when decoding, where applicable (type String)
667
+ *
668
+ */
669
+ CharacterSet:4,"4":"CharacterSet",
670
+ /**
671
+ *
672
+ * * Allowed lengths of encoded data -- reject anything else. Maps to an {@code int[]}.
673
+ *
674
+ */
675
+ AllowedLengths:5,"5":"AllowedLengths",
676
+ /**
677
+ *
678
+ * * Assume Code 39 codes employ a check digit. Doesn't matter what it maps to;
679
+ * * use {@link Boolean#TRUE}.
680
+ *
681
+ */
682
+ AssumeCode39CheckDigit:6,"6":"AssumeCode39CheckDigit",
683
+ /**
684
+ *
685
+ * * Assume the barcode is being processed as a GS1 barcode, and modify behavior as needed.
686
+ * * For example this affects FNC1 handling for Code 128 (aka GS1-128). Doesn't matter what it maps to;
687
+ * * use {@link Boolean#TRUE}.
688
+ *
689
+ */
690
+ AssumeGs1:7,"7":"AssumeGs1",
691
+ /**
692
+ *
693
+ * * If true, return the start and end digits in a Codabar barcode instead of stripping them. They
694
+ * * are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them
695
+ * * to not be. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
696
+ *
697
+ */
698
+ ReturnCodabarStartEnd:8,"8":"ReturnCodabarStartEnd",
699
+ /**
700
+ *
701
+ * * The caller needs to be notified via callback when a possible {@link RXingResultPoint}
702
+ * * is found. Maps to a {@link RXingResultPointCallback}.
703
+ *
704
+ */
705
+ NeedResultPointCallback:9,"9":"NeedResultPointCallback",
706
+ /**
707
+ *
708
+ * * Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this.
709
+ * * Maps to an {@code int[]} of the allowed extension lengths, for example [2], [5], or [2, 5].
710
+ * * If it is optional to have an extension, do not set this hint. If this is set,
711
+ * * and a UPC or EAN barcode is found but an extension is not, then no result will be returned
712
+ * * at all.
713
+ *
714
+ */
715
+ AllowedEanExtensions:10,"10":"AllowedEanExtensions",
716
+ /**
717
+ *
718
+ * * If true, also tries to decode as inverted image. All configured decoders are simply called a
719
+ * * second time with an inverted image. Doesn't matter what it maps to; use {@link Boolean#TRUE}.
720
+ *
721
+ */
722
+ AlsoInverted:11,"11":"AlsoInverted",
723
+ /**
724
+ *
725
+ * * Translate the ASCII values parsed by the Telepen reader into the Telepen Numeric form; use {@link Boolean#TRUE}.
726
+ *
727
+ */
728
+ TelepenAsNumeric:12,"12":"TelepenAsNumeric", });
715
729
 
716
730
  const BarcodeResultFinalization = (typeof FinalizationRegistry === 'undefined')
717
731
  ? { register: () => {}, unregister: () => {} }
@@ -953,48 +967,6 @@ export class EncodeHintDictionary {
953
967
  }
954
968
  }
955
969
 
956
- const MultiDecodeResultFinalization = (typeof FinalizationRegistry === 'undefined')
957
- ? { register: () => {}, unregister: () => {} }
958
- : new FinalizationRegistry(ptr => wasm.__wbg_multidecoderesult_free(ptr >>> 0));
959
- /**
960
- */
961
- export class MultiDecodeResult {
962
-
963
- static __wrap(ptr) {
964
- ptr = ptr >>> 0;
965
- const obj = Object.create(MultiDecodeResult.prototype);
966
- obj.__wbg_ptr = ptr;
967
- MultiDecodeResultFinalization.register(obj, obj.__wbg_ptr, obj);
968
- return obj;
969
- }
970
-
971
- __destroy_into_raw() {
972
- const ptr = this.__wbg_ptr;
973
- this.__wbg_ptr = 0;
974
- MultiDecodeResultFinalization.unregister(this);
975
- return ptr;
976
- }
977
-
978
- free() {
979
- const ptr = this.__destroy_into_raw();
980
- wasm.__wbg_multidecoderesult_free(ptr);
981
- }
982
- /**
983
- */
984
- constructor() {
985
- const ret = wasm.multidecoderesult_new();
986
- this.__wbg_ptr = ret >>> 0;
987
- return this;
988
- }
989
- /**
990
- * @returns {BarcodeResult | undefined}
991
- */
992
- next() {
993
- const ret = wasm.multidecoderesult_next(this.__wbg_ptr);
994
- return ret === 0 ? undefined : BarcodeResult.__wrap(ret);
995
- }
996
- }
997
-
998
970
  export function __wbindgen_object_drop_ref(arg0) {
999
971
  takeObject(arg0);
1000
972
  };
@@ -1004,6 +976,11 @@ export function __wbindgen_string_new(arg0, arg1) {
1004
976
  return addHeapObject(ret);
1005
977
  };
1006
978
 
979
+ export function __wbg_barcoderesult_new(arg0) {
980
+ const ret = BarcodeResult.__wrap(arg0);
981
+ return addHeapObject(ret);
982
+ };
983
+
1007
984
  export function __wbg_new_d9bc3a0147634640() {
1008
985
  const ret = new Map();
1009
986
  return addHeapObject(ret);
Binary file