A little more accurate algorithm for downsampling. Could not find any Java libraries for doing it.