Improved code

- Included most changes done by David Tschumperlé prior to inclusion in CImg distribution.