import BarcodeFormat from '../BarcodeFormat' ; import BinaryBitmap from '../BinaryBitmap' ; import ChecksumException from '../ChecksumException' ; import DecodeHintType from '../DecodeHintType' ; import FormatException from '../FormatException' ; import NotFoundException from '../NotFoundException' ; import Reader from '../Reader' ; import Result from '../Result' ; import ResultPoint from '../ResultPoint' ; import PDF417Common from './PDF417Common' ; import Integer from '../util/Integer' ; import PDF417ResultMetadata from './PDF417ResultMetadata' ; import ResultMetadataType from '../ResultMetadataType' ; import MultipleBarcodeReader from '../multi/MultipleBarcodeReader' ; import Detector from './detector/Detector' ; import PDF417ScanningDecoder from './decoder/PDF417ScanningDecoder' ; import { int } from '../../customTypings' ; author Guenther Grau
  export default class PDF417Reader implements Reader , MultipleBarcodeReader { return throws throws throws public decode ( image , hints = null ) { let result = PDF417Reader . decode ( image , hints , false ) ; if ( result == null || result . length === 0 || result [ 0 ] == null ) { throw NotFoundException . getNotFoundInstance ( ) ; } return result [ 0 ] ; } param BinaryBitmap param image throws public decodeMultiple ( image , hints = null ) { try { return PDF417Reader . decode ( image , hints , true ) ; } catch ( ignored ) { if ( ignored instanceof FormatException || ignored instanceof ChecksumException ) { throw NotFoundException . getNotFoundInstance ( ) ; } throw ignored ; } } param image param hints param multiple throws throws throws private static decode ( image , hints , multiple ) { const results = new Array < Result > ( ) ; const detectorResult = Detector . detectMultiple ( image , hints , multiple ) ; for ( const points of detectorResult . getPoints ( ) ) { const decoderResult = PDF417ScanningDecoder . decode ( detectorResult . getBits ( ) , points [ 4 ] , points [ 5 ] , points [ 6 ] , points [ 7 ] , PDF417Reader . getMinCodewordWidth ( points ) , PDF417Reader . getMaxCodewordWidth ( points ) ) ; const result = new Result ( decoderResult . getText ( ) , decoderResult . getRawBytes ( ) , undefined , points , BarcodeFormat . PDF_417 ) ; result . putMetadata ( ResultMetadataType . ERROR_CORRECTION_LEVEL , decoderResult . getECLevel ( ) ) ; const pdf417ResultMetadata = decoderResult . getOther ( ) ; if ( pdf417ResultMetadata != null ) { result . putMetadata ( ResultMetadataType . PDF417_EXTRA_METADATA , pdf417ResultMetadata ) ; } results . push ( result ) ; } return results . map ( x => x ) ; } private static getMaxWidth ( p1 , p2 ) { if ( p1 == null || p2 == null ) { return 0 ; } return < int > Math . trunc ( Math . abs ( p1 . getX ( ) - p2 . getX ( ) ) ) ; } private static getMinWidth ( p1 , p2 ) { if ( p1 == null || p2 == null ) { return Integer . MAX_VALUE ; } return < int > Math . trunc ( Math . abs ( p1 . getX ( ) - p2 . getX ( ) ) ) ; } private static getMaxCodewordWidth ( p ) { return Math . floor ( Math . max ( Math . max ( PDF417Reader . getMaxWidth ( p [ 0 ] , p [ 4 ] ) , PDF417Reader . getMaxWidth ( p [ 6 ] , p [ 2 ] ) * PDF417Common . MODULES_IN_CODEWORD / PDF417Common . MODULES_IN_STOP_PATTERN ) , Math . max ( PDF417Reader . getMaxWidth ( p [ 1 ] , p [ 5 ] ) , PDF417Reader . getMaxWidth ( p [ 7 ] , p [ 3 ] ) * PDF417Common . MODULES_IN_CODEWORD / PDF417Common . MODULES_IN_STOP_PATTERN ) ) ) ; } private static getMinCodewordWidth ( p ) { return Math . floor ( Math . min ( Math . min ( PDF417Reader . getMinWidth ( p [ 0 ] , p [ 4 ] ) , PDF417Reader . getMinWidth ( p [ 6 ] , p [ 2 ] ) * PDF417Common . MODULES_IN_CODEWORD / PDF417Common . MODULES_IN_STOP_PATTERN ) , Math . min ( PDF417Reader . getMinWidth ( p [ 1 ] , p [ 5 ] ) , PDF417Reader . getMinWidth ( p [ 7 ] , p [ 3 ] ) * PDF417Common . MODULES_IN_CODEWORD / PDF417Common . MODULES_IN_STOP_PATTERN ) ) ) ; } public reset ( ) { } }