diff --git a/src/file_data.rs b/src/file_data.rs index a5d6028..fea064a 100644 --- a/src/file_data.rs +++ b/src/file_data.rs @@ -1,7 +1,6 @@ -use factor::factor::factor; - use crate::image::Image; use crate::parser::ParserType; +use crate::ImageType; pub struct Raw(Vec); @@ -12,23 +11,17 @@ impl Raw { fn byte_count(&self) -> usize { self.0.len() } - fn cga_count(&self) -> usize { - self.byte_count() * 4 - } - fn ega_count(&self) -> usize { - self.byte_count() * 2 - } - pub fn cga_possible(&self) -> bool { - self.cga_count() <= 64_000 - } - pub fn cga_fullscreen(&self) -> bool { - self.cga_count() == 64_000 + + pub fn pixel_count(&self, itype: ImageType) -> usize { + itype.pixel_count(self.byte_count()) } - pub fn cga_widths(&self) -> Vec { - factor(self.cga_count().try_into().unwrap()) + + pub fn fullscreen(&self, itype: ImageType) -> bool { + itype.fullscreen(self.byte_count()) } - pub fn ega_widths(&self) -> Vec { - factor(self.ega_count().try_into().unwrap()) + + pub fn widths(&self, itype: ImageType) -> Vec { + itype.widths(self.byte_count()) } pub fn parse(&self, parser: ParserType, width: usize) -> Image { diff --git a/src/lib.rs b/src/lib.rs index 80aab00..91de810 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ #![doc = include_str!("../README.md")] +use factor::factor::factor; + pub mod color; pub mod file_data; pub mod image; @@ -38,10 +40,31 @@ impl ImageType { Self::EGA => 16, } } + pub fn word_size(&self) -> usize { match self { Self::CGA => 2, Self::EGA => 4, } } + + pub fn words_per_byte(&self) -> usize { + 8 / self.word_size() + } + + pub fn pixel_count(&self, byte_count: usize) -> usize { + byte_count * self.words_per_byte() + } + + pub fn fullscreen(&self, byte_count: usize) -> bool { + //this does not yet handle all the different EGA cases, or cga monochrome etc + self.pixel_count(byte_count) == 64_000 + } + + pub fn widths(&self, byte_count: usize) -> Vec { + factor(self.pixel_count(byte_count).try_into().unwrap()) + .into_iter() + .filter(|&x| x < 80) + .collect() + } }