pub struct Bitmap<MR: crate::memory::MemoryRegion> {
pub image_data: crate::memory::Ptr<MR>,
pub palette_data: Option<crate::memory::Ptr<MR>>,
pub format: crate::display_list::options::BitmapExtFormat,
pub width: u32,
pub height: u32,
pub stride: u32,
}
impl<MR: crate::memory::MemoryRegion> Bitmap<MR> {
pub fn new_without_palette(
format: crate::display_list::options::BitmapFormat,
base: crate::memory::Ptr<MR>,
width: u32,
height: u32,
) -> Self {
use core::convert::TryFrom;
let ext_format = match crate::display_list::options::BitmapExtFormat::try_from(format) {
Ok(fmt) => fmt,
Err(_) => panic!("new_without_palette does not support extended bitmap formats"),
};
Self {
image_data: base,
palette_data: None,
format: ext_format,
width: width,
height: height,
stride: format.minimum_stride(width),
}
}
pub fn byte_length(&mut self) -> u32 {
return self.height * self.stride;
}
pub fn data_slice(&mut self) -> crate::memory::Slice<MR> {
return self.image_data.slice_length(self.byte_length());
}
}