mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-16 10:39:53 +00:00
Set up decoder infrastructure
This commit is contained in:
@@ -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('Can’t 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 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user