diff options
Diffstat (limited to 'evc/src/codec/encode.rs')
-rw-r--r-- | evc/src/codec/encode.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/evc/src/codec/encode.rs b/evc/src/codec/encode.rs index a5cb94b..9ebbda1 100644 --- a/evc/src/codec/encode.rs +++ b/evc/src/codec/encode.rs @@ -4,19 +4,22 @@ use crate::{block::Block, frame::Frame, vec2::Vec2, view::View}; pub struct EncodeConfig { pub translate: bool, pub ref_thres: f64, + pub max_diff_size: isize, + pub min_block_size: isize, } pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfig) -> Block { - let (diff, translation) = if view.area() > 10_000 { + let (diff, translation) = if view.area() > config.max_diff_size { (f64::INFINITY, Vec2::ZERO) } else if config.translate { let mut best_diff = f64::INFINITY; let mut best_translation = Vec2::ZERO; for x in [-32, -16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16, 32] { for y in [-32, -16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16, 32] { - let diff = View::diff(&view, &prev) / view.area() as f64; + let translation = Vec2 { x, y }; + let diff = View::diff(&view, &prev.offset(translation)) / view.area() as f64; if diff < best_diff { - best_translation = Vec2 { x, y }; + best_translation = translation; best_diff = diff; } } @@ -28,7 +31,7 @@ pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfi if diff < config.ref_thres { Block::Reference { translation } } else { - if view.size.x < 16 { + if view.size.x < config.min_block_size { Block::Literal(view.pixels()) } else { let [av, bv] = view.split(); |