use tiny_led_matrix::{Render, MAX_BRIGHTNESS};
#[derive(Copy, Clone, Debug)]
pub struct GreyscaleImage (
[[u8; 5]; 5]
);
impl GreyscaleImage {
pub const fn new(data: &[[u8; 5]; 5]) -> GreyscaleImage {
GreyscaleImage(*data)
}
pub const fn blank() -> GreyscaleImage {
GreyscaleImage([[0; 5]; 5])
}
}
impl Render for GreyscaleImage {
fn brightness_at(&self, x: usize, y: usize) -> u8 {
self.0[y][x]
}
}
impl Render for &GreyscaleImage {
fn brightness_at(&self, x: usize, y: usize) -> u8 {
GreyscaleImage::brightness_at(self, x, y)
}
}
#[derive(Copy, Clone, Debug)]
pub struct BitImage (
[u8; 5]
);
impl BitImage {
pub const fn new(im: &[[u8; 5]; 5]) -> BitImage {
const fn row_byte(row: [u8; 5]) -> u8 {
row[0] | row[1]<<1 | row[2]<<2 | row[3]<<3 | row[4]<<4
};
BitImage([
row_byte(im[0]),
row_byte(im[1]),
row_byte(im[2]),
row_byte(im[3]),
row_byte(im[4]),
])
}
pub const fn blank() -> BitImage {
BitImage([0; 5])
}
}
impl Render for BitImage {
fn brightness_at(&self, x: usize, y: usize) -> u8 {
let rowdata = self.0[y];
if rowdata & (1<<x) != 0 {MAX_BRIGHTNESS as u8} else {0}
}
}
impl Render for &BitImage {
fn brightness_at(&self, x: usize, y: usize) -> u8 {
BitImage::brightness_at(self, x, y)
}
}