about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDevon Sawatsky <novedevo@gmail.com>2021-09-27 22:23:06 -0700
committergennyble <gen@nyble.dev>2021-09-28 23:05:18 +0000
commitff994f5f25bd10c7bca9a2d59992584d39e335dd (patch)
tree907af8af371d916d6151ed22cfbad1cf6501f67f /src
parentb8cdcfd74141db80bc1b1da71f8d120f3a0812d1 (diff)
downloadcolorsquash-ff994f5f25bd10c7bca9a2d59992584d39e335dd.tar.gz
colorsquash-ff994f5f25bd10c7bca9a2d59992584d39e335dd.zip
add some parallelism
Diffstat (limited to 'src')
-rw-r--r--src/main.rs7
1 files changed, 5 insertions, 2 deletions
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);