HTML5 canvas 3D pixel array
2011
16
Nov
This is another demo from 2009-ish. When I started experimenting with canvas, I felt uncomfortable with the 1-dimensionality of CanvasPixelArray. I wrote this script to convert it into a more logical format: X by Y by RGBA. Let me rephrase that. By "more logical", I mean "more logical, to me, at the time). 1D is fine, and I can't think of any use for this script. But, nonetheless, here it is, including the original description.
canvas pixarray
After loading an image file into a <canvas> element, you can retrieve its pixels with getImageData(). The problem is that the array of pixels is one-dimensional. The array would look something like this for a set of N pixels Pi where each pixel has bands RGBA with values 0..255:
( P0R, P0G, P0B, P0A, P1R, P1G, P1B, P1A, ... , P(N-1)R, P(N-1)G, P(N-1)B, P(N-1)A )
That's really tough to work with, so this script converts that to a more logical 3D array (X by Y by RGBA)
This canvas drawn from an image file:
This canvas drawn from the 3D image array: