aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-12-06 18:55:12 +0100
committermetamuffin <metamuffin@disroot.org>2022-12-06 18:55:12 +0100
commitc4e995d29209e0e0a1aafd9652971b8980fafb15 (patch)
tree733f1359bd8150dfc90c4abb3281f136db2418a9
parentc5d4cb9602ed18907d321f2d61f30e1159f58dbf (diff)
downloadvideo-codec-experiments-c4e995d29209e0e0a1aafd9652971b8980fafb15.tar
video-codec-experiments-c4e995d29209e0e0a1aafd9652971b8980fafb15.tar.bz2
video-codec-experiments-c4e995d29209e0e0a1aafd9652971b8980fafb15.tar.zst
minor improvements
-rw-r--r--evc/src/bin/decode.rs5
-rw-r--r--evc/src/bin/encode.rs4
-rw-r--r--evc/src/codec/decode.rs2
-rw-r--r--evc/src/codec/encode.rs11
-rw-r--r--evc/src/vec2.rs6
-rw-r--r--evc/src/view.rs3
6 files changed, 24 insertions, 7 deletions
diff --git a/evc/src/bin/decode.rs b/evc/src/bin/decode.rs
index 01729ab..f2f4c65 100644
--- a/evc/src/bin/decode.rs
+++ b/evc/src/bin/decode.rs
@@ -58,8 +58,11 @@ fn draw_debug(block: &Block, mut target: View<&mut Frame>) {
draw_debug(a, at);
draw_debug(b, bt);
}
- Block::Reference { translation: _ } => {
+ Block::Reference { translation } => {
target.draw_box(Pixel::BLUE);
+ target
+ .frame
+ .draw_line(target.center(), target.center() + *translation, Pixel::BLUE)
}
}
}
diff --git a/evc/src/bin/encode.rs b/evc/src/bin/encode.rs
index d6029aa..79ec934 100644
--- a/evc/src/bin/encode.rs
+++ b/evc/src/bin/encode.rs
@@ -21,7 +21,7 @@ pub struct EncodeArgs {
#[arg(short = 'H', long)]
height: usize,
- #[arg(short = 't', long, default_value = "0.9")]
+ #[arg(short = 't', long, default_value = "1.5")]
ref_thres: f64,
#[arg(short = 'T', long)]
no_translation: bool,
@@ -37,6 +37,8 @@ fn main() -> anyhow::Result<()> {
let config = EncodeConfig {
translate: !args.no_translation,
ref_thres: args.ref_thres,
+ max_diff_size: 10_000,
+ min_block_size: 12,
};
let size = Vec2 {
diff --git a/evc/src/codec/decode.rs b/evc/src/codec/decode.rs
index f4559c8..e6fa918 100644
--- a/evc/src/codec/decode.rs
+++ b/evc/src/codec/decode.rs
@@ -9,6 +9,6 @@ pub fn decode_block(block: &Block, mut target: View<&mut Frame>, prev: View<&Fra
decode_block(a, at, ap);
decode_block(b, bt, bp);
}
- Block::Reference { translation: _ } => target.copy_from(&prev),
+ Block::Reference { translation } => target.copy_from(&prev.offset(*translation)),
}
}
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();
diff --git a/evc/src/vec2.rs b/evc/src/vec2.rs
index ffee124..b1dd1b4 100644
--- a/evc/src/vec2.rs
+++ b/evc/src/vec2.rs
@@ -7,6 +7,12 @@ pub struct Vec2 {
}
impl Vec2 {
pub const ZERO: Vec2 = Vec2 { x: 0, y: 0 };
+ pub fn downscale(&self, f: isize) -> Self {
+ Self {
+ x: self.x / f,
+ y: self.y / f,
+ }
+ }
}
impl Ser for Vec2 {
diff --git a/evc/src/view.rs b/evc/src/view.rs
index 45c1728..36cdf42 100644
--- a/evc/src/view.rs
+++ b/evc/src/view.rs
@@ -18,6 +18,9 @@ impl<T> View<T> {
pub fn area(&self) -> isize {
self.size.x * self.size.y
}
+ pub fn center(&self) -> Vec2 {
+ self.offset + self.size.downscale(2)
+ }
}
impl<T> View<&mut T> {