Image perceptual hash calculation in javascript