diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 14f4cf5..ebdf793 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | mod app; | 1 | mod app; |
2 | mod bitmap; | 2 | mod bitmap; |
3 | mod command; | ||
3 | mod consts; | 4 | mod consts; |
4 | mod dither; | 5 | mod dither; |
5 | mod symmetry; | 6 | mod symmetry; |
@@ -8,8 +9,41 @@ mod utils; | |||
8 | 9 | ||
9 | use app::AppState; | 10 | use app::AppState; |
10 | 11 | ||
12 | use std::{ | ||
13 | env, | ||
14 | fs::OpenOptions, | ||
15 | io::{Cursor, Read}, | ||
16 | }; | ||
17 | |||
18 | use obi::Image; | ||
19 | |||
11 | pub fn main() { | 20 | pub fn main() { |
12 | let sdl_context = sdl2::init().unwrap(); | 21 | let sdl_context = sdl2::init().unwrap(); |
13 | let ttf_context = sdl2::ttf::init().unwrap(); | 22 | let ttf_context = sdl2::ttf::init().unwrap(); |
14 | AppState::init(200, 200, &sdl_context, &ttf_context).run(); | 23 | let args: Vec<_> = env::args().collect(); |
24 | if args.len() < 2 { | ||
25 | AppState::init(200, 200, &sdl_context, &ttf_context, None).run(); | ||
26 | return; | ||
27 | } else { | ||
28 | let path = args.get(1).unwrap(); | ||
29 | let image_src = OpenOptions::new() | ||
30 | .read(true) | ||
31 | .write(false) | ||
32 | .create(false) | ||
33 | .open(path); | ||
34 | if let Ok(mut image) = image_src { | ||
35 | let mut buf = Vec::new(); | ||
36 | image.read_to_end(&mut buf).unwrap(); | ||
37 | let decoded = Image::decode(&mut (Cursor::new(buf))).unwrap(); | ||
38 | let (width, height) = (decoded.width(), decoded.height()); | ||
39 | AppState::init( | ||
40 | width, | ||
41 | height, | ||
42 | &sdl_context, | ||
43 | &ttf_context, | ||
44 | Some(decoded.data), | ||
45 | ) | ||
46 | .run(); | ||
47 | } | ||
48 | } | ||
15 | } | 49 | } |