mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 09:39:15 +00:00
Adressing smaller review comments
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { canDecode, fileToBitmap } from '../../lib/util';
|
import { canDecodeImage, fileToBitmap } from '../../lib/util';
|
||||||
|
|
||||||
export const name = 'Browser JPEG Decoder';
|
export const name = 'Browser JPEG Decoder';
|
||||||
export const supportedExtensions = ['jpg', 'jpeg'];
|
export const supportedExtensions = ['jpg', 'jpeg'];
|
||||||
@@ -11,5 +11,5 @@ export async function decode(file: File): Promise<ImageBitmap> {
|
|||||||
const jpegFile = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAn/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AJVAA//Z';
|
const jpegFile = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAn/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AJVAA//Z';
|
||||||
|
|
||||||
export function isSupported(): Promise<boolean> {
|
export function isSupported(): Promise<boolean> {
|
||||||
return canDecode(jpegFile);
|
return canDecodeImage(jpegFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { canDecode, fileToBitmap } from '../../lib/util';
|
import { canDecodeImage, fileToBitmap } from '../../lib/util';
|
||||||
|
|
||||||
export const name = 'Browser PNG Decoder';
|
export const name = 'Browser PNG Decoder';
|
||||||
export const supportedExtensions = ['png'];
|
export const supportedExtensions = ['png'];
|
||||||
@@ -11,5 +11,5 @@ export async function decode(file: File): Promise<ImageBitmap> {
|
|||||||
const pngFile = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII=';
|
const pngFile = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII=';
|
||||||
|
|
||||||
export function isSupported(): Promise<boolean> {
|
export function isSupported(): Promise<boolean> {
|
||||||
return canDecode(pngFile);
|
return canDecodeImage(pngFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { canDecode, fileToBitmap } from '../../lib/util';
|
import { canDecodeImage, fileToBitmap } from '../../lib/util';
|
||||||
|
|
||||||
export const name = 'Browser WebP Decoder';
|
export const name = 'Browser WebP Decoder';
|
||||||
export const supportedExtensions = ['webp'];
|
export const supportedExtensions = ['webp'];
|
||||||
@@ -11,5 +11,5 @@ export async function decode(file: File): Promise<ImageBitmap> {
|
|||||||
const webpFile = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=';
|
const webpFile = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=';
|
||||||
|
|
||||||
export function isSupported(): Promise<boolean> {
|
export function isSupported(): Promise<boolean> {
|
||||||
return canDecode(webpFile);
|
return canDecodeImage(webpFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export default class WebpDecoder {
|
|||||||
},
|
},
|
||||||
onRuntimeInitialized() {
|
onRuntimeInitialized() {
|
||||||
// An Emscripten is a then-able that, for some reason, `then()`s itself,
|
// An Emscripten is a then-able that, for some reason, `then()`s itself,
|
||||||
// causing an infite loop when you wrap it in a real promise. Deleten the `then`
|
// causing an infite loop when you wrap it in a real promise. Deleting the `then`
|
||||||
// prop solves this for now.
|
// prop solves this for now.
|
||||||
// See: https://github.com/kripken/emscripten/blob/incoming/src/postamble.js#L129
|
// See: https://github.com/kripken/emscripten/blob/incoming/src/postamble.js#L129
|
||||||
// TODO(surma@): File a bug with Emscripten on this.
|
// TODO(surma@): File a bug with Emscripten on this.
|
||||||
|
|||||||
@@ -11,6 +11,5 @@ export async function decode(file: File): Promise<ImageBitmap> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function isSupported(): Promise<boolean> {
|
export async function isSupported(): Promise<boolean> {
|
||||||
// TODO(@surma): Should we do wasm detection here or something?
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,7 +184,6 @@ export default class App extends Component<Props, State> {
|
|||||||
if (!decoder) {
|
if (!decoder) {
|
||||||
throw new Error('Can’t find a decoder for the given file');
|
throw new Error('Can’t find a decoder for the given file');
|
||||||
}
|
}
|
||||||
console.log(`Decoding using ${decoder.name}`);
|
|
||||||
const bmp = await decoder.decode(file);
|
const bmp = await decoder.decode(file);
|
||||||
// compute the corresponding ImageData once since it only changes when the file changes:
|
// compute the corresponding ImageData once since it only changes when the file changes:
|
||||||
const data = await bitmapToImageData(bmp);
|
const data = await bitmapToImageData(bmp);
|
||||||
@@ -251,7 +250,7 @@ export default class App extends Component<Props, State> {
|
|||||||
loadedCounter: loadingCounter,
|
loadedCounter: loadingCounter,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setState({ images });
|
this.setState({ images, error: '' });
|
||||||
}
|
}
|
||||||
|
|
||||||
render({ }: Props, { loading, error, images }: State) {
|
render({ }: Props, { loading, error, images }: State) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export async function canvasEncode(data: ImageData, type: string, quality?: numb
|
|||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function canDecode(data: string): Promise<boolean> {
|
export function canDecodeImage(data: string): Promise<boolean> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const img = document.createElement('img');
|
const img = document.createElement('img');
|
||||||
img.src = data;
|
img.src = data;
|
||||||
|
|||||||
Reference in New Issue
Block a user