From cc1f02a71bd3ad5235ac92dec2d9c516c74f8b1c Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 6 Dec 2022 08:41:48 +0100 Subject: decode somewhat works --- evc/src/block.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'evc/src/block.rs') diff --git a/evc/src/block.rs b/evc/src/block.rs index f58bcb3..98e3b54 100644 --- a/evc/src/block.rs +++ b/evc/src/block.rs @@ -1,3 +1,5 @@ +use anyhow::bail; + use crate::{ pixel::Pixel, ser::{Ser, Sink, Source}, @@ -28,8 +30,9 @@ impl Block { a.write(sink)?; b.write(sink)?; } - BlockInner::Reference { translation: _ } => { + BlockInner::Reference { translation } => { sink.put(2u8)?; + // sink.put(*translation)?; } } Ok(()) @@ -39,15 +42,20 @@ impl Block { let inner = match source.get::()? { 0 => BlockInner::Literal(source.get()?), 1 => BlockInner::Split(Box::new({ - let subsize = if size.0 > size.1 { + let subsize_left = if size.0 > size.1 { (size.0 / 2, size.1) } else { (size.0, size.1 / 2) }; - [Block::read(source, subsize)?, Block::read(source, subsize)?] + let subsize_right = (size.0 - subsize_left.0, size.1 - subsize_left.1); + let a = Block::read(source, subsize_left)?; + let b = Block::read(source, subsize_right)?; + [a, b] })), - 2 => todo!(), - _ => panic!("file corrupt"), + 2 => BlockInner::Reference { + translation: (0, 0), //source.get()?, + }, + x => bail!("corrupt block type ({})", x), }; Ok(Self { size, inner }) -- cgit v1.2.3-70-g09d2