Adressing smaller review comments

This commit is contained in:
Surma
2018-07-16 13:55:32 +01:00
parent b310c97044
commit b15545402a
7 changed files with 9 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
import { canDecode, fileToBitmap } from '../../lib/util';
import { canDecodeImage, fileToBitmap } from '../../lib/util';
export const name = 'Browser JPEG Decoder';
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';
export function isSupported(): Promise<boolean> {
return canDecode(jpegFile);
return canDecodeImage(jpegFile);
}

View File

@@ -1,4 +1,4 @@
import { canDecode, fileToBitmap } from '../../lib/util';
import { canDecodeImage, fileToBitmap } from '../../lib/util';
export const name = 'Browser PNG Decoder';
export const supportedExtensions = ['png'];
@@ -11,5 +11,5 @@ export async function decode(file: File): Promise<ImageBitmap> {
const pngFile = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII=';
export function isSupported(): Promise<boolean> {
return canDecode(pngFile);
return canDecodeImage(pngFile);
}

View File

@@ -1,4 +1,4 @@
import { canDecode, fileToBitmap } from '../../lib/util';
import { canDecodeImage, fileToBitmap } from '../../lib/util';
export const name = 'Browser WebP Decoder';
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=';
export function isSupported(): Promise<boolean> {
return canDecode(webpFile);
return canDecodeImage(webpFile);
}

View File

@@ -32,7 +32,7 @@ export default class WebpDecoder {
},
onRuntimeInitialized() {
// 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.
// See: https://github.com/kripken/emscripten/blob/incoming/src/postamble.js#L129
// TODO(surma@): File a bug with Emscripten on this.

View File

@@ -11,6 +11,5 @@ export async function decode(file: File): Promise<ImageBitmap> {
}
export async function isSupported(): Promise<boolean> {
// TODO(@surma): Should we do wasm detection here or something?
return true;
}

View File

@@ -184,7 +184,6 @@ export default class App extends Component<Props, State> {
if (!decoder) {
throw new Error('Cant find a decoder for the given file');
}
console.log(`Decoding using ${decoder.name}`);
const bmp = await decoder.decode(file);
// compute the corresponding ImageData once since it only changes when the file changes:
const data = await bitmapToImageData(bmp);
@@ -251,7 +250,7 @@ export default class App extends Component<Props, State> {
loadedCounter: loadingCounter,
};
this.setState({ images });
this.setState({ images, error: '' });
}
render({ }: Props, { loading, error, images }: State) {

View File

@@ -96,7 +96,7 @@ export async function canvasEncode(data: ImageData, type: string, quality?: numb
return blob;
}
export function canDecode(data: string): Promise<boolean> {
export function canDecodeImage(data: string): Promise<boolean> {
return new Promise((resolve) => {
const img = document.createElement('img');
img.src = data;