rxing-wasm 0.3.0 → 0.3.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
@@ -24,6 +24,37 @@ function decodeBarcode(canvas) {
24
24
  }
25
25
  ```
26
26
 
27
+ The `convert_canvas_to_luma` function is used to convert a canvas to the luma 8
28
+ format that rxing expects. An example might look like to below.
29
+
30
+ ```javascript
31
+ function decodeBarcode(canvas) {
32
+ let height = canvas.height;
33
+ let width = canvas.width;
34
+ let luma8Data = convert_canvas_to_luma(canvas);
35
+ let parsedBarcode = decode_barcode(luma8Data, width, height);
36
+
37
+ return parsedBarcode;
38
+ }
39
+ ```
40
+
41
+ The `convert_imagedata_to_luma` function is used to convert an ImageData object to the luma 8
42
+ format that rxing expects. An example might look like to below.
43
+
44
+ ```javascript
45
+ function decodeBarcode(canvas) {
46
+ let context = canvas.getContext('2d');
47
+ let height = canvas.height;
48
+ let width = canvas.width;
49
+ let imageData = context.getImageData(0, 0, width, height);
50
+
51
+ let luma8Data = convert_imagedata_to_luma(imageData);
52
+ let parsedBarcode = decode_barcode(luma8Data, width, height);
53
+
54
+ return parsedBarcode;
55
+ }
56
+ ```
57
+
27
58
  ## Hints
28
59
  ### Using the `DecodeHintDictionary` class
29
60
  Add a hint with `set_hint(hint: DecodeHintTypes, value: string)`. The function returns `true` if the hint was added and `false` if it was not. The value of hint must be a `number` representing on of the enum values for `DecodeHintTypes`. The easiest way to use this is to simply pass in one of the values from `DecodeHintTypes`.
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.3.0",
5
+ "version": "0.3.1",
6
6
  "license": "Apache 2.0",
7
7
  "repository": {
8
8
  "type": "git",
package/rxing_wasm.d.ts CHANGED
@@ -41,6 +41,16 @@ export function decode_barcode(data: Uint8Array, width: number, height: number,
41
41
  */
42
42
  export function convert_js_image_to_luma(data: Uint8Array): Uint8Array;
43
43
  /**
44
+ * @param {HTMLCanvasElement} canvas
45
+ * @returns {Uint8Array}
46
+ */
47
+ export function convert_canvas_to_luma(canvas: HTMLCanvasElement): Uint8Array;
48
+ /**
49
+ * @param {ImageData} image_data
50
+ * @returns {Uint8Array}
51
+ */
52
+ export function convert_imagedata_to_luma(image_data: ImageData): Uint8Array;
53
+ /**
44
54
  * Decode a barcode from an array of rgba data.
45
55
  * Pixel data is in the form of:
46
56
  * Each pixel is one u32, [r,g,b].
@@ -242,83 +252,6 @@ export enum EncodeHintTypes {
242
252
  TelepenAsNumeric = 19,
243
253
  }
244
254
  /**
245
- * Available barcode types
246
- */
247
- export enum BarcodeFormat {
248
- /**
249
- * Aztec 2D barcode format.
250
- */
251
- AZTEC = 0,
252
- /**
253
- * CODABAR 1D format.
254
- */
255
- CODABAR = 1,
256
- /**
257
- * Code 39 1D format.
258
- */
259
- Code39 = 2,
260
- /**
261
- * Code 93 1D format.
262
- */
263
- Code93 = 3,
264
- /**
265
- * Code 128 1D format.
266
- */
267
- Code128 = 4,
268
- /**
269
- * Data Matrix 2D barcode format.
270
- */
271
- DataMatrix = 5,
272
- /**
273
- * EAN-8 1D format.
274
- */
275
- Ean8 = 6,
276
- /**
277
- * EAN-13 1D format.
278
- */
279
- Ean13 = 7,
280
- /**
281
- * ITF (Interleaved Two of Five) 1D format.
282
- */
283
- ITF = 8,
284
- /**
285
- * MaxiCode 2D barcode format.
286
- */
287
- MAXICODE = 9,
288
- /**
289
- * PDF417 format.
290
- */
291
- Pdf417 = 10,
292
- /**
293
- * QR Code 2D barcode format.
294
- */
295
- QrCode = 11,
296
- /**
297
- * RSS 14
298
- */
299
- Rss14 = 12,
300
- /**
301
- * RSS EXPANDED
302
- */
303
- RssExpanded = 13,
304
- /**
305
- * UPC-A 1D format.
306
- */
307
- UpcA = 14,
308
- /**
309
- * UPC-E 1D format.
310
- */
311
- UpcE = 15,
312
- /**
313
- * UPC/EAN extension format. Not a stand-alone format.
314
- */
315
- UpcEanExtension = 16,
316
- MicroQR = 17,
317
- Telepen = 18,
318
- RectangularMicroQR = 19,
319
- UnsuportedFormat = 20,
320
- }
321
- /**
322
255
  */
323
256
  export enum DecodeHintTypes {
324
257
  /**
@@ -415,6 +348,83 @@ export enum DecodeHintTypes {
415
348
  TelepenAsNumeric = 12,
416
349
  }
417
350
  /**
351
+ * Available barcode types
352
+ */
353
+ export enum BarcodeFormat {
354
+ /**
355
+ * Aztec 2D barcode format.
356
+ */
357
+ AZTEC = 0,
358
+ /**
359
+ * CODABAR 1D format.
360
+ */
361
+ CODABAR = 1,
362
+ /**
363
+ * Code 39 1D format.
364
+ */
365
+ Code39 = 2,
366
+ /**
367
+ * Code 93 1D format.
368
+ */
369
+ Code93 = 3,
370
+ /**
371
+ * Code 128 1D format.
372
+ */
373
+ Code128 = 4,
374
+ /**
375
+ * Data Matrix 2D barcode format.
376
+ */
377
+ DataMatrix = 5,
378
+ /**
379
+ * EAN-8 1D format.
380
+ */
381
+ Ean8 = 6,
382
+ /**
383
+ * EAN-13 1D format.
384
+ */
385
+ Ean13 = 7,
386
+ /**
387
+ * ITF (Interleaved Two of Five) 1D format.
388
+ */
389
+ ITF = 8,
390
+ /**
391
+ * MaxiCode 2D barcode format.
392
+ */
393
+ MAXICODE = 9,
394
+ /**
395
+ * PDF417 format.
396
+ */
397
+ Pdf417 = 10,
398
+ /**
399
+ * QR Code 2D barcode format.
400
+ */
401
+ QrCode = 11,
402
+ /**
403
+ * RSS 14
404
+ */
405
+ Rss14 = 12,
406
+ /**
407
+ * RSS EXPANDED
408
+ */
409
+ RssExpanded = 13,
410
+ /**
411
+ * UPC-A 1D format.
412
+ */
413
+ UpcA = 14,
414
+ /**
415
+ * UPC-E 1D format.
416
+ */
417
+ UpcE = 15,
418
+ /**
419
+ * UPC/EAN extension format. Not a stand-alone format.
420
+ */
421
+ UpcEanExtension = 16,
422
+ MicroQR = 17,
423
+ Telepen = 18,
424
+ RectangularMicroQR = 19,
425
+ UnsuportedFormat = 20,
426
+ }
427
+ /**
418
428
  */
419
429
  export class BarcodeResult {
420
430
  free(): void;
package/rxing_wasm_bg.js CHANGED
@@ -279,6 +279,56 @@ export function convert_js_image_to_luma(data) {
279
279
  }
280
280
  }
281
281
 
282
+ let stack_pointer = 128;
283
+
284
+ function addBorrowedObject(obj) {
285
+ if (stack_pointer == 1) throw new Error('out of js stack');
286
+ heap[--stack_pointer] = obj;
287
+ return stack_pointer;
288
+ }
289
+ /**
290
+ * @param {HTMLCanvasElement} canvas
291
+ * @returns {Uint8Array}
292
+ */
293
+ export function convert_canvas_to_luma(canvas) {
294
+ try {
295
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
296
+ wasm.convert_canvas_to_luma(retptr, addBorrowedObject(canvas));
297
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
298
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
299
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
300
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
301
+ if (r3) {
302
+ throw takeObject(r2);
303
+ }
304
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
305
+ wasm.__wbindgen_free(r0, r1 * 1, 1);
306
+ return v1;
307
+ } finally {
308
+ wasm.__wbindgen_add_to_stack_pointer(16);
309
+ heap[stack_pointer++] = undefined;
310
+ }
311
+ }
312
+
313
+ /**
314
+ * @param {ImageData} image_data
315
+ * @returns {Uint8Array}
316
+ */
317
+ export function convert_imagedata_to_luma(image_data) {
318
+ try {
319
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
320
+ wasm.convert_imagedata_to_luma(retptr, addBorrowedObject(image_data));
321
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
322
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
323
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
324
+ wasm.__wbindgen_free(r0, r1 * 1, 1);
325
+ return v1;
326
+ } finally {
327
+ wasm.__wbindgen_add_to_stack_pointer(16);
328
+ heap[stack_pointer++] = undefined;
329
+ }
330
+ }
331
+
282
332
  let cachedUint32Memory0 = null;
283
333
 
284
334
  function getUint32Memory0() {
@@ -389,6 +439,13 @@ export function decode_multi(data, width, height, hints, filter_image) {
389
439
  }
390
440
  }
391
441
 
442
+ function handleError(f, args) {
443
+ try {
444
+ return f.apply(this, args);
445
+ } catch (e) {
446
+ wasm.__wbindgen_exn_store(addHeapObject(e));
447
+ }
448
+ }
392
449
  /**
393
450
  */
394
451
  export const EncodeHintTypes = Object.freeze({
@@ -560,78 +617,6 @@ ForceC40:17,"17":"ForceC40",
560
617
  */
561
618
  Code128Compact:18,"18":"Code128Compact",TelepenAsNumeric:19,"19":"TelepenAsNumeric", });
562
619
  /**
563
- * Available barcode types
564
- */
565
- export const BarcodeFormat = Object.freeze({
566
- /**
567
- * Aztec 2D barcode format.
568
- */
569
- AZTEC:0,"0":"AZTEC",
570
- /**
571
- * CODABAR 1D format.
572
- */
573
- CODABAR:1,"1":"CODABAR",
574
- /**
575
- * Code 39 1D format.
576
- */
577
- Code39:2,"2":"Code39",
578
- /**
579
- * Code 93 1D format.
580
- */
581
- Code93:3,"3":"Code93",
582
- /**
583
- * Code 128 1D format.
584
- */
585
- Code128:4,"4":"Code128",
586
- /**
587
- * Data Matrix 2D barcode format.
588
- */
589
- DataMatrix:5,"5":"DataMatrix",
590
- /**
591
- * EAN-8 1D format.
592
- */
593
- Ean8:6,"6":"Ean8",
594
- /**
595
- * EAN-13 1D format.
596
- */
597
- Ean13:7,"7":"Ean13",
598
- /**
599
- * ITF (Interleaved Two of Five) 1D format.
600
- */
601
- ITF:8,"8":"ITF",
602
- /**
603
- * MaxiCode 2D barcode format.
604
- */
605
- MAXICODE:9,"9":"MAXICODE",
606
- /**
607
- * PDF417 format.
608
- */
609
- Pdf417:10,"10":"Pdf417",
610
- /**
611
- * QR Code 2D barcode format.
612
- */
613
- QrCode:11,"11":"QrCode",
614
- /**
615
- * RSS 14
616
- */
617
- Rss14:12,"12":"Rss14",
618
- /**
619
- * RSS EXPANDED
620
- */
621
- RssExpanded:13,"13":"RssExpanded",
622
- /**
623
- * UPC-A 1D format.
624
- */
625
- UpcA:14,"14":"UpcA",
626
- /**
627
- * UPC-E 1D format.
628
- */
629
- UpcE:15,"15":"UpcE",
630
- /**
631
- * UPC/EAN extension format. Not a stand-alone format.
632
- */
633
- UpcEanExtension:16,"16":"UpcEanExtension",MicroQR:17,"17":"MicroQR",Telepen:18,"18":"Telepen",RectangularMicroQR:19,"19":"RectangularMicroQR",UnsuportedFormat:20,"20":"UnsuportedFormat", });
634
- /**
635
620
  */
636
621
  export const DecodeHintTypes = Object.freeze({
637
622
  /**
@@ -726,6 +711,78 @@ AlsoInverted:11,"11":"AlsoInverted",
726
711
  *
727
712
  */
728
713
  TelepenAsNumeric:12,"12":"TelepenAsNumeric", });
714
+ /**
715
+ * Available barcode types
716
+ */
717
+ export const BarcodeFormat = Object.freeze({
718
+ /**
719
+ * Aztec 2D barcode format.
720
+ */
721
+ AZTEC:0,"0":"AZTEC",
722
+ /**
723
+ * CODABAR 1D format.
724
+ */
725
+ CODABAR:1,"1":"CODABAR",
726
+ /**
727
+ * Code 39 1D format.
728
+ */
729
+ Code39:2,"2":"Code39",
730
+ /**
731
+ * Code 93 1D format.
732
+ */
733
+ Code93:3,"3":"Code93",
734
+ /**
735
+ * Code 128 1D format.
736
+ */
737
+ Code128:4,"4":"Code128",
738
+ /**
739
+ * Data Matrix 2D barcode format.
740
+ */
741
+ DataMatrix:5,"5":"DataMatrix",
742
+ /**
743
+ * EAN-8 1D format.
744
+ */
745
+ Ean8:6,"6":"Ean8",
746
+ /**
747
+ * EAN-13 1D format.
748
+ */
749
+ Ean13:7,"7":"Ean13",
750
+ /**
751
+ * ITF (Interleaved Two of Five) 1D format.
752
+ */
753
+ ITF:8,"8":"ITF",
754
+ /**
755
+ * MaxiCode 2D barcode format.
756
+ */
757
+ MAXICODE:9,"9":"MAXICODE",
758
+ /**
759
+ * PDF417 format.
760
+ */
761
+ Pdf417:10,"10":"Pdf417",
762
+ /**
763
+ * QR Code 2D barcode format.
764
+ */
765
+ QrCode:11,"11":"QrCode",
766
+ /**
767
+ * RSS 14
768
+ */
769
+ Rss14:12,"12":"Rss14",
770
+ /**
771
+ * RSS EXPANDED
772
+ */
773
+ RssExpanded:13,"13":"RssExpanded",
774
+ /**
775
+ * UPC-A 1D format.
776
+ */
777
+ UpcA:14,"14":"UpcA",
778
+ /**
779
+ * UPC-E 1D format.
780
+ */
781
+ UpcE:15,"15":"UpcE",
782
+ /**
783
+ * UPC/EAN extension format. Not a stand-alone format.
784
+ */
785
+ UpcEanExtension:16,"16":"UpcEanExtension",MicroQR:17,"17":"MicroQR",Telepen:18,"18":"Telepen",RectangularMicroQR:19,"19":"RectangularMicroQR",UnsuportedFormat:20,"20":"UnsuportedFormat", });
729
786
 
730
787
  const BarcodeResultFinalization = (typeof FinalizationRegistry === 'undefined')
731
788
  ? { register: () => {}, unregister: () => {} }
@@ -981,6 +1038,45 @@ export function __wbg_barcoderesult_new(arg0) {
981
1038
  return addHeapObject(ret);
982
1039
  };
983
1040
 
1041
+ export function __wbg_instanceof_CanvasRenderingContext2d_20bf99ccc051643b(arg0) {
1042
+ let result;
1043
+ try {
1044
+ result = getObject(arg0) instanceof CanvasRenderingContext2D;
1045
+ } catch (_) {
1046
+ result = false;
1047
+ }
1048
+ const ret = result;
1049
+ return ret;
1050
+ };
1051
+
1052
+ export function __wbg_getImageData_740186e596b34364() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
1053
+ const ret = getObject(arg0).getImageData(arg1, arg2, arg3, arg4);
1054
+ return addHeapObject(ret);
1055
+ }, arguments) };
1056
+
1057
+ export function __wbg_width_aee8b8809b033b05(arg0) {
1058
+ const ret = getObject(arg0).width;
1059
+ return ret;
1060
+ };
1061
+
1062
+ export function __wbg_height_80053d3c71b338e0(arg0) {
1063
+ const ret = getObject(arg0).height;
1064
+ return ret;
1065
+ };
1066
+
1067
+ export function __wbg_getContext_df50fa48a8876636() { return handleError(function (arg0, arg1, arg2) {
1068
+ const ret = getObject(arg0).getContext(getStringFromWasm0(arg1, arg2));
1069
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1070
+ }, arguments) };
1071
+
1072
+ export function __wbg_data_c02d3aac6da15e9f(arg0, arg1) {
1073
+ const ret = getObject(arg1).data;
1074
+ const ptr1 = passArray8ToWasm0(ret, wasm.__wbindgen_malloc);
1075
+ const len1 = WASM_VECTOR_LEN;
1076
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
1077
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
1078
+ };
1079
+
984
1080
  export function __wbg_new_d9bc3a0147634640() {
985
1081
  const ret = new Map();
986
1082
  return addHeapObject(ret);
Binary file