From cf35e041dda0c24037cea3b28b127afa31c8dd3b Mon Sep 17 00:00:00 2001 From: mindv0rtex Date: Fri, 26 Feb 2021 15:52:17 -0500 Subject: [PATCH] Make vertical blur parallel. --- src/blur.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/blur.rs b/src/blur.rs index 5dcf603..b651d52 100644 --- a/src/blur.rs +++ b/src/blur.rs @@ -100,18 +100,19 @@ impl Blur { } } + // The outer loop cannot be parallelized because we need to use the buffer sequentially. for (i, dst_row) in dst.chunks_exact_mut(width).enumerate() { let bottom_off = ((i + height - radius - 1) & (height - 1)) * width; let bottom_row = &src[bottom_off..bottom_off + width]; let top_off = ((i + radius) & (height - 1)) * width; let top_row = &src[top_off..top_off + width]; - for (dst, buf, bottom, top) in - multizip((dst_row, &mut self.row_buffer, bottom_row, top_row)) - { - *buf += top - bottom; - *dst = *buf * weight; - } + (dst_row, &mut self.row_buffer, bottom_row, top_row) + .into_par_iter() + .for_each(|(dst, buf, bottom, top)| { + *buf += top - bottom; + *dst = *buf * weight; + }); } } }