fix or silence clippy warnings
authorKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 16 Dec 2020 08:51:41 +0000 (09:51 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 16 Dec 2020 08:51:41 +0000 (09:51 +0100)
nihav-itu/src/codecs/h264/cabac.rs
nihav-itu/src/codecs/h264/cabac_coder.rs
nihav-itu/src/codecs/h264/cavlc.rs
nihav-itu/src/codecs/h264/dsp.rs
nihav-itu/src/codecs/h264/mod.rs
nihav-itu/src/codecs/h264/pic_ref.rs
nihav-itu/src/codecs/h264/sets.rs
nihav-itu/src/codecs/h264/slice.rs
nihav-itu/src/codecs/h264/types.rs
nihav-itu/src/codecs/mod.rs
nihav-itu/src/lib.rs

index 554da2a808681d25d8f41cd317acab5e80fd6f5a..4be9a0dcbc263e97c34fcf5205602838adf03387 100644 (file)
@@ -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;
index 453ebc9fcb1d140565efcddb3404f861ab3fe6f3..0e148092ff93385c67abde41f53267124e437f7d 100644 (file)
@@ -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;
         }
index 4c598a48c90e0f1aa4a28b92f1263f4c484f5f70..73d9c6bff36621d58e3f80a60b024e690c3b5c81 100644 (file)
@@ -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;
index 2cd08fcb38e0c6359801b3f923d16ddb59261438..87dc8d9fd97b301003d89fe52488eb71d0192f2c 100644 (file)
@@ -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;
index 5ecd05cc6fd875baacc8ad4ef1e19981e3a0418a..976b8b575a47178af71eb5095132ef5fff33fa3c 100644 (file)
@@ -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];
 
index 88d453d724fbbbae602ffbdbc91224bd65fd423d..81889a2cf3ad79591bb85110393ca519346440ec 100644 (file)
@@ -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<Option<PictureInfo>>, ref_pics: &Vec<PictureInfo>, long_term: &Vec<Option<PictureInfo>>, reord_info: &ReorderingInfo, cur_id: u16, pic_num_mask: u16) {
+fn form_ref_list(ref_list: &mut Vec<Option<PictureInfo>>, ref_pics: &[PictureInfo], long_term: &[Option<PictureInfo>], 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 {
index 88566992e3748baeefaf91fb9a3eb15ebf8b4d3f..5bd51a955e395abb3c96405203901648779fff0d 100644 (file)
@@ -50,6 +50,7 @@ pub fn is_high_profile(profile: u8) -> bool {
     }
 }
 
+#[allow(clippy::cyclomatic_complexity)]
 pub fn parse_sps(src: &[u8]) -> DecoderResult<SeqParameterSet> {
     let mut br = BitReader::new(src, BitReaderMode::BE);
     let mut sps: SeqParameterSet = unsafe { std::mem::zeroed() };
index a4ce4bf0271c92817151ef4b1039bbb948e260b0..7250fafad4ae25bbed365075e83526a92f5b69fb 100644 (file)
@@ -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<SliceHeader> {
     let mut hdr: SliceHeader = unsafe { std::mem::zeroed() };
 
index 5adeab17f14202641adafe60cd443b52a516a51b..6b5d0100c5810583ce9faa24c0bb5f94bab998d9 100644 (file)
@@ -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);
index d4167b566244ee3f3be60e0c21ada7f6631122ca..ec35801c8286491e3c09b069d6b2691b0256341b 100644 (file)
@@ -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;
 
index 4f6557660648157c33ffecd317e04de312978b55..234a472027fd11ff137f9ae6f9b02024767fd327 100644 (file)
@@ -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;