From: Kostya Shishkov Date: Wed, 16 Dec 2020 08:51:41 +0000 (+0100) Subject: fix or silence clippy warnings X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=4a1ca15c9298340e8f2cb2ad6016109375cc45b9;p=nihav.git fix or silence clippy warnings --- diff --git a/nihav-itu/src/codecs/h264/cabac.rs b/nihav-itu/src/codecs/h264/cabac.rs index 554da2a..4be9a0d 100644 --- a/nihav-itu/src/codecs/h264/cabac.rs +++ b/nihav-itu/src/codecs/h264/cabac.rs @@ -258,6 +258,7 @@ fn decode_mv(cabac: &mut CABAC, ctx0: usize, ctx1: usize) -> MV { MV{ x, y } } +#[allow(clippy::cyclomatic_complexity)] pub fn decode_mb_pred_cabac(cabac: &mut CABAC, slice_hdr: &SliceHeader, mb_type: MBType, sstate: &mut SliceState, mb_info: &mut CurrentMBInfo) { mb_info.mb_type = mb_type; let num_l0 = slice_hdr.num_ref_idx_l0_active; diff --git a/nihav-itu/src/codecs/h264/cabac_coder.rs b/nihav-itu/src/codecs/h264/cabac_coder.rs index 453ebc9..0e14809 100644 --- a/nihav-itu/src/codecs/h264/cabac_coder.rs +++ b/nihav-itu/src/codecs/h264/cabac_coder.rs @@ -143,13 +143,13 @@ impl<'a> CABAC<'a> { val_mps }; self.states[idx] = if bit == val_mps { - TRANS_IDX_MPS[state_idx] + TRANS_IDX_MPS[state_idx] + (if val_mps { 0x80 } else { 0 }) } else { if state_idx == 0 { val_mps = !val_mps; } - TRANS_IDX_LPS[state_idx] - } + (if val_mps { 0x80 } else { 0 }); + TRANS_IDX_LPS[state_idx] + (if val_mps { 0x80 } else { 0 }) + }; self.renorm(); bit } @@ -188,7 +188,7 @@ impl<'a> CABAC<'a> { } self.cod_range <<= shift; self.cod_offset <<= shift; - self.cod_offset |= u16::from(self.bitbuf >> (16 - shift)); + self.cod_offset |= self.bitbuf >> (16 - shift); self.bitbuf <<= shift; self.bits -= shift; } diff --git a/nihav-itu/src/codecs/h264/cavlc.rs b/nihav-itu/src/codecs/h264/cavlc.rs index 4c598a4..73d9c6b 100644 --- a/nihav-itu/src/codecs/h264/cavlc.rs +++ b/nihav-itu/src/codecs/h264/cavlc.rs @@ -106,6 +106,7 @@ fn read_mvs(br: &mut BitReader, mvs: &mut [MV]) -> DecoderResult<()> { Ok(()) } +#[allow(clippy::cyclomatic_complexity)] pub fn decode_mb_pred_cavlc(br: &mut BitReader, slice_hdr: &SliceHeader, mb_type: MBType, sstate: &mut SliceState, mb_info: &mut CurrentMBInfo) -> DecoderResult<()> { mb_info.mb_type = mb_type; let num_l0 = slice_hdr.num_ref_idx_l0_active; diff --git a/nihav-itu/src/codecs/h264/dsp.rs b/nihav-itu/src/codecs/h264/dsp.rs index 2cd08fc..87dc8d9 100644 --- a/nihav-itu/src/codecs/h264/dsp.rs +++ b/nihav-itu/src/codecs/h264/dsp.rs @@ -46,12 +46,12 @@ pub fn chroma_dc_transform(blk: &mut [i16; 4], qp: u8) { blk[2] = t1 + t3; blk[3] = t1 - t3; if qp < 6 { - let mul = i16::from(LEVEL_SCALE[0][qp as usize]); + let mul = LEVEL_SCALE[0][qp as usize]; for el in blk.iter_mut() { *el = el.wrapping_mul(mul) >> 1; } } else { - let mul = i16::from(LEVEL_SCALE[0][(qp % 6) as usize]); + let mul = LEVEL_SCALE[0][(qp % 6) as usize]; let shift = qp / 6 - 1; for el in blk.iter_mut() { *el = el.wrapping_mul(mul) << shift; @@ -113,14 +113,14 @@ macro_rules! transform { pub fn idct_luma_dc(blk: &mut [i16; 16], qp: u8) { if qp < 12 { - let mul = i16::from(LEVEL_SCALE[0][(qp % 6) as usize]); + let mul = LEVEL_SCALE[0][(qp % 6) as usize]; let shift = 2 - qp / 6; let bias = 1 << shift >> 1; for el in blk.iter_mut() { *el = el.wrapping_mul(mul).wrapping_add(bias) >> shift; } } else { - let mul = i16::from(LEVEL_SCALE[0][(qp % 6) as usize]); + let mul = LEVEL_SCALE[0][(qp % 6) as usize]; let shift = qp / 6 - 2; for el in blk.iter_mut() { *el = el.wrapping_mul(mul) << shift; diff --git a/nihav-itu/src/codecs/h264/mod.rs b/nihav-itu/src/codecs/h264/mod.rs index 5ecd05c..976b8b5 100644 --- a/nihav-itu/src/codecs/h264/mod.rs +++ b/nihav-itu/src/codecs/h264/mod.rs @@ -15,6 +15,10 @@ mod types; pub use types::*; mod pic_ref; pub use pic_ref::*; +#[allow(clippy::identity_op)] +#[allow(clippy::erasing_op)] +#[allow(clippy::many_single_char_names)] +#[allow(clippy::range_plus_one)] mod dsp; use dsp::*; mod cabac; @@ -653,6 +657,7 @@ println!("PAFF?"); } } } + #[allow(clippy::cyclomatic_complexity)] fn handle_macroblock(&mut self, mb_info: &mut CurrentMBInfo) { let pps = &self.pps[self.cur_pps]; diff --git a/nihav-itu/src/codecs/h264/pic_ref.rs b/nihav-itu/src/codecs/h264/pic_ref.rs index 88d453d..81889a2 100644 --- a/nihav-itu/src/codecs/h264/pic_ref.rs +++ b/nihav-itu/src/codecs/h264/pic_ref.rs @@ -215,6 +215,7 @@ impl FrameRefs { self.ref_pics.truncate(0); self.long_term.truncate(0); } + #[allow(clippy::cyclomatic_complexity)] pub fn select_refs(&mut self, sps: &SeqParameterSet, slice_hdr: &SliceHeader, cur_id: u32) { self.ref_list0.truncate(0); self.ref_list1.truncate(0); @@ -408,7 +409,7 @@ impl FrameRefs { } } -fn form_ref_list(ref_list: &mut Vec>, ref_pics: &Vec, long_term: &Vec>, reord_info: &ReorderingInfo, cur_id: u16, pic_num_mask: u16) { +fn form_ref_list(ref_list: &mut Vec>, ref_pics: &[PictureInfo], long_term: &[Option], reord_info: &ReorderingInfo, cur_id: u16, pic_num_mask: u16) { let mut ref_pic_id = cur_id; for (&op, &num) in reord_info.reordering_of_pic_nums_idc.iter().zip(reord_info.abs_diff_or_num.iter()).take(reord_info.num_ops) { if op < 2 { diff --git a/nihav-itu/src/codecs/h264/sets.rs b/nihav-itu/src/codecs/h264/sets.rs index 8856699..5bd51a9 100644 --- a/nihav-itu/src/codecs/h264/sets.rs +++ b/nihav-itu/src/codecs/h264/sets.rs @@ -50,6 +50,7 @@ pub fn is_high_profile(profile: u8) -> bool { } } +#[allow(clippy::cyclomatic_complexity)] pub fn parse_sps(src: &[u8]) -> DecoderResult { let mut br = BitReader::new(src, BitReaderMode::BE); let mut sps: SeqParameterSet = unsafe { std::mem::zeroed() }; diff --git a/nihav-itu/src/codecs/h264/slice.rs b/nihav-itu/src/codecs/h264/slice.rs index a4ce4bf..7250faf 100644 --- a/nihav-itu/src/codecs/h264/slice.rs +++ b/nihav-itu/src/codecs/h264/slice.rs @@ -124,6 +124,7 @@ pub fn parse_slice_header_minimal(br: &mut BitReader) -> DecoderResult<(usize, S Ok((first_mb_in_slice, slice_type)) } +#[allow(clippy::cyclomatic_complexity)] pub fn parse_slice_header(br: &mut BitReader, sps_arr: &[SeqParameterSet], pps_arr: &[PicParameterSet], is_idr: bool, nal_ref_idc: u8) -> DecoderResult { let mut hdr: SliceHeader = unsafe { std::mem::zeroed() }; diff --git a/nihav-itu/src/codecs/h264/types.rs b/nihav-itu/src/codecs/h264/types.rs index 5adeab1..6b5d010 100644 --- a/nihav-itu/src/codecs/h264/types.rs +++ b/nihav-itu/src/codecs/h264/types.rs @@ -645,6 +645,7 @@ impl SliceState { } ctx } + #[allow(clippy::if_same_then_else)] pub fn predict(&mut self, xpos: usize, ypos: usize, bw: usize, bh: usize, ref_l: usize, diff_mv: MV, ref_idx: PicRef) { let midx = self.get_cur_blk4_idx(0) + xpos / 4 + ypos / 4 * self.blk4.stride; let ridx = self.get_cur_blk8_idx(0) + xpos / 8 + ypos / 8 * self.blk8.stride; @@ -747,15 +748,9 @@ impl SliceState { } } pub fn predict_direct_sub(&mut self, frame_refs: &FrameRefs, temporal_mv: bool, cur_id: u16, blk4: usize) { - if temporal_mv { - let (mv0, ref0, mv1, ref1) = self.get_direct_mv(frame_refs, temporal_mv, cur_id, blk4); - self.get_cur_blk4(blk4).mv = [mv0, mv1]; - self.get_cur_blk8(blk4_to_blk8(blk4)).ref_idx = [ref0, ref1]; - } else { - let (mv0, ref0, mv1, ref1) = self.get_direct_mv(frame_refs, temporal_mv, cur_id, blk4); - self.get_cur_blk4(blk4).mv = [mv0, mv1]; - self.get_cur_blk8(blk4_to_blk8(blk4)).ref_idx = [ref0, ref1]; - } + let (mv0, ref0, mv1, ref1) = self.get_direct_mv(frame_refs, temporal_mv, cur_id, blk4); + self.get_cur_blk4(blk4).mv = [mv0, mv1]; + self.get_cur_blk8(blk4_to_blk8(blk4)).ref_idx = [ref0, ref1]; } pub fn get_direct_mv(&self, frame_refs: &FrameRefs, temporal_mv: bool, cur_id: u16, blk4: usize) -> (MV, PicRef, MV, PicRef) { let (mbi, r1_poc, r1_long) = frame_refs.get_colocated_info(self.mb_x, self.mb_y); diff --git a/nihav-itu/src/codecs/mod.rs b/nihav-itu/src/codecs/mod.rs index d4167b5..ec35801 100644 --- a/nihav-itu/src/codecs/mod.rs +++ b/nihav-itu/src/codecs/mod.rs @@ -4,6 +4,7 @@ macro_rules! validate { ($a:expr) => { if !$a { println!("check failed at {}:{}", file!(), line!()); return Err(DecoderError::InvalidData); } }; } +#[allow(clippy::too_many_arguments)] #[cfg(feature="decoder_h264")] mod h264; diff --git a/nihav-itu/src/lib.rs b/nihav-itu/src/lib.rs index 4f65576..234a472 100644 --- a/nihav-itu/src/lib.rs +++ b/nihav-itu/src/lib.rs @@ -1,6 +1,9 @@ extern crate nihav_core; extern crate nihav_codec_support; +#[allow(clippy::collapsible_if)] +#[allow(clippy::needless_range_loop)] +#[allow(clippy::useless_let_if_seq)] mod codecs; pub use crate::codecs::itu_register_all_decoders;