Improve the code yoo 💙🥰🦀

This commit is contained in:
Anas Elgarhy 2022-10-03 21:00:39 +02:00
parent 9d26bf939a
commit 1031014e27
2 changed files with 12 additions and 16 deletions

View file

@ -41,8 +41,6 @@ pub mod args {
Ok(()) Ok(())
} }
} }
} }
pub mod enums { pub mod enums {

View file

@ -1,10 +1,8 @@
use image::{GenericImageView, DynamicImage}; use image::{GenericImageView, DynamicImage};
use colored::{ColoredString, Colorize}; use colored::{ColoredString, Colorize};
use crate::args::{ use crate::args::{
args::Arguments, args::Arguments,
enums::Mode enums::Mode,
}; };
pub fn generate_ascii(image: DynamicImage, args: &Arguments) -> Vec<ColoredString> { pub fn generate_ascii(image: DynamicImage, args: &Arguments) -> Vec<ColoredString> {
@ -19,7 +17,7 @@ pub fn generate_ascii(image: DynamicImage, args: &Arguments) -> Vec<ColoredStrin
output.push(get_character( output.push(get_character(
image.get_pixel(x, y), image.get_pixel(x, y),
&characters, args.mode, &characters, args.mode,
&args.background &args.background,
)); ));
} }
} }
@ -35,7 +33,7 @@ pub fn generate_ascii(image: DynamicImage, args: &Arguments) -> Vec<ColoredStrin
fn get_character( fn get_character(
pixel: image::Rgba<u8>, pixel: image::Rgba<u8>,
characters: &Vec<char>, mode: Mode, characters: &Vec<char>, mode: Mode,
background: &Option<String> background: &Option<String>,
) -> ColoredString { ) -> ColoredString {
let intent = if pixel[3] == 0 { 0 } else { pixel[0] / 3 + pixel[1] / 3 + pixel[2] / 3 }; let intent = if pixel[3] == 0 { 0 } else { pixel[0] / 3 + pixel[1] / 3 + pixel[2] / 3 };