use crate::{BLOCK_SIZE, Frame, huffman::decode_huff}; 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) -> Vec { let buf = decode_huff(a); let mut buf = buf.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 } }