preserve import { AbstractDistanceCalculator } from './distanceCalculator' ; /**
 * TODO: check quality of this distance equation
 * TODO: ask author for usage rights
 * taken from:
 *  http *  https export class PNGQuant extends AbstractDistanceCalculator { /**
     * Author's comments
     * px_b.rgb = px.rgb + 0*(1-px.a) // blend px on black
     * px_b.a   = px.a   + 1*(1-px.a)
     * px_w.rgb = px.rgb + 1*(1-px.a) // blend px on white
     * px_w.a   = px.a   + 1*(1-px.a)
     *
     * px_b.rgb = px.rgb              // difference same as in opaque RGB
     * px_b.a   = 1
     * px_w.rgb = px.rgb - px.a       // difference simplifies to formula below
     * px_w.a   = 1
     *
     * (px.rgb - px.a) - (py.rgb - py.a)
     * (px.rgb - py.rgb) + (py.a - px.a)
     *
     */ calculateRaw ( r1 , g1 , b1 , a1 , r2 , g2 , b2 , a2 ) { const alphas = ( a2 - a1 ) * this . _whitePoint . a ; return ( this . _colordifferenceCh ( r1 * this . _whitePoint . r , r2 * this . _whitePoint . r , alphas ) + this . _colordifferenceCh ( g1 * this . _whitePoint . g , g2 * this . _whitePoint . g , alphas ) + this . _colordifferenceCh ( b1 * this . _whitePoint . b , b2 * this . _whitePoint . b , alphas ) ) ; } private _colordifferenceCh ( x , y , alphas ) { const black = x - y ; const white = black + alphas ; return black * black + white * white ; } protected _setDefaults ( ) { } }