From 460b05963de555fd22de3b33020b8a4ee58ca567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Fri, 1 Jun 2018 16:45:40 +0100 Subject: [PATCH] Parallel alphas --- src/png/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/png/mod.rs b/src/png/mod.rs index 12fdb3e2..a213969c 100644 --- a/src/png/mod.rs +++ b/src/png/mod.rs @@ -15,6 +15,7 @@ use std::fs::File; use std::io::{Read, Seek, SeekFrom}; use std::iter::Iterator; use std::path::Path; +use rayon::prelude::*; const STD_COMPRESSION: u8 = 8; const STD_STRATEGY: u8 = 2; // Huffman only @@ -601,13 +602,16 @@ impl PngData { pub fn try_alpha_reduction(&mut self, alphas: &HashSet) { assert!(!alphas.is_empty()); + let alphas = alphas.iter().collect::>(); let best = alphas - .iter() - .filter_map(|alpha| { + .par_iter() + .with_max_len(1) + .filter_map(|&alpha| { let mut image = self.clone(); image.reduce_alpha_channel(*alpha); STD_FILTERS - .iter() + .par_iter() + .with_max_len(1) .filter_map(|f| { deflate::deflate( &image.filter_image(*f),