Re-implement nearest-neighbor interpolation

Fix for issue 295, there was, what amounts to an off by one error in the
original code, which was causing the problem in issue 295.

This error was probably not very noticable in larger images, but as
pointed out by the bug report smaller images may contain more distortion
than necessary.

Wasn't entirely sure how to correct the original code, so replaced it with
entirely new code.