Skip to content

Commit

Permalink
more setup for moving to multiple preview images
Browse files Browse the repository at this point in the history
  • Loading branch information
knzai committed Aug 3, 2024
1 parent 541acb9 commit 7f51c3f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/file_data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use factor::factor::factor;

use crate::image::Image;
use crate::parser::ParserType;
use crate::ImageType;

pub struct Raw(Vec<u8>);

Expand All @@ -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<i64> {
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<i64> {
factor(self.ega_count().try_into().unwrap())

pub fn widths(&self, itype: ImageType) -> Vec<i64> {
itype.widths(self.byte_count())
}

pub fn parse(&self, parser: ParserType, width: usize) -> Image {
Expand Down
23 changes: 23 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![doc = include_str!("../README.md")]

use factor::factor::factor;

pub mod color;
pub mod file_data;
pub mod image;
Expand Down Expand Up @@ -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<i64> {
factor(self.pixel_count(byte_count).try_into().unwrap())
.into_iter()
.filter(|&x| x < 80)
.collect()
}
}

0 comments on commit 7f51c3f

Please sign in to comment.