2022-10-03 14:59:34 +00:00
|
|
|
use clap::Parser;
|
|
|
|
use image::GenericImageView;
|
2022-10-03 18:50:48 +00:00
|
|
|
|
2022-10-10 20:17:21 +00:00
|
|
|
use std::io::Result;
|
2022-10-03 14:59:34 +00:00
|
|
|
|
|
|
|
extern crate pretty_env_logger;
|
2022-10-10 20:17:21 +00:00
|
|
|
|
2022-10-03 18:13:59 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2022-10-03 14:04:38 +00:00
|
|
|
|
|
|
|
mod args;
|
2022-10-03 18:13:59 +00:00
|
|
|
mod ascii_processor;
|
2022-10-10 20:17:21 +00:00
|
|
|
mod output;
|
2022-10-03 14:04:38 +00:00
|
|
|
|
2022-10-10 20:17:21 +00:00
|
|
|
use crate::args::{args::Arguments, enums::OutputMethod};
|
2022-10-03 18:13:59 +00:00
|
|
|
|
|
|
|
use crate::ascii_processor::generate_ascii;
|
2022-10-03 14:04:38 +00:00
|
|
|
|
2022-10-10 20:17:21 +00:00
|
|
|
fn main() -> Result<()> {
|
2022-10-03 14:59:34 +00:00
|
|
|
// Initialize the logger
|
|
|
|
pretty_env_logger::init();
|
|
|
|
info!("Successfully initialized logger");
|
|
|
|
info!("Parsing arguments");
|
|
|
|
// Parse the arguments
|
2022-10-03 14:04:38 +00:00
|
|
|
let arguments = Arguments::parse();
|
2022-10-03 14:59:34 +00:00
|
|
|
info!("Successfully parsed arguments");
|
|
|
|
trace!("Arguments: {:?}", arguments);
|
|
|
|
|
2022-10-03 18:13:59 +00:00
|
|
|
// Validate the arguments
|
|
|
|
info!("Validating arguments");
|
|
|
|
match arguments.validate() {
|
|
|
|
Ok(_) => (),
|
|
|
|
Err(e) => {
|
|
|
|
error!("Failed to validate arguments: {}", e);
|
|
|
|
eprintln!("Failed to validate arguments: {}", e);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-03 14:59:34 +00:00
|
|
|
// Open the image
|
|
|
|
info!("Opening image: {}", arguments.image);
|
2022-10-03 18:13:59 +00:00
|
|
|
let image = match image::open(arguments.image.clone()) {
|
2022-10-03 14:59:34 +00:00
|
|
|
Ok(image) => image,
|
|
|
|
Err(e) => {
|
|
|
|
error!("Failed to open image: {:?}", e);
|
|
|
|
eprintln!("Failed to open image: {:?}", e);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
info!("Successfully opened image");
|
|
|
|
trace!("Image dimensions: {:?}", image.dimensions());
|
|
|
|
|
2022-10-10 20:17:21 +00:00
|
|
|
generate_ascii(image, &arguments, output::prepare_output(&arguments)?)?;
|
2022-10-03 18:50:48 +00:00
|
|
|
info!("Successfully processed image");
|
2022-10-10 20:17:21 +00:00
|
|
|
Ok(())
|
2022-10-03 11:09:12 +00:00
|
|
|
}
|