about summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index c257dea..02c2950 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -24,23 +24,19 @@ fn main() {
     let selected_colors = quantize(image.pixels());
 
     // Max complexity is O(n * max_colors)
-    for color in image.pixels_mut() {
-        let quantized = {
-            let mut min_difference = f32::MAX;
-            let mut min_difference_color = *color;
-
-            for selected_color in &selected_colors {
-                let difference = rgb_difference(color, selected_color);
-                if difference < min_difference {
-                    min_difference = difference;
-                    min_difference_color = *selected_color;
-                }
+    image.pixels_mut().par_bridge().for_each(|color| {
+        let mut min_difference = f32::MAX;
+        let mut min_difference_color = *color;
+
+        for selected_color in &selected_colors {
+            let difference = rgb_difference(color, selected_color);
+            if difference < min_difference {
+                min_difference = difference;
+                min_difference_color = *selected_color;
             }
-            min_difference_color
-        };
-
-        *color = quantized;
-    }
+        }
+        *color = min_difference_color
+    });
 
     image.save(outname).expect("Failed to write out");
 }