import Reader from '../Reader' ; import ResultPoint from '../ResultPoint' ; import Result from '../Result' ; import BarcodeFormat from '../BarcodeFormat' ; import BinaryBitmap from '../BinaryBitmap' ; import DecodeHintType from '../DecodeHintType' ; import ResultMetadataType from '../ResultMetadataType' ; import DecoderResult from '../common/DecoderResult' ; import System from '../util/System' ; import Decoder from './decoder/Decoder' ; import Detector from './detector/Detector' ; import Exception from '../../core/Exception' ; author David Olivier
  export default class AztecReader implements Reader { return throws throws public decode ( image , hints = null ) { let exception = null ; let detector = new Detector ( image . getBlackMatrix ( ) ) ; let points = null ; let decoderResult = null ; try { let detectorResult = detector . detectMirror ( false ) ; points = detectorResult . getPoints ( ) ; this . reportFoundResultPoints ( hints , points ) ; decoderResult = new Decoder ( ) . decode ( detectorResult ) ; } catch ( e ) { exception = e ; } if ( decoderResult == null ) { try { let detectorResult = detector . detectMirror ( true ) ; points = detectorResult . getPoints ( ) ; this . reportFoundResultPoints ( hints , points ) ; decoderResult = new Decoder ( ) . decode ( detectorResult ) ; } catch ( e ) { if ( exception != null ) { throw exception ; } throw e ; } } let result = new Result ( decoderResult . getText ( ) , decoderResult . getRawBytes ( ) , decoderResult . getNumBits ( ) , points , BarcodeFormat . AZTEC , System . currentTimeMillis ( ) ) ; let byteSegments = decoderResult . getByteSegments ( ) ; if ( byteSegments != null ) { result . putMetadata ( ResultMetadataType . BYTE_SEGMENTS , byteSegments ) ; } let ecLevel = decoderResult . getECLevel ( ) ; if ( ecLevel != null ) { result . putMetadata ( ResultMetadataType . ERROR_CORRECTION_LEVEL , ecLevel ) ; } return result ; } private reportFoundResultPoints ( hints , points ) { if ( hints != null ) { let rpcb = hints . get ( DecodeHintType . NEED_RESULT_POINT_CALLBACK ) ; if ( rpcb != null ) { points . forEach ( ( point , idx , arr ) => { rpcb . foundPossibleResultPoint ( point ) ; } ) ; } } } public reset ( ) { } }