diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | src/main.rs | 7 |
3 files changed, 11 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock index 8f6ffed..7b23b4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,7 @@ version = "0.1.0" dependencies = [ "image", "kmeans_colors", + "rayon", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f389eed..a116a39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,11 @@ edition = "2021" [dependencies] image = "0.23.14" +rayon = "*" [dependencies.kmeans_colors] version = "0.3" -default-features = false \ No newline at end of file +default-features = false + +[profile.release] +debug = true \ No newline at end of file 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<u8>, usize)> = colors.into_iter().collect(); + let mut sorted: Vec<(Rgb<u8>, 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<u8>, z: &Rgb<u8>) -> f32 { let (a, b, c) = pixel_rgb_to_hsv(a); let (d, e, f) = pixel_rgb_to_hsv(z); |