From: Kostya Shishkov Date: Tue, 23 Jun 2020 08:58:35 +0000 (+0200) Subject: codec_support/blockdsp: add halfpel interpolation functions X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=0faa067bfda9b9460a1c7275859089f5b01e0a67;p=nihav.git codec_support/blockdsp: add halfpel interpolation functions --- diff --git a/nihav-codec-support/src/codecs/blockdsp.rs b/nihav-codec-support/src/codecs/blockdsp.rs index 94dcfc0..9f70582 100644 --- a/nihav-codec-support/src/codecs/blockdsp.rs +++ b/nihav-codec-support/src/codecs/blockdsp.rs @@ -257,3 +257,57 @@ pub fn copy_block(dst: &mut NASimpleVideoFrame, src: NAVideoBufferRef, c &sbuf[saddr..], sstride, bw, bh); } } + +fn hpel_interp00(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize) +{ + let mut didx = 0; + let mut sidx = 0; + for _ in 0..bh { + dst[didx..][..bw].copy_from_slice(&src[sidx..][..bw]); + didx += dstride; + sidx += sstride; + } +} + +fn hpel_interp01(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize) +{ + let mut didx = 0; + let mut sidx = 0; + for _ in 0..bh { + for x in 0..bw { dst[didx + x] = ((u16::from(src[sidx + x]) + u16::from(src[sidx + x + 1]) + 1) >> 1) as u8; } + didx += dstride; + sidx += sstride; + } +} + +fn hpel_interp10(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize) +{ + let mut didx = 0; + let mut sidx = 0; + for _ in 0..bh { + for x in 0..bw { dst[didx + x] = ((u16::from(src[sidx + x]) + u16::from(src[sidx + x + sstride]) + 1) >> 1) as u8; } + didx += dstride; + sidx += sstride; + } +} + +fn hpel_interp11(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize) +{ + let mut didx = 0; + let mut sidx = 0; + for _ in 0..bh { + for x in 0..bw { + dst[didx + x] = ((u16::from(src[sidx + x]) + + u16::from(src[sidx + x + 1]) + + u16::from(src[sidx + x + sstride]) + + u16::from(src[sidx + x + sstride + 1]) + 2) >> 2) as u8; + } + didx += dstride; + sidx += sstride; + } +} + +/// Half-pixel interpolation functions. +pub const HALFPEL_INTERP_FUNCS: &[BlkInterpFunc] = &[ + hpel_interp00, hpel_interp01, hpel_interp10, hpel_interp11 ]; +