diff options
author | metamuffin <metamuffin@disroot.org> | 2022-11-21 16:59:50 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-11-21 16:59:50 +0100 |
commit | 5248831232fa22a1f3d6515f7f6c7bee8994faf2 (patch) | |
tree | fdbff884248948d124ab864e21d65fe49c6ca0e2 /dhwt-codec/src/trim.rs | |
download | video-codec-experiments-5248831232fa22a1f3d6515f7f6c7bee8994faf2.tar video-codec-experiments-5248831232fa22a1f3d6515f7f6c7bee8994faf2.tar.bz2 video-codec-experiments-5248831232fa22a1f3d6515f7f6c7bee8994faf2.tar.zst |
unify repos
Diffstat (limited to 'dhwt-codec/src/trim.rs')
-rw-r--r-- | dhwt-codec/src/trim.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/dhwt-codec/src/trim.rs b/dhwt-codec/src/trim.rs new file mode 100644 index 0000000..85a920a --- /dev/null +++ b/dhwt-codec/src/trim.rs @@ -0,0 +1,36 @@ +use crate::io::{Value, TWO, ZERO}; +use std::ops::{Index, IndexMut}; + +pub fn trim<X: Index<usize, Output = Value> + IndexMut<usize, Output = Value>>( + size: usize, + a: &mut X, +) { + let half = size / 2; + let quarter = size / 4; + for i in 0..(size / 2 / 4) { + let hi = half + i * 4; + let qi = quarter + i * 2; + a[qi] = (a[qi + 0] + a[qi + 1]) / TWO; + a[qi + 1] = (a[hi + 0] + a[hi + 1] + a[hi + 2] + a[hi + 3]) / (TWO * TWO); + } + for i in half..size { + a[i] = ZERO; + } +} + +pub fn untrim<X: Index<usize, Output = Value> + IndexMut<usize, Output = Value>>( + size: usize, + a: &mut X, +) { + let half = size / 2; + let quarter = size / 4; + for i in 0..(size / 2 / 4) { + let hi = half + i * 4; + let qi = quarter + i * 2; + a[hi + 0] = a[qi + 1]; + a[hi + 1] = a[qi + 1]; + a[hi + 2] = a[qi + 1]; + a[hi + 3] = a[qi + 1]; + a[qi + 1] = a[qi]; + } +} |