import React from "react"; import ImageInput from "./ImageInput"; import ImageOutput from "./ImageOutput"; import Ditherer from "./lib/Ditherer"; import ImagePreview from "./ImagePreview"; import Header from "./Header"; enum AppState { NO_IMAGE, IMAGE_LOADED, IMAGE_PROCESSED, } function App() { const [baseImage, setBaseImage] = React.useState(); const [ditheredImage, setDitheredImage] = React.useState(); const [appState, setAppState] = React.useState(AppState.NO_IMAGE); const handleImageSubmit = async (data: Blob) => { setBaseImage(data); setAppState(AppState.IMAGE_LOADED); try { const imageArray = new Uint8ClampedArray(await data.arrayBuffer()); const ditheredImage = await new Ditherer().dither(imageArray); setDitheredImage(new Blob([ditheredImage], { type: "image/png" })); setAppState(AppState.IMAGE_PROCESSED); } catch (e) { console.error(e); window.alert("Something went wrong. Please try again."); } }; return (

Go+Wasm image dithering tool

Load an image, click Go and wait (potentially for a while) for the image to be processed using the Floyd-Steinberg algorithm.

WebAssembly might run out of memory when processing larger images.

{appState === AppState.IMAGE_LOADED && baseImage && ( )} {appState === AppState.IMAGE_PROCESSED && ditheredImage && ( )}
); } export default App;