use core::convert::TryInto;
use embedded_graphics::{
pixelcolor::{raw::RawU24, Rgb888},
prelude::*,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ColorTable<'a> {
data: &'a [u8],
}
impl<'a> ColorTable<'a> {
pub(crate) const fn new(data: &'a [u8]) -> Self {
Self { data }
}
pub const fn len(&self) -> usize {
self.data.len() / 4
}
pub fn get(&self, index: u32) -> Option<Rgb888> {
let offset = index as usize * 4;
let bytes = self.data.get(offset..offset + 4)?;
let raw = u32::from_le_bytes(bytes.try_into().unwrap());
Some(RawU24::from_u32(raw).into())
}
}