X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-codec-support%2Fsrc%2Fcodecs%2Fblockdsp.rs;h=9f70582c17a09fbf4db08353e4a70f7bc46b9262;hb=0faa067bfda9b9460a1c7275859089f5b01e0a67;hp=94dcfc026424fa29df2a628fac907f51abc9fa6c;hpb=86081fed61d59fb1ea35ac34628450c9b0c00702;p=nihav.git 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 ]; +