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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
use crate::{BLOCK_SIZE, Frame, LastFrames, frame_to_frame_rect_copy};
use framework::BitstreamFilter;
use glam::{IVec2, ivec2};
use std::collections::VecDeque;
pub struct Dec {
res: IVec2,
last: LastFrames,
}
impl BitstreamFilter for Dec {
const INPUT_CODEC_ID: &str = "V_VCEMTREE";
const OUTPUT_CODEC_ID: &str = "V_UNCOMPRESSED";
fn new(width: u32, height: u32) -> Self {
Self {
res: ivec2(width as i32, height as i32),
last: LastFrames {
frame_offset: 0,
frames: VecDeque::new(),
},
}
}
fn process_block(&mut self, a: Vec<u8>) -> Vec<u8> {
let mut a = a.as_slice();
let mut frame = Frame::new(self.res);
for bx in 0..self.res.x / BLOCK_SIZE {
for by in 0..self.res.y / BLOCK_SIZE {
let boff = ivec2(bx * BLOCK_SIZE, by * BLOCK_SIZE);
let kind = a[0];
a = &a[1..];
if kind == 0 {
let size = frame.import_rect(boff, IVec2::splat(BLOCK_SIZE), &a);
a = &a[size..];
} else {
let rframeindex =
u64::from_le_bytes([a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]]);
a = &a[8..];
let offx = i16::from_le_bytes([a[0], a[1]]);
a = &a[2..];
let offy = i16::from_le_bytes([a[0], a[1]]);
a = &a[2..];
let rframe = &self.last.frames[(rframeindex - self.last.frame_offset) as usize];
frame_to_frame_rect_copy(
rframe,
&mut frame,
IVec2::splat(BLOCK_SIZE),
ivec2(offx as i32, offy as i32),
boff,
);
}
}
}
self.last.frames.push_back(frame.clone());
frame.data
}
}
|