A rough'n'ready port of the pieces of libsquish that I needed.

I'll tidy this up and spin this off into its own repository soon.