forked from external-repos/squoosh
Feature test decoding capability
This commit is contained in:
@@ -1,14 +1,16 @@
|
|||||||
import { builtinDecode, sniffMimeType, canDecodeImage } from '../lib/util';
|
import { builtinDecode, sniffMimeType, canDecodeImage } from '../lib/util';
|
||||||
import Processor from './processor';
|
import Processor from './processor';
|
||||||
import webpDataUrl from 'url-loader!./tiny.webp';
|
import webpDataUrl from 'url-loader!./tiny.webp';
|
||||||
|
import avifDataUrl from 'url-loader!./tiny.avif';
|
||||||
|
|
||||||
const webPSupported = canDecodeImage(webpDataUrl);
|
const webPSupported = canDecodeImage(webpDataUrl);
|
||||||
|
const avifSupported = canDecodeImage(avifDataUrl);
|
||||||
|
|
||||||
export async function decodeImage(blob: Blob, processor: Processor): Promise<ImageData> {
|
export async function decodeImage(blob: Blob, processor: Processor): Promise<ImageData> {
|
||||||
const mimeType = await sniffMimeType(blob);
|
const mimeType = await sniffMimeType(blob);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (mimeType === 'image/avif') {
|
if (mimeType === 'image/avif' && !(await avifSupported)) {
|
||||||
return await processor.avifDecode(blob);
|
return await processor.avifDecode(blob);
|
||||||
}
|
}
|
||||||
if (mimeType === 'image/webp' && !(await webPSupported)) {
|
if (mimeType === 'image/webp' && !(await webPSupported)) {
|
||||||
|
|||||||
BIN
src/codecs/tiny.avif
Normal file
BIN
src/codecs/tiny.avif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 303 B |
Reference in New Issue
Block a user