added grayscale support
This commit is contained in:
parent
21d740cf70
commit
8de99aefac
|
|
@ -116,7 +116,7 @@ pub fn to_braille_ascii(image: DynamicImage, threshold: u8) -> Vec<Vec<Ascii>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
str.push(Ascii { char: char::from_u32(braille_value).unwrap(), rgb: [(r/8) as u8, (g/8) as u8, (b/8) as u8] });
|
str.push(Ascii::new_with_char(char::from_u32(braille_value).unwrap(), (r/8) as u8, (g/8) as u8, (b/8) as u8));
|
||||||
}
|
}
|
||||||
out.push(str);
|
out.push(str);
|
||||||
str = Vec::new();
|
str = Vec::new();
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,13 @@ pub struct Cli {
|
||||||
#[arg(short = 'c', long)]
|
#[arg(short = 'c', long)]
|
||||||
pub complex: bool,
|
pub complex: bool,
|
||||||
/// Display ASCII art in full colour
|
/// Display ASCII art in full colour
|
||||||
|
///
|
||||||
|
/// Takes priority over '--grayscale'
|
||||||
#[arg(short = 'C', long)]
|
#[arg(short = 'C', long)]
|
||||||
pub colour: bool,
|
pub colour: bool,
|
||||||
|
/// Display ASCII art in grayscale
|
||||||
|
#[arg(short= 'g', long)]
|
||||||
|
pub grayscale: bool,
|
||||||
/// Use braille characters instead of ASCII
|
/// Use braille characters instead of ASCII
|
||||||
///
|
///
|
||||||
/// Takes priority over '--complex' and '--map'
|
/// Takes priority over '--complex' and '--map'
|
||||||
|
|
@ -49,7 +54,7 @@ pub struct Cli {
|
||||||
pub width: Option<u32>,
|
pub width: Option<u32>,
|
||||||
/// Save the output to a file, instead of printing to terminal
|
/// Save the output to a file, instead of printing to terminal
|
||||||
///
|
///
|
||||||
/// Incompatible with '--colour'
|
/// Incompatible with '--colour' and '--grayscale'
|
||||||
#[arg(short = 'o', long = "output")]
|
#[arg(short = 'o', long = "output")]
|
||||||
pub output: Option<PathBuf>,
|
pub output: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
@ -62,6 +67,7 @@ impl Cli {
|
||||||
pub fn debug_print(&self) {
|
pub fn debug_print(&self) {
|
||||||
debug!("complex: {}", self.complex);
|
debug!("complex: {}", self.complex);
|
||||||
debug!("colour: {}", self.colour);
|
debug!("colour: {}", self.colour);
|
||||||
|
debug!("grayscale: {}", self.grayscale);
|
||||||
debug!("braille: {}", self.braille);
|
debug!("braille: {}", self.braille);
|
||||||
debug!("debug: {}", self.debug);
|
debug!("debug: {}", self.debug);
|
||||||
debug!("full: {}", self.full);
|
debug!("full: {}", self.full);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,12 @@ mod ascii_manipulation;
|
||||||
mod output;
|
mod output;
|
||||||
mod model_rgb_ascii;
|
mod model_rgb_ascii;
|
||||||
|
|
||||||
|
//todo:
|
||||||
|
/* custom background color, print font in white
|
||||||
|
* --formats flag
|
||||||
|
* --version flag
|
||||||
|
*/
|
||||||
|
|
||||||
/// This is the main function.
|
/// This is the main function.
|
||||||
///
|
///
|
||||||
/// It drives the CLI module, calls the appropriate convert functions and directs output.
|
/// It drives the CLI module, calls the appropriate convert functions and directs output.
|
||||||
|
|
@ -45,6 +51,6 @@ fn main() {
|
||||||
if let Some(output) = cli.output {
|
if let Some(output) = cli.output {
|
||||||
print_file(out, output);
|
print_file(out, output);
|
||||||
} else {
|
} else {
|
||||||
print_terminal(out, cli.colour);
|
print_terminal(out, cli.colour, cli.grayscale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
//! This module contains the Ascii struct.
|
//! This module contains the Ascii struct.
|
||||||
|
|
||||||
/// This struct represents one character + rgb colour.
|
/// This struct represents one character + rgb colour.
|
||||||
|
///
|
||||||
|
/// attributes:
|
||||||
|
/// char: char - the character associated with this ASCII value
|
||||||
|
/// rgb: [u8; 3] - vec of 3 u8 values representing red, green, and blue respectively
|
||||||
|
/// col_depthL u8 - the depth of the rgb values, calculated through the luminosity method
|
||||||
pub struct Ascii {
|
pub struct Ascii {
|
||||||
pub char: char,
|
pub char: char,
|
||||||
pub rgb: [u8; 3],
|
pub rgb: [u8; 3],
|
||||||
|
pub col_depth: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ascii {
|
impl Ascii {
|
||||||
|
|
@ -21,6 +27,25 @@ impl Ascii {
|
||||||
Ascii {
|
Ascii {
|
||||||
char: char::from(ch),
|
char: char::from(ch),
|
||||||
rgb: [r, g, b],
|
rgb: [r, g, b],
|
||||||
|
col_depth: (r as f32 * 0.3 + g as f32 * 0.59 + b as f32 * 0.11) as u8,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This function creates a new Ascii instance.
|
||||||
|
///
|
||||||
|
/// Arguments:
|
||||||
|
/// ch: char - the character
|
||||||
|
/// r: u8 - Red colour value
|
||||||
|
/// g: u8 - Green colour value
|
||||||
|
/// b: u8 - Blue colour value
|
||||||
|
///
|
||||||
|
/// returns:
|
||||||
|
/// self
|
||||||
|
pub fn new_with_char(ch: char, r: u8, g: u8, b: u8) -> Self {
|
||||||
|
Ascii {
|
||||||
|
char: ch,
|
||||||
|
rgb: [r, g, b],
|
||||||
|
col_depth: (r as f32 * 0.3 + g as f32 * 0.59 + b as f32 * 0.11) as u8,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,7 +13,7 @@ use crate::model_rgb_ascii::Ascii;
|
||||||
/// arguments:
|
/// arguments:
|
||||||
/// art: Vec<Vec<Ascii>> - vector of vectors representing the art
|
/// art: Vec<Vec<Ascii>> - vector of vectors representing the art
|
||||||
/// in_colour: bool - whether to print in colour or as hard white
|
/// in_colour: bool - whether to print in colour or as hard white
|
||||||
pub fn print_terminal(art: Vec<Vec<Ascii>>, in_colour: bool) {
|
pub fn print_terminal(art: Vec<Vec<Ascii>>, in_colour: bool, grayscale: bool) {
|
||||||
for line in art {
|
for line in art {
|
||||||
for ascii in line {
|
for ascii in line {
|
||||||
if in_colour {
|
if in_colour {
|
||||||
|
|
@ -21,6 +21,11 @@ pub fn print_terminal(art: Vec<Vec<Ascii>>, in_colour: bool) {
|
||||||
SetForegroundColor(Color::Rgb {r: ascii.rgb[0], g: ascii.rgb[1], b: ascii.rgb[2]}),
|
SetForegroundColor(Color::Rgb {r: ascii.rgb[0], g: ascii.rgb[1], b: ascii.rgb[2]}),
|
||||||
Print(ascii.char),
|
Print(ascii.char),
|
||||||
ResetColor);
|
ResetColor);
|
||||||
|
} else if grayscale {
|
||||||
|
let _ = execute!(stdout(),
|
||||||
|
SetForegroundColor(Color::Rgb {r: ascii.col_depth, g: ascii.col_depth, b: ascii.col_depth}),
|
||||||
|
Print(ascii.char),
|
||||||
|
ResetColor);
|
||||||
} else {
|
} else {
|
||||||
print!("{}", ascii.char);
|
print!("{}", ascii.char);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue