foliojs / png.js

A (animated) PNG decoder in JavaScript for the HTML5 canvas element and Node.js
http://devongovett.github.com/png.js
MIT License
489 stars 92 forks source link

"Invalid arguments" when pixelBytes set to 0.5 #11

Open tremby opened 11 years ago

tremby commented 11 years ago

I want to load in some very small images with indexed colour, in the browser. I don't actually want to display the image, only read the colours of the pixels, but documentation is a little thin, and I'm only as far as using the example code to load the image into a canvas element and it's throwing an "invalid arguments" error.

Breaking as the error is thrown shows it's at png.js line 231:

pixels = new Uint8Array(scanlineLength * this.height);

because scanlineLength is set to 7.5.

That was set a few lines earlier, because width is 15 and pixelBytes is 0.5, and pixelBytes is 0.5 because pixelBitLength is 4 and this is divided by 8.

Sample image is at http://tremby.net/dump/finn.png