import BitMatrix from './BitMatrix' ; import PerspectiveTransform from './PerspectiveTransform' ; import Exception from './../Exception' ; /**
 * Implementations of this class can, given locations of finder patterns for a QR code in an
 * image, sample the right points in the image to reconstruct the QR code, accounting for
 * perspective distortion. It is abstracted since it is relatively expensive and should be allowed
 * to take advantage of platform-specific optimized implementations, like Sun's Java Advanced
 * Imaging library, but which may not be available in other environments such as J2ME, and vice
 * versa.
 *
 * The implementation used can be controlled by calling  {@link #setGridSampler(GridSampler)} * with an instance of a class which implements this interface.
 *
 *  author Sean Owen
  abstract class GridSampler { param image param dimensionX width of  BitMatrix to sample from image
     *  param dimensionY height of  BitMatrix to sample from image
     *  param p1ToX param p1ToY param p2ToX param p2ToY param p3ToX param p3ToY param p4ToX param p4ToY param p1FromX param p1FromY param p2FromX param p2FromY param p3FromX param p3FromY param p4FromX param p4FromY return { link throws public abstract sampleGrid ( image , dimensionX , dimensionY , p1ToX , p1ToY , p2ToX , p2ToY , p3ToX , p3ToY , p4ToX , p4ToY , p1FromX , p1FromY , p2FromX , p2FromY , p3FromX , p3FromY , p4FromX , p4FromY ) ; public abstract sampleGridWithTransform ( image , dimensionX , dimensionY , transform ) ; param image param points throws protected static checkAndNudgePoints ( image , points ) { const width = image . getWidth ( ) ; const height = image . getHeight ( ) ; let nudged = true ; for ( let offset = 0 ; offset < points . length && nudged ; offset += 2 ) { const x = Math . floor ( points [ offset ] ) ; const y = Math . floor ( points [ offset + 1 ] ) ; if ( x < - 1 || x > width || y < - 1 || y > height ) { throw new Exception ( Exception . NotFoundException ) ; } nudged = false ; if ( x == - 1 ) { points [ offset ] = 0.0 ; nudged = true ; } else if ( x == width ) { points [ offset ] = width - 1 ; nudged = true ; } if ( y == - 1 ) { points [ offset + 1 ] = 0.0 ; nudged = true ; } else if ( y == height ) { points [ offset + 1 ] = height - 1 ; nudged = true ; } } nudged = true ; for ( let offset = points . length - 2 ; offset >= 0 && nudged ; offset -= 2 ) { const x = Math . floor ( points [ offset ] ) ; const y = Math . floor ( points [ offset + 1 ] ) ; if ( x < - 1 || x > width || y < - 1 || y > height ) { throw new Exception ( Exception . NotFoundException ) ; } nudged = false ; if ( x == - 1 ) { points [ offset ] = 0.0 ; nudged = true ; } else if ( x == width ) { points [ offset ] = width - 1 ; nudged = true ; } if ( y == - 1 ) { points [ offset + 1 ] = 0.0 ; nudged = true ; } else if ( y == height ) { points [ offset + 1 ] = height - 1 ; nudged = true ; } } } } export default GridSampler ;