Skip to main content

maurice_lib/
raw_image.rs

1use crate::hardware::screen::color::COLOR_DEPTH;
2use std::fmt::Display;
3
4#[derive(Debug)]
5pub struct RawImage<'a> {
6    pub(crate) data: &'a Vec<u8>,
7    pub(crate) width: usize,
8    pub(crate) height: usize,
9}
10
11impl Display for RawImage<'_> {
12    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13        write!(f, "RawImage(width={}, height={})", self.width, self.height)
14    }
15}
16
17impl<'a> RawImage<'a> {
18    pub(crate) fn new_with_data(width: usize, height: usize, data: &'a Vec<u8>) -> Self {
19        assert_eq!(data.len(), width * height * COLOR_DEPTH);
20        Self {
21            data,
22            width,
23            height,
24        }
25    }
26}