* This method adds state to the MultiFormatReader. By setting the hints once, subsequent calls * to decodeWithState(image) can reuse the same set of readers without reallocating memory. This * is important for performance in continuous scan clients. * * @param hints The set of hi
(hints?: Map<DecodeHintType, any> | null)
| 103 | * @param hints The set of hints to use for subsequent calls to decode(image) |
| 104 | */ |
| 105 | public setHints(hints?: Map<DecodeHintType, any> | null): void { |
| 106 | this.hints = hints; |
| 107 | |
| 108 | const tryHarder: boolean = hints !== null && hints !== undefined && undefined !== hints.get(DecodeHintType.TRY_HARDER); |
| 109 | /*@SuppressWarnings("unchecked")*/ |
| 110 | const formats = hints === null || hints === undefined ? null : <BarcodeFormat[]>hints.get(DecodeHintType.POSSIBLE_FORMATS); |
| 111 | const readers = new Array<Reader>(); |
| 112 | if (formats !== null && formats !== undefined) { |
| 113 | const addOneDReader: boolean = formats.some(f => |
| 114 | f === BarcodeFormat.UPC_A || |
| 115 | f === BarcodeFormat.UPC_E || |
| 116 | f === BarcodeFormat.EAN_13 || |
| 117 | f === BarcodeFormat.EAN_8 || |
| 118 | f === BarcodeFormat.CODABAR || |
| 119 | f === BarcodeFormat.CODE_39 || |
| 120 | f === BarcodeFormat.CODE_93 || |
| 121 | f === BarcodeFormat.CODE_128 || |
| 122 | f === BarcodeFormat.ITF || |
| 123 | f === BarcodeFormat.RSS_14 || |
| 124 | f === BarcodeFormat.RSS_EXPANDED |
| 125 | ); |
| 126 | // Put 1D readers upfront in "normal" mode |
| 127 | |
| 128 | // TYPESCRIPTPORT: TODO: uncomment below as they are ported |
| 129 | |
| 130 | if (addOneDReader && !tryHarder) { |
| 131 | readers.push(new MultiFormatOneDReader(hints)); |
| 132 | } |
| 133 | if (formats.includes(BarcodeFormat.QR_CODE)) { |
| 134 | readers.push(new QRCodeReader()); |
| 135 | } |
| 136 | if (formats.includes(BarcodeFormat.MICRO_QR_CODE)) { |
| 137 | readers.push(new MicroQRCodeReader()); |
| 138 | } |
| 139 | if (formats.includes(BarcodeFormat.DATA_MATRIX)) { |
| 140 | readers.push(new DataMatrixReader()); |
| 141 | } |
| 142 | if (formats.includes(BarcodeFormat.AZTEC)) { |
| 143 | readers.push(new AztecReader()); |
| 144 | } |
| 145 | if (formats.includes(BarcodeFormat.PDF_417)) { |
| 146 | readers.push(new PDF417Reader()); |
| 147 | } |
| 148 | if (formats.includes(BarcodeFormat.MAXICODE)) { |
| 149 | readers.push(new MaxiCodeReader()); |
| 150 | } |
| 151 | // At end in "try harder" mode |
| 152 | if (addOneDReader && tryHarder) { |
| 153 | readers.push(new MultiFormatOneDReader(hints)); |
| 154 | } |
| 155 | } |
| 156 | if (readers.length === 0) { |
| 157 | if (!tryHarder) { |
| 158 | readers.push(new MultiFormatOneDReader(hints)); |
| 159 | } |
| 160 | |
| 161 | readers.push(new QRCodeReader()); |
| 162 | readers.push(new MicroQRCodeReader()); |
no test coverage detected