Some down-scaling problems fixed.

The down-scaling code from SOIL expecting resizing only by the powers
of two, so when an image is to be shrunk, its width and height are
divided by two again and again until both are in the acceptable range.