mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-18 19:49:04 +00:00
"native" to "builtin" (#788)
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { nativeDecode, sniffMimeType, canDecodeImage } from '../lib/util';
|
||||
import { builtinDecode, sniffMimeType, canDecodeImage } from '../lib/util';
|
||||
import Processor from './processor';
|
||||
import webpDataUrl from 'url-loader!./tiny.webp';
|
||||
|
||||
const nativeWebPSupported = canDecodeImage(webpDataUrl);
|
||||
const webPSupported = canDecodeImage(webpDataUrl);
|
||||
|
||||
export async function decodeImage(blob: Blob, processor: Processor): Promise<ImageData> {
|
||||
const mimeType = await sniffMimeType(blob);
|
||||
|
||||
try {
|
||||
if (mimeType === 'image/webp' && !(await nativeWebPSupported)) {
|
||||
if (mimeType === 'image/webp' && !(await webPSupported)) {
|
||||
return await processor.webpDecode(blob);
|
||||
}
|
||||
|
||||
// Otherwise, just throw it at the browser's decoder.
|
||||
return await nativeDecode(blob);
|
||||
return await builtinDecode(blob);
|
||||
} catch (err) {
|
||||
throw Error("Couldn't decode image");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { nativeResize, NativeResizeMethod, drawableToImageData } from '../../lib/util';
|
||||
import { builtinResize, BuiltinResizeMethod, drawableToImageData } from '../../lib/util';
|
||||
import { BrowserResizeOptions, VectorResizeOptions } from './processor-meta';
|
||||
import { getContainOffsets } from './util';
|
||||
|
||||
@@ -12,9 +12,9 @@ export function browserResize(data: ImageData, opts: BrowserResizeOptions): Imag
|
||||
({ sx, sy, sw, sh } = getContainOffsets(sw, sh, opts.width, opts.height));
|
||||
}
|
||||
|
||||
return nativeResize(
|
||||
return builtinResize(
|
||||
data, sx, sy, sw, sh, opts.width, opts.height,
|
||||
opts.method.slice('browser-'.length) as NativeResizeMethod,
|
||||
opts.method.slice('browser-'.length) as BuiltinResizeMethod,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user