aboutsummaryrefslogtreecommitdiff
path: root/evc/src/block.rs
diff options
context:
space:
mode:
Diffstat (limited to 'evc/src/block.rs')
-rw-r--r--evc/src/block.rs18
1 files changed, 13 insertions, 5 deletions
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::<u8>()? {
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 })