DON'T USE THIS .... A reference implementation in javascript, based on true story (picturefill).