duck: fix or silence clippy warnings
authorKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 16 Jun 2020 10:11:32 +0000 (12:11 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 16 Jun 2020 10:11:32 +0000 (12:11 +0200)
13 files changed:
nihav-duck/src/codecs/mod.rs
nihav-duck/src/codecs/on2avc.rs
nihav-duck/src/codecs/truemotion2.rs
nihav-duck/src/codecs/truemotion2x.rs
nihav-duck/src/codecs/truemotionrt.rs
nihav-duck/src/codecs/vp3.rs
nihav-duck/src/codecs/vp5.rs
nihav-duck/src/codecs/vp56.rs
nihav-duck/src/codecs/vp6.rs
nihav-duck/src/codecs/vp7.rs
nihav-duck/src/codecs/vp7dsp.rs
nihav-duck/src/codecs/vpcommon.rs
nihav-duck/src/lib.rs

index a094f2d345404a7baa92d04ffe22e349df930e12..c5412e9683912587b95d88a362261af9360e53d9 100644 (file)
@@ -9,30 +9,51 @@ mod truemotion1;
 #[cfg(feature="decoder_truemotionrt")]
 mod truemotionrt;
 #[cfg(feature="decoder_truemotion2")]
+#[allow(clippy::needless_range_loop)]
 mod truemotion2;
 #[cfg(feature="decoder_truemotion2x")]
 mod truemotion2x;
 #[cfg(any(feature="decoder_vp3", feature="decoder_vp4", feature="decoder_vp5", feature="decoder_vp6", feature="decoder_vp7"))]
 #[macro_use]
+#[allow(clippy::erasing_op)]
+#[allow(clippy::needless_range_loop)]
+#[allow(clippy::too_many_arguments)]
+#[allow(clippy::useless_let_if_seq)]
 mod vpcommon;
 #[cfg(any(feature="decoder_vp3", feature="decoder_vp4"))]
+#[allow(clippy::needless_range_loop)]
+#[allow(clippy::too_many_arguments)]
 mod vp3;
 #[cfg(any(feature="decoder_vp5", feature="decoder_vp6"))]
+#[allow(clippy::needless_range_loop)]
+#[allow(clippy::useless_let_if_seq)]
+#[allow(clippy::too_many_arguments)]
 mod vp56;
 #[cfg(feature="decoder_vp5")]
+#[allow(clippy::needless_range_loop)]
 mod vp5;
 #[cfg(feature="decoder_vp6")]
+#[allow(clippy::needless_range_loop)]
 mod vp6;
 #[cfg(feature="decoder_vp7")]
+#[allow(clippy::needless_range_loop)]
+#[allow(clippy::useless_let_if_seq)]
 mod vp7;
 #[cfg(feature="decoder_vp7")]
 mod vp7data;
 #[cfg(feature="decoder_vp7")]
+#[allow(clippy::erasing_op)]
+#[allow(clippy::needless_range_loop)]
+#[allow(clippy::too_many_arguments)]
+#[allow(clippy::useless_let_if_seq)]
 mod vp7dsp;
 
 #[cfg(any(feature="decoder_dk3_adpcm", feature="decoder_dk4_adpcm"))]
 mod dkadpcm;
 #[cfg(feature="decoder_on2avc")]
+#[allow(clippy::manual_memcpy)]
+#[allow(clippy::needless_range_loop)]
+#[allow(clippy::too_many_arguments)]
 mod on2avc;
 #[cfg(feature="decoder_on2avc")]
 mod on2avcdata;
index 2cd7a8802a190ac7b9a7fe4c65eb7913898767d9..d65dbd668f2de6c563575c9b691a9a90660882b2 100644 (file)
@@ -220,7 +220,7 @@ impl AVCDecoder {
                             scale               = br.read(7)? as i16;
                             first = false
                         } else {
-                            scale               += br.read_cb(&self.codebooks.scale_cb)? as i16;
+                            scale               += i16::from(br.read_cb(&self.codebooks.scale_cb)?);
                             validate!((scale >= 0) && (scale < 128));
                         }
                         self.scales[cur_band] = scale as u8;
@@ -331,6 +331,7 @@ impl AVCDecoder {
         }
         Ok(())
     }
+    #[allow(clippy::cyclomatic_complexity)]
     fn synth_channel(&mut self, chno: usize, dst: &mut [f32]) {
         let coeffs = &mut self.coeffs[chno];
         let delay  = &mut self.delay[chno];
@@ -490,12 +491,12 @@ macro_rules! synth_step0_template {
         fn $name(src: &[f32], dst: &mut [f32], step: usize, off: usize, sp: &SynthParams) {
             for i in 0..step {
                 for j in 0..sp.p0 {
-                    dst[i] += ((src[j] as f64) * $tab[sp.idx][j][i]) as f32;
+                    dst[i] += (f64::from(src[j]) * $tab[sp.idx][j][i]) as f32;
                 }
             }
             for i in 0..step {
                 for j in 0..sp.p1 {
-                    dst[$size - step + i] += ((src[sp.p0 + off + j] as f64) * $tab[sp.idx][sp.p0 + j][i]) as f32;
+                    dst[$size - step + i] += (f64::from(src[sp.p0 + off + j]) * $tab[sp.idx][sp.p0 + j][i]) as f32;
                 }
             }
         }
@@ -511,7 +512,7 @@ fn synth_step1(src: &[f32], dst: &mut [f32], size: usize, stride: usize, step: u
 {
     let mut pos = step - 1;
     for _ in 0..off {
-        let scale = src[p0] as f64;
+        let scale = f64::from(src[p0]);
         p0 += 1;
         pos &= size - 1;
         for i in 0..pos.min(step) {
@@ -683,7 +684,7 @@ fn synth_generic(src: &[f32], dst: &mut [f32], tmpbuf: &mut [f32; COEFFS * 2], i
     (&mut dst[..size]).copy_from_slice(&src[..size]);
     let mut order_idx = 0;
     synth_recursive(dst, tmpbuf, size, order, &mut order_idx, false);
-    for i in 0..COEFFS { dst[i] *= 0.125; }
+    for el in dst.iter_mut().take(COEFFS) { *el *= 0.125; }
 }
 
 fn synth1024(dsp: &mut SynthDSP, src: &[f32], dst: &mut [f32], tmpbuf: &mut [f32; COEFFS * 2], is_40khz: bool) {
index d0ef79361d7326d04e37fdf12f109cec846628d5..09c9844ce45257151be5aae2cec27db9910b707c 100644 (file)
@@ -336,6 +336,7 @@ struct TM2Decoder {
 
 impl TM2Decoder {
     fn new() -> Self { Self::default() }
+    #[allow(clippy::manual_memcpy)]
     fn decode_blocks(&mut self) -> DecoderResult<bool> {
         let ydst = &mut self.cur_frame.ydata;
         let udst = &mut self.cur_frame.udata;
@@ -434,7 +435,7 @@ impl TM2Decoder {
                         for _ in 0..4 {
                             for x in 0..4 {
                                 let dy = self.streams[TM2StreamType::Update as usize].get_token()?;
-                                ydst[yoff + x] = ((ysrc[yoff + x] as i32) + dy) as u8;
+                                ydst[yoff + x] = (i32::from(ysrc[yoff + x]) + dy) as u8;
                             }
                             yoff += ystride;
                         }
index e2325ab1880d4e3815033e3ab817da89354c01a3..76ca244352d82cf0f538661aedcced6623526ba1 100644 (file)
@@ -275,6 +275,9 @@ impl TM2XDecoder {
         Ok(())
     }
 
+    #[allow(clippy::int_plus_one)]
+    #[allow(clippy::manual_memcpy)]
+    #[allow(clippy::cyclomatic_complexity)]
     fn decode_frame(&mut self, src: &[u8]) -> DecoderResult<()> {
         let mut mr = MemoryReader::new_read(src);
         let mut br = ByteReader::new(&mut mr);
index 554715fbd6529bf76836652919e44a5c6533128e..98d885825ed367b60394d6ad73a87a9996f1da17 100644 (file)
@@ -14,6 +14,7 @@ const TMRT_DELTA_TAB: [&[i16]; 3] = [
 
 impl TMRTDecoder {
     fn new() -> Self { Self::default() }
+    #[allow(clippy::too_many_arguments)]
     fn decode_plane(&self, br: &mut BitReader, dst: &mut [u8], mut off: usize, stride: usize, w: usize, h: usize, hscale: bool, dbits: u8, is_chroma: bool) -> DecoderResult<()> {
         let delta_tab = TMRT_DELTA_TAB[(dbits - 2) as usize];
         let step = if !hscale { 1 } else { 2 };
index e456cfa9fb55f656c4504a11f17633ad5230475d..c6dc62d2670d4193af7e6db2ba0e0e43ffda1793 100644 (file)
@@ -168,6 +168,7 @@ impl VP40AuxCodes {
     }
 }
 
+#[allow(clippy::large_enum_variant)]
 enum Codes {
     None,
     VP30(VP30Codes),
@@ -290,7 +291,7 @@ fn vp30_read_coded_run1(br: &mut BitReader) -> DecoderResult<usize> {
     let idx                                     = br.peek(5) as usize;
     let sym = (VP30_CRUN1_LUT[idx] >> 4) as usize;
     let bits = VP30_CRUN1_LUT[idx] & 0xF;
-                                                br.skip(bits as u32)?;
+                                                br.skip(u32::from(bits))?;
     if sym < 7 {
         Ok(sym)
     } else if sym == 7 {
@@ -546,7 +547,7 @@ fn expand_token(blk: &mut Block, br: &mut BitReader, eob_run: &mut usize, token:
 macro_rules! fill_dc_pred {
     ($self: expr, $ref_id: expr, $pred: expr, $pp: expr, $bit: expr, $idx: expr) => {
         if $self.blocks[$idx].coded && $self.blocks[$idx].btype.get_ref_id() == $ref_id {
-            $pred[$bit] = $self.blocks[$idx].coeffs[0] as i32;
+            $pred[$bit] = i32::from($self.blocks[$idx].coeffs[0]);
             $pp |= 1 << $bit;
         }
     };
@@ -1133,11 +1134,11 @@ impl VP34Decoder {
                     let saddr = (self.blk_addr[cur_blk] >> 2).min(self.blk_addr[cur_blk + 1] >> 2).min(self.blk_addr[cur_blk + 2] >> 2).min(self.blk_addr[cur_blk + 3] >> 2);
                     for i in 0..4 {
                         let blk = &mut self.blocks[saddr + (i & 1) + (i >> 1) * self.mb_w * 2];
-                        blk.mv.x = br.read_cb(x_cb)? as i16;
+                        blk.mv.x = i16::from(br.read_cb(x_cb)?);
                         if x_sign {
                             blk.mv.x = -blk.mv.x;
                         }
-                        blk.mv.y = br.read_cb(y_cb)? as i16;
+                        blk.mv.y = i16::from(br.read_cb(y_cb)?);
                         if y_sign {
                             blk.mv.y = -blk.mv.y;
                         }
@@ -1155,8 +1156,8 @@ impl VP34Decoder {
                             let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.abs() as usize]];
                             let x_sign = last_mv.x < 0;
                             let y_sign = last_mv.y < 0;
-                            let x               = br.read_cb(x_cb)? as i16;
-                            let y               = br.read_cb(y_cb)? as i16;
+                            let x               = i16::from(br.read_cb(x_cb)?);
+                            let y               = i16::from(br.read_cb(y_cb)?);
                             cur_mv = MV { x: if !x_sign { x } else { -x }, y: if !y_sign { y } else { -y } };
                             last2_mv = last_mv;
                             last_mv = cur_mv;
@@ -1173,8 +1174,8 @@ impl VP34Decoder {
                             let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv_g.y.abs() as usize]];
                             let x_sign = last_mv_g.x < 0;
                             let y_sign = last_mv_g.y < 0;
-                            let x               = br.read_cb(x_cb)? as i16;
-                            let y               = br.read_cb(y_cb)? as i16;
+                            let x               = i16::from(br.read_cb(x_cb)?);
+                            let y               = i16::from(br.read_cb(y_cb)?);
                             cur_mv = MV { x: if !x_sign { x } else { -x }, y: if !y_sign { y } else { -y } };
                             last_mv_g = cur_mv;
                         },
@@ -1450,10 +1451,10 @@ impl VP34Decoder {
         let mut pred = 0i32;
         for i in 0..4 {
             if (pp & (1 << i)) != 0 {
-                pred += (preds[i] as i32) * (VP31_DC_WEIGHTS[pp][i] as i32);
+                pred += (preds[i] as i32) * i32::from(VP31_DC_WEIGHTS[pp][i]);
             }
         }
-        pred /= VP31_DC_WEIGHTS[pp][4] as i32;
+        pred /= i32::from(VP31_DC_WEIGHTS[pp][4]);
         if (pp & 7) == 7 {
             if (pred - preds[2]).abs() > 128 { return preds[2] as i16; }
             if (pred - preds[0]).abs() > 128 { return preds[0] as i16; }
@@ -1552,6 +1553,7 @@ impl VP34Decoder {
             }
         }
     }
+    #[allow(clippy::cyclomatic_complexity)]
     fn output_blocks_inter(&mut self, frm: &mut NASimpleVideoFrame<u8>) {
         let mut blk_idx = 0;
         let bstride = self.mb_w * 2;
index 179227adb4d64464176e537e106ac9f52bd01c6a..36579a5bf1a88c62048cb98ad75a718ad974802c 100644 (file)
@@ -255,7 +255,7 @@ impl NADecoder for VP5Decoder {
     fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
         if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
             let myvinfo = NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, YUV420_FORMAT);
-            let myinfo = NACodecTypeInfo::Video(myvinfo.clone());
+            let myinfo = NACodecTypeInfo::Video(myvinfo);
             self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
             self.dec.init(supp, myvinfo)?;
             Ok(())
index 6f9f18c15b5538e7aec45f18b65720591904ed47..b8cad1722aea16590e2f51791568df1d9689d27a 100644 (file)
@@ -70,7 +70,7 @@ struct Node {
 }
 
 fn prob2weight(a: u8, b: u8) -> u8 {
-    let w = (((a as u16) * (b as u16)) >> 8) as u8;
+    let w = ((u16::from(a) * u16::from(b)) >> 8) as u8;
     if w == 0 {
         1
     } else {
@@ -132,7 +132,7 @@ impl VP6Huff {
         let mut nlen = 0;
 
         for w in weights.iter().rev() {
-            let weight = *w as u16;
+            let weight = u16::from(*w);
             let mut pos = nlen;
             for i in 0..nlen {
                 if nodes[i].weight > weight {
@@ -192,8 +192,8 @@ impl<'a> ReadHuff for BitReader<'a> {
     fn read_huff(&mut self, huff: &VP6Huff) -> DecoderResult<u8> {
         let peekval                             = self.peek(16);
         for (i, (code, bit)) in huff.codes.iter().zip(huff.bits.iter()).enumerate() {
-            if (peekval >> (16 - *bit)) == (*code as u32) {
-                self.skip(*bit as u32)?;
+            if (peekval >> (16 - *bit)) == u32::from(*code) {
+                self.skip(u32::from(*bit))?;
                 return Ok(i as u8);
             }
         }
@@ -394,7 +394,7 @@ pub fn expand_token_bc(bc: &mut BoolCoder, val_probs: &[u8; 11], token: u8, vers
         if token != 0 {
             sign                                = bc.read_bool();
         }
-        level = token as i16;
+        level = i16::from(token);
     } else {
         let cat: usize = vp_tree!(bc, val_probs[6],
                                   vp_tree!(bc, val_probs[7], 0, 1),
@@ -563,7 +563,7 @@ impl VP56Decoder {
         self.fstate = FrameState::new();
         self.fstate.dc_quant = VP56_DC_QUANTS[hdr.quant as usize] * 4;
         self.fstate.ac_quant = VP56_AC_QUANTS[hdr.quant as usize] * 4;
-        self.loop_thr = VP56_FILTER_LIMITS[hdr.quant as usize] as i16;
+        self.loop_thr = i16::from(VP56_FILTER_LIMITS[hdr.quant as usize]);
 
         self.last_mbt = VPMBType::InterNoMV;
         for vec in self.top_ctx.iter_mut() {
@@ -656,11 +656,11 @@ impl VP56Decoder {
                 let mut total = 0;
                 for i in 0..10 {
                     if i == mode { continue; }
-                    cnt[i] = 100 * (prob_xmitted[i * 2] as u32);
+                    cnt[i] = 100 * u32::from(prob_xmitted[i * 2]);
                     total += cnt[i];
                 }
-                let sum = (prob_xmitted[mode * 2] as u32) + (prob_xmitted[mode * 2 + 1] as u32);
-                mdl.probs[9] = 255 - rescale_mb_mode_prob(prob_xmitted[mode * 2 + 1] as u32, sum);
+                let sum = u32::from(prob_xmitted[mode * 2]) + u32::from(prob_xmitted[mode * 2 + 1]);
+                mdl.probs[9] = 255 - rescale_mb_mode_prob(u32::from(prob_xmitted[mode * 2 + 1]), sum);
 
                 let inter_mv0_weight = (cnt[0] as u32) + (cnt[2] as u32);
                 let inter_mv1_weight = (cnt[3] as u32) + (cnt[4] as u32);
@@ -751,6 +751,7 @@ impl VP56Decoder {
         }
         Ok(self.last_mbt)
     }
+    #[allow(clippy::cyclomatic_complexity)]
     fn decode_mb(&mut self, frm: &mut NASimpleVideoFrame<u8>, bc: &mut BoolCoder, cr: &mut CoeffReader, br: &mut dyn VP56Parser, hdr: &VP56Header, alpha: bool) -> DecoderResult<()> {
         const FOURMV_SUB_TYPE: [VPMBType; 4] = [ VPMBType::InterNoMV, VPMBType::InterMV, VPMBType::InterNearest, VPMBType::InterNear ];
 
@@ -766,7 +767,7 @@ impl VP56Decoder {
             let prob = if mb_x == 0 {
                     iprob
                 } else if !self.ilace_mb {
-                    iprob + (((256 - (iprob as u16)) >> 1) as u8)
+                    iprob + (((256 - u16::from(iprob)) >> 1) as u8)
                 } else {
                     iprob - (iprob >> 1)
                 };
index 4f014faf13cbad7f53498cb527ddb9a9ac6edff3..ddc8e633c0595d23063528e02e62882e34f0840c 100644 (file)
@@ -395,7 +395,7 @@ impl VP56Parser for VP6BR {
         if copy_mode {
             let src = &tmp_blk[2 * 16 + 2..];
             for (dline, sline) in dbuf.chunks_mut(dst.stride[plane]).zip(src.chunks(16)).take(8) {
-                for i in 0..8 { dline[i] = sline[i]; }
+                dline[..8].copy_from_slice(&sline[..8]);
             }
         } else if bicubic {
             let coeff_h = &VP6_BICUBIC_COEFFS[self.filter_alpha][mx as usize];
@@ -499,9 +499,9 @@ fn decode_token_huff(br: &mut BitReader, huff: &VP6Huff) -> DecoderResult<(i16,
         0   => Ok((0, false)),
         1 | 2 | 3 | 4 => {
             if !br.read_bool()? {
-                Ok((tok as i16, false))
+                Ok((i16::from(tok), false))
             } else {
-                Ok((-(tok as i16), false))
+                Ok((-i16::from(tok), false))
             }
         },
         5 | 6 | 7 | 8 | 9 | 10 => {
@@ -546,7 +546,7 @@ fn decode_zero_run_huff(br: &mut BitReader, huff: &VP6Huff) -> DecoderResult<usi
     }
 }
 
-
+#[allow(clippy::too_many_arguments)]
 fn get_block(dst: &mut [u8], dstride: usize, src: NAVideoBufferRef<u8>, comp: usize,
              dx: usize, dy: usize, mv_x: i16, mv_y: i16)
 {
@@ -566,9 +566,7 @@ fn get_block(dst: &mut [u8], dstride: usize, src: NAVideoBufferRef<u8>, comp: us
         let saddr = soff + ((sx - 2) as usize) + ((sy - 2) as usize) * sstride;
         let src = &sbuf[saddr..];
         for (dline, sline) in dst.chunks_mut(dstride).zip(src.chunks(sstride)).take(12) {
-            for i in 0..12 {
-                dline[i] = sline[i];
-            }
+            dline[..12].copy_from_slice(&sline[..12]);
         }
     }
 }
@@ -578,7 +576,7 @@ fn calc_variance(src: &[u8], stride: usize) -> u16 {
     let mut ssum = 0;
     for line in src.chunks(stride * 2).take(4) {
         for el in line.iter().take(8).step_by(2) {
-            let pix = *el as u32;
+            let pix = u32::from(*el);
             sum += pix;
             ssum += pix * pix;
         }
@@ -588,13 +586,13 @@ fn calc_variance(src: &[u8], stride: usize) -> u16 {
 
 macro_rules! mc_filter {
     (bilinear; $a: expr, $b: expr, $c: expr) => {
-        ((($a as u16) * (8 - $c) + ($b as u16) * $c + 4) >> 3) as u8
+        ((u16::from($a) * (8 - $c) + u16::from($b) * $c + 4) >> 3) as u8
     };
     (bicubic; $src: expr, $off: expr, $step: expr, $coeffs: expr) => {
-        ((($src[$off - $step]     as i32) * ($coeffs[0] as i32) +
-          ($src[$off]             as i32) * ($coeffs[1] as i32) +
-          ($src[$off + $step]     as i32) * ($coeffs[2] as i32) +
-          ($src[$off + $step * 2] as i32) * ($coeffs[3] as i32) + 64) >> 7).min(255).max(0) as u8
+        ((i32::from($src[$off - $step]    ) * i32::from($coeffs[0]) +
+          i32::from($src[$off]            ) * i32::from($coeffs[1]) +
+          i32::from($src[$off + $step]    ) * i32::from($coeffs[2]) +
+          i32::from($src[$off + $step * 2]) * i32::from($coeffs[3]) + 64) >> 7).min(255).max(0) as u8
     }
 }
 
@@ -631,6 +629,7 @@ fn mc_bilinear(dst: &mut [u8], dstride: usize, src: &[u8], mut soff: usize, sstr
     }
 }
 
+#[allow(clippy::trivially_copy_pass_by_ref)]
 fn mc_bicubic(dst: &mut [u8], dstride: usize, src: &[u8], mut soff: usize, sstride: usize, coeffs_w: &[i16; 4], coeffs_h: &[i16; 4]) {
     if coeffs_h[1] == 128 {
         for dline in dst.chunks_mut(dstride).take(8) {
@@ -692,7 +691,7 @@ impl NADecoder for VP6Decoder {
                     VP_YUVA420_FORMAT
                 };
             let myvinfo = NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt);
-            let myinfo = NACodecTypeInfo::Video(myvinfo.clone());
+            let myinfo = NACodecTypeInfo::Video(myvinfo);
             self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
             self.dec.init(supp, myvinfo)?;
             Ok(())
index 4d300cc6d1e2fbe5468abeccc8d3aef23ba2db8d..d40a81d0726b1b3e546c715a10f28c5c9083c05e 100644 (file)
@@ -143,7 +143,7 @@ struct SBParams<'a> {
     qmat:       &'a [i16; 16],
 }
 
-fn decode_subblock<'a>(bc: &mut BoolCoder, coeffs: &mut [i16; 16], ctype: usize, pctx: u8, sbparams: &SBParams) -> u8 {
+fn decode_subblock(bc: &mut BoolCoder, coeffs: &mut [i16; 16], ctype: usize, pctx: u8, sbparams: &SBParams) -> u8 {
     const COEF_BANDS: [usize; 16] = [ 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7 ];
 
     let mut has_nz = 0;
@@ -1071,17 +1071,17 @@ impl VP7Decoder {
             2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
           ]];
 
-        let edge_thr    = (loop_str as i16) + 2;
-        let luma_thr    = loop_str as i16;
-        let chroma_thr  = (loop_str as i16) * 2;
+        let edge_thr    = i16::from(loop_str) + 2;
+        let luma_thr    = i16::from(loop_str);
+        let chroma_thr  = i16::from(loop_str) * 2;
         let inner_thr   = if self.dstate.loop_sharpness == 0 {
-                loop_str as i16
+                i16::from(loop_str)
             } else {
-                let bound1 = (9 - self.dstate.loop_sharpness) as i16;
+                let bound1 = i16::from(9 - self.dstate.loop_sharpness);
                 let shift = (self.dstate.loop_sharpness + 3) >> 2;
-                ((loop_str as i16) >> shift).min(bound1)
+                (i16::from(loop_str) >> shift).min(bound1)
             };
-        let hev_thr     = HIGH_EDGE_VAR_THR[if self.dstate.is_intra { 1 } else { 0 }][loop_str as usize] as i16;
+        let hev_thr     = i16::from(HIGH_EDGE_VAR_THR[if self.dstate.is_intra { 1 } else { 0 }][loop_str as usize]);
 
         let ystride = dframe.stride[0];
         let ustride = dframe.stride[1];
@@ -1126,7 +1126,7 @@ impl NADecoder for VP7Decoder {
         if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
             let fmt = YUV420_FORMAT;
             let myvinfo = NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt);
-            let myinfo = NACodecTypeInfo::Video(myvinfo.clone());
+            let myinfo = NACodecTypeInfo::Video(myvinfo);
             self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
 
             supp.pool_u8.set_dec_bufs(4);
@@ -1137,6 +1137,7 @@ impl NADecoder for VP7Decoder {
             Err(DecoderError::InvalidData)
         }
     }
+    #[allow(clippy::cyclomatic_complexity)]
     fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
         let src = pkt.get_buffer();
 
index bf21d62e9957bd806facf27d5501214deb7eef5b..27d6fb4ff56a6abb305b7d17d9e08966024772ae 100644 (file)
@@ -65,10 +65,10 @@ const DCT_COEFFS: [i32; 16] = [
 pub fn idct4x4(coeffs: &mut [i16; 16]) {
     let mut tmp = [0i16; 16];
     for (src, dst) in coeffs.chunks(4).zip(tmp.chunks_mut(4)) {
-        let s0 = src[0] as i32;
-        let s1 = src[1] as i32;
-        let s2 = src[2] as i32;
-        let s3 = src[3] as i32;
+        let s0 = i32::from(src[0]);
+        let s1 = i32::from(src[1]);
+        let s2 = i32::from(src[2]);
+        let s3 = i32::from(src[3]);
 
         let t0 = (s0 + s2).wrapping_mul(23170);
         let t1 = (s0 - s2).wrapping_mul(23170);
@@ -81,10 +81,10 @@ pub fn idct4x4(coeffs: &mut [i16; 16]) {
         dst[3] = ((t0 - t2) >> 14) as i16;
     }
     for i in 0..4 {
-        let s0 = tmp[i + 4 * 0] as i32;
-        let s1 = tmp[i + 4 * 1] as i32;
-        let s2 = tmp[i + 4 * 2] as i32;
-        let s3 = tmp[i + 4 * 3] as i32;
+        let s0 = i32::from(tmp[i + 4 * 0]);
+        let s1 = i32::from(tmp[i + 4 * 1]);
+        let s2 = i32::from(tmp[i + 4 * 2]);
+        let s3 = i32::from(tmp[i + 4 * 3]);
 
         let t0 = (s0 + s2).wrapping_mul(23170) + 0x20000;
         let t1 = (s0 - s2).wrapping_mul(23170) + 0x20000;
@@ -99,7 +99,7 @@ pub fn idct4x4(coeffs: &mut [i16; 16]) {
 }
 
 pub fn idct4x4_dc(coeffs: &mut [i16; 16]) {
-    let dc = (((((coeffs[0] as i32) * DCT_COEFFS[0]) >> 14) * DCT_COEFFS[0] + 0x20000) >> 18) as i16;
+    let dc = ((((i32::from(coeffs[0]) * DCT_COEFFS[0]) >> 14) * DCT_COEFFS[0] + 0x20000) >> 18) as i16;
     for el in coeffs.iter_mut() {
         *el = dc;
     }
@@ -109,14 +109,14 @@ pub fn add_coeffs4x4(dst: &mut [u8], off: usize, stride: usize, coeffs: &[i16; 1
     let dst = &mut dst[off..];
     for (out, src) in dst.chunks_mut(stride).zip(coeffs.chunks(4)) {
         for (oel, iel) in out.iter_mut().take(4).zip(src.iter()) {
-            *oel = clip_u8((*oel as i16) + *iel);
+            *oel = clip_u8(i16::from(*oel) + *iel);
         }
     }
 }
 pub fn add_coeffs16x1(dst: &mut [u8], off: usize, coeffs: &[i16; 16]) {
     let dst = &mut dst[off..];
     for (oel, iel) in dst.iter_mut().take(16).zip(coeffs.iter()) {
-        *oel = clip_u8((*oel as i16) + *iel);
+        *oel = clip_u8(i16::from(*oel) + *iel);
     }
 }
 
@@ -134,13 +134,13 @@ pub trait IntraPred {
                 };
             if ipred.has_left {
                 for el in ipred.left.iter().take(Self::SIZE) {
-                    dcsum += *el as u16;
+                    dcsum += u16::from(*el);
                 }
                 dcshift += 1;
             }
             if ipred.has_top {
                 for el in ipred.top.iter().take(Self::SIZE) {
-                    dcsum += *el as u16;
+                    dcsum += u16::from(*el);
                 }
                 dcshift += 1;
             }
@@ -171,10 +171,10 @@ pub trait IntraPred {
         }
     }
     fn ipred_tm(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
-        let tl = ipred.tl as i16;
+        let tl = i16::from(ipred.tl);
         for m in 0..Self::SIZE {
             for n in 0..Self::SIZE {
-                dst[off + n] = clip_u8((ipred.left[m] as i16) + (ipred.top[n] as i16) - tl);
+                dst[off + n] = clip_u8(i16::from(ipred.left[m]) + i16::from(ipred.top[n]) - tl);
             }
             off += stride;
         }
@@ -189,18 +189,18 @@ impl IntraPred for IPred8x8 { const SIZE: usize = 8; }
 
 macro_rules! load_pred4 {
     (topleft; $ipred: expr) => {{
-        let tl = $ipred.tl as u16;
-        let a0 = $ipred.top[0] as u16;
-        let l0 = $ipred.left[0] as u16;
+        let tl = u16::from($ipred.tl);
+        let a0 = u16::from($ipred.top[0]);
+        let l0 = u16::from($ipred.left[0]);
         ((l0 + tl * 2 + a0 + 2) >> 2) as u8
     }};
     (top; $ipred: expr) => {{
-        let tl = $ipred.tl as u16;
-        let a0 = $ipred.top[0] as u16;
-        let a1 = $ipred.top[1] as u16;
-        let a2 = $ipred.top[2] as u16;
-        let a3 = $ipred.top[3] as u16;
-        let a4 = $ipred.top[4] as u16;
+        let tl = u16::from($ipred.tl);
+        let a0 = u16::from($ipred.top[0]);
+        let a1 = u16::from($ipred.top[1]);
+        let a2 = u16::from($ipred.top[2]);
+        let a3 = u16::from($ipred.top[3]);
+        let a4 = u16::from($ipred.top[4]);
         let p0 = ((tl + a0 * 2 + a1 + 2) >> 2) as u8;
         let p1 = ((a0 + a1 * 2 + a2 + 2) >> 2) as u8;
         let p2 = ((a1 + a2 * 2 + a3 + 2) >> 2) as u8;
@@ -208,11 +208,11 @@ macro_rules! load_pred4 {
         (p0, p1, p2, p3)
     }};
     (top8; $ipred: expr) => {{
-        let t3 = $ipred.top[3] as u16;
-        let t4 = $ipred.top[4] as u16;
-        let t5 = $ipred.top[5] as u16;
-        let t6 = $ipred.top[6] as u16;
-        let t7 = $ipred.top[7] as u16;
+        let t3 = u16::from($ipred.top[3]);
+        let t4 = u16::from($ipred.top[4]);
+        let t5 = u16::from($ipred.top[5]);
+        let t6 = u16::from($ipred.top[6]);
+        let t7 = u16::from($ipred.top[7]);
         let p4 = ((t3 + t4 * 2 + t5 + 2) >> 2) as u8;
         let p5 = ((t4 + t5 * 2 + t6 + 2) >> 2) as u8;
         let p6 = ((t5 + t6 * 2 + t7 + 2) >> 2) as u8;
@@ -220,11 +220,11 @@ macro_rules! load_pred4 {
         (p4, p5, p6, p7)
     }};
     (topavg; $ipred: expr) => {{
-        let tl = $ipred.tl as u16;
-        let a0 = $ipred.top[0] as u16;
-        let a1 = $ipred.top[1] as u16;
-        let a2 = $ipred.top[2] as u16;
-        let a3 = $ipred.top[3] as u16;
+        let tl = u16::from($ipred.tl);
+        let a0 = u16::from($ipred.top[0]);
+        let a1 = u16::from($ipred.top[1]);
+        let a2 = u16::from($ipred.top[2]);
+        let a3 = u16::from($ipred.top[3]);
         let p0 = ((tl + a0 + 1) >> 1) as u8;
         let p1 = ((a0 + a1 + 1) >> 1) as u8;
         let p2 = ((a1 + a2 + 1) >> 1) as u8;
@@ -232,12 +232,12 @@ macro_rules! load_pred4 {
         (p0, p1, p2, p3)
     }};
     (left; $ipred: expr) => {{
-        let tl = $ipred.tl as u16;
-        let l0 = $ipred.left[0] as u16;
-        let l1 = $ipred.left[1] as u16;
-        let l2 = $ipred.left[2] as u16;
-        let l3 = $ipred.left[3] as u16;
-        let l4 = $ipred.left[4] as u16;
+        let tl = u16::from($ipred.tl);
+        let l0 = u16::from($ipred.left[0]);
+        let l1 = u16::from($ipred.left[1]);
+        let l2 = u16::from($ipred.left[2]);
+        let l3 = u16::from($ipred.left[3]);
+        let l4 = u16::from($ipred.left[4]);
         let p0 = ((tl + l0 * 2 + l1 + 2) >> 2) as u8;
         let p1 = ((l0 + l1 * 2 + l2 + 2) >> 2) as u8;
         let p2 = ((l1 + l2 * 2 + l3 + 2) >> 2) as u8;
@@ -245,11 +245,11 @@ macro_rules! load_pred4 {
         (p0, p1, p2, p3)
     }};
     (left8; $ipred: expr) => {{
-        let l3 = $ipred.left[3] as u16;
-        let l4 = $ipred.left[4] as u16;
-        let l5 = $ipred.left[5] as u16;
-        let l6 = $ipred.left[6] as u16;
-        let l7 = $ipred.left[7] as u16;
+        let l3 = u16::from($ipred.left[3]);
+        let l4 = u16::from($ipred.left[4]);
+        let l5 = u16::from($ipred.left[5]);
+        let l6 = u16::from($ipred.left[6]);
+        let l7 = u16::from($ipred.left[7]);
         let p4 = ((l3 + l4 * 2 + l5 + 2) >> 2) as u8;
         let p5 = ((l4 + l5 * 2 + l6 + 2) >> 2) as u8;
         let p6 = ((l5 + l6 * 2 + l7 + 2) >> 2) as u8;
@@ -257,11 +257,11 @@ macro_rules! load_pred4 {
         (p4, p5, p6, p7)
     }};
     (leftavg; $ipred: expr) => {{
-        let tl = $ipred.tl as u16;
-        let l0 = $ipred.left[0] as u16;
-        let l1 = $ipred.left[1] as u16;
-        let l2 = $ipred.left[2] as u16;
-        let l3 = $ipred.left[3] as u16;
+        let tl = u16::from($ipred.tl);
+        let l0 = u16::from($ipred.left[0]);
+        let l1 = u16::from($ipred.left[1]);
+        let l2 = u16::from($ipred.left[2]);
+        let l3 = u16::from($ipred.left[3]);
         let p0 = ((tl + l0 + 1) >> 1) as u8;
         let p1 = ((l0 + l1 + 1) >> 1) as u8;
         let p2 = ((l1 + l2 + 1) >> 1) as u8;
@@ -276,10 +276,10 @@ impl IPred4x4 {
         let dc;
         let mut dcsum = 0;
         for el in ipred.left.iter().take(4) {
-            dcsum += *el as u16;
+            dcsum += u16::from(*el);
         }
         for el in ipred.top.iter().take(4) {
-            dcsum += *el as u16;
+            dcsum += u16::from(*el);
         }
         dc = ((dcsum + (1 << 2)) >> 3) as u8;
         for _ in 0..4 {
@@ -291,10 +291,10 @@ impl IPred4x4 {
         }
     }
     pub fn ipred_tm(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
-        let tl = ipred.tl as i16;
+        let tl = i16::from(ipred.tl);
         for m in 0..4 {
             for n in 0..4 {
-                dst[off + n] = clip_u8((ipred.left[m] as i16) + (ipred.top[n] as i16) - tl);
+                dst[off + n] = clip_u8(i16::from(ipred.left[m]) + i16::from(ipred.top[n]) - tl);
             }
             off += stride;
         }
@@ -310,7 +310,7 @@ impl IPred4x4 {
     }
     pub fn ipred_he(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
         let (p0, p1, p2, _) = load_pred4!(left; ipred);
-        let p3 = (((ipred.left[2] as u16) + (ipred.left[3] as u16) * 3 + 2) >> 2) as u8;
+        let p3 = ((u16::from(ipred.left[2]) + u16::from(ipred.left[3]) * 3 + 2) >> 2) as u8;
         let hor_pred = [p0, p1, p2, p3];
         for m in 0..4 {
             for n in 0..4 {
@@ -362,7 +362,7 @@ impl IPred4x4 {
         let (_,  t1, t2, t3) = load_pred4!(top;     ipred);
         let (t4, t5, t6, _)  = load_pred4!(top8;    ipred);
         let (_,  m1, m2, m3) = load_pred4!(topavg;  ipred);
-        let m4 = (((ipred.top[3] as u16) + (ipred.top[4] as u16) + 1) >> 1) as u8;
+        let m4 = ((u16::from(ipred.top[3]) + u16::from(ipred.top[4]) + 1) >> 1) as u8;
 
         dst[off + 0] = m1; dst[off + 1] = m2; dst[off + 2] = m3; dst[off + 3] = m4;
         off += stride;
@@ -389,7 +389,7 @@ impl IPred4x4 {
     pub fn ipred_hu(dst: &mut [u8], mut off: usize, stride: usize, ipred: &IPredContext) {
         let (_, m1, m2, m3) = load_pred4!(leftavg; ipred);
         let (_, l1, l2, _)  = load_pred4!(left;    ipred);
-        let l3 = (((ipred.left[2] as u16) + (ipred.left[3] as u16) * 3 + 2) >> 2) as u8;
+        let l3 = ((u16::from(ipred.left[2]) + u16::from(ipred.left[3]) * 3 + 2) >> 2) as u8;
         let p3 = ipred.left[3];
 
         dst[off + 0] = m1; dst[off + 1] = l1; dst[off + 2] = m2; dst[off + 3] = l2;
@@ -410,10 +410,10 @@ pub type LoopFilterFunc = fn(buf: &mut [u8], off: usize, step: usize, stride: us
 
 pub fn simple_loop_filter(buf: &mut [u8], mut off: usize, step: usize, stride: usize, len: usize, thr: i16, _thr_inner: i16, _thr_hev: i16) {
     for _ in 0..len {
-        let p1 = buf[off - step * 2] as i16;
-        let p0 = buf[off - step * 1] as i16;
-        let q0 = buf[off + step * 0] as i16;
-        let q1 = buf[off + step * 1] as i16;
+        let p1 = i16::from(buf[off - step * 2]);
+        let p0 = i16::from(buf[off - step * 1]);
+        let q0 = i16::from(buf[off + step * 0]);
+        let q1 = i16::from(buf[off + step * 1]);
         let dpq = p0 - q0;
         if dpq.abs() < thr {
             let diff = delta(p1, p0, q0, q1);
@@ -428,16 +428,16 @@ pub fn simple_loop_filter(buf: &mut [u8], mut off: usize, step: usize, stride: u
 
 fn normal_loop_filter(buf: &mut [u8], mut off: usize, step: usize, stride: usize, len: usize, thr: i16, thr_inner: i16, thr_hev: i16, edge: bool) {
     for _ in 0..len {
-        let p0 = buf[off - step * 1] as i16;
-        let q0 = buf[off + step * 0] as i16;
+        let p0 = i16::from(buf[off - step * 1]);
+        let q0 = i16::from(buf[off + step * 0]);
         let dpq = p0 - q0;
         if dpq.abs() <= thr {
-            let p3 = buf[off - step * 4] as i16;
-            let p2 = buf[off - step * 3] as i16;
-            let p1 = buf[off - step * 2] as i16;
-            let q1 = buf[off + step * 1] as i16;
-            let q2 = buf[off + step * 2] as i16;
-            let q3 = buf[off + step * 3] as i16;
+            let p3 = i16::from(buf[off - step * 4]);
+            let p2 = i16::from(buf[off - step * 3]);
+            let p1 = i16::from(buf[off - step * 2]);
+            let q1 = i16::from(buf[off + step * 1]);
+            let q2 = i16::from(buf[off + step * 2]);
+            let q3 = i16::from(buf[off + step * 3]);
             let dp2 = p3 - p2;
             let dp1 = p2 - p1;
             let dp0 = p1 - p0;
@@ -502,17 +502,17 @@ const VP7_BICUBIC_FILTERS: [[i16; 6]; 8] = [
 
 macro_rules! interpolate {
     ($src: expr, $off: expr, $step: expr, $mode: expr) => {{
-        let s0 = $src[$off + 0 * $step] as i32;
-        let s1 = $src[$off + 1 * $step] as i32;
-        let s2 = $src[$off + 2 * $step] as i32;
-        let s3 = $src[$off + 3 * $step] as i32;
-        let s4 = $src[$off + 4 * $step] as i32;
-        let s5 = $src[$off + 5 * $step] as i32;
+        let s0 = i32::from($src[$off + 0 * $step]);
+        let s1 = i32::from($src[$off + 1 * $step]);
+        let s2 = i32::from($src[$off + 2 * $step]);
+        let s3 = i32::from($src[$off + 3 * $step]);
+        let s4 = i32::from($src[$off + 4 * $step]);
+        let s5 = i32::from($src[$off + 5 * $step]);
         let filt = &VP7_BICUBIC_FILTERS[$mode];
         let src = [s0, s1, s2, s3, s4, s5];
         let mut val = 64;
         for (s, c) in src.iter().zip(filt.iter()) {
-            val += s * (*c as i32);
+            val += s * i32::from(*c);
         }
         clip_u8((val >> 7) as i16)
     }}
index e6446afc436830029323a1c05a1d4c000a0b4f98..8474dc6a211561ecf347535a80352bbd3e736bc9 100644 (file)
@@ -112,7 +112,7 @@ pub struct BoolCoder<'a> {
 impl<'a> BoolCoder<'a> {
     pub fn new(src: &'a [u8]) -> DecoderResult<Self> {
         if src.len() < 3 { return Err(DecoderError::ShortData); }
-        let value = ((src[0] as u32) << 24) | ((src[1] as u32) << 16) | ((src[2] as u32) << 8) | (src[3] as u32);
+        let value = (u32::from(src[0]) << 24) | (u32::from(src[1]) << 16) | (u32::from(src[2]) << 8) | u32::from(src[3]);
         Ok(Self { src, pos: 4, value, range: 255, bits: 8 })
     }
     pub fn read_bool(&mut self) -> bool {
@@ -120,7 +120,7 @@ impl<'a> BoolCoder<'a> {
     }
     pub fn read_prob(&mut self, prob: u8) -> bool {
         self.renorm();
-        let split = 1 + (((self.range - 1) * (prob as u32)) >> 8);
+        let split = 1 + (((self.range - 1) * u32::from(prob)) >> 8);
         let bit;
         if self.value < (split << 24) {
             self.range = split;
@@ -167,7 +167,7 @@ impl<'a> BoolCoder<'a> {
         self.value <<= shift;
         self.bits   -= shift as i32;
         if (self.bits <= 0) && (self.pos < self.src.len()) {
-            self.value |= (self.src[self.pos] as u32) << (-self.bits as u8);
+            self.value |= u32::from(self.src[self.pos]) << (-self.bits as u8);
             self.pos += 1;
             self.bits += 8;
         }
@@ -176,7 +176,7 @@ impl<'a> BoolCoder<'a> {
             self.value <<= 1;
             self.bits   -= 1;
             if (self.bits <= 0) && (self.pos < self.src.len()) {
-                self.value |= self.src[self.pos] as u32;
+                self.value |= u32::from(self.src[self.pos]);
                 self.pos += 1;
                 self.bits = 8;
             }
@@ -186,7 +186,7 @@ impl<'a> BoolCoder<'a> {
         for _ in 0..nbytes {
             self.value <<= 8;
             if self.pos < self.src.len() {
-                self.value |= self.src[self.pos] as u32;
+                self.value |= u32::from(self.src[self.pos]);
                 self.pos += 1;
             }
         }
@@ -194,8 +194,9 @@ impl<'a> BoolCoder<'a> {
 }
 
 #[allow(dead_code)]
+#[allow(clippy::trivially_copy_pass_by_ref)]
 pub fn rescale_prob(prob: u8, weights: &[i16; 2], maxval: i32) -> u8 {
-    ((((prob as i32) * (weights[0] as i32) + 128) >> 8) + (weights[1] as i32)).min(maxval).max(1) as u8
+    (((i32::from(prob) * i32::from(weights[0]) + 128) >> 8) + i32::from(weights[1])).min(maxval).max(1) as u8
 }
 
 macro_rules! vp_tree {
@@ -323,7 +324,7 @@ pub fn vp_add_block(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: usize,
     let mut off = frm.offset[plane] + bx * 8 + by * 8 * frm.stride[plane];
     for y in 0..8 {
         for x in 0..8 {
-            frm.data[off + x] = (coeffs[x + y * 8] + (frm.data[off + x] as i16)).min(255).max(0) as u8;
+            frm.data[off + x] = (coeffs[x + y * 8] + i16::from(frm.data[off + x])).min(255).max(0) as u8;
         }
         off += frm.stride[plane];
     }
@@ -334,7 +335,7 @@ pub fn vp_add_block_ilace(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: u
     let mut off = frm.offset[plane] + bx * 8 + ((by & !1) * 8 + (by & 1)) * frm.stride[plane];
     for y in 0..8 {
         for x in 0..8 {
-            frm.data[off + x] = (coeffs[x + y * 8] + (frm.data[off + x] as i16)).min(255).max(0) as u8;
+            frm.data[off + x] = (coeffs[x + y * 8] + i16::from(frm.data[off + x])).min(255).max(0) as u8;
         }
         off += frm.stride[plane] * 2;
     }
@@ -346,7 +347,7 @@ pub fn vp_add_block_dc(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: usiz
     let mut off = frm.offset[plane] + bx * 8 + by * 8 * frm.stride[plane];
     for _ in 0..8 {
         for x in 0..8 {
-            frm.data[off + x] = (dc + (frm.data[off + x] as i16)).min(255).max(0) as u8;
+            frm.data[off + x] = (dc + i16::from(frm.data[off + x])).min(255).max(0) as u8;
         }
         off += frm.stride[plane];
     }
@@ -355,10 +356,10 @@ pub fn vp_add_block_dc(coeffs: &mut [i16; 64], bx: usize, by: usize, plane: usiz
 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 a = i16::from(data[off - step * 2]);
+        let b = i16::from(data[off - step]);
+        let c = i16::from(data[off]);
+        let d = i16::from(data[off + step]);
         let mut diff = ((a - d) + 3 * (c - b) + 4) >> 3;
         if diff.abs() >= 2 * loop_str {
             diff = 0;
@@ -420,7 +421,7 @@ fn vp3_interp00(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw:
     let mut didx = 0;
     let mut sidx = 0;
     for _ in 0..bh {
-        for x in 0..bw { dst[didx + x] = src[sidx + x]; }
+        dst[didx..][..bw].copy_from_slice(&src[sidx..][..bw]);
         didx += dstride;
         sidx += sstride;
     }
@@ -431,7 +432,7 @@ fn vp3_interp01(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw:
     let mut didx = 0;
     let mut sidx = 0;
     for _ in 0..bh {
-        for x in 0..bw { dst[didx + x] = (((src[sidx + x] as u16) + (src[sidx + x + 1] as u16)) >> 1) as u8; }
+        for x in 0..bw { dst[didx + x] = ((u16::from(src[sidx + x]) + u16::from(src[sidx + x + 1])) >> 1) as u8; }
         didx += dstride;
         sidx += sstride;
     }
@@ -442,7 +443,7 @@ fn vp3_interp10(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw:
     let mut didx = 0;
     let mut sidx = 0;
     for _ in 0..bh {
-        for x in 0..bw { dst[didx + x] = (((src[sidx + x] as u16) + (src[sidx + x + sstride] as u16)) >> 1) as u8; }
+        for x in 0..bw { dst[didx + x] = ((u16::from(src[sidx + x]) + u16::from(src[sidx + x + sstride])) >> 1) as u8; }
         didx += dstride;
         sidx += sstride;
     }
@@ -454,8 +455,8 @@ fn vp3_interp1x(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw:
     let mut sidx = 0;
     for _ in 0..bh {
         for x in 0..bw {
-            dst[didx + x] = (((src[sidx + x] as u16) +
-                              (src[sidx + x + sstride + 1] as u16)) >> 1) as u8;
+            dst[didx + x] = ((u16::from(src[sidx + x]) +
+                              u16::from(src[sidx + x + sstride + 1])) >> 1) as u8;
         }
         didx += dstride;
         sidx += sstride;
@@ -468,8 +469,8 @@ fn vp3_interp1y(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw:
     let mut sidx = 0;
     for _ in 0..bh {
         for x in 0..bw {
-            dst[didx + x] = (((src[sidx + x + 1] as u16) +
-                              (src[sidx + x + sstride] as u16)) >> 1) as u8;
+            dst[didx + x] = ((u16::from(src[sidx + x + 1]) +
+                              u16::from(src[sidx + x + sstride])) >> 1) as u8;
         }
         didx += dstride;
         sidx += sstride;
index 69c29682cd5812dd59dab1ca60e97c0e2f31ec60..a3d59f0b01b176fb82cb753aa51dca523fc5adac 100644 (file)
@@ -1,6 +1,11 @@
 extern crate nihav_core;
 extern crate nihav_codec_support;
 
+#[allow(clippy::collapsible_if)]
+#[allow(clippy::excessive_precision)]
+#[allow(clippy::identity_op)]
+#[allow(clippy::unreadable_literal)]
+#[allow(clippy::verbose_bit_mask)]
 mod codecs;
 
 pub use crate::codecs::duck_register_all_codecs;