Improved custom_draw flipping code to handle being upside-down as well.