This is kind of slow but yields much nicer results compared to (bi)linear interpolation. I should probably add gamma correction...
The image utility now uses this tool instead of parsing images on its own.