1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pub struct Image {
    pixels: Vec<Pixel>,
    width: usize,
    #[allow(dead_code)]
    height: usize,
}

#[derive(Clone, Copy)]
pub struct Pixel {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: u8,
}

impl Image {
    pub fn new(width: usize, height: usize) -> Self {
        Self {
            pixels: vec![
                Pixel {
                    r: 0,
                    g: 0,
                    b: 0,
                    a: 0
                };
                width * height
            ],
            width,
            height,
        }
    }

    pub fn put_pixel(&mut self, x: usize, y: usize, pixel: Pixel) {
        self.pixels[self.width * y + x] = pixel;
    }
}