Set up decoder infrastructure

This commit is contained in:
Surma
2018-07-04 15:18:47 +01:00
parent 6e8f8bbe41
commit 790a5b580d
10 changed files with 5450 additions and 3143 deletions

View File

@@ -26,6 +26,8 @@ import {
encoderMap,
} from '../../codecs/encoders';
import { findDecoder } from '../../codecs/decoders';
interface SourceImage {
file: File;
bmp: ImageBitmap;
@@ -176,7 +178,12 @@ export default class App extends Component<Props, State> {
async updateFile(file: File) {
this.setState({ loading: true });
try {
const bmp = await createImageBitmap(file);
const decoder = await findDecoder(file);
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);
@@ -186,6 +193,7 @@ export default class App extends Component<Props, State> {
loading: false,
});
} catch (err) {
console.error(err);
this.setState({ error: 'IMAGE_INVALID', loading: false });
}
}