check pixel coordinates before write