platform: smart_leds: move StrideSampler into mappings module
This commit is contained in:
parent
16c0c9524d
commit
202876b42f
@ -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<Virtual>, &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
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Virtual>, &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<P: Pixbuf, T: FastWrite> Debug for StrideOutput<P, T> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
f.debug_struct("StrideOutput").finish()
|
||||
@ -53,10 +36,7 @@ impl<P: Pixbuf, T: FastWrite> StrideOutput<P, T> {
|
||||
impl<P: Pixbuf, T: FastWrite> Sample for StrideOutput<P, T> {
|
||||
type Pixel = P::Pixel;
|
||||
fn sample(&mut self, rect: &Rectangle<Virtual>) -> impl PixelView<Pixel = Self::Pixel> {
|
||||
StrideSampler {
|
||||
pixbuf: &mut self.pixbuf,
|
||||
selection: self.stride_map.select(rect)
|
||||
}
|
||||
StrideSampler::new(&mut self.pixbuf,self.stride_map.select(rect))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user