import DecodeHintType from './DecodeHintType' ; import Reader from './Reader' ; import Result from './Result' ; import BinaryBitmap from './BinaryBitmap' ; import BarcodeFormat from './BarcodeFormat' ; import QRCodeReader from './qrcode/QRCodeReader' ; import AztecReader from './aztec/AztecReader' ; import MultiFormatOneDReader from './oned/MultiFormatOneDReader' ; import DataMatrixReader from './datamatrix/DataMatrixReader' ; import NotFoundException from './NotFoundException' ; import PDF417Reader from './pdf417/PDF417Reader' ; import ReaderException from './ReaderException' ; author Sean Owen
 *  author dswitkin google export default class MultiFormatReader implements Reader { private hints : Map < DecodeHintType , any > | null ; private readers : Reader [ ] ; param image return throws param image param hints return throws public decode ( image , hints ? ) { this . setHints ( hints ) ; return this . decodeInternal ( image ) ; } param image return throws public decodeWithState ( image ) { if ( this . readers === null || this . readers === undefined ) { this . setHints ( null ) ; } return this . decodeInternal ( image ) ; } param hints public setHints ( hints ? ) { this . hints = hints ; const tryHarder = hints !== null && hints !== undefined && undefined !== hints . get ( DecodeHintType . TRY_HARDER ) ; const formats = hints === null || hints === undefined ? null : < BarcodeFormat [ ] > hints . get ( DecodeHintType . POSSIBLE_FORMATS ) ; const readers = new Array < Reader > ( ) ; if ( formats !== null && formats !== undefined ) { const addOneDReader = formats . some ( f => f === BarcodeFormat . UPC_A || f === BarcodeFormat . UPC_E || f === BarcodeFormat . EAN_13 || f === BarcodeFormat . EAN_8 || f === BarcodeFormat . CODABAR || f === BarcodeFormat . CODE_39 || f === BarcodeFormat . CODE_93 || f === BarcodeFormat . CODE_128 || f === BarcodeFormat . ITF || f === BarcodeFormat . RSS_14 || f === BarcodeFormat . RSS_EXPANDED ) ; if ( addOneDReader && ! tryHarder ) { readers . push ( new MultiFormatOneDReader ( hints ) ) ; } if ( formats . includes ( BarcodeFormat . QR_CODE ) ) { readers . push ( new QRCodeReader ( ) ) ; } if ( formats . includes ( BarcodeFormat . DATA_MATRIX ) ) { readers . push ( new DataMatrixReader ( ) ) ; } if ( formats . includes ( BarcodeFormat . AZTEC ) ) { readers . push ( new AztecReader ( ) ) ; } if ( formats . includes ( BarcodeFormat . PDF_417 ) ) { readers . push ( new PDF417Reader ( ) ) ; } if ( addOneDReader && tryHarder ) { readers . push ( new MultiFormatOneDReader ( hints ) ) ; } } if ( readers . length === 0 ) { if ( ! tryHarder ) { readers . push ( new MultiFormatOneDReader ( hints ) ) ; } readers . push ( new QRCodeReader ( ) ) ; readers . push ( new DataMatrixReader ( ) ) ; readers . push ( new AztecReader ( ) ) ; readers . push ( new PDF417Reader ( ) ) ; if ( tryHarder ) { readers . push ( new MultiFormatOneDReader ( hints ) ) ; } } this . readers = readers ; } public reset ( ) { if ( this . readers !== null ) { for ( const reader of this . readers ) { reader . reset ( ) ; } } } throws private decodeInternal ( image ) { if ( this . readers === null ) { throw new ReaderException ( 'No readers where selected, nothing can be read.' ) ; } for ( const reader of this . readers ) { try { return reader . decode ( image , this . hints ) ; } catch ( ex ) { if ( ex instanceof ReaderException ) { continue ; } } } throw new NotFoundException ( 'No MultiFormat Readers were able to detect the code.' ) ; } }