minor memory optimizations
Add support for arbitrary input image formats