Diffstat (limited to 'src/diffusion.rs')
| -rw-r--r-- | src/diffusion.rs | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/src/diffusion.rs b/src/diffusion.rs index ea58adc..494fa7e 100644 --- a/src/diffusion.rs +++ b/src/diffusion.rs @@ -9,10 +9,8 @@ pub fn atkinson(image: Image<&[f32], 4>, palette: &[[f32; 4]]) -> Image<Box<[f32 let kd = map(palette); let mut image = Image::build(image.width(), image.height()).buf(image.buffer().to_vec().into_boxed_slice()); - let w = image.width(); - let h = image.height(); let eighth = [1. / 8.; 4]; - for (x, y) in (0..h).flat_map(move |y| (0..w).map(move |x| (x, y))) { + for (x, y) in image.serpent() { unsafe { /* * 1 1 @@ -44,9 +42,7 @@ pub fn jarvis<const FAC: u8>( let kd = map(palette); let mut image = Image::build(image.width(), image.height()).buf(image.buffer().to_vec().into_boxed_slice()); - let w = image.width(); - let h = image.height(); - for (x, y) in (0..h).flat_map(move |y| (0..w).map(move |x| (x, y))) { + for (x, y) in image.serpent() { #[rustfmt::skip] unsafe { let p = image.pixel(x, y); @@ -86,9 +82,7 @@ pub fn floyd_steinberg<const FAC: u8>( let kd = map(palette); let mut image = Image::build(image.width(), image.height()).buf(image.buffer().to_vec().into_boxed_slice()); - let w = image.width(); - let h = image.height(); - for (x, y) in (0..h).flat_map(move |y| (0..w).map(move |x| (x, y))) { + for (x, y) in image.serpent() { unsafe { let p = image.pixel(x, y); let new = palette[kd.find_nearest(p) as usize]; |