diff options
author | metamuffin <metamuffin@disroot.org> | 2022-12-08 09:13:17 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-12-08 09:13:17 +0100 |
commit | 6001cdeff335e12583a398acbb5a8a42c01bc077 (patch) | |
tree | 4c1c515cbf33e727f5db317880aadd425a1e0b96 /evc/src/helpers | |
parent | 8b7792d6aa27578221fee7cc8be1ceb202602a5a (diff) | |
download | video-codec-experiments-6001cdeff335e12583a398acbb5a8a42c01bc077.tar video-codec-experiments-6001cdeff335e12583a398acbb5a8a42c01bc077.tar.bz2 video-codec-experiments-6001cdeff335e12583a398acbb5a8a42c01bc077.tar.zst |
fast mode
Diffstat (limited to 'evc/src/helpers')
-rw-r--r-- | evc/src/helpers/pixel.rs | 22 | ||||
-rw-r--r-- | evc/src/helpers/vector.rs | 3 |
2 files changed, 18 insertions, 7 deletions
diff --git a/evc/src/helpers/pixel.rs b/evc/src/helpers/pixel.rs index 964040d..816d7dc 100644 --- a/evc/src/helpers/pixel.rs +++ b/evc/src/helpers/pixel.rs @@ -27,17 +27,16 @@ impl Pixel { a.r.abs_diff(b.r) as usize, a.r.abs_diff(b.r) as usize, ); + // fast_sqrt(rd * rd + gd * gd + bd * bd) SQRT[rd + gd + bd] } - + #[inline] pub fn average(a: Pixel, b: Pixel) -> Pixel { - //? this functions is broken - // TODO dont loose accuracy Pixel { - r: (a.r >> 1) + (b.r >> 1), - g: (a.g >> 1) + (b.g >> 1), - b: (a.b >> 1) + (b.b >> 1), + r: ((a.r as u16 + b.r as u16) >> 1) as u8, + g: ((a.g as u16 + b.g as u16) >> 1) as u8, + b: ((a.b as u16 + b.b as u16) >> 1) as u8, } } @@ -51,7 +50,7 @@ impl Pixel { } } -const SQRT: [usize; 256 * 3] = gen_sqrt_lookup(); +pub const SQRT: [usize; 256 * 3] = gen_sqrt_lookup(); const fn gen_sqrt_lookup<const N: usize>() -> [usize; N] { let mut arr = [0; N]; @@ -70,3 +69,12 @@ const fn sqrt(x: f32) -> f32 { let a = (a + x / a) * 0.5; a } + +pub fn fast_sqrt(x: usize) -> usize { + let a = 1; + let a = (a + x / (a + 1)) / 2; + let a = (a + x / (a + 1)) / 2; + // let a = (a + x / (a + 1)) / 2; + // let a = (a + x / (a + 1)) / 2; + a +} diff --git a/evc/src/helpers/vector.rs b/evc/src/helpers/vector.rs index f411832..7cb180a 100644 --- a/evc/src/helpers/vector.rs +++ b/evc/src/helpers/vector.rs @@ -31,6 +31,9 @@ impl<T: std::ops::Mul<Output = T> + Copy> Vec2<T> { y: self.y * f, } } + pub fn area(&self) -> T { + self.x * self.y + } } impl Vec2<isize> { |