Skip to content

Commit 7f51c3f

Browse files
committed
more setup for moving to multiple preview images
1 parent 541acb9 commit 7f51c3f

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

src/file_data.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use factor::factor::factor;
2-
31
use crate::image::Image;
42
use crate::parser::ParserType;
3+
use crate::ImageType;
54

65
pub struct Raw(Vec<u8>);
76

@@ -12,23 +11,17 @@ impl Raw {
1211
fn byte_count(&self) -> usize {
1312
self.0.len()
1413
}
15-
fn cga_count(&self) -> usize {
16-
self.byte_count() * 4
17-
}
18-
fn ega_count(&self) -> usize {
19-
self.byte_count() * 2
20-
}
21-
pub fn cga_possible(&self) -> bool {
22-
self.cga_count() <= 64_000
23-
}
24-
pub fn cga_fullscreen(&self) -> bool {
25-
self.cga_count() == 64_000
14+
15+
pub fn pixel_count(&self, itype: ImageType) -> usize {
16+
itype.pixel_count(self.byte_count())
2617
}
27-
pub fn cga_widths(&self) -> Vec<i64> {
28-
factor(self.cga_count().try_into().unwrap())
18+
19+
pub fn fullscreen(&self, itype: ImageType) -> bool {
20+
itype.fullscreen(self.byte_count())
2921
}
30-
pub fn ega_widths(&self) -> Vec<i64> {
31-
factor(self.ega_count().try_into().unwrap())
22+
23+
pub fn widths(&self, itype: ImageType) -> Vec<i64> {
24+
itype.widths(self.byte_count())
3225
}
3326

3427
pub fn parse(&self, parser: ParserType, width: usize) -> Image {

src/lib.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![doc = include_str!("../README.md")]
22

3+
use factor::factor::factor;
4+
35
pub mod color;
46
pub mod file_data;
57
pub mod image;
@@ -38,10 +40,31 @@ impl ImageType {
3840
Self::EGA => 16,
3941
}
4042
}
43+
4144
pub fn word_size(&self) -> usize {
4245
match self {
4346
Self::CGA => 2,
4447
Self::EGA => 4,
4548
}
4649
}
50+
51+
pub fn words_per_byte(&self) -> usize {
52+
8 / self.word_size()
53+
}
54+
55+
pub fn pixel_count(&self, byte_count: usize) -> usize {
56+
byte_count * self.words_per_byte()
57+
}
58+
59+
pub fn fullscreen(&self, byte_count: usize) -> bool {
60+
//this does not yet handle all the different EGA cases, or cga monochrome etc
61+
self.pixel_count(byte_count) == 64_000
62+
}
63+
64+
pub fn widths(&self, byte_count: usize) -> Vec<i64> {
65+
factor(self.pixel_count(byte_count).try_into().unwrap())
66+
.into_iter()
67+
.filter(|&x| x < 80)
68+
.collect()
69+
}
4770
}

0 commit comments

Comments
 (0)