mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-16 02:29:50 +00:00
OxiPNG + threads PoC
This commit is contained in:
committed by
Ingvar Stepanyan
parent
685558847f
commit
4c658b79ef
27
codecs/oxipng/main.js
Normal file
27
codecs/oxipng/main.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import initOxiPNG, { start_main_thread, optimise } from './pkg/squoosh_oxipng.js';
|
||||
import wasmUrl from "./pkg/squoosh_oxipng_bg.wasm";
|
||||
|
||||
async function startMainThread() {
|
||||
await initOxiPNG(fetch(wasmUrl));
|
||||
start_main_thread({
|
||||
length: navigator.hardwareConcurrency,
|
||||
pop: () => ({
|
||||
postMessage: data => {
|
||||
postMessage({ type: 'spawn', data });
|
||||
}
|
||||
})
|
||||
});
|
||||
return {
|
||||
optimise
|
||||
};
|
||||
}
|
||||
|
||||
const mainThread = startMainThread();
|
||||
addEventListener('message', async ({ data: { id, args } }) => {
|
||||
try {
|
||||
let result = (await mainThread).optimise(...args);
|
||||
postMessage({ ok: true, id, result });
|
||||
} catch (result) {
|
||||
postMessage({ ok: false, id, result });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user