Improve the code yoo 💙🥰🦀
This commit is contained in:
parent
9d26bf939a
commit
1031014e27
2 changed files with 12 additions and 16 deletions
16
src/args.rs
16
src/args.rs
|
@ -3,27 +3,27 @@ pub mod args {
|
|||
use super::enums::*;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about=None, color=ColorChoice::Always)]
|
||||
#[command(author, version, about, long_about = None, color = ColorChoice::Always)]
|
||||
pub struct Arguments {
|
||||
/// The art mode to use
|
||||
#[arg(short, long, default_value="normal-ascii")]
|
||||
#[arg(short, long, default_value = "normal-ascii")]
|
||||
pub mode: Mode,
|
||||
#[arg(long, default_value="stdout", alias="mo")]
|
||||
#[arg(long, default_value = "stdout", alias = "mo")]
|
||||
pub output_method: OutputMethod,
|
||||
/// The image to convert to ASCII art
|
||||
pub image: String,
|
||||
/// The character to use for drawing the image (lighter to darker)
|
||||
/// You can user one character if you uses the color mode
|
||||
#[arg(short, long, default_value=" .,-~!;:=*&%$@#")]
|
||||
#[arg(short, long, default_value = " .,-~!;:=*&%$@#")]
|
||||
pub characters: String,
|
||||
/// The output scale (1 is the original size)
|
||||
#[arg(short, long, default_value="4")]
|
||||
#[arg(short, long, default_value = "4")]
|
||||
pub scale: u32,
|
||||
/// The background color to use
|
||||
#[arg(short, long, default_value=None)]
|
||||
#[arg(short, long, default_value = None)]
|
||||
pub background: Option<String>,
|
||||
/// The output file to write to (if output_method is file)
|
||||
#[arg(short, long, default_value="ascii_image.txt")]
|
||||
#[arg(short, long, default_value = "ascii_image.txt")]
|
||||
pub output: String,
|
||||
}
|
||||
|
||||
|
@ -41,8 +41,6 @@ pub mod args {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
pub mod enums {
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
|
||||
|
||||
use image::{GenericImageView, DynamicImage};
|
||||
use colored::{ColoredString, Colorize};
|
||||
use crate::args::{
|
||||
args::Arguments,
|
||||
enums::Mode
|
||||
enums::Mode,
|
||||
};
|
||||
|
||||
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(
|
||||
image.get_pixel(x, y),
|
||||
&characters, args.mode,
|
||||
&args.background
|
||||
&args.background,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +33,7 @@ pub fn generate_ascii(image: DynamicImage, args: &Arguments) -> Vec<ColoredStrin
|
|||
fn get_character(
|
||||
pixel: image::Rgba<u8>,
|
||||
characters: &Vec<char>, mode: Mode,
|
||||
background: &Option<String>
|
||||
background: &Option<String>,
|
||||
) -> ColoredString {
|
||||
let intent = if pixel[3] == 0 { 0 } else { pixel[0] / 3 + pixel[1] / 3 + pixel[2] / 3 };
|
||||
|
||||
|
|
Loading…
Reference in a new issue