|
|
@ -2,12 +2,15 @@ |
|
|
|
/// <reference lib="webworker" />
|
|
|
|
|
|
|
|
import * as platform from './platform'; |
|
|
|
import pngv3 from "./pngv3"; |
|
|
|
import { initial_settings } from './stores'; |
|
|
|
//import { initial_settings } from './stores';
|
|
|
|
//import { initial_settings } from './stores';
|
|
|
|
//import pngv3 from "./pngv3";
|
|
|
|
//import webm from "./webm";
|
|
|
|
//import gif from "./gif";
|
|
|
|
import jpg from "./jpg"; |
|
|
|
//import jpg from "./jpg";
|
|
|
|
import thirdeye from "./thirdeye"; |
|
|
|
import pomf from "./pomf"; |
|
|
|
//import pomf from "./pomf";
|
|
|
|
|
|
|
|
console.log("Worker started"); |
|
|
|
|
|
|
@ -99,7 +102,7 @@ export interface ImageProcessor { |
|
|
|
} |
|
|
|
|
|
|
|
const processors: ImageProcessor[] = |
|
|
|
[thirdeye, pomf, pngv3, jpg]; //, webm, gif
|
|
|
|
[thirdeye];//, pomf, pngv3, jpg]; //, webm, gif
|
|
|
|
|
|
|
|
const processImage = async (srcs: AsyncGenerator<string, void, void>, fn: string, hex: string, prevurl: string) => { |
|
|
|
const ret = await Promise.all(processors.filter(e => e.match(fn)).map(async proc => { |
|
|
@ -155,44 +158,50 @@ const processImage = async (srcs: AsyncGenerator<string, void, void>, fn: string |
|
|
|
return ret.filter(e => e).map(e => e!); |
|
|
|
}; |
|
|
|
|
|
|
|
onmessage = async (msg: MessageEvent<any>) => { |
|
|
|
const des = deserializeMessage(msg.data); |
|
|
|
switch (des.type) { |
|
|
|
case 'ipc': { |
|
|
|
platform.setupPort(des.port); |
|
|
|
break; |
|
|
|
} |
|
|
|
case 'cmd': { |
|
|
|
switch (des.fun) { |
|
|
|
case 'processImage': { |
|
|
|
//console.log('Received process image command', des);
|
|
|
|
const res = await processImage(des.args[0], des.args[1], des.args[2], des.args[3]); |
|
|
|
//console.log('Finished process image command', des);
|
|
|
|
const tr: Transferable[] = []; |
|
|
|
for (const ef of res) { |
|
|
|
for (const e of ef[0]) { |
|
|
|
if (Buffer.isBuffer(e.thumbnail) || e.thumbnail instanceof Uint8Array) |
|
|
|
tr.push(e.thumbnail.buffer); |
|
|
|
if (Buffer.isBuffer(e.data) || e.data instanceof Uint8Array) |
|
|
|
tr.push(e.data.buffer); |
|
|
|
const snooze = (n:number) => new Promise(_ => setTimeout(_, n)); |
|
|
|
|
|
|
|
(async () => { |
|
|
|
onmessage = async (msg: MessageEvent<any>) => { |
|
|
|
console.log(msg.data); |
|
|
|
const des = deserializeMessage(msg.data); |
|
|
|
switch (des.type) { |
|
|
|
case 'ipc': { |
|
|
|
platform.setupPort(des.port); |
|
|
|
break; |
|
|
|
} |
|
|
|
case 'cmd': { |
|
|
|
switch (des.fun) { |
|
|
|
case 'processImage': { |
|
|
|
await initial_settings; |
|
|
|
//console.log('Received process image command', des);
|
|
|
|
const res = await processImage(des.args[0], des.args[1], des.args[2], des.args[3]); |
|
|
|
//console.log('Finished process image command', des);
|
|
|
|
const tr: Transferable[] = []; |
|
|
|
for (const ef of res) { |
|
|
|
for (const e of ef[0]) { |
|
|
|
if (Buffer.isBuffer(e.thumbnail) || e.thumbnail instanceof Uint8Array) |
|
|
|
tr.push(e.thumbnail.buffer); |
|
|
|
if (Buffer.isBuffer(e.data) || e.data instanceof Uint8Array) |
|
|
|
tr.push(e.data.buffer); |
|
|
|
} |
|
|
|
} |
|
|
|
//console.log('Sent reply', res, des);
|
|
|
|
postMessage({ |
|
|
|
type: 'reply', |
|
|
|
id: des.id, |
|
|
|
res |
|
|
|
}, [...new Set(tr)]); |
|
|
|
} |
|
|
|
//console.log('Sent reply', res, des);
|
|
|
|
postMessage({ |
|
|
|
type: 'reply', |
|
|
|
id: des.id, |
|
|
|
res |
|
|
|
}, [...new Set(tr)]); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case 'ag': { |
|
|
|
const cb = pendinggens[des.id].shift(); |
|
|
|
if (cb) { |
|
|
|
cb(des.res); |
|
|
|
case 'ag': { |
|
|
|
const cb = pendinggens[des.id].shift(); |
|
|
|
if (cb) { |
|
|
|
cb(des.res); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
})(); |