From f9fea83ed4d9f4ab6fd2b16018d95dd77e0e3062 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Mon, 26 Jan 2026 20:30:40 +0100 Subject: [PATCH] slightly improve printing and explanations --- src/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index b3b6365..147edf1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,7 +62,8 @@ fn encode_standard(pixels: &[[u8; 4]], width: u32, height: u32) -> Vec { w } -/// Simple program to optimise palette based PNGs +/// Simple program to optimise palette based PNGs and substitute certain rgb values +/// Assumes that there is only alpha 0 and alpha 255 #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Args { @@ -79,14 +80,14 @@ struct Args { fn parse_rgb(hex: String) -> Result<[u8; 4], String> { if hex.len() != 6 { - return Err("expected rrggbb".into()); + return Err("Expected the format rrggbb".into()); } let bytes: Vec = (0..6) .step_by(2) .map(|i| u8::from_str_radix(&hex[i..i + 2], 16)) .collect::>() - .map_err(|_| "invalid hex color")?; + .map_err(|_| "Invalid hex color")?; Ok([bytes[0], bytes[1], bytes[2], 0xff]) } @@ -109,9 +110,9 @@ fn main() { .map(|[a, b]| (*a, *b)) .collect(); if asubs_len == 0 { - println!("no substitutions selected, only re-encoding") + println!("No substitutions selected, only re-encoding") } else { - println!("substitutions to use: {:?}", pairs); + println!("Using substitutions: {:?}", pairs); } let decoder = PngDecoder::new(BufReader::new(File::open(in_path).unwrap())).unwrap(); @@ -127,8 +128,11 @@ fn main() { let plte_data = encode_plte(image_data.as_slice(), width, height); let std_data = encode_standard(image_data.as_slice(), width, height); - println!("plte data has length {}", plte_data.len(),); - println!("std data has length {}", std_data.len(),); + println!( + "Palette data has length {}, standard has {}", + plte_data.len(), + std_data.len() + ); let mut file = File::create(out_path).unwrap(); if plte_data.len() <= std_data.len() {