fix off-by-one in writePNG() method