diff options
author | Devon Sawatsky <novedevo@gmail.com> | 2021-09-27 20:04:10 -0700 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2021-09-28 23:05:18 +0000 |
commit | b1f06dbfb6404434ab211add1a12b0b08dcbc7e2 (patch) | |
tree | f6a8688240dde94a632919d1a4ffe66b0243b377 | |
parent | 9afc0408a36fc887167eb95b206a127104a11ea8 (diff) | |
download | colorsquash-b1f06dbfb6404434ab211add1a12b0b08dcbc7e2.tar.gz colorsquash-b1f06dbfb6404434ab211add1a12b0b08dcbc7e2.zip |
remove debug statements
-rw-r--r-- | src/main.rs | 40 |
1 files changed, 3 insertions, 37 deletions
diff --git a/src/main.rs b/src/main.rs index b72e912..9b75920 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, env::args, time::Instant}; +use std::{collections::HashMap, env::args}; use image::io::Reader as ImageReader; use image::{buffer::Pixels, Rgb}; @@ -9,26 +9,18 @@ const TOLERANCE: f32 = 0.6; const RGB_TOLERANCE: f32 = 10.0 * TOLERANCE; fn main() { - let before = Instant::now(); let filename = args().nth(1).unwrap(); let outname = args().nth(2).unwrap(); // The percent of RGB value difference a color has to surpass to be considered unique - println!("File is {}", &filename); - let imageread = ImageReader::open(&filename).expect("Failed to open image!"); let mut image = imageread .decode() .expect("Failed to decode image!") .into_rgb8(); - println!("Decoded!"); - let before_algo = Instant::now(); - let selected_colors = quantize(image.pixels()); - println!("Selected {} colors! Creating map...", selected_colors.len()); - let mut color_map: HashMap<Rgb<u8>, Rgb<u8>> = HashMap::with_capacity(image.len() / 2); // Selected colors are themselves for color in selected_colors.iter() { @@ -54,37 +46,11 @@ fn main() { color_map.insert(*color, min_difference_color); } - println!("Mapped! Filling in image..."); - for pixel in image.pixels_mut() { pixel.clone_from(color_map.get(pixel).unwrap()); } - println!( - "Filled! Took {}ms. Recounting colors...", - Instant::now().duration_since(before_algo).as_millis() - ); - - let mut recounted_colors = Vec::with_capacity(MAX_COLORS); - // Recount colors - for pixel in image.pixels() { - if !recounted_colors.contains(pixel) { - println!("Found unique color! Now {}", recounted_colors.len()); - recounted_colors.push(*pixel); - } - } - - println!( - "Aiming for a max of {} colors, got {}", - MAX_COLORS, - recounted_colors.len() - ); - image.save(outname).expect("Failed to write out"); - println!( - "Took {}ms", - Instant::now().duration_since(before).as_millis() - ); } fn quantize(pixels: Pixels<Rgb<u8>>) -> Vec<Rgb<u8>> { @@ -131,7 +97,7 @@ fn quantize(pixels: Pixels<Rgb<u8>>) -> Vec<Rgb<u8>> { selected_colors } - +#[allow(clippy::many_single_char_names)] fn rgb_difference(a: &Rgb<u8>, z: &Rgb<u8>) -> f32 { //((a.0[0] as i16 - b.0[0] as i16).abs() + (a.0[1] as i16 - b.0[1] as i16).abs() +(a.0[2] as i16 - b.0[2] as i16).abs()) as u16 //(a.0[0] as i16 - b.0[0] as i16).abs().max((a.0[1] as i16 - b.0[1] as i16).abs().max(a.0[2] as i16 - b.0[2] as i16).abs()) as u16 @@ -146,7 +112,7 @@ fn rgb_difference(a: &Rgb<u8>, z: &Rgb<u8>) -> f32 { (((c - f) * (c - f)) + ((a - d).abs() / 90.0) + (b - e).abs()) as f32 } -#[warn(clippy::float_cmp)] +#[allow(clippy::float_cmp)] fn pixel_rgb_to_hsv(a: &Rgb<u8>) -> (f32, f32, f32) { let (r, g, b) = ( a.0[0] as f32 / 256.0, |