diff options
author | metamuffin <metamuffin@disroot.org> | 2025-05-05 15:09:54 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-05-05 15:09:54 +0200 |
commit | 306f96164784a8cbf405e72fa4364d6523366e95 (patch) | |
tree | 51717fc139871baa438aad806f4923669ae0896c /old/dhwt-codec/src/trim.rs | |
parent | 9cc089e2d6e841879e430b01d2f3d92c8820523e (diff) | |
download | video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar.bz2 video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar.zst |
old dir
Diffstat (limited to 'old/dhwt-codec/src/trim.rs')
-rw-r--r-- | old/dhwt-codec/src/trim.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/old/dhwt-codec/src/trim.rs b/old/dhwt-codec/src/trim.rs new file mode 100644 index 0000000..85a920a --- /dev/null +++ b/old/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]; + } +} |