mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26: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
22 lines
774 B
TypeScript
22 lines
774 B
TypeScript
import { nativeDecode, sniffMimeType, canDecodeImage } from '../lib/util';
|
||
import Processor from './processor';
|
||
|
||
// tslint:disable-next-line:max-line-length It’s a data URL. Whatcha gonna do?
|
||
const webpFile = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=';
|
||
const nativeWebPSupported = canDecodeImage(webpFile);
|
||
|
||
export async function decodeImage(blob: Blob, processor: Processor): Promise<ImageData> {
|
||
const mimeType = await sniffMimeType(blob);
|
||
|
||
try {
|
||
if (mimeType === 'image/webp' && !(await nativeWebPSupported)) {
|
||
return await processor.webpDecode(blob);
|
||
}
|
||
|
||
// Otherwise, just throw it at the browser's decoder.
|
||
return await nativeDecode(blob);
|
||
} catch (err) {
|
||
throw Error("Couldn't decode image");
|
||
}
|
||
}
|