Performance enhancements

Identified several places to speed up image rendering

Thanks to @mdboom and asv here!