in sync with incoming hq2x code in FFmpeg