Probably not the fastest, but SDL does this.

--
Mats