mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-09-29 19:42:23 +02:00
Squash Odysseus development history
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/* Encode a batch of canvas bitmaps without blocking the editor thread. */
|
||||
self.onmessage = async event => {
|
||||
const bitmaps = Array.isArray(event.data?.bitmaps) ? event.data.bitmaps : [];
|
||||
try {
|
||||
const blobs = [];
|
||||
for (const bitmap of bitmaps) {
|
||||
if (!bitmap?.width || !bitmap?.height) {
|
||||
blobs.push(null);
|
||||
continue;
|
||||
}
|
||||
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
|
||||
canvas.getContext('2d').drawImage(bitmap, 0, 0);
|
||||
blobs.push(await canvas.convertToBlob({ type: 'image/png' }));
|
||||
bitmap.close?.();
|
||||
}
|
||||
self.postMessage({ blobs });
|
||||
} catch (error) {
|
||||
for (const bitmap of bitmaps) bitmap?.close?.();
|
||||
self.postMessage({ error: String(error?.message || error) });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user