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"; import Palette from "./Palette"; 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, palette: Palette) => { setBaseImage(data); setAppState(AppState.IMAGE_LOADED); try { const imageArray = new Uint8ClampedArray(await data.arrayBuffer()); const ditheredImage = await new Ditherer().dither(imageArray, palette); 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, select a palette, click Go and wait for the image to be processed using the Floyd-Steinberg algorithm.

The preview image is scaled using the nearest-neighbor algorithm, which might cause artifacts in some cases. Download the image for the best experience.

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