From 7cadbf8aada4b82b6b7bfcfd25f1409bfff48a5b Mon Sep 17 00:00:00 2001 From: Waveplate Date: Sun, 15 Dec 2024 07:33:48 -0800 Subject: [PATCH] apply luma-only effects --- src/main.rs | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7910da2..6889cf0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,36 +5,37 @@ mod effects; use reqwest; use url::Url; - use photon_rs::PhotonImage; use std::{error::Error, io::Cursor, process::exit}; - #[tokio::main] async fn main() { let args = args::parse_args(); match load_image_from_url_or_path(args.image.as_str()).await { - Ok(mut image) => { - image = effects::apply_effects( - &args, - image, - ); + Ok(image) => { + let image_luma = effects::apply_luma_effects(&args, image.clone()); + let image_chroma = effects::apply_effects(&args, image.clone()); - let canvas = draw::AnsiImage::new(image); + let canvas_luma = draw::AnsiImage::new(image_luma.clone()); + let canvas_chroma = draw::AnsiImage::new(image_chroma.clone()); - match (args.irc, args.ansi, args.ansi24, args.qb) { - (true, _, _, true) => println!("{}", draw::irc_draw_qb(canvas, &args).as_str()), - (true, _, _, false) => println!("{}", draw::irc_draw(canvas, &args).as_str()), - (_, true, _, true) => println!("{}", draw::ansi_draw_8bit_qb(canvas, &args).as_str()), - (_, true, _, false) => println!("{}", draw::ansi_draw_8bit(canvas, &args).as_str()), - (_, _, true, true) => println!("{}", draw::ansi_draw_24bit_qb(canvas).as_str()), - (_, _, true, false) => println!("{}", draw::ansi_draw_24bit(canvas).as_str()), - (_, _, _, true) => println!("{}", draw::irc_draw_qb(canvas, &args).as_str()), - _ => println!("{}", draw::irc_draw(canvas, &args).as_str()), + match (args.irc, args.ansi, args.ansi24, args.qb, args.braille) { + (true, _, _, true, false) => println!("{}", draw::irc_draw_qb(&canvas_chroma, &args)), + (true, _, _, false, false) => println!("{}", draw::irc_draw(&canvas_chroma, &args)), + (true, _, _, _, true) => println!("{}", draw::irc_draw_braille(&canvas_luma, &canvas_chroma, &args)), + (_, true, _, true, false) => println!("{}", draw::ansi_draw_8bit_qb(&canvas_chroma, &args)), + (_, true, _, false, false) => println!("{}", draw::ansi_draw_8bit(&canvas_chroma, &args)), + (_, true, _, _, true) => println!("{}", draw::ansi_draw_braille_8bit(&canvas_luma, &canvas_chroma, &args)), + (_, _, true, true, false) => println!("{}", draw::ansi_draw_24bit_qb(&canvas_chroma)), + (_, _, true, false, false) => println!("{}", draw::ansi_draw_24bit(&canvas_chroma)), + (_, _, true, _, true) => println!("{}", draw::ansi_draw_braille_24bit(&canvas_luma, &canvas_chroma, &args)), + (_, _, _, true, false) => println!("{}", draw::irc_draw_qb(&canvas_chroma, &args)), + (_, _, _, _, true) => println!("{}", draw::irc_draw_braille(&canvas_luma, &canvas_chroma, &args)), + _ => println!("{}", draw::irc_draw(&canvas_chroma, &args)), } - } + Err(e) => { eprintln!("Error: {}", e); exit(1); @@ -47,7 +48,6 @@ async fn load_image_from_url_or_path(image: &str) -> Result { let response = reqwest::get(url).await?; let bytes = response.bytes().await?; - let image_data = Cursor::new(bytes); match photon_rs::native::open_image_from_bytes(image_data.into_inner().as_ref()) { Ok(image) => Ok(image), @@ -62,4 +62,3 @@ async fn load_image_from_url_or_path(image: &str) -> Result