import type { TextureReply } from './art-textures'; import { luminancePlane } from './luminance'; self.onmessage = ({ data: image }: MessageEvent) => { try { const { width, height } = image; const canvas = new OffscreenCanvas(width, height); const context = canvas.getContext('2d', { willReadFrequently: true })!; context.drawImage(image, 0, 0); const plane = luminancePlane(context.getImageData(0, 0, width, height).data, width, height); self.postMessage({ image: plane } satisfies TextureReply, { transfer: [plane.pixels.buffer] }); } catch (error) { self.postMessage({ error: String(error) } satisfies TextureReply); } finally { image.close(); } };