mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26:20 +00:00
Its working now
This commit is contained in:
@@ -192,17 +192,35 @@ interface DrawableToImageDataOptions {
|
||||
sh?: number;
|
||||
}
|
||||
|
||||
function getWidth(
|
||||
drawable: ImageBitmap | HTMLImageElement | VideoFrame,
|
||||
): number {
|
||||
if ('displayWidth' in drawable) {
|
||||
return drawable.displayWidth;
|
||||
}
|
||||
return drawable.width;
|
||||
}
|
||||
|
||||
function getHeight(
|
||||
drawable: ImageBitmap | HTMLImageElement | VideoFrame,
|
||||
): number {
|
||||
if ('displayHeight' in drawable) {
|
||||
return drawable.displayHeight;
|
||||
}
|
||||
return drawable.height;
|
||||
}
|
||||
|
||||
export function drawableToImageData(
|
||||
drawable: ImageBitmap | HTMLImageElement,
|
||||
drawable: ImageBitmap | HTMLImageElement | VideoFrame,
|
||||
opts: DrawableToImageDataOptions = {},
|
||||
): ImageData {
|
||||
const {
|
||||
width = drawable.width,
|
||||
height = drawable.height,
|
||||
width = getWidth(drawable),
|
||||
height = getHeight(drawable),
|
||||
sx = 0,
|
||||
sy = 0,
|
||||
sw = drawable.width,
|
||||
sh = drawable.height,
|
||||
sw = getWidth(drawable),
|
||||
sh = getHeight(drawable),
|
||||
} = opts;
|
||||
|
||||
// Make canvas same size as image
|
||||
|
||||
@@ -21,6 +21,6 @@ export async function decode(
|
||||
// Non-obvious way to turn an Blob into a ReadableStream
|
||||
data: new Response(blob).body!,
|
||||
});
|
||||
const result = await decoder.decode();
|
||||
return drawableToImageData(result.image);
|
||||
const { image } = await decoder.decode();
|
||||
return drawableToImageData(image);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,47 @@ interface ImageDecodeResult {
|
||||
complete: boolean;
|
||||
}
|
||||
|
||||
// Absolutely not correct, but it’s all we need and I’m lazy.
|
||||
type VideoFrame = ImageBitmap;
|
||||
// I didn’t do all the types because the class is kinda complex.
|
||||
// I focused on what we need.
|
||||
declare class VideoFrame {
|
||||
codedWidth: number;
|
||||
codedHeight: number;
|
||||
cropLeft: number;
|
||||
cropTop: number;
|
||||
cropWidth: number;
|
||||
cropHeight: number;
|
||||
displayWidth: number;
|
||||
displayHeight: number;
|
||||
|
||||
clone(): VideoFrame;
|
||||
close(): void;
|
||||
}
|
||||
|
||||
interface CanvasDrawImage {
|
||||
drawImage(
|
||||
image: CanvasImageSource | VideoFrame,
|
||||
dx: number,
|
||||
dy: number,
|
||||
): void;
|
||||
drawImage(
|
||||
image: CanvasImageSource | VideoFrame,
|
||||
dx: number,
|
||||
dy: number,
|
||||
dw: number,
|
||||
dh: number,
|
||||
): void;
|
||||
drawImage(
|
||||
image: CanvasImageSource | VideoFrame,
|
||||
sx: number,
|
||||
sy: number,
|
||||
sw: number,
|
||||
sh: number,
|
||||
dx: number,
|
||||
dy: number,
|
||||
dw: number,
|
||||
dh: number,
|
||||
): void;
|
||||
}
|
||||
|
||||
declare class ImageDecoder {
|
||||
static isTypeSupported(type: string): Promise<boolean>;
|
||||
|
||||
Reference in New Issue
Block a user