1 | import { Barcode } from "./barcode";
|
2 | import { ImageSettings } from "./imageSettings";
|
3 |
|
4 | /**
|
5 | * A result of a scanning operation on an image.
|
6 | */
|
7 | export class ScanResult {
|
8 | /**
|
9 | * The list of barcodes found in the image (can be empty).
|
10 | */
|
11 | public readonly barcodes: Barcode[];
|
12 | /**
|
13 | * The image data given as a byte array, formatted accordingly to the set settings ([[imageSettings]]).
|
14 | */
|
15 | public readonly imageData: Uint8ClampedArray;
|
16 |
|
17 | /**
|
18 | * The configuration object defining the properties of the processed image ([[imageData]]).
|
19 | */
|
20 | public readonly imageSettings: ImageSettings;
|
21 |
|
22 | /**
|
23 | * @hidden
|
24 | *
|
25 | * The list of manually rejected barcodes.
|
26 | */
|
27 | public readonly rejectedCodes: Set<Barcode>;
|
28 |
|
29 | /**
|
30 | * @hidden
|
31 | *
|
32 | * Create a ScanResult instance.
|
33 | *
|
34 | * @param barcodes The list of barcodes found in the image.
|
35 | * @param imageData The image data given as a byte array, formatted accordingly to the set settings.
|
36 | * @param imageSettings The configuration object defining the properties of the processed image.
|
37 | */
|
38 | constructor(barcodes: Barcode[], imageData: Uint8ClampedArray, imageSettings: ImageSettings) {
|
39 | this.barcodes = barcodes;
|
40 | this.imageData = imageData;
|
41 | this.imageSettings = imageSettings;
|
42 | this.rejectedCodes = new Set();
|
43 | }
|
44 |
|
45 | /**
|
46 | * Prevent playing a sound, vibrating or flashing the GUI for a particular code.
|
47 | * If all codes in the result are rejected (or no barcode is present), sound, vibration and GUI flashing will be
|
48 | * suppressed.
|
49 | *
|
50 | * Rejected codes will still be part of the [[ScanResult.barcodes]] property like all other codes.
|
51 | *
|
52 | * @param barcode The barcode to be rejected.
|
53 | */
|
54 | public rejectCode(barcode: Barcode): void {
|
55 | this.rejectedCodes.add(barcode);
|
56 | }
|
57 | }
|