Fix index calculation errors in PixelBuffer.js