2021-12-11 15:51:45 +00:00
|
|
|
import React from "react";
|
2021-12-12 16:50:58 +00:00
|
|
|
import ImageInput from "./ImageInput";
|
|
|
|
import ImageOutput from "./ImageOutput";
|
|
|
|
import Ditherer from "./Ditherer";
|
|
|
|
import ImagePreview from "./ImagePreview";
|
|
|
|
import Header from "./Header";
|
|
|
|
|
|
|
|
enum AppState {
|
|
|
|
NO_IMAGE,
|
|
|
|
IMAGE_LOADED,
|
|
|
|
IMAGE_PROCESSED,
|
|
|
|
}
|
2021-12-11 13:21:08 +00:00
|
|
|
|
|
|
|
function App() {
|
2021-12-12 16:50:58 +00:00
|
|
|
const [baseImage, setBaseImage] = React.useState<Uint8ClampedArray>();
|
|
|
|
const [ditheredImage, setDitheredImage] = React.useState<Uint8ClampedArray>();
|
|
|
|
const [appState, setAppState] = React.useState<AppState>(AppState.NO_IMAGE);
|
|
|
|
|
|
|
|
const handleImageSubmit = async (data: Uint8ClampedArray) => {
|
|
|
|
setBaseImage(data);
|
|
|
|
setAppState(AppState.IMAGE_LOADED);
|
|
|
|
const ditheredImage = await new Ditherer().dither(data);
|
|
|
|
setDitheredImage(ditheredImage);
|
|
|
|
setAppState(AppState.IMAGE_PROCESSED);
|
2021-12-11 15:19:48 +00:00
|
|
|
};
|
|
|
|
|
2021-12-11 13:21:08 +00:00
|
|
|
return (
|
2021-12-12 16:50:58 +00:00
|
|
|
<div className="bg-nord-6 text-nord-0 min-h-screen">
|
|
|
|
<Header />
|
|
|
|
<main className="container mx-auto">
|
|
|
|
<article className="max-w-prose mx-auto pb-5 px-2">
|
|
|
|
<h1 className="text-3xl text-center pb-3">
|
|
|
|
Go+Wasm image dithering tool
|
|
|
|
</h1>
|
|
|
|
<aside className="text-xl text-center pb-3">
|
|
|
|
Featuring the Nord Color Palette
|
|
|
|
</aside>
|
|
|
|
<p>
|
|
|
|
Load an image, click Go and wait (potentially for a while) for the
|
|
|
|
image to be processed using the Floyd-Steinberg algorithm.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
WebAssembly might run out of memory when processing larger images.
|
|
|
|
</p>
|
|
|
|
</article>
|
|
|
|
<ImageInput onImageSubmit={handleImageSubmit}></ImageInput>
|
|
|
|
{appState === AppState.IMAGE_LOADED && (
|
|
|
|
<ImagePreview imageData={baseImage as Uint8ClampedArray} />
|
|
|
|
)}
|
|
|
|
{appState === AppState.IMAGE_PROCESSED && (
|
|
|
|
<ImageOutput imageData={ditheredImage as Uint8ClampedArray} />
|
|
|
|
)}
|
|
|
|
</main>
|
2021-12-11 15:19:48 +00:00
|
|
|
</div>
|
2021-12-11 13:21:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|