File tree 2 files changed +33
-17
lines changed
2 files changed +33
-17
lines changed Original file line number Diff line number Diff line change 1
- use factor:: factor:: factor;
2
-
3
1
use crate :: image:: Image ;
4
2
use crate :: parser:: ParserType ;
3
+ use crate :: ImageType ;
5
4
6
5
pub struct Raw ( Vec < u8 > ) ;
7
6
@@ -12,23 +11,17 @@ impl Raw {
12
11
fn byte_count ( & self ) -> usize {
13
12
self . 0 . len ( )
14
13
}
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 ( ) )
26
17
}
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 ( ) )
29
21
}
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 ( ) )
32
25
}
33
26
34
27
pub fn parse ( & self , parser : ParserType , width : usize ) -> Image {
Original file line number Diff line number Diff line change 1
1
#![ doc = include_str ! ( "../README.md" ) ]
2
2
3
+ use factor:: factor:: factor;
4
+
3
5
pub mod color;
4
6
pub mod file_data;
5
7
pub mod image;
@@ -38,10 +40,31 @@ impl ImageType {
38
40
Self :: EGA => 16 ,
39
41
}
40
42
}
43
+
41
44
pub fn word_size ( & self ) -> usize {
42
45
match self {
43
46
Self :: CGA => 2 ,
44
47
Self :: EGA => 4 ,
45
48
}
46
49
}
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
+ }
47
70
}
You can’t perform that action at this time.
0 commit comments