aboutsummaryrefslogtreecommitdiff
path: root/mtree-test/src/lib.rs
blob: 1214cbf4091c17057b6b5ee023642928aa737a04 (plain)
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
use glam::I16Vec2;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AbsRef {
    pub off: I16Vec2,
    pub frame: u64,
}

pub struct Frame(pub Vec<u8>);
impl Frame {
    pub fn index(&self, res: I16Vec2, p: I16Vec2) -> [usize; 3] {
        let res = res.as_usizevec2();
        let p = p.as_usizevec2();

        let ystride = res.y;
        let ysize = res.x * ystride;
        let uvstride = res.x / 2;
        let usize = uvstride * (res.y / 2);
        let puv = p / 2;
        [
            p.x + p.y * ystride,
            ysize + puv.x + puv.y * uvstride,
            ysize + usize + puv.x + puv.y * uvstride,
        ]
    }
    pub fn get(&self, res: I16Vec2, p: I16Vec2) -> [u8; 3] {
        self.index(res, p).map(|i| self.0[i])
    }
}