diff --git a/src/mappings.rs b/src/mappings.rs index a417468..1f4ac61 100644 --- a/src/mappings.rs +++ b/src/mappings.rs @@ -1,6 +1,8 @@ +use crate::buffers::Pixbuf; use crate::geometry::*; use crate::lib8::interpolate::scale8; +use crate::render::PixelView; use core::cmp::{max, min}; use core::fmt::{Formatter, Debug}; @@ -301,3 +303,29 @@ impl<'a> CoordinateView<'a> for StrideView<'a> { None } } + +pub struct StrideSampler<'a, P: Pixbuf> { + pixbuf: &'a mut P, + selection: StrideView<'a> +} + +impl<'a, P: Pixbuf> StrideSampler<'a, P> { + pub fn new(pixbuf: &'a mut P, selection: StrideView<'a>) -> Self { + StrideSampler { + pixbuf, + selection + } + } +} + +impl<'a, P: Pixbuf> PixelView for StrideSampler<'a, P> { + type Pixel = P::Pixel; + fn next(&mut self) -> Option<(Coordinates, &mut Self::Pixel)> { + if let Some((virt, coords)) = self.selection.next() { + let idx = self.selection.map.strides[coords.x as usize].pixel_idx_for_offset(coords.y); + Some((virt, &mut self.pixbuf[idx])) + } else { + None + } + } +} \ No newline at end of file diff --git a/src/platform/smart_leds_lib.rs b/src/platform/smart_leds_lib.rs index e2c8bde..e0c9ffc 100644 --- a/src/platform/smart_leds_lib.rs +++ b/src/platform/smart_leds_lib.rs @@ -8,23 +8,6 @@ use crate::mappings::*; use core::fmt::Debug; -struct StrideSampler<'a, P: Pixbuf> { - pixbuf: &'a mut P, - selection: StrideView<'a> -} - -impl<'a, P: Pixbuf> PixelView for StrideSampler<'a, P> { - type Pixel = P::Pixel; - fn next(&mut self) -> Option<(Coordinates, &mut Self::Pixel)> { - if let Some((virt, coords)) = self.selection.next() { - let idx = self.selection.map.strides[coords.x as usize].pixel_idx_for_offset(coords.y); - Some((virt, &mut self.pixbuf[idx])) - } else { - None - } - } -} - impl Debug for StrideOutput { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("StrideOutput").finish() @@ -53,10 +36,7 @@ impl StrideOutput { impl Sample for StrideOutput { type Pixel = P::Pixel; fn sample(&mut self, rect: &Rectangle) -> impl PixelView { - StrideSampler { - pixbuf: &mut self.pixbuf, - selection: self.stride_map.select(rect) - } + StrideSampler::new(&mut self.pixbuf,self.stride_map.select(rect)) } }