buffers: move Pixmap out of smart_leds and into buffers
This commit is contained in:
parent
4000e1d0e7
commit
94567b9b60
@ -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<S: Surface + Default> Surfaces for SurfacePool<S> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Pixbuf: AsMilliwatts + IndexMut<usize, Output=Self::Pixel> {
|
||||
type Pixel: HardwarePixel;
|
||||
fn new() -> Self;
|
||||
fn blank(&mut self);
|
||||
fn iter_with_brightness(&self, brightness: u8) -> impl Iterator<Item = Self::Pixel> + Send;
|
||||
fn pixel_count(&self) -> usize;
|
||||
}
|
||||
|
||||
impl<T: HardwarePixel, const PIXEL_NUM: usize> 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<Item=T> + Send {
|
||||
self.iter().map(move |x| { x.scale8(brightness)})
|
||||
}
|
||||
}
|
@ -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<usize, Output=Self::Pixel> {
|
||||
type Pixel: HardwarePixel;
|
||||
fn new() -> Self;
|
||||
fn blank(&mut self);
|
||||
fn iter_with_brightness(&self, brightness: u8) -> impl Iterator<Item = Self::Pixel> + Send;
|
||||
fn pixel_count(&self) -> usize;
|
||||
}
|
||||
|
||||
struct StrideSampler<'a, P: Pixbuf> {
|
||||
pixbuf: &'a mut P,
|
||||
@ -81,24 +73,6 @@ impl<P: Pixbuf<Pixel=T::Color>, T: FastWrite> Output for StrideOutput<P, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: HardwarePixel, const PIXEL_NUM: usize> 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<Item=T> + Send {
|
||||
self.iter().map(move |x| { x.scale8(brightness)})
|
||||
}
|
||||
}
|
||||
pub trait FastWrite {
|
||||
type Target: SmartLedsWrite;
|
||||
type Color: HardwarePixel;
|
||||
|
Loading…
x
Reference in New Issue
Block a user