diff --git a/README.md b/README.md index 38e4321..1277063 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Including terminal or wasm produces the corresponding binary ### Priority - [x] ~~gif or png output (half the point of the whole library).~~ - [x] ~~If I use image::DynamicImage there are additional encoders/decoders that will be free~~ +- [ ] wasm web based processing app - basic happy path with no options works - [ ] Zooming/scaling (for png and gui output) - [ ] Additional EGA planar encodings - [ ] Map viewing (the other half): using the tile/spritesheets as palettes for larger images in psuedo CGA/EGA form (common in 80s games) diff --git a/src/png.rs b/src/png.rs index b8cfbf7..38cbbe8 100644 --- a/src/png.rs +++ b/src/png.rs @@ -46,3 +46,18 @@ pub fn output( img.save(path) } + +pub fn write_to( + bytes: &mut Vec, + image_data: RawGrid, + palette: ColorPalette, +) -> Result<(), image::ImageError> { + let mut img = RgbImage::new(image_data[0].len() as u32, image_data.len() as u32); + + for (x, row) in image_data.iter().enumerate() { + for (y, index) in row.iter().enumerate() { + img.put_pixel(y as u32, x as u32, palette[*index as usize].to_rgb()); + } + } + img.write_to(&mut Cursor::new(bytes), image::ImageFormat::Png) +} diff --git a/src/wasm/main.rs b/src/wasm/main.rs index 6d3cd02..e127ba0 100644 --- a/src/wasm/main.rs +++ b/src/wasm/main.rs @@ -2,7 +2,6 @@ extern crate base64; use std::collections::HashMap; - use base64::engine::general_purpose::STANDARD; use base64::Engine; use gloo::file::callbacks::FileReader; @@ -11,6 +10,11 @@ use web_sys::{DragEvent, Event, FileList, HtmlInputElement}; use yew::html::TargetCast; use yew::{html, Callback, Component, Context, Html}; +use cega::color::palette::palette_from_abbr; +use cega::image::Image; +use cega::parser::ParserType; +use cega::png; + struct FileDetails { name: String, file_type: String, @@ -76,7 +80,7 @@ impl Component for App { fn view(&self, ctx: &Context) -> Html { html! {
-

{ "Upload Your Files To The Cloud" }

+

{ "Process your image files" }