From: Kostya Shishkov Date: Wed, 15 May 2019 12:36:43 +0000 (+0200) Subject: core: fix some clippy warnings X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=fdb4b2fbe87ca6e15f6d5e8ad040b7c9ee883053;p=nihav.git core: fix some clippy warnings --- diff --git a/nihav-core/src/codecs/blockdsp.rs b/nihav-core/src/codecs/blockdsp.rs index 70b8420..86fb864 100644 --- a/nihav-core/src/codecs/blockdsp.rs +++ b/nihav-core/src/codecs/blockdsp.rs @@ -131,10 +131,12 @@ pub fn edge_emu(src: &NAVideoBuffer, xpos: isize, ypos: isize, bw: usize, bh } } +pub type BlkInterpFunc = fn(&mut [u8], usize, &[u8], usize, usize, usize); + pub fn copy_blocks(dst: &mut NAVideoBuffer, src: &NAVideoBuffer, dx: usize, dy: usize, sx: isize, sy: isize, bw: usize, bh: usize, preborder: usize, postborder: usize, - mode: usize, interp: &[fn(&mut [u8], usize, &[u8], usize, usize, usize)]) + mode: usize, interp: &[BlkInterpFunc]) { let pre = if mode != 0 { preborder as isize } else { 0 }; let post = if mode != 0 { postborder as isize } else { 0 }; diff --git a/nihav-core/src/codecs/h263/code.rs b/nihav-core/src/codecs/h263/code.rs index fa02e4e..1f101a2 100644 --- a/nihav-core/src/codecs/h263/code.rs +++ b/nihav-core/src/codecs/h263/code.rs @@ -270,7 +270,7 @@ fn h263_interp11(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: } } -pub const H263_INTERP_FUNCS: &[fn(&mut [u8], usize, &[u8], usize, usize, usize)] = &[ +pub const H263_INTERP_FUNCS: &[blockdsp::BlkInterpFunc] = &[ h263_interp00, h263_interp01, h263_interp10, h263_interp11 ]; fn h263_interp00_avg(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, bw: usize, bh: usize) @@ -336,7 +336,7 @@ fn h263_interp11_avg(dst: &mut [u8], dstride: usize, src: &[u8], sstride: usize, } } -pub const H263_INTERP_AVG_FUNCS: &[fn(&mut [u8], usize, &[u8], usize, usize, usize)] = &[ +pub const H263_INTERP_AVG_FUNCS: &[blockdsp::BlkInterpFunc] = &[ h263_interp00_avg, h263_interp01_avg, h263_interp10_avg, h263_interp11_avg ]; pub struct H263BlockDSP { } diff --git a/nihav-core/src/codecs/h263/data.rs b/nihav-core/src/codecs/h263/data.rs index 36b22e1..4f6a705 100644 --- a/nihav-core/src/codecs/h263/data.rs +++ b/nihav-core/src/codecs/h263/data.rs @@ -127,10 +127,10 @@ impl CodebookDescReader for H263ShortCodeReader { #[derive(Clone,Copy)] pub struct H263RLSym { run: u8, level: i8 } impl H263RLSym { - pub fn get_run(&self) -> u8 { self.run } - pub fn is_last(&self) -> bool { self.level < 0 } - pub fn is_escape(&self) -> bool { (self.run == 0) && (self.level == 0) } - pub fn get_level(&self) -> i16 { if self.level < 0 { -self.level as i16 } else { self.level as i16 } } + pub fn get_run(self) -> u8 { self.run } + pub fn is_last(self) -> bool { self.level < 0 } + pub fn is_escape(self) -> bool { (self.run == 0) && (self.level == 0) } + pub fn get_level(self) -> i16 { if self.level < 0 { -self.level as i16 } else { self.level as i16 } } } pub struct H263RLCodeDesc { code: u8, bits: u8, sym: H263RLSym } diff --git a/nihav-core/src/codecs/h263/decoder.rs b/nihav-core/src/codecs/h263/decoder.rs index 502187d..2a841ba 100644 --- a/nihav-core/src/codecs/h263/decoder.rs +++ b/nihav-core/src/codecs/h263/decoder.rs @@ -522,7 +522,7 @@ impl H263BaseDecoder { } pub fn get_bframe(&mut self, bdsp: &BlockDSP) -> DecoderResult { - if !self.has_b || !self.ipbs.get_lastref().is_some() || !self.ipbs.get_nextref().is_some() { + if !self.has_b || self.ipbs.get_lastref().is_none() || self.ipbs.get_nextref().is_none() { return Err(DecoderError::MissingReference); } self.has_b = false; @@ -533,7 +533,7 @@ impl H263BaseDecoder { let mut b_buf = bufinfo.get_vbuf().unwrap(); if let (Some(ref bck_buf), Some(ref fwd_buf)) = (self.ipbs.get_nextref(), self.ipbs.get_lastref()) { - recon_b_frame(&mut b_buf, fwd_buf, bck_buf, self.mb_w, self.mb_h, &self.b_data, bdsp); + recon_b_frame(&mut b_buf, fwd_buf, bck_buf, self.mb_w, self.mb_h, self.b_data.as_slice(), bdsp); } self.b_data.truncate(0); @@ -542,7 +542,7 @@ impl H263BaseDecoder { } fn recon_b_frame(b_buf: &mut NAVideoBuffer, bck_buf: &NAVideoBuffer, fwd_buf: &NAVideoBuffer, - mb_w: usize, mb_h: usize, b_data: &Vec, bdsp: &BlockDSP) { + mb_w: usize, mb_h: usize, b_data: &[BMB], bdsp: &BlockDSP) { let mut cbpi = CBPInfo::new(); let mut cur_mb = 0; cbpi.reset(mb_w); diff --git a/nihav-core/src/codecs/h263/mod.rs b/nihav-core/src/codecs/h263/mod.rs index 76cd7a1..6f3d548 100644 --- a/nihav-core/src/codecs/h263/mod.rs +++ b/nihav-core/src/codecs/h263/mod.rs @@ -4,6 +4,7 @@ use crate::frame::NAVideoBuffer; #[allow(clippy::many_single_char_names)] pub mod code; pub mod data; +#[allow(clippy::needless_range_loop)] pub mod decoder; pub trait BlockDecoder { @@ -29,8 +30,8 @@ pub enum Type { } impl Type { - pub fn is_ref(&self) -> bool { - match *self { + pub fn is_ref(self) -> bool { + match self { Type::I | Type::P | Type::PB => true, _ => false, } @@ -49,9 +50,9 @@ impl PBInfo { pub fn new(trb: u8, dbquant: u8, improved: bool) -> Self { PBInfo{ trb, dbquant, improved } } - pub fn get_trb(&self) -> u8 { self.trb } - pub fn get_dbquant(&self) -> u8 { self.dbquant } - pub fn is_improved(&self) -> bool { self.improved } + pub fn get_trb(self) -> u8 { self.trb } + pub fn get_dbquant(self) -> u8 { self.dbquant } + pub fn is_improved(self) -> bool { self.improved } } #[allow(dead_code)] @@ -253,7 +254,7 @@ impl BlockInfo { pub fn get_num_mvs2(&self) -> usize { self.num_mv2 } pub fn get_mv2(&self, idx: usize) -> MV { self.mv2[idx] } pub fn set_mv(&mut self, mvs: &[MV]) { - if mvs.len() > 0 { self.skip = false; } + if !mvs.is_empty() { self.skip = false; } let mut mv_arr: [MV; 4] = [MV::new(0, 0), MV::new(0, 0), MV::new(0, 0), MV::new(0, 0)]; for i in 0..mvs.len() { mv_arr[i] = mvs[i]; } self.mv = mv_arr; @@ -266,7 +267,7 @@ impl BlockInfo { self.num_mv2 = bbinfo.get_num_mv(); } pub fn set_b_mv(&mut self, mvs: &[MV]) { - if mvs.len() > 0 { self.skip = false; } + if !mvs.is_empty() { self.skip = false; } let mut mv_arr: [MV; 2] = [ZERO_MV, ZERO_MV]; for i in 0..mvs.len() { mv_arr[i] = mvs[i]; } self.mv2 = mv_arr; diff --git a/nihav-core/src/dsp/dct.rs b/nihav-core/src/dsp/dct.rs index ae04e8e..b3415e3 100644 --- a/nihav-core/src/dsp/dct.rs +++ b/nihav-core/src/dsp/dct.rs @@ -48,7 +48,7 @@ impl DCT { perm_tab.push(0); // size = 1 perm_tab.push(0); // size = 2 perm_tab.push(1); - for blen in 2..bits+1 { + for blen in 2..=bits { let ssize = 1 << blen; for i in 0..ssize { perm_tab.push(swp_idx(i, blen)); } } @@ -66,7 +66,7 @@ impl DCT { tab.push((consts::PI / 8.0).sin()); // size = 1 tab.push((consts::PI / 8.0).cos()); if bits > 1 { - for blen in 1..bits+1 { + for blen in 1..=bits { let tsize = 1 << blen; let base = consts::PI / ((tsize * 8) as f32); for i in 0..tsize { @@ -153,7 +153,7 @@ fn reverse_bits(inval: u32) -> u32 { let mut val = inval; for _ in 0..8 { ret = (ret << 4) | (REV_TAB[(val & 0xF) as usize] as u32); - val = val >> 4; + val >>= 4; } ret } diff --git a/nihav-core/src/dsp/fft.rs b/nihav-core/src/dsp/fft.rs index ee4ab7c..a626ad9 100644 --- a/nihav-core/src/dsp/fft.rs +++ b/nihav-core/src/dsp/fft.rs @@ -245,7 +245,7 @@ impl FFTSplitRadix { let size = 1 << bits; let mut table = Vec::with_capacity(size); for _ in 0..4 { table.push(FFTC_ZERO); } - for b in 3..(bits+1) { + for b in 3..=bits { let qsize = (1 << (b - 2)) as usize; let base = -consts::PI / ((qsize * 2) as f32); for k in 0..qsize { @@ -648,7 +648,7 @@ fn gen_sr_perms(swaps: &mut [usize], size: usize) { gen_sr_perms(&mut swaps[3*size/4..], size/4); } -fn gen_swaps_for_perm(swaps: &mut Vec, perms: &Vec) { +fn gen_swaps_for_perm(swaps: &mut Vec, perms: &[usize]) { let mut idx_arr: Vec = Vec::with_capacity(perms.len()); for i in 0..perms.len() { idx_arr.push(i); } let mut run_size = 0; @@ -719,7 +719,7 @@ impl FFTBuilder { for (mode, _) in ffts.iter().rev() { mode.permute(&mut perms); } - gen_swaps_for_perm(&mut swaps, &perms); + gen_swaps_for_perm(&mut swaps, perms.as_slice()); FFT { perms, swaps, ffts } } @@ -733,7 +733,7 @@ pub struct RDFT { fwd_fft: bool, } -fn crossadd(a: &FFTComplex, b: &FFTComplex) -> FFTComplex { +fn crossadd(a: FFTComplex, b: FFTComplex) -> FFTComplex { FFTComplex { re: a.re + b.re, im: a.im - b.im } } @@ -748,7 +748,7 @@ impl RDFT { let in0 = buf[n + 1]; let in1 = buf[self.size - n - 1]; - let t0 = crossadd(&in0, &in1); + let t0 = crossadd(in0, in1); let t1 = FFTComplex { re: in1.im + in0.im, im: in1.re - in0.re }; let tab = self.table[n]; let t2 = FFTComplex { re: t1.im * tab.im + t1.re * tab.re, im: t1.im * tab.re - t1.re * tab.im }; @@ -771,11 +771,11 @@ impl RDFT { let in0 = buf[n + 1]; let in1 = buf[self.size - n - 1]; - let t0 = crossadd(&in0, &in1).scale(0.5); + let t0 = crossadd(in0, in1).scale(0.5); let t1 = FFTComplex { re: in0.im + in1.im, im: in0.re - in1.re }; let t2 = t1 * self.table[n]; - buf[n + 1] = crossadd(&t0, &t2); + buf[n + 1] = crossadd(t0, t2); buf[self.size - n - 1] = FFTComplex { re: t0.re - t2.re, im: -(t0.im + t2.im) }; } let a = buf[0].re; diff --git a/nihav-core/src/dsp/window.rs b/nihav-core/src/dsp/window.rs index 42b6b6d..92a2655 100644 --- a/nihav-core/src/dsp/window.rs +++ b/nihav-core/src/dsp/window.rs @@ -13,19 +13,18 @@ pub fn generate_window(mode: WindowType, scale: f32, size: usize, half: bool, ds for n in 0..size { dst[n] = scale; } }, WindowType::Sine => { - let param; - if half { - param = consts::PI / ((2 * size) as f32); - } else { - param = consts::PI / (size as f32); - } + let param = if half { + consts::PI / ((2 * size) as f32) + } else { + consts::PI / (size as f32) + }; for n in 0..size { dst[n] = (((n as f32) + 0.5) * param).sin() * scale; } }, WindowType::KaiserBessel(alpha) => { let dlen = if half { size as f32 } else { (size as f32) * 0.5 }; - let alpha2 = ((alpha * consts::PI / dlen) * (alpha * consts::PI / dlen)) as f64; + let alpha2 = f64::from((alpha * consts::PI / dlen) * (alpha * consts::PI / dlen)); let mut kb: Vec = Vec::with_capacity(size); let mut sum = 0.0; @@ -45,7 +44,7 @@ pub fn generate_window(mode: WindowType, scale: f32, size: usize, half: bool, ds fn bessel_i0(inval: f64) -> f64 { let mut val: f64 = 1.0; for n in (1..64).rev() { - val *= inval / ((n * n) as f64); + val *= inval / f64::from(n * n); val += 1.0; } val diff --git a/nihav-core/src/lib.rs b/nihav-core/src/lib.rs index 08e7134..a3e2df1 100644 --- a/nihav-core/src/lib.rs +++ b/nihav-core/src/lib.rs @@ -1,12 +1,17 @@ #[cfg(feature="decoders")] +#[allow(clippy::cast_lossless)] +#[allow(clippy::identity_op)] +#[allow(clippy::too_many_arguments)] #[allow(clippy::unreadable_literal)] pub mod codecs; #[cfg(feature="demuxers")] pub mod demuxers; +#[allow(clippy::too_many_arguments)] pub mod formats; pub mod frame; +#[allow(clippy::too_many_arguments)] pub mod io; pub mod refs; pub mod register; @@ -15,6 +20,9 @@ pub mod detect; pub mod scale; #[cfg(feature="dsp")] +#[allow(clippy::excessive_precision)] +#[allow(clippy::identity_op)] +#[allow(clippy::needless_range_loop)] #[allow(clippy::unreadable_literal)] pub mod dsp;