Adding the Quite OK Image (QOI) Codec (#1384)

This commit is contained in:
Aryan Pingle
2023-10-20 13:58:59 +05:30
committed by GitHub
parent f374068fb2
commit d87eff7645
19 changed files with 295 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import qoiDecoder, { QOIModule } from 'codecs/qoi/dec/qoi_dec';
import { initEmscriptenModule, blobToArrayBuffer } from 'features/worker-utils';
let emscriptenModule: Promise<QOIModule>;
export default async function decode(blob: Blob): Promise<ImageData> {
if (!emscriptenModule) {
emscriptenModule = initEmscriptenModule(qoiDecoder);
}
const [module, data] = await Promise.all([
emscriptenModule,
blobToArrayBuffer(blob),
]);
const result = module.decode(data);
if (!result) throw new Error('Decoding error');
return result;
}