From 4df7c1f1cbe0c3f79eec6be2474aead263f166c8 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 20 Dec 2022 08:57:35 +0100 Subject: infra for compressed literal --- evc/src/codec/encode/mod.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'evc/src/codec/encode') diff --git a/evc/src/codec/encode/mod.rs b/evc/src/codec/encode/mod.rs index 336f298..76fb481 100644 --- a/evc/src/codec/encode/mod.rs +++ b/evc/src/codec/encode/mod.rs @@ -30,7 +30,7 @@ pub enum EncodeMode { AdvancedPartial, } -pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfig) -> Block { +pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfig) -> (f64, Block) { let (diff, refblock) = if view.area() > config.max_diff_area { ( f64::INFINITY, @@ -57,10 +57,10 @@ pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfi (diff - irrelevance, refblock) }; if diff < config.ref_thres { - refblock + (diff, refblock) } else { if view.size.x < config.min_block_size || view.size.y < config.min_block_size { - Block::Literal(view.pixels()) + (0.0, Block::Literal(view.pixels())) } else { let [av, bv] = unsafe { std::mem::transmute::<_, [View<&'static Frame>; 2]>(view.split()) }; @@ -69,7 +69,7 @@ pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfi let config = unsafe { std::mem::transmute::<_, &'static EncodeConfig>(config) }; // only bother to do multithreading, when the block is big. - let (a, b) = if view.area() > 100 { + let ((ad, a), (bd, b)) = if view.area() > 100 { both_par( || encode_block(av, ap, config), || encode_block(bv, bp, config), @@ -79,15 +79,18 @@ pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfi (encode_block(av, ap, config), encode_block(bv, bp, config)) }; - if a.is_literal() && b.is_literal() { - Block::Literal(view.pixels()) - } else if Block::identical_ref(&a, &b) { - Block::Reference { - translation: Vec2::::ZERO, - } - } else { - Block::Split(Box::new([a, b])) - } + ( + ad + bd, + if a.is_literal() && b.is_literal() { + Block::Literal(view.pixels()) + } else if Block::identical_ref(&a, &b) { + Block::Reference { + translation: Vec2::::ZERO, + } + } else { + Block::Split(Box::new([a, b])) + }, + ) } } } -- cgit v1.2.3-70-g09d2