diff options
author | metamuffin <metamuffin@disroot.org> | 2022-12-07 18:40:24 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-12-07 18:40:24 +0100 |
commit | 7be0d5039db7e8660bced13698178bf1d6758109 (patch) | |
tree | a8723d67b6bab98656b182478b6418f2361260fa /evc/src/codec | |
parent | 8ca219c6b0d5448fd4529713ccd093e89de4e252 (diff) | |
download | video-codec-experiments-7be0d5039db7e8660bced13698178bf1d6758109.tar video-codec-experiments-7be0d5039db7e8660bced13698178bf1d6758109.tar.bz2 video-codec-experiments-7be0d5039db7e8660bced13698178bf1d6758109.tar.zst |
refactor
Diffstat (limited to 'evc/src/codec')
-rw-r--r-- | evc/src/codec/decode.rs | 5 | ||||
-rw-r--r-- | evc/src/codec/encode.rs | 80 |
2 files changed, 56 insertions, 29 deletions
diff --git a/evc/src/codec/decode.rs b/evc/src/codec/decode.rs index e6fa918..2da320f 100644 --- a/evc/src/codec/decode.rs +++ b/evc/src/codec/decode.rs @@ -10,5 +10,10 @@ pub fn decode_block(block: &Block, mut target: View<&mut Frame>, prev: View<&Fra decode_block(b, bt, bp); } Block::Reference { translation } => target.copy_from(&prev.offset(*translation)), + Block::AdvancedReference { + translation: _, + transform: _, + value_scale: _, + } => todo!(), } } diff --git a/evc/src/codec/encode.rs b/evc/src/codec/encode.rs index b11bbc0..5ce0b16 100644 --- a/evc/src/codec/encode.rs +++ b/evc/src/codec/encode.rs @@ -4,48 +4,70 @@ use crate::{ helpers::{pixel::Pixel, threading::both_par, vector::Vec2}, view::View, }; +use clap::ValueEnum; #[derive(Debug, Clone)] pub struct EncodeConfig { - pub translate: bool, + pub mode: EncodeMode, pub ref_thres: f64, - pub max_diff_size: isize, + pub max_diff_area: isize, pub min_block_size: isize, pub max_threads: usize, - // pub importance_k: f64, - // pub importance_scale: f64, } -pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfig) -> Block { - // let importance = importance(&view); +#[derive(Debug, Clone, ValueEnum)] +pub enum EncodeMode { + Trivial, + Default, + Advanced, +} + - let (diff, translation) = if view.area() > config.max_diff_size { - (f64::INFINITY, Vec2::<isize>::ZERO) - } else if config.translate { - let mut best_diff = f64::INFINITY; - let mut best_translation = Vec2::<isize>::ZERO; - const OFFSETS: &[isize] = &[-64, -32, -16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16, 32, 64]; - for x in OFFSETS { - for y in OFFSETS { - let translation = Vec2 { x: *x, y: *y }; - let diff = View::diff(&view, &prev.offset(translation)); // / view.area() as f64; - if diff < best_diff { - best_translation = translation; - best_diff = diff; +pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfig) -> Block { + let (diff, refblock) = if view.area() > config.max_diff_area { + ( + f64::INFINITY, + Block::Reference { + translation: Vec2::<isize>::ZERO, + }, + ) + } else { + match config.mode { + EncodeMode::Trivial => ( + View::diff(&view, &prev) / view.area() as f64, + Block::Reference { + translation: Vec2::<isize>::ZERO, + }, + ), + EncodeMode::Default => { + let mut best_diff = f64::INFINITY; + let mut best_translation = Vec2::<isize>::ZERO; + const OFFSETS: &[isize] = + &[-64, -32, -16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16, 32, 64]; + for x in OFFSETS { + for y in OFFSETS { + let translation = Vec2 { x: *x, y: *y }; + let diff = View::diff(&view, &prev.offset(translation)); // / view.area() as f64; + if diff < best_diff { + best_translation = translation; + best_diff = diff; + } + } } + ( + best_diff, + Block::Reference { + translation: best_translation, + }, + ) + } + EncodeMode::Advanced => { + todo!() } } - (best_diff, best_translation) - } else { - ( - View::diff(&view, &prev) / view.area() as f64, - Vec2::<isize>::ZERO, - ) }; - // config.importance_k) - // / (config.importance_k + importance * config.importance_scale) - if diff < (config.ref_thres) { - Block::Reference { translation } + if diff < config.ref_thres { + refblock } else { if view.size.x < config.min_block_size || view.size.y < config.min_block_size { Block::Literal(view.pixels()) |