Skip to content

Instantly share code, notes, and snippets.

@Gelio
Created November 17, 2017 21:49
Show Gist options
  • Save Gelio/f806c1d96a53a8aa34c5014fe1c19315 to your computer and use it in GitHub Desktop.
Save Gelio/f806c1d96a53a8aa34c5014fe1c19315 to your computer and use it in GitHub Desktop.
onmessage = (e: MessageEvent) => {
const messageType: FillWorkerMessageType = e.data.type;
switch (messageType) {
case FillWorkerMessageType.InitialData:
appFillData = e.data.appFillData;
canvasWidth = e.data.width;
canvasHeight = e.data.height;
break;
case FillWorkerMessageType.StartFill:
// allocating new memory
canvasImageData = new ImageData(canvasWidth, canvasHeight);
break;
case FillWorkerMessageType.FillStrips:
fillStrips(e.data.fillStrips);
break;
case FillWorkerMessageType.EndFill:
const arrayBuffer = canvasImageData.data.buffer;
postMessage(arrayBuffer, [arrayBuffer]);
break;
default:
console.error('Unknown worker message type', messageType);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment