diff --git a/src/file_data.rs b/src/file_data.rs index 0a1a66f..2abd080 100644 --- a/src/file_data.rs +++ b/src/file_data.rs @@ -24,14 +24,21 @@ impl Raw { itype.widths(self.byte_count()) } + pub fn heights(&self, itype: ImageType, width: usize) -> Vec { + itype.heights(self.byte_count(), width) + } + pub fn parse(&self, parser: ParserType, width: usize) -> Image { Image(parser.process_input(&self.0, width)) } pub fn previews(&self) -> Vec { + // if let Some(width) = width { + // }else { self.widths(ImageType::CGA) .iter() .map(|w| Image(ParserType::CGA.process_input(&self.0, *w as usize))) .collect() + // } } } diff --git a/src/lib.rs b/src/lib.rs index 900f3a4..646edbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,9 +62,17 @@ impl ImageType { } pub fn widths(&self, byte_count: usize) -> Vec { - factor(self.pixel_count(byte_count).try_into().unwrap()) + Self::factors(self.pixel_count(byte_count), 80) + } + + pub fn heights(&self, byte_count: usize, width: usize) -> Vec { + Self::factors(self.pixel_count(byte_count) / width, 50) + } + + pub fn factors(num: usize, upper: usize) -> Vec { + factor(num.try_into().unwrap()) .into_iter() - .filter(|&x| x > 4 && x < 80) + .filter(|&x| x >= 4 && x <= upper.try_into().unwrap()) .collect() } } diff --git a/src/wasm/image.rs b/src/wasm/image.rs index bf85cc1..654eb1d 100644 --- a/src/wasm/image.rs +++ b/src/wasm/image.rs @@ -1,6 +1,6 @@ use base64::{engine::general_purpose::STANDARD, Engine}; -use web_sys::{HtmlElement, HtmlInputElement}; +use web_sys::HtmlInputElement; use yew::{html, Callback, Component, Context, Event, Html, Properties, SubmitEvent, TargetCast}; use crate::color::palette::palette_from_abbr; @@ -57,7 +57,10 @@ impl ImageComponent { let _ = png::write_to(&mut bytes, tile(p.data(), self.height), palette.clone()); let src = format!("data:application/png;base64,{}", STANDARD.encode(bytes)); html! { - + + {p.width()} + + } }) .collect()