aboutsummaryrefslogtreecommitdiff
path: root/evc/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'evc/src/bin')
-rw-r--r--evc/src/bin/decode.rs33
-rw-r--r--evc/src/bin/encode.rs12
2 files changed, 39 insertions, 6 deletions
diff --git a/evc/src/bin/decode.rs b/evc/src/bin/decode.rs
index af6edc6..44fcbe4 100644
--- a/evc/src/bin/decode.rs
+++ b/evc/src/bin/decode.rs
@@ -5,6 +5,7 @@ use evc::{
block::{Block, BlockInner},
frame::Frame,
header::Header,
+ pixel::Pixel,
ser::Source,
view::View,
};
@@ -12,10 +13,13 @@ use std::io::{BufReader, BufWriter};
#[derive(Parser)]
#[clap(about, version)]
-pub struct DecodeArgs {}
+pub struct DecodeArgs {
+ #[arg(long)]
+ debug: bool,
+}
fn main() -> anyhow::Result<()> {
- let _args = DecodeArgs::parse();
+ let args = DecodeArgs::parse();
let mut input = BufReader::new(std::io::stdin());
let mut output = BufWriter::new(std::io::stdout());
@@ -36,7 +40,14 @@ fn main() -> anyhow::Result<()> {
prev.view((0, 0), size),
);
- frame.write(&mut output).context("writing raw frame")?;
+ if args.debug {
+ let mut f2 = frame.clone();
+ draw_debug(&block, f2.view_mut((0, 0), size));
+ f2.write(&mut output).context("writing raw frame")?;
+ } else {
+ frame.write(&mut output).context("writing raw frame")?;
+ }
+
prev = frame;
}
drop(input);
@@ -55,3 +66,19 @@ fn blit_block(block: &Block, mut target: View<&mut Frame>, prev: View<&Frame>) {
BlockInner::Reference { translation: _ } => target.copy_from(&prev),
}
}
+
+fn draw_debug(block: &Block, mut target: View<&mut Frame>) {
+ match &block.inner {
+ BlockInner::Literal(_) => {
+ target.draw_box(Pixel::GREEN);
+ }
+ BlockInner::Split(box [a, b]) => {
+ let [at, bt] = target.split_mut_unsafe();
+ draw_debug(a, at);
+ draw_debug(b, bt);
+ }
+ BlockInner::Reference { translation: _ } => {
+ target.draw_box(Pixel::BLUE);
+ }
+ }
+}
diff --git a/evc/src/bin/encode.rs b/evc/src/bin/encode.rs
index 1934e26..3e34a3c 100644
--- a/evc/src/bin/encode.rs
+++ b/evc/src/bin/encode.rs
@@ -54,7 +54,7 @@ fn main() -> anyhow::Result<()> {
fn encode_block(view: View<&Frame>, prev: View<&Frame>) -> Block {
let diff = View::diff(&view, &prev) / view.area() as f64;
// eprintln!("{:?} {diff}", view.size);
- let inner = if diff < 0.5 {
+ let inner = if diff < 0.9 {
BlockInner::Reference {
translation: (0, 0),
}
@@ -62,9 +62,15 @@ fn encode_block(view: View<&Frame>, prev: View<&Frame>) -> Block {
if view.size.0 < 32 {
BlockInner::Literal(view.pixels())
} else {
- let [a, b] = view.split();
+ let [av, bv] = view.split();
let [ap, bp] = prev.split();
- BlockInner::Split(Box::new([encode_block(a, ap), encode_block(b, bp)]))
+ let a = encode_block(av, ap);
+ let b = encode_block(bv, bp);
+ if a.is_literal() && b.is_literal() {
+ BlockInner::Literal(view.pixels())
+ } else {
+ BlockInner::Split(Box::new([a, b]))
+ }
}
};