preserve import { AbstractImageQuantizer } from './imageQuantizer' ; import { AbstractDistanceCalculator } from '../distance/distanceCalculator' ; import { PointContainer } from '../utils/pointContainer' ; import { Palette } from '../utils/palette' ; import { ImageQuantizerYieldValue } from './imageQuantizerYieldValue' ; import { ProgressTracker } from '../utils/progressTracker' ; export class NearestColor extends AbstractImageQuantizer { private _distance : AbstractDistanceCalculator ; constructor ( colorDistanceCalculator ) { super ( ) ; this . _distance = colorDistanceCalculator ; } /**
     * Mutates pointContainer
     */ * quantize ( pointContainer , palette ) { const pointArray = pointContainer . getPointArray ( ) ; const width = pointContainer . getWidth ( ) ; const height = pointContainer . getHeight ( ) ; const tracker = new ProgressTracker ( height , 99 ) ; for ( let y = 0 ; y < height ; y ++ ) { if ( tracker . shouldNotify ( y ) ) { yield { progress : tracker . progress , } ; } for ( let x = 0 , idx = y * width ; x < width ; x ++ , idx ++ ) { const point = pointArray [ idx ] ; point . from ( palette . getNearestColor ( this . _distance , point ) ) ; } } yield { pointContainer , progress : 100 , } ; } }