Shu-yu Guo for Surma
Motivation: ImageData
// ctx is a CanvasRenderingContext2D
const imageData =
ctx.getImageData(0, 0,
ctx.canvas.width,
ctx.canvas.height);
// imageData.data is a Uint8ClampedArray
// containing data in the scheme
// [ r0, g0, b0, a0, r1, g1, b1, a1, ... ]
What If I Want to Access Just the Alpha Values?
I Mean, I can...
const getAlpha = (u8,idx) => u8[idx*4+3];
But Wouldn’t It Be Nice
const alphas =
new Uint8ClampedArray(
imageData.buffer,
3 * Uint8Array.BYTES_PER_ELEMENT,
imageData.width * imageData.height,
/* stride */ 4);
N-Dimensional Data in Many Places
Proposed API
new TypedArray(buffer[, byteOffset[, length[, stride]]]);
Feature Detection
"stride" in new TypedArray()
No Options Bag
No Unaligned Access
Stage 1?