From a18a2ec6e2b06b0c7086f366a9fcf08c2772ecd4 Mon Sep 17 00:00:00 2001 From: kageru Date: Sun, 2 Jun 2019 10:12:38 +0200 Subject: [PATCH] adg.Mask actually works and seems to be faster than the old version --- Cargo.toml | 2 +- src/mask.rs | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4ea4dd8..07af6d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] failure = "0.1" -faster = "0.5" +faster = { git = "https://github.com/AdamNiederer/faster.git" } lazy_static = "1.3.0" num = "0.2" rand = "0.6" diff --git a/src/mask.rs b/src/mask.rs index 407629d..27c950d 100644 --- a/src/mask.rs +++ b/src/mask.rs @@ -1,5 +1,6 @@ use failure::Error; -use faster::*; +use faster::into_iters::*; +use faster::iters::*; use super::PLUGIN_NAME; use vapoursynth::api::API; use vapoursynth::core::CoreRef; @@ -17,13 +18,11 @@ pub struct Mask<'core> { } lazy_static! { - static ref FLOAT_RANGE: [f32; 1000] = { - let mut floats = [0f32; 1000]; - floats.iter_mut() + static ref FLOAT_RANGE: Vec = { + [0f32; 1000].iter() .enumerate() .map(|(i, _f)| (i as f32) * 0.001) - .for_each(drop); - floats + .collect::>() }; } @@ -96,13 +95,9 @@ impl<'core> Filter<'core> for Mask<'core> { let lut: Vec = FLOAT_RANGE.iter().map(|x| get_mask_value(*x, average, self.luma_scaling)).collect(); for row in 0..frame.height(0) { - //panic!(format!("{:?}", frame.plane_row::(0, 1000))); - //for (pixel, src_pixel) in frame.plane_row_mut::(0, row).iter_mut() - // .zip(src_frame.plane_row::(0, row).iter()) { - //*pixel = lut[(src_pixel * 1000f32) as usize]; - for (pixel, src_pixel) in frame.plane_row_mut::(0, row).simd_iter_mut() - .simd_zip(src_frame.plane_row(0, row).simd_iter()) { - *pixel = lut[(src_pixel * f32s(1000.0)) as usize]; + for (pixel, src_pixel) in frame.plane_row_mut::(0, row).iter_mut() + .zip(src_frame.plane_row::(0, row).iter()) { + *pixel = lut[(src_pixel * 1000f32) as usize]; } } Ok(frame.into())