Performance improvement for setSubImage