game: fix or silence clippy warnings
authorKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 16 Jun 2020 10:12:22 +0000 (12:12 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 16 Jun 2020 10:12:22 +0000 (12:12 +0200)
nihav-game/src/codecs/bmv3.rs
nihav-game/src/codecs/gremlinvideo.rs
nihav-game/src/codecs/lhst500f22.rs
nihav-game/src/codecs/midivid.rs
nihav-game/src/codecs/midivid3.rs
nihav-game/src/codecs/vmd.rs
nihav-game/src/demuxers/bmv.rs
nihav-game/src/demuxers/vmd.rs
nihav-game/src/lib.rs

index a9d7f71e9222f00cdf292babda4f6a4b0e0d262b..cde7892fd512756f6d5de94c7f3bd55f0282dfb8 100644 (file)
@@ -110,6 +110,7 @@ impl BMV3VideoDecoder {
             is_intra:   false,
         }
     }
+    #[allow(clippy::identity_op)]
     fn decode_frame(&mut self, br: &mut ByteReader) -> DecoderResult<()> {
         let mut idx = 0;
         loop {
@@ -532,6 +533,7 @@ impl BMV3AudioDecoder {
     }
 }
 
+#[allow(clippy::identity_op)]
 fn decode_block(mode: u8, src: &[u8], dst: &mut [i16], mut pred: i16) -> i16 {
     let steps = &BMV_AUDIO_STEPS[mode as usize];
     let mut val2 = 0;
index 73f42255d549ef612f38cfb739aa96dbe3bb995a..4b53ae87a5784ea71bc51bc008a9c96a503ddd3c 100644 (file)
@@ -143,17 +143,17 @@ impl GremlinVideoDecoder {
         let mut sidx = PREAMBLE_SIZE;
         let mut didx = 0;
 
-        for i in 0..768 { dst[paloff + i] = self.pal[i]; }
+        dst[paloff..][..768].copy_from_slice(&self.pal);
         if !self.scale_v && !self.scale_h {
             for _ in 0..h {
-                for x in 0..w { dst[didx + x] = self.frame[sidx + x]; }
+                dst[didx..][..w].copy_from_slice(&self.frame[sidx..][..w]);
                 sidx += w;
                 didx += stride;
             }
         } else {
             for y in 0..h {
                 if !self.scale_v {
-                    for x in 0..w { dst[didx + x] = self.frame[sidx + x]; }
+                    dst[didx..][..w].copy_from_slice(&self.frame[sidx..][..w]);
                 } else {
                     for x in 0..w { dst[didx + x] = self.frame[sidx + x/2]; }
                 }
@@ -247,6 +247,7 @@ impl GremlinVideoDecoder {
         Ok(())
     }
 
+    #[allow(clippy::identity_op)]
     fn decode_method68(&mut self, br: &mut ByteReader,
                        skip: usize, use8: bool) -> DecoderResult<()> {
         let mut bits = Bits32::new();
index e3535f57359a7282dfbbd8398122c79230351c8a..e795070050ab70469e07d3ef1ca61dd49e000402 100644 (file)
@@ -313,6 +313,7 @@ impl LHDecoder {
         }
         Ok(())
     }
+    #[allow(clippy::identity_op)]
     fn unpack_samples(&mut self, br: &mut BitReader) -> DecoderResult<()> {
         for grp in 0..3 {
             for gr in 0..4 {
@@ -368,7 +369,7 @@ impl NADecoder for LHDecoder {
     fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
         if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() {
             self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), 1, SND_F32P_FORMAT, CODEC_SAMPLES);
-            self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo.clone()));
+            self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo));
             self.chmap = NAChannelMap::from_str("C").unwrap();
             Ok(())
         } else {
index 74ec75f6b33f689abf7d891d0b48f8584738bf13..611ca60daced7aeed95d7e4ec006858e700439ab 100644 (file)
@@ -22,10 +22,10 @@ fn lz_decompress(src: &[u8], dst: &mut [u8]) -> DecoderResult<()> {
     let mut dpos = 0;
     let end = src.len();
     while spos < end {
-        let oplo = src[spos] as u16;
+        let oplo = u16::from(src[spos]);
         spos += 1;
         if spos >= end { return Err(DecoderError::ShortData); }
-        let ophi = src[spos] as u16;
+        let ophi = u16::from(src[spos]);
         spos += 1;
         let mut op = (ophi << 8) | oplo;
         for _ in 0..16 {
@@ -58,6 +58,7 @@ fn lz_decompress(src: &[u8], dst: &mut [u8]) -> DecoderResult<()> {
     Ok(())
 }
 
+#[allow(clippy::identity_op)]
 fn decode_frame(frm: &mut NASimpleVideoFrame<u8>, src: &[u8], width: usize, height: usize) -> DecoderResult<bool> {
     validate!(src.len() > 8);
     let num_vec     = read_u16le(&src[0..])? as usize;
index 7ffb04548b31f3c28d17ab1d5c9dd04035fc0c49..3a3c161d72befedfb2e25a94f5ee677237893b5d 100644 (file)
@@ -297,11 +297,11 @@ fn decode_values(br: &mut BitReader, dst: &mut [i16], cb: &Codebook<u32>) -> Dec
 }
 
 fn dequant(val: i16, q: i16) -> i32 {
-    (val as i32) * (q as i32)
+    i32::from(val) * i32::from(q)
 }
 
 fn scale_coef(val: i32, scale: i16) -> i32 {
-    ((val as i32) * (scale as i32)) >> 8
+    (val * i32::from(scale)) >> 8
 }
 
 macro_rules! idct_1d {
@@ -334,6 +334,8 @@ macro_rules! idct_1d {
     }
 }
 
+#[allow(clippy::erasing_op)]
+#[allow(clippy::identity_op)]
 fn idct(blk: &mut [i32; 64]) {
     for i in 0..8 {
         idct_1d!(blk[i + 0 * 8], blk[i + 1 * 8], blk[i + 2 * 8], blk[i + 3 * 8],
@@ -343,7 +345,7 @@ fn idct(blk: &mut [i32; 64]) {
         idct_1d!(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7]);
     }
     for el in blk.iter_mut() {
-        *el = *el >> 5;
+        *el >>= 5;
     }
 }
 
@@ -394,7 +396,7 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16
             let dc = dequant(coeffs[0], qmat[0]) >> 5;
             for line in dst.chunks_mut(stride).take(8) {
                 for el in line.iter_mut().take(8) {
-                    *el = ((*el as i32) + dc).max(0).min(255) as u8;
+                    *el = (i32::from(*el) + dc).max(0).min(255) as u8;
                 }
             }
         },
@@ -407,7 +409,7 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16
             idct(&mut blk);
             for (line, row) in dst.chunks_mut(stride).zip(blk.chunks(8)).take(8) {
                 for (dst, coef) in line.iter_mut().zip(row.iter()).take(8) {
-                    *dst = (*dst as i32 + *coef).max(0).min(255) as u8;
+                    *dst = (i32::from(*dst) + *coef).max(0).min(255) as u8;
                 }
             }
         },
@@ -419,7 +421,7 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16
             idct(&mut blk);
             for (line, row) in dst.chunks_mut(stride).zip(blk.chunks(8)).take(8) {
                 for (dst, coef) in line.iter_mut().zip(row.iter()).take(8) {
-                    *dst = (*dst as i32 + *coef).max(0).min(255) as u8;
+                    *dst = (i32::from(*dst) + *coef).max(0).min(255) as u8;
                 }
             }
         },
@@ -428,13 +430,13 @@ fn decode_block_inter(dst: &mut [u8], stride: usize, btype: usize, coeffs: &[i16
 
 fn init_quant(qmat: &mut [i16; 64], base_qmat: &[u8; 64], quant: u8) {
     let q = if quant < 50 {
-            5000 / (quant.max(1) as i32)
+            5000 / i32::from(quant.max(1))
         } else {
-            ((100 - quant.min(100)) * 2) as i32
+            i32::from((100 - quant.min(100)) * 2)
         };
     for (inq, (outq, scale)) in base_qmat.iter().zip(qmat.iter_mut().zip(QUANT_MATRIX.iter())) {
-        let val = (((*inq as i32) * q + 50) / 100).max(1).min(0x7FFF);
-        *outq = ((val * (*scale as i32) + 0x800) >> 12) as i16;
+        let val = ((i32::from(*inq) * q + 50) / 100).max(1).min(0x7FFF);
+        *outq = ((val * i32::from(*scale) + 0x800) >> 12) as i16;
     }
 }
 
index 939dcd6d25891b719160d9375628cbd930afcfd3..110548a7917642d84266a666a35a129c6a9201cd 100644 (file)
@@ -451,7 +451,7 @@ impl NADecoder for VMDAudioDecoder {
             let edata = info.get_extradata();
             let flags = if let Some(ref buf) = edata {
                     validate!(buf.len() >= 2);
-                    (buf[0] as u16) | ((buf[1] as u16) << 8)
+                    u16::from(buf[0]) | (u16::from(buf[1]) << 8)
                 } else {
                     0
                 };
@@ -480,13 +480,15 @@ impl NADecoder for VMDAudioDecoder {
                 }
             };
             self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), ainfo.get_channels(), fmt, ainfo.get_block_len());
-            self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo.clone()));
+            self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo));
             self.chmap = NAChannelMap::from_str(if channels == 1 { "C" } else { "L,R" }).unwrap();
             Ok(())
         } else {
             Err(DecoderError::InvalidData)
         }
     }
+    #[allow(clippy::identity_op)]
+    #[allow(clippy::cyclomatic_complexity)]
     fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
         let info = pkt.get_stream().get_info();
         if let NACodecTypeInfo::Audio(_) = info.get_properties() {
index 19019d450d0c61cb3596a578e83abdbd50908464..fafd6f0da5d00e698eb415518ec353285385e9bd 100644 (file)
@@ -116,6 +116,7 @@ struct BMV3Demuxer<'a> {
 
 impl<'a> DemuxCore<'a> for BMV3Demuxer<'a> {
     #[allow(unused_variables)]
+    #[allow(clippy::cast_lossless)]
     fn open(&mut self, strmgr: &mut StreamManager, _seek_index: &mut SeekIndex) -> DemuxerResult<()> {
         let src = &mut self.src;
 
index c6da8f46d6810a0603d9543193f158652daaacc8..3c6e1526cc365bdac8d19ca27969be44149b0d1e 100644 (file)
@@ -160,7 +160,7 @@ impl<'a> DemuxCore<'a> for VMDDemuxer<'a> {
 
         let is_video = cur_frame.chtype == CHTYPE_VIDEO;
         let mut buf: Vec<u8> = Vec::with_capacity(FRAME_HDR_SIZE + (cur_frame.size as usize));
-        if !(is_video && self.is_indeo) && !(!is_video && self.is_lhaud) {
+        if !((is_video && self.is_indeo) || (!is_video && self.is_lhaud)) {
             buf.extend_from_slice(&cur_frame.hdr);
             buf.resize(FRAME_HDR_SIZE + (cur_frame.size as usize), 0);
             self.src.read_buf(&mut buf[FRAME_HDR_SIZE..])?;
index f2a94f98f19e178ccfd548e8669a90281f6d6129..f619cb919087039176ebcf1d1b61d05faec8698f 100644 (file)
@@ -1,7 +1,15 @@
 extern crate nihav_core;
 extern crate nihav_codec_support;
 
+#[allow(clippy::collapsible_if)]
+#[allow(clippy::excessive_precision)]
+#[allow(clippy::needless_range_loop)]
+#[allow(clippy::unreadable_literal)]
+#[allow(clippy::useless_let_if_seq)]
 mod codecs;
 pub use crate::codecs::game_register_all_codecs;
+#[allow(clippy::collapsible_if)]
+#[allow(clippy::needless_range_loop)]
+#[allow(clippy::unreadable_literal)]
 mod demuxers;
-pub use crate::demuxers::game_register_all_demuxers;
\ No newline at end of file
+pub use crate::demuxers::game_register_all_demuxers;