diff options
Diffstat (limited to 'evc/src/block.rs')
-rw-r--r-- | evc/src/block.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/evc/src/block.rs b/evc/src/block.rs index 8d7686f..cbf69bf 100644 --- a/evc/src/block.rs +++ b/evc/src/block.rs @@ -5,15 +5,16 @@ use crate::{ }; use anyhow::bail; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum Block { Literal(Vec<Pixel>), + CompressedLiteral(Vec<Pixel>), Split(Box<[Block; 2]>), Reference { translation: Vec2<isize> }, AdvancedReference(AdvancedReference), } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct AdvancedReference { pub translation: Vec2<i8>, pub transform: Mat2<i8>, @@ -31,14 +32,15 @@ impl Block { sink.put(0u8)?; pixels.write_const_size(sink, size.area() as usize)?; } + Block::CompressedLiteral(_) => bail!("compressed literal is not supported"), Block::Split(box [a, b]) => { - sink.put(1u8)?; + sink.put(2u8)?; let [asize, bsize] = split_size(size); a.write(sink, asize)?; b.write(sink, bsize)?; } Block::Reference { translation } => { - sink.put(2u8)?; + sink.put(3u8)?; sink.put(Small(*translation))?; } Block::AdvancedReference(AdvancedReference { @@ -46,7 +48,7 @@ impl Block { transform, value_scale, }) => { - sink.put(3u8)?; + sink.put(4u8)?; sink.put((*translation, *transform, *value_scale))?; } } @@ -56,16 +58,17 @@ impl Block { pub fn read(source: &mut impl std::io::Read, size: Vec2<isize>) -> anyhow::Result<Self> { Ok(match source.get::<u8>()? { 0 => Block::Literal(Vec::read_const_size(source, size.area() as usize)?), - 1 => Block::Split(Box::new({ + 1 => bail!("compressed literal is not supported"), + 2 => Block::Split(Box::new({ let [asize, bsize] = split_size(size); let a = Block::read(source, asize)?; let b = Block::read(source, bsize)?; [a, b] })), - 2 => Block::Reference { + 3 => Block::Reference { translation: source.get::<Small<Vec2<isize>>>()?.0, }, - 3 => Block::AdvancedReference(AdvancedReference { + 4 => Block::AdvancedReference(AdvancedReference { translation: source.get()?, transform: source.get()?, value_scale: source.get()?, @@ -95,13 +98,8 @@ impl Block { pub fn is_literal(&self) -> bool { matches!(self, Block::Literal(..)) } - pub fn is_ref_without_translation(&self) -> bool { - matches!( - self, - Block::Reference { - translation: Vec2::<isize>::ZERO - } - ) + pub fn identical_ref(a: &Self, b: &Self) -> bool { + matches!(a, Block::Reference { .. }) && a == b } } |