diff options
Diffstat (limited to 'evc/src')
-rw-r--r-- | evc/src/bin/encode.rs | 26 | ||||
-rw-r--r-- | evc/src/codec/encode/advanced.rs | 30 | ||||
-rw-r--r-- | evc/src/codec/encode/mod.rs | 4 | ||||
-rw-r--r-- | evc/src/debug.rs | 45 | ||||
-rw-r--r-- | evc/src/helpers/matrix.rs | 4 | ||||
-rw-r--r-- | evc/src/helpers/vector.rs | 10 | ||||
-rw-r--r-- | evc/src/refsampler.rs | 2 |
7 files changed, 70 insertions, 51 deletions
diff --git a/evc/src/bin/encode.rs b/evc/src/bin/encode.rs index 4b7e26c..135a0e8 100644 --- a/evc/src/bin/encode.rs +++ b/evc/src/bin/encode.rs @@ -24,6 +24,13 @@ pub struct EncodeArgs { #[arg(short, long)] mode: EncodeMode, + #[arg(long)] + no_linear_transform: bool, + #[arg(long)] + no_value_scale: bool, + #[arg(long)] + no_translate: bool, + #[arg(short, long, default_value = "8")] jobs: usize, @@ -48,8 +55,9 @@ fn main() -> anyhow::Result<()> { max_diff_area: 10_000, min_block_size: args.min_block_size, max_threads: args.jobs, - do_matrix_transform: false, - do_value_scale: false, + do_translate: !args.no_translate, + do_linear_transform: !args.no_linear_transform, + do_value_scale: !args.no_value_scale, }; let size = Vec2 { @@ -73,13 +81,13 @@ fn main() -> anyhow::Result<()> { let (error, mut root) = encode_block(v1, v2, &config); - compress_block( - &mut root, - Vec2 { - x: size.x as usize, - y: size.y as usize, - }, - ); + // compress_block( + // &mut root, + // Vec2 { + // x: size.x as usize, + // y: size.y as usize, + // }, + // ); root.write(&mut output, size) .context("writing encoded frame")?; diff --git a/evc/src/codec/encode/advanced.rs b/evc/src/codec/encode/advanced.rs index e15d8f2..0e45176 100644 --- a/evc/src/codec/encode/advanced.rs +++ b/evc/src/codec/encode/advanced.rs @@ -21,23 +21,25 @@ pub fn default( loop { let (mut d, mut p) = (diff, pm.clone()); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x += 4); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x -= 4); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y += 4); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y -= 4); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x += 2); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x -= 2); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y += 2); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y -= 2); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x += 1); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x -= 1); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y += 1); - pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y -= 1); + if config.do_translate { + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x += 4); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x -= 4); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y += 4); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y -= 4); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x += 2); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x -= 2); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y += 2); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y -= 2); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x += 1); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.x -= 1); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y += 1); + pk(&view, &prev, &mut d, &mut p, &pm, |p| p.translation.y -= 1); + } if config.do_value_scale { pk(&view, &prev, &mut d, &mut p, &pm, |p| p.value_scale += 1); pk(&view, &prev, &mut d, &mut p, &pm, |p| p.value_scale -= 1); } - if config.do_matrix_transform { + if config.do_linear_transform { pk(&view, &prev, &mut d, &mut p, &pm, |p| p.transform.a -= 1); pk(&view, &prev, &mut d, &mut p, &pm, |p| p.transform.a += 1); pk(&view, &prev, &mut d, &mut p, &pm, |p| p.transform.b -= 1); @@ -83,7 +85,7 @@ pub fn partial( pk(&view, &prev, &mut d, &mut p, &pm, |p| p.value_scale += 1); pk(&view, &prev, &mut d, &mut p, &pm, |p| p.value_scale -= 1); - + if d >= diff { break (diff, Block::AdvancedReference(pm)); } diff --git a/evc/src/codec/encode/mod.rs b/evc/src/codec/encode/mod.rs index 76fb481..8b7b342 100644 --- a/evc/src/codec/encode/mod.rs +++ b/evc/src/codec/encode/mod.rs @@ -17,8 +17,10 @@ pub struct EncodeConfig { pub min_block_size: isize, pub max_threads: usize, pub weight_factor: f64, + + pub do_translate: bool, pub do_value_scale: bool, - pub do_matrix_transform: bool, + pub do_linear_transform: bool, } #[derive(Debug, Clone, ValueEnum)] diff --git a/evc/src/debug.rs b/evc/src/debug.rs index c3ea7d0..96f5777 100644 --- a/evc/src/debug.rs +++ b/evc/src/debug.rs @@ -24,24 +24,18 @@ impl View<&mut Frame> { impl Frame { pub fn draw_line(&mut self, start: Vec2<f32>, end: Vec2<f32>, color: Pixel) { - let (sx, sy) = (start.x as f32, start.y as f32); - let (ex, ey) = (end.x as f32, end.y as f32); - let (dx, dy) = (ex - sx, ey - sy); - let len = (dx * dx + dy * dy).sqrt(); - let (nx, ny) = (dx / len, dy / len); - let (mut cx, mut cy) = (sx, sy); + let diff = end - start; + let len = (diff.x * diff.x + diff.y * diff.y).sqrt(); + let normal = Vec2 { + x: diff.x / len, + y: diff.y / len, + }; + let mut cursor = start.clone(); let mut lc = 0.0; while lc < len { - self.set( - Vec2 { - x: cx as isize, - y: cy as isize, - }, - color, - ); + self.set(cursor.into(), color); lc += 0.5; - cx += nx * 0.5; - cy += ny * 0.5; + cursor = cursor + normal.scale(0.5); } } } @@ -91,17 +85,22 @@ pub fn draw_debug(block: &Block, mut target: View<&mut Frame>) { x: map_scalar8(r.translation.x), y: map_scalar8(r.translation.y), }; - let tl = mat.transform(translation) + target.offset.into(); - let tr = - mat.transform(translation + target.size.x_only().into()) + target.offset.into(); - let bl = - mat.transform(translation + target.size.y_only().into()) + target.offset.into(); - let br = mat.transform(translation + target.size.into()) + target.offset.into(); + let halfsize = Into::<Vec2<f32>>::into(target.size).scale(0.5); + let transform = |p| translation + mat.transform(p - halfsize) + halfsize; + let (tl, tr, bl, br) = ( + transform(Vec2::<f32>::ZERO) + target.offset.into(), + transform(target.size.x_only().into()) + target.offset.into(), + transform(target.size.y_only().into()) + target.offset.into(), + transform(target.size.into()) + target.offset.into(), + ); + if tl.y != tr.y || tl.x != bl.x { + eprintln!("{tl:?} {tr:?} {bl:?} {br:?}"); + } + target.draw_box(Pixel::CYAN); target.frame.draw_line(tl, tr, Pixel::MAGENTA); target.frame.draw_line(tr, br, Pixel::MAGENTA); target.frame.draw_line(bl, br, Pixel::MAGENTA); target.frame.draw_line(tl, bl, Pixel::MAGENTA); - target.draw_box(Pixel::CYAN); } - } + }; } diff --git a/evc/src/helpers/matrix.rs b/evc/src/helpers/matrix.rs index c3c120b..0007440 100644 --- a/evc/src/helpers/matrix.rs +++ b/evc/src/helpers/matrix.rs @@ -12,8 +12,8 @@ impl<T: std::ops::Mul<Output = T> + std::ops::Add<Output = T> + Copy> Mat2<T> { #[inline] pub fn transform(&self, v: Vec2<T>) -> Vec2<T> { Vec2 { - x: self.a * v.x + self.b * v.x, - y: self.c * v.y + self.d * v.y, + x: self.a * v.x + self.b * v.y, + y: self.c * v.x + self.d * v.y, } } } diff --git a/evc/src/helpers/vector.rs b/evc/src/helpers/vector.rs index 0209c58..a4766d1 100644 --- a/evc/src/helpers/vector.rs +++ b/evc/src/helpers/vector.rs @@ -20,6 +20,14 @@ impl From<Vec2<u16>> for Vec2<isize> { } } } +impl From<Vec2<f32>> for Vec2<isize> { + fn from(value: Vec2<f32>) -> Self { + Self { + x: value.x as isize, + y: value.y as isize, + } + } +} impl Vec2<isize> { pub const ZERO: Vec2<isize> = Vec2 { x: 0, y: 0 }; @@ -58,7 +66,7 @@ impl Vec2<isize> { Self { x: self.x, y: 0 } } pub fn y_only(&self) -> Self { - Self { x: self.x, y: 0 } + Self { x: 0, y: self.y } } } diff --git a/evc/src/refsampler.rs b/evc/src/refsampler.rs index d6f2bb1..8a8f44f 100644 --- a/evc/src/refsampler.rs +++ b/evc/src/refsampler.rs @@ -21,7 +21,7 @@ impl<'a> Sampler<'a> { #[inline] pub fn sample(&self, p: Vec2<f32>) -> Pixel { self.view - .sample(self.translation + self.transform.transform(p + self.halfsize) - self.halfsize) + .sample(self.translation + self.transform.transform(p - self.halfsize) + self.halfsize) .scale(self.value_scale) } pub fn from_refblock( |