From: Kostya Shishkov Date: Wed, 5 Jun 2019 17:11:27 +0000 (+0200) Subject: vp3: move loop filter to common X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=8d8ddfe10445b9561fb36e5e25980fe3fb95c2ea;p=nihav.git vp3: move loop filter to common --- diff --git a/nihav-duck/src/codecs/vp3.rs b/nihav-duck/src/codecs/vp3.rs index 796fbf6..2e6137f 100644 --- a/nihav-duck/src/codecs/vp3.rs +++ b/nihav-duck/src/codecs/vp3.rs @@ -506,39 +506,14 @@ fn vp3_interp11(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: } } -fn vp31_loop_filter(data: &mut [u8], mut off: usize, step: usize, stride: usize, loop_str: i16) { - for _ in 0..8 { - let a = data[off - step * 2] as i16; - let b = data[off - step] as i16; - let c = data[off] as i16; - let d = data[off + step] as i16; - let mut diff = ((a - d) + 3 * (c - b) + 4) >> 3; - if diff.abs() >= 2 * loop_str { - diff = 0; - } else if diff.abs() >= loop_str { - if diff < 0 { - diff = -diff - 2 * loop_str; - } else { - diff = -diff + 2 * loop_str; - } - } - if diff != 0 { - data[off - step] = (b + diff).max(0).min(255) as u8; - data[off] = (c - diff).max(0).min(255) as u8; - } - - off += stride; - } -} - fn vp31_loop_filter_v(frm: &mut NASimpleVideoFrame, x: usize, y: usize, plane: usize, loop_str: i16) { let off = frm.offset[plane] + x + y * frm.stride[plane]; - vp31_loop_filter(frm.data, off, 1, frm.stride[plane], loop_str); + vp31_loop_filter(frm.data, off, 1, frm.stride[plane], 8, loop_str); } fn vp31_loop_filter_h(frm: &mut NASimpleVideoFrame, x: usize, y: usize, plane: usize, loop_str: i16) { let off = frm.offset[plane] + x + y * frm.stride[plane]; - vp31_loop_filter(frm.data, off, frm.stride[plane], 1, loop_str); + vp31_loop_filter(frm.data, off, frm.stride[plane], 1, 8, loop_str); } pub const VP3_INTERP_FUNCS: &[blockdsp::BlkInterpFunc] = &[ vp3_interp00, vp3_interp01, vp3_interp10, vp3_interp11 ]; diff --git a/nihav-duck/src/codecs/vpcommon.rs b/nihav-duck/src/codecs/vpcommon.rs index cac264b..8ea6a47 100644 --- a/nihav-duck/src/codecs/vpcommon.rs +++ b/nihav-duck/src/codecs/vpcommon.rs @@ -186,3 +186,30 @@ pub fn vp_add_block_dc(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: usiz off += frm.stride[plane]; } } + +pub fn vp31_loop_filter(data: &mut [u8], mut off: usize, step: usize, stride: usize, + len: usize, loop_str: i16) { + for _ in 0..len { + let a = data[off - step * 2] as i16; + let b = data[off - step] as i16; + let c = data[off] as i16; + let d = data[off + step] as i16; + let mut diff = ((a - d) + 3 * (c - b) + 4) >> 3; + if diff.abs() >= 2 * loop_str { + diff = 0; + } else if diff.abs() >= loop_str { + if diff < 0 { + diff = -diff - 2 * loop_str; + } else { + diff = -diff + 2 * loop_str; + } + } + if diff != 0 { + data[off - step] = (b + diff).max(0).min(255) as u8; + data[off] = (c - diff).max(0).min(255) as u8; + } + + off += stride; + } +} +