mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 09:17:20 +00:00
* Refactoring codecs * Plugging in new processor * Fixing decorator * MozJPEG free issue * Better worker aborting, and terminate workers that aren't used for 10 seconds * Better comment * Ooops, half-typed comment * Uncommenting problematic line * Surma fixed it! * Abstracting WASM initialisation * Better comment * Don't need this. * Adding ticket * noInitalRun * Reverting MozJPEG issue demo * Making a const for worker timeout * Inline docs * Bail early rather than nesting * Addressing nits
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { expose } from 'comlink';
|
|
import { EncodeOptions as MozJPEGEncoderOptions } from './mozjpeg/encoder-meta';
|
|
import { QuantizeOptions } from './imagequant/processor-meta';
|
|
import { EncodeOptions as OptiPNGEncoderOptions } from './optipng/encoder-meta';
|
|
import { EncodeOptions as WebPEncoderOptions } from './webp/encoder-meta';
|
|
|
|
async function mozjpegEncode(
|
|
data: ImageData, options: MozJPEGEncoderOptions,
|
|
): Promise<ArrayBuffer> {
|
|
const { encode } = await import('./mozjpeg/encoder');
|
|
return encode(data, options);
|
|
}
|
|
|
|
async function quantize(data: ImageData, opts: QuantizeOptions): Promise<ImageData> {
|
|
const { process } = await import('./imagequant/processor');
|
|
return process(data, opts);
|
|
}
|
|
|
|
async function optiPngEncode(
|
|
data: BufferSource, options: OptiPNGEncoderOptions,
|
|
): Promise<ArrayBuffer> {
|
|
const { compress } = await import('./optipng/encoder');
|
|
return compress(data, options);
|
|
}
|
|
|
|
async function webpEncode(
|
|
data: ImageData, options: WebPEncoderOptions,
|
|
): Promise<ArrayBuffer> {
|
|
const { encode } = await import('./webp/encoder');
|
|
return encode(data, options);
|
|
}
|
|
|
|
async function webpDecode(data: ArrayBuffer): Promise<ImageData> {
|
|
const { decode } = await import('./webp/decoder');
|
|
return decode(data);
|
|
}
|
|
|
|
const exports = { mozjpegEncode, quantize, optiPngEncode, webpEncode, webpDecode };
|
|
export type ProcessorWorkerApi = typeof exports;
|
|
|
|
expose(exports, self);
|