From 94567b9b606cb7689764787f6eede5ef496e8f05 Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Fri, 29 Nov 2024 19:00:07 +0100 Subject: [PATCH] buffers: move Pixmap out of smart_leds and into buffers --- src/buffers.rs | 31 ++++++++++++++++++++++++++++++- src/platform/smart_leds_lib.rs | 30 ++---------------------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/buffers.rs b/src/buffers.rs index 35bf116..807f4bf 100644 --- a/src/buffers.rs +++ b/src/buffers.rs @@ -1,11 +1,13 @@ use crate::geometry::*; use crate::lib8::interpolate::Fract8Ops; -use crate::render::{PixelView, Sample, Shader, Surface, Surfaces}; +use crate::power::AsMilliwatts; +use crate::render::{PixelView, Sample, Shader, Surface, Surfaces, HardwarePixel}; use std::fmt::Debug; use std::rc::Rc; use std::cell::RefCell; use std::io; +use std::ops::IndexMut; #[cfg(feature="threads")] use std::sync::{Arc, Mutex}; @@ -183,3 +185,30 @@ impl Surfaces for SurfacePool { } } } + +pub trait Pixbuf: AsMilliwatts + IndexMut { + type Pixel: HardwarePixel; + fn new() -> Self; + fn blank(&mut self); + fn iter_with_brightness(&self, brightness: u8) -> impl Iterator + Send; + fn pixel_count(&self) -> usize; +} + +impl Pixbuf for [T; PIXEL_NUM] { + type Pixel = T; + fn new() -> Self { + [T::default(); PIXEL_NUM] + } + + fn pixel_count(&self) -> usize { + self.len() + } + + fn blank(&mut self) { + self.fill(T::default()) + } + + fn iter_with_brightness(&self, brightness: u8) -> impl Iterator + Send { + self.iter().map(move |x| { x.scale8(brightness)}) + } +} \ No newline at end of file diff --git a/src/platform/smart_leds_lib.rs b/src/platform/smart_leds_lib.rs index ac8014d..62b8c41 100644 --- a/src/platform/smart_leds_lib.rs +++ b/src/platform/smart_leds_lib.rs @@ -1,20 +1,12 @@ use smart_leds_trait::SmartLedsWrite; +use crate::buffers::Pixbuf; use crate::render::{HardwarePixel, Output, PixelView, Sample}; -use crate::power::{brightness_for_mw, AsMilliwatts}; +use crate::power::brightness_for_mw; use crate::geometry::*; use crate::mappings::*; use std::fmt::Debug; -use std::ops::IndexMut; - -pub trait Pixbuf: AsMilliwatts + IndexMut { - type Pixel: HardwarePixel; - fn new() -> Self; - fn blank(&mut self); - fn iter_with_brightness(&self, brightness: u8) -> impl Iterator + Send; - fn pixel_count(&self) -> usize; -} struct StrideSampler<'a, P: Pixbuf> { pixbuf: &'a mut P, @@ -81,24 +73,6 @@ impl, T: FastWrite> Output for StrideOutput { } } -impl Pixbuf for [T; PIXEL_NUM] { - type Pixel = T; - fn new() -> Self { - [T::default(); PIXEL_NUM] - } - - fn pixel_count(&self) -> usize { - self.len() - } - - fn blank(&mut self) { - self.fill(T::default()) - } - - fn iter_with_brightness(&self, brightness: u8) -> impl Iterator + Send { - self.iter().map(move |x| { x.scale8(brightness)}) - } -} pub trait FastWrite { type Target: SmartLedsWrite; type Color: HardwarePixel;