I\'d like to generate images in a bit of asm.js code running on a web worker. And I\'d like to regularly composite the latest state of that computation onto a user-visible 2
Is there some other way to turn a byte array into something you can feed to
drawImage?
You can post the ArrayBuffer of Uint8ClampedArray object to main thread; at main thread substitute using .putImageData() for .drawImage(). As indicated by @Kaiido, it is not necessary to create an ImageData object at Worker
var imgBytes = new Uint8ClampedArray(buffer, offset);
postMessage(imgBytes.buffer, [imgBytes.buffer]);
at main thread
worker.onmessage = function(e) {
console.log(e.data); // `ArrayBuffer`
ctx.putImageData(new ImageData(new Uint8ClampedArray(e.data), width, height), 0, 0);
}
http://plnkr.co/edit/N0v1YQHQX2rdFfHcOKeR?p=preview