aboutsummaryrefslogtreecommitdiff
path: root/test2/src/encode.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-05-07 15:17:24 +0200
committermetamuffin <metamuffin@disroot.org>2025-05-07 15:17:24 +0200
commite33685969d072f369ea2f30c08403f6b3a8e8686 (patch)
tree4b8bc7fedc62f7845125f69367a217cfa7558038 /test2/src/encode.rs
parent736ebd6102eb5df134acbda8aac94f034d5bebe4 (diff)
downloadvideo-codec-experiments-e33685969d072f369ea2f30c08403f6b3a8e8686.tar
video-codec-experiments-e33685969d072f369ea2f30c08403f6b3a8e8686.tar.bz2
video-codec-experiments-e33685969d072f369ea2f30c08403f6b3a8e8686.tar.zst
switch to nv12 pixel format
Diffstat (limited to 'test2/src/encode.rs')
-rw-r--r--test2/src/encode.rs40
1 files changed, 12 insertions, 28 deletions
diff --git a/test2/src/encode.rs b/test2/src/encode.rs
index 799d8d4..54c7a3a 100644
--- a/test2/src/encode.rs
+++ b/test2/src/encode.rs
@@ -57,7 +57,7 @@ impl BitstreamFilter for Enc {
}
}
- if best_d < 8 * 8 * 10 {
+ if best_d < 8 * 8 * 20 {
Frame::copy_block(&self.last, &mut frame, best_off, boff);
}
}
@@ -95,22 +95,14 @@ impl Frame {
}
// Chroma
- let uplane_off = res.x * res.y;
- let vplane_off = uplane_off + (res.x * res.y) / 4;
+ let uvplane_off = res.x * res.y;
for y in 0..BLOCK_SIZE / 2 {
- let ay_off = aoff.x / 2 + (y + aoff.y / 2) * res.x / 2;
- let by_off = boff.x / 2 + (y + boff.y / 2) * res.x / 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 / 2 {
- let ay_index = ay_off + x;
- let by_index = by_off + x;
-
- bframe.data[(by_index + uplane_off) as usize] =
- aframe.data[(ay_index + uplane_off) as usize];
- bframe.data[(by_index + vplane_off) as usize] =
- aframe.data[(ay_index + vplane_off) as usize];
- }
+ 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 {
@@ -130,23 +122,15 @@ impl Frame {
}
// Chroma
- let uplane_off = res.x * res.y;
- let vplane_off = uplane_off + (res.x * res.y) / 4;
+ let uvplane_off = res.x * res.y;
for y in 0..BLOCK_SIZE / 2 {
- let ay_off = aoff.x / 2 + (y + aoff.y / 2) * res.x / 2;
- let by_off = boff.x / 2 + (y + boff.y / 2) * res.x / 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 / 2 {
- let ay_index = ay_off + x;
- let by_index = by_off + x;
-
- diff += aframe.data[(ay_index + uplane_off) as usize]
- .abs_diff(bframe.data[(by_index + uplane_off) as usize])
- as u32;
- diff += aframe.data[(ay_index + vplane_off) as usize]
- .abs_diff(bframe.data[(by_index + vplane_off) as usize])
- as u32;
+ 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;
}
}