memory optimization for very large images