see http://www.ivank.net/blogspot/dithering/dithering.html