diff options
author | metamuffin <metamuffin@disroot.org> | 2022-12-06 16:45:30 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-12-06 16:45:30 +0100 |
commit | 849c3769fbd38940c9bfa73bcea160848a38d9b6 (patch) | |
tree | ad7cfc70b4c121e94a46e89e7c95f260abbcd791 /evc/src/block.rs | |
parent | 624471a4b1f2e1656a2ba46070d8f127dcd0e364 (diff) | |
download | video-codec-experiments-849c3769fbd38940c9bfa73bcea160848a38d9b6.tar video-codec-experiments-849c3769fbd38940c9bfa73bcea160848a38d9b6.tar.bz2 video-codec-experiments-849c3769fbd38940c9bfa73bcea160848a38d9b6.tar.zst |
simplify block type
Diffstat (limited to 'evc/src/block.rs')
-rw-r--r-- | evc/src/block.rs | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/evc/src/block.rs b/evc/src/block.rs index dae538c..8daba5c 100644 --- a/evc/src/block.rs +++ b/evc/src/block.rs @@ -6,13 +6,7 @@ use crate::{ }; #[derive(Clone, Debug)] -pub struct Block { - pub size: (usize, usize), - pub inner: BlockInner, -} - -#[derive(Clone, Debug)] -pub enum BlockInner { +pub enum Block { Literal(Vec<Pixel>), Split(Box<[Block; 2]>), Reference { translation: (usize, usize) }, @@ -20,17 +14,17 @@ pub enum BlockInner { impl Block { pub fn write(&self, sink: &mut impl std::io::Write) -> anyhow::Result<()> { - match &self.inner { - BlockInner::Literal(pixels) => { + match &self { + Block::Literal(pixels) => { sink.put(0u8)?; pixels.write(sink)?; } - BlockInner::Split(box [a, b]) => { + Block::Split(box [a, b]) => { sink.put(1u8)?; a.write(sink)?; b.write(sink)?; } - BlockInner::Reference { translation: _ } => { + Block::Reference { translation: _ } => { sink.put(2u8)?; // sink.put(*translation)?; } @@ -39,9 +33,9 @@ impl Block { } pub fn read(source: &mut impl std::io::Read, size: (usize, usize)) -> anyhow::Result<Self> { - let inner = match source.get::<u8>()? { - 0 => BlockInner::Literal(source.get()?), - 1 => BlockInner::Split(Box::new({ + Ok(match source.get::<u8>()? { + 0 => Block::Literal(source.get()?), + 1 => Block::Split(Box::new({ let vert = size.0 > size.1; let asize = if vert { (size.0 / 2, size.1) @@ -58,18 +52,16 @@ impl Block { let b = Block::read(source, bsize)?; [a, b] })), - 2 => BlockInner::Reference { + 2 => Block::Reference { translation: (0, 0), //source.get()?, }, x => bail!("corrupt block type ({})", x), - }; - - Ok(Self { size, inner }) + }) } } impl Block { pub fn is_literal(&self) -> bool { - matches!(self.inner, BlockInner::Literal(..)) + matches!(self, Block::Literal(..)) } } |