Skip to content

Commit

Permalink
setup for height wizard step
Browse files Browse the repository at this point in the history
  • Loading branch information
knzai committed Aug 4, 2024
1 parent 8536ab9 commit d236f03
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/file_data.rs
Original file line number Diff line number Diff line change
@@ -24,14 +24,21 @@ impl Raw {
itype.widths(self.byte_count())
}

pub fn heights(&self, itype: ImageType, width: usize) -> Vec<i64> {
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<Image> {
// if let Some(width) = width {
// }else {
self.widths(ImageType::CGA)
.iter()
.map(|w| Image(ParserType::CGA.process_input(&self.0, *w as usize)))
.collect()
// }
}
}
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -62,9 +62,17 @@ impl ImageType {
}

pub fn widths(&self, byte_count: usize) -> Vec<i64> {
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<i64> {
Self::factors(self.pixel_count(byte_count) / width, 50)
}

pub fn factors(num: usize, upper: usize) -> Vec<i64> {
factor(num.try_into().unwrap())
.into_iter()
.filter(|&x| x > 4 && x < 80)
.filter(|&x| x >= 4 && x <= upper.try_into().unwrap())
.collect()
}
}
7 changes: 5 additions & 2 deletions src/wasm/image.rs
Original file line number Diff line number Diff line change
@@ -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! {
<img src={ src } />
<span>
{p.width()}
<img src={ src } />
</span>
}
})
.collect()

0 comments on commit d236f03

Please sign in to comment.