diff options
author | metamuffin <metamuffin@disroot.org> | 2025-05-07 16:17:44 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-05-07 16:17:44 +0200 |
commit | 24ecbd5e91f125bd68a4d538eeb5a9839f16a4e6 (patch) | |
tree | e902614fc7a66b110e6863d5b10fa494e157bdad /test2/src/encode.rs | |
parent | e33685969d072f369ea2f30c08403f6b3a8e8686 (diff) | |
download | video-codec-experiments-24ecbd5e91f125bd68a4d538eeb5a9839f16a4e6.tar video-codec-experiments-24ecbd5e91f125bd68a4d538eeb5a9839f16a4e6.tar.bz2 video-codec-experiments-24ecbd5e91f125bd68a4d538eeb5a9839f16a4e6.tar.zst |
bugs everywhere
Diffstat (limited to 'test2/src/encode.rs')
-rw-r--r-- | test2/src/encode.rs | 92 |
1 files changed, 19 insertions, 73 deletions
diff --git a/test2/src/encode.rs b/test2/src/encode.rs index 54c7a3a..ed091cb 100644 --- a/test2/src/encode.rs +++ b/test2/src/encode.rs @@ -1,4 +1,4 @@ -use crate::BLOCK_SIZE; +use crate::{BLOCK_SIZE, Frame}; use framework::BitstreamFilter; use glam::{IVec2, ivec2}; @@ -24,12 +24,16 @@ impl BitstreamFilter for Enc { res: self.res, }; + let mut out = Vec::new(); + let mut oldblock = Vec::new(); + let mut newblock = Vec::new(); + for by in 0..frame.res.y / BLOCK_SIZE { for bx in 0..frame.res.x / BLOCK_SIZE { let boff = ivec2(bx * BLOCK_SIZE, by * BLOCK_SIZE); let mut best_d = Frame::compare_block(&frame, &self.last, boff, boff); - let mut best_off = ivec2(0, 0); + let mut best_off = boff; for granularity in [8, 4, 2, 1] { for dir in [ @@ -57,83 +61,25 @@ impl BitstreamFilter for Enc { } } - if best_d < 8 * 8 * 20 { - Frame::copy_block(&self.last, &mut frame, best_off, boff); - } - } - } - - self.last = frame.clone(); - frame.data - } -} - -#[derive(Clone)] -struct Frame { - res: IVec2, - data: Vec<u8>, -} - -impl Frame { - fn new(res: IVec2) -> Self { - Frame { - res, - data: vec![127; (res.x * res.y + res.x * res.y / 2) as usize], - } - } - fn copy_block(aframe: &Frame, bframe: &mut Frame, aoff: IVec2, boff: IVec2) { - assert_eq!(aframe.res, bframe.res); - let res = aframe.res; - - // Luma - for y in 0..BLOCK_SIZE { - let ay_off = aoff.x + (y + aoff.y) * res.x; - let by_off = boff.x + (y + boff.y) * res.x; - - bframe.data[by_off as usize..(by_off + BLOCK_SIZE) as usize] - .copy_from_slice(&aframe.data[ay_off as usize..(ay_off + BLOCK_SIZE) as usize]); - } - - // Chroma - let uvplane_off = res.x * res.y; - - for y in 0..BLOCK_SIZE / 2 { - let ay_off = uvplane_off + (aoff.x & !1) + (y + aoff.y / 2) * res.x; - let by_off = uvplane_off + (boff.x & !1) + (y + boff.y / 2) * res.x; - - bframe.data[by_off as usize..(by_off + BLOCK_SIZE) as usize] - .copy_from_slice(&aframe.data[ay_off as usize..(ay_off + BLOCK_SIZE) as usize]); - } - } - fn compare_block(aframe: &Frame, bframe: &Frame, aoff: IVec2, boff: IVec2) -> u32 { - assert_eq!(aframe.res, bframe.res); - let res = aframe.res; - let mut diff = 0; + oldblock.clear(); + frame.export_block(boff, &mut oldblock); - // Luma - for y in 0..BLOCK_SIZE { - let ay_off = aoff.x + (y + aoff.y) * res.x; - let by_off = boff.x + (y + boff.y) * res.x; + Frame::copy_block(&self.last, &mut frame, best_off, boff); - for x in 0..BLOCK_SIZE { - diff += aframe.data[(ay_off + x) as usize] - .abs_diff(bframe.data[(by_off + x) as usize]) as u32 - } - } + newblock.clear(); + frame.export_block(boff, &mut newblock); - // Chroma - let uvplane_off = res.x * res.y; + let reloff = best_off - boff; + out.push((reloff.x + 127) as u8); + out.push((reloff.y + 127) as u8); - for y in 0..BLOCK_SIZE / 2 { - let ay_off = uvplane_off + (aoff.x & !1) + (y + aoff.y / 2) * res.x; - let by_off = uvplane_off + (boff.x & !1) + (y + boff.y / 2) * res.x; - - for x in 0..BLOCK_SIZE { - diff += aframe.data[(ay_off + x) as usize] - .abs_diff(bframe.data[(by_off + x) as usize]) as u32; + for i in 0..(BLOCK_SIZE * BLOCK_SIZE + BLOCK_SIZE * BLOCK_SIZE / 4) { + out.push(newblock[i as usize] - oldblock[i as usize] + 127) + } } } - diff + self.last = frame.clone(); + out } } |