mod app; mod bitmap; mod command; mod consts; mod dither; mod lisp; mod message; mod symmetry; mod undo; mod utils; use app::AppState; use std::{ env, fs::OpenOptions, io::{Cursor, Read}, path::{Path, PathBuf}, }; use log::{error, info}; use obi::Image; pub fn main() { env_logger::init(); let sdl_context = sdl2::init(); if sdl_context.is_err() { error!("Unable to find libsdl2 ... Exiting"); return; } let sdl_context = sdl_context.unwrap(); info!("Initialized SDL context"); let ttf_context = sdl2::ttf::init(); if ttf_context.is_err() { error!("Unable to find SDL2_ttf ... Exiting"); return; } let ttf_context = ttf_context.unwrap(); info!("Initialized SDL_ttf context"); let args: Vec<_> = env::args().collect(); if args.len() < 2 { AppState::init(160, 160, &sdl_context, &ttf_context, None, None).run(); return; } else { let path = PathBuf::from(args.get(1).unwrap()); let image_src = OpenOptions::new() .read(true) .write(false) .create(false) .open(&path); if let Ok(mut image) = image_src { let mut buf = Vec::new(); image.read_to_end(&mut buf).unwrap(); let decoded = Image::decode(&mut (Cursor::new(buf))).unwrap(); let (width, height) = (decoded.width(), decoded.height()); AppState::init( width, height, &sdl_context, &ttf_context, Some(decoded.data), Some(&path), ) .run(); } else { } } }