mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-18 11:39:08 +00:00
Integrate encoder
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import webp_enc, { WebPModule } from '../../../codecs/webp_enc/webp_enc';
|
||||
import wasmUrl from '../../../codecs/webp_enc/webp_enc.wasm';
|
||||
import jxl_enc, { JXLModule } from '../../../codecs/jxl_enc/jxl_enc';
|
||||
import wasmUrl from '../../../codecs/jxl_enc/jxl_enc.wasm';
|
||||
import { EncodeOptions } from './encoder-meta';
|
||||
import { initEmscriptenModule } from '../util';
|
||||
|
||||
let emscriptenModule: Promise<WebPModule>;
|
||||
let emscriptenModule: Promise<JXLModule>;
|
||||
|
||||
export async function encode(data: ImageData, options: EncodeOptions): Promise<ArrayBuffer> {
|
||||
if (!emscriptenModule) emscriptenModule = initEmscriptenModule(webp_enc, wasmUrl);
|
||||
if (!emscriptenModule) emscriptenModule = initEmscriptenModule(jxl_enc, wasmUrl);
|
||||
|
||||
const module = await emscriptenModule;
|
||||
const resultView = module.encode(data.data, data.width, data.height, options);
|
||||
const resultView = module.encode(data.data, data.width, data.height);
|
||||
const result = new Uint8Array(resultView);
|
||||
module.free_result();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user