aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs36
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 @@
1mod app; 1mod app;
2mod bitmap; 2mod bitmap;
3mod command;
3mod consts; 4mod consts;
4mod dither; 5mod dither;
5mod symmetry; 6mod symmetry;
@@ -8,8 +9,41 @@ mod utils;
8 9
9use app::AppState; 10use app::AppState;
10 11
12use std::{
13 env,
14 fs::OpenOptions,
15 io::{Cursor, Read},
16};
17
18use obi::Image;
19
11pub fn main() { 20pub 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}