diff options
author | Devon Sawatsky <novedevo@gmail.com> | 2021-09-27 22:34:00 -0700 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2021-09-28 23:05:18 +0000 |
commit | 55b3701a970dda00d22945234055f8b668bb3967 (patch) | |
tree | 7fdbab2ad977f26d998c3182760374528284dbfd | |
parent | 12ed34dcf9ff0bea6f33730548dbba63ea0e85d8 (diff) | |
download | colorsquash-55b3701a970dda00d22945234055f8b668bb3967.tar.gz colorsquash-55b3701a970dda00d22945234055f8b668bb3967.zip |
parallelize
-rw-r--r-- | src/main.rs | 28 |
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"); } |