mod gaussian;
use gaussian::RecursiveGaussian;
pub struct Blur {
kernel: RecursiveGaussian,
temp: Vec<f32>,
width: usize,
height: usize,
}
impl Blur {
#[must_use]
pub fn new(width: usize, height: usize) -> Self {
Blur {
kernel: RecursiveGaussian,
temp: vec![0.0f32; width * height],
width,
height,
}
}
pub fn shrink_to(&mut self, width: usize, height: usize) {
self.temp.truncate(width * height);
self.width = width;
self.height = height;
}
pub fn blur(&mut self, img: &[Vec<f32>; 3]) -> [Vec<f32>; 3] {
[
self.blur_plane(&img[0]),
self.blur_plane(&img[1]),
self.blur_plane(&img[2]),
]
}
fn blur_plane(&mut self, plane: &[f32]) -> Vec<f32> {
let mut out = vec![0f32; self.width * self.height];
self.kernel
.horizontal_pass(plane, &mut self.temp, self.width);
self.kernel
.vertical_pass_chunked::<128, 32>(&self.temp, &mut out, self.width, self.height);
out
}
}