aboutsummaryrefslogtreecommitdiff
path: root/test2/src/decode.rs
blob: da0538b6fb17bb92589b68ad0360628939c131f3 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::{BLOCK_SIZE, Frame};
use framework::BitstreamFilter;
use glam::{IVec2, ivec2};

pub struct Dec {
    res: IVec2,
    last: Frame,
}
impl BitstreamFilter for Dec {
    const INPUT_CODEC_ID: &str = "V_VCETEST2";
    const OUTPUT_CODEC_ID: &str = "V_UNCOMPRESSED";

    fn new(width: u32, height: u32) -> Self {
        let res = ivec2(width as i32, height as i32);
        Self {
            res,
            last: Frame::new(res),
        }
    }

    fn process_block(&mut self, a: Vec<u8>) -> Vec<u8> {
        let mut buf = a.as_slice();
        let mut frame = Frame::new(self.res);
        for by in 0..frame.res.y / BLOCK_SIZE {
            for bx in 0..frame.res.x / BLOCK_SIZE {
                let boff = ivec2(bx * BLOCK_SIZE, by * BLOCK_SIZE);

                let reloff = ivec2(buf[0] as i32 - 127, buf[1] as i32 - 127);
                buf = &buf[2..];

                let roff = reloff + boff;

                Frame::copy_block(&self.last, &mut frame, roff, boff);

                let size = frame.import_block_diff(boff, buf);
                buf = &buf[size..];
            }
        }

        self.last = frame.clone();
        frame.data
    }
}