From ff994f5f25bd10c7bca9a2d59992584d39e335dd Mon Sep 17 00:00:00 2001 From: Devon Sawatsky Date: Mon, 27 Sep 2021 22:23:06 -0700 Subject: add some parallelism --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 7af53d6..7b2ae62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,9 +3,11 @@ use std::{collections::HashMap, env::args}; use image::io::Reader as ImageReader; use image::Rgb; +use rayon::prelude::*; + const MAX_COLORS: usize = 256; -const TOLERANCE: f32 = 0.6; +const TOLERANCE: f32 = 0.025; const RGB_TOLERANCE: f32 = 10.0 * TOLERANCE; fn main() { @@ -65,7 +67,7 @@ where } } - let mut sorted: Vec<(Rgb, usize)> = colors.into_iter().collect(); + let mut sorted: Vec<(Rgb, usize)> = colors.into_par_iter().collect(); sorted.sort_by(|(colour1, freq1), (colour2, freq2)| { freq2 .cmp(freq1) @@ -91,6 +93,7 @@ where } #[allow(clippy::many_single_char_names)] +#[inline(always)] fn rgb_difference(a: &Rgb, z: &Rgb) -> f32 { let (a, b, c) = pixel_rgb_to_hsv(a); let (d, e, f) = pixel_rgb_to_hsv(z); -- cgit 1.4.1-3-g733a5