aboutsummaryrefslogtreecommitdiff
path: root/mtree-test/src/bin/decode.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-05-06 00:05:13 +0200
committermetamuffin <metamuffin@disroot.org>2025-05-06 00:05:13 +0200
commit110f6738b89d22a384f5ec580b452ef411b975bb (patch)
tree1bfcb2446e46f36ce60f529d349d5d6b180e672d /mtree-test/src/bin/decode.rs
parent2c09942bc1af0a1f41c0e3ee52323deede19e6bd (diff)
downloadvideo-codec-experiments-110f6738b89d22a384f5ec580b452ef411b975bb.tar
video-codec-experiments-110f6738b89d22a384f5ec580b452ef411b975bb.tar.bz2
video-codec-experiments-110f6738b89d22a384f5ec580b452ef411b975bb.tar.zst
theory works, reality not yet
Diffstat (limited to 'mtree-test/src/bin/decode.rs')
-rw-r--r--mtree-test/src/bin/decode.rs47
1 files changed, 45 insertions, 2 deletions
diff --git a/mtree-test/src/bin/decode.rs b/mtree-test/src/bin/decode.rs
index 6ff2cb3..0fc8ba4 100644
--- a/mtree-test/src/bin/decode.rs
+++ b/mtree-test/src/bin/decode.rs
@@ -1,6 +1,7 @@
use framework::{BitstreamFilter, bitstream_filter_main};
use glam::{I16Vec2, i16vec2};
-use std::io::Result;
+use mtree_test::{BLOCK_SIZE, Frame, LastFrames, frame_to_frame_rect_copy};
+use std::{collections::VecDeque, io::Result};
fn main() -> Result<()> {
bitstream_filter_main::<Dec>()
@@ -8,6 +9,7 @@ fn main() -> Result<()> {
struct Dec {
res: I16Vec2,
+ last: LastFrames,
}
impl BitstreamFilter for Dec {
const INPUT_CODEC_ID: &str = "V_VCEMTREE";
@@ -16,9 +18,50 @@ impl BitstreamFilter for Dec {
fn new(width: u32, height: u32) -> Self {
Self {
res: i16vec2(width as i16, height as i16),
+ last: LastFrames {
+ frame_offset: 0,
+ frames: VecDeque::new(),
+ },
}
}
fn process_block(&mut self, a: Vec<u8>) -> Vec<u8> {
- a
+ 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 = i16vec2(bx * BLOCK_SIZE, by * BLOCK_SIZE);
+ let brect = boff..boff + I16Vec2::splat(BLOCK_SIZE);
+ let kind = a[0];
+ a = &a[1..];
+ if kind == 0 {
+ let size = frame.import_rect(self.res, brect, &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(
+ self.res,
+ &mut frame,
+ rframe,
+ I16Vec2::splat(BLOCK_SIZE),
+ boff,
+ i16vec2(offx, offy),
+ );
+ }
+ }
+ }
+
+ self.last.frames.push_back(frame.clone());
+
+ eprintln!("out frame");
+ frame.0
}
}