Allow output sizes < 8 px wide or input < 4 px wide

This pads the input image before scaling, then chops off the excess in
the result. It's not the most efficient way, but this should not be a
common case.
Use accurate rounding in swscale

Otherwise images can get a very slight color tint with certain scaling
configurations.
Make sure the output size is always greater than 0