Skip to content

Commit d236f03

Browse files
committed
setup for height wizard step
1 parent 8536ab9 commit d236f03

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/file_data.rs

+7
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ impl Raw {
2424
itype.widths(self.byte_count())
2525
}
2626

27+
pub fn heights(&self, itype: ImageType, width: usize) -> Vec<i64> {
28+
itype.heights(self.byte_count(), width)
29+
}
30+
2731
pub fn parse(&self, parser: ParserType, width: usize) -> Image {
2832
Image(parser.process_input(&self.0, width))
2933
}
3034

3135
pub fn previews(&self) -> Vec<Image> {
36+
// if let Some(width) = width {
37+
// }else {
3238
self.widths(ImageType::CGA)
3339
.iter()
3440
.map(|w| Image(ParserType::CGA.process_input(&self.0, *w as usize)))
3541
.collect()
42+
// }
3643
}
3744
}

src/lib.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,17 @@ impl ImageType {
6262
}
6363

6464
pub fn widths(&self, byte_count: usize) -> Vec<i64> {
65-
factor(self.pixel_count(byte_count).try_into().unwrap())
65+
Self::factors(self.pixel_count(byte_count), 80)
66+
}
67+
68+
pub fn heights(&self, byte_count: usize, width: usize) -> Vec<i64> {
69+
Self::factors(self.pixel_count(byte_count) / width, 50)
70+
}
71+
72+
pub fn factors(num: usize, upper: usize) -> Vec<i64> {
73+
factor(num.try_into().unwrap())
6674
.into_iter()
67-
.filter(|&x| x > 4 && x < 80)
75+
.filter(|&x| x >= 4 && x <= upper.try_into().unwrap())
6876
.collect()
6977
}
7078
}

src/wasm/image.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use base64::{engine::general_purpose::STANDARD, Engine};
22

3-
use web_sys::{HtmlElement, HtmlInputElement};
3+
use web_sys::HtmlInputElement;
44
use yew::{html, Callback, Component, Context, Event, Html, Properties, SubmitEvent, TargetCast};
55

66
use crate::color::palette::palette_from_abbr;
@@ -57,7 +57,10 @@ impl ImageComponent {
5757
let _ = png::write_to(&mut bytes, tile(p.data(), self.height), palette.clone());
5858
let src = format!("data:application/png;base64,{}", STANDARD.encode(bytes));
5959
html! {
60-
<img src={ src } />
60+
<span>
61+
{p.width()}
62+
<img src={ src } />
63+
</span>
6164
}
6265
})
6366
.collect()

0 commit comments

Comments
 (0)