Add WebP2 support

This commit is contained in:
Surma
2020-10-30 16:56:52 +00:00
committed by Ingvar Stepanyan
parent e60ffddfd7
commit 18b2bd1135
24 changed files with 726 additions and 2 deletions

20
src/codecs/wp2/decoder.ts Normal file
View File

@@ -0,0 +1,20 @@
import wp2_dec, { WP2Module } from '../../../codecs/wp2/dec/wp2_dec';
import wasmUrl from '../../../codecs/wp2/dec/wp2_dec.wasm';
import { initEmscriptenModule } from '../util';
let emscriptenModule: Promise<WP2Module>;
export async function decode(data: ArrayBuffer): Promise<ImageData> {
if (!emscriptenModule) emscriptenModule = initEmscriptenModule(wp2_dec, wasmUrl);
const module = await emscriptenModule;
const rawImage = module.decode(data);
const result = new ImageData(
new Uint8ClampedArray(rawImage.buffer),
rawImage.width,
rawImage.height,
);
module.free_result();
return result;
}