From: Kostya Shishkov Date: Fri, 8 Nov 2024 17:32:22 +0000 (+0100) Subject: nihav_indeo: fix or refresh clippy warnings X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=39cd2175cb601d1b092d3e246aca50c37cd1651d;p=nihav.git nihav_indeo: fix or refresh clippy warnings --- diff --git a/nihav-indeo/src/codecs/imc.rs b/nihav-indeo/src/codecs/imc.rs index ea4d0b0..79c8dfd 100644 --- a/nihav-indeo/src/codecs/imc.rs +++ b/nihav-indeo/src/codecs/imc.rs @@ -185,18 +185,19 @@ impl BitAlloc { if free_bits > cur_bits { let mut tmp: [f32; BANDS] = [BITALLOC_LIMIT; BANDS]; - for band in 0..BANDS { - if self.band_bits[band] != 6 { - tmp[band] = f32::from(self.band_bits[band]) * -2.0 + ch_data.bit_est[band] - 0.415; + for (dst, (&band_bits, &bit_est)) in tmp.iter_mut() + .zip(self.band_bits.iter().zip(ch_data.bit_est.iter())) { + if band_bits != 6 { + *dst = f32::from(band_bits) * -2.0 + bit_est - 0.415; } } let mut peak = 0.0; while (peak > BITALLOC_LIMIT) && (cur_bits < free_bits) { peak = BITALLOC_LIMIT; let mut idx: Option = None; - for band in 0..BANDS { - if tmp[band] > peak { - peak = tmp[band]; + for (band, &level) in tmp.iter().enumerate() { + if level > peak { + peak = level; idx = Some(band); } } @@ -219,17 +220,18 @@ impl BitAlloc { if cur_bits > free_bits { let mut tmp: [f32; BANDS] = [BITALLOC_TOP_LIMIT; BANDS]; - for band in start..BANDS { - if self.band_bits[band] != 0 { - tmp[band] = f32::from(self.band_bits[band]) * -2.0 + ch_data.bit_est[band] - 0.415 + 2.0; + for (dst, (&band_bits, &bit_est)) in tmp.iter_mut() + .zip(self.band_bits.iter().zip(ch_data.bit_est.iter())).skip(start) { + if band_bits != 0 { + *dst = f32::from(band_bits) * -2.0 + bit_est - 0.415 + 2.0; } } while free_bits < cur_bits { let mut low = BITALLOC_TOP_LIMIT; let mut idx = 0; - for band in 0..BANDS { - if tmp[band] < low { - low = tmp[band]; + for (band, &level) in tmp.iter().enumerate() { + if level < low { + low = level; idx = band; } } @@ -255,9 +257,10 @@ impl BitAlloc { fn adjust_bit_allocation(&mut self, ch_data: &mut IMCChannel, free_bits: i32) { let mut tmp: [f32; BANDS] = [BITALLOC_LIMIT; BANDS]; - for band in 0..BANDS { - if self.band_bits[band] != 6 { - tmp[band] = f32::from(self.band_bits[band]) * -2.0 + ch_data.bit_est[band] - 0.415; + for (dst, (&band_bits, &bit_est)) in tmp.iter_mut() + .zip(self.band_bits.iter().zip(ch_data.bit_est.iter())) { + if band_bits != 6 { + *dst = f32::from(band_bits) * -2.0 + bit_est - 0.415; } } let mut used_bits: i32 = 0; @@ -265,9 +268,9 @@ impl BitAlloc { while (peak > BITALLOC_LIMIT) && (used_bits < free_bits) { peak = BITALLOC_LIMIT; let mut idx: Option = None; - for band in 0..BANDS { - if tmp[band] > peak { - peak = tmp[band]; + for (band, &level) in tmp.iter().enumerate() { + if level > peak { + peak = level; idx = Some(band); } } @@ -299,18 +302,18 @@ struct LUTs { impl LUTs { fn new() -> Self { let mut exp_lev: [f32; 16] = [0.0; 16]; - for lev in 0..16 { - exp_lev[lev] = 10.0f32.powf(-(lev as f32) * 0.4375); + for (lev, el) in exp_lev.iter_mut().enumerate() { + *el = 10.0f32.powf(-(lev as f32) * 0.4375); } let mut exp_10: [f32; 32] = [0.0; 32]; - for i in 0..32 { - exp_10[i] = 10.0f32.powf(((i as f32) - 16.0) * 0.25); + for (i, el) in exp_10.iter_mut().enumerate() { + *el = 10.0f32.powf(((i as f32) - 16.0) * 0.25); } let mut sqrt_tab: [f32; 32] = [0.0; 32]; - for i in 0..32 { - sqrt_tab[i] = (i as f32).sqrt(); + for (i, el) in sqrt_tab.iter_mut().enumerate() { + *el = (i as f32).sqrt(); } LUTs { exp_lev, exp_10, sqrt_tab } @@ -420,17 +423,17 @@ impl IMCDecoder { freq_min[band] = tmp_freq; } - for band in 0..BANDS { + for (dst, &freq_max) in self.cycle1.iter_mut().zip(freq_max.iter()) { let mut s_band = BANDS - 1; - while s_band > 0 && freq_max[band] <= freq_mid[s_band] { s_band -= 1; } - self.cycle1[band] = s_band + 1; + while s_band > 0 && freq_max <= freq_mid[s_band] { s_band -= 1; } + *dst = s_band + 1; } self.cycle2[0] = 0; - for band in 1..BANDS { + for (dst, &freq_min) in self.cycle2.iter_mut().zip(freq_min.iter()).skip(1) { let mut s_band = 0; - while s_band < BANDS-1 && freq_min[band] >= freq_mid[s_band] { s_band += 1; } - self.cycle2[band] = s_band - 1; + while s_band < BANDS-1 && freq_min >= freq_mid[s_band] { s_band += 1; } + *dst = s_band - 1; } } @@ -463,7 +466,7 @@ impl IMCDecoder { let mut tmp2: [f32; BANDS+1] = [0.0; BANDS+1]; let mut tmp3: [f32; BANDS] = [0.0; BANDS]; - for band in 0..BANDS { + for (band, dst) in tmp3.iter_mut().enumerate() { ch_data.mask_wght[band] = 0.0; let val; if self.ba.band_width[band] > 0 { @@ -474,28 +477,26 @@ impl IMCDecoder { ch_data.log_floor2[band] = -30000.0; } let tmp = val * (self.ba.band_width[band] as f64) * 0.01; - if val <= 1.0e-30 { tmp3[band] = 0.0; } - else { tmp3[band] = tmp as f32; } + *dst = if val <= 1.0e-30 { 0.0 } else { tmp as f32 }; } - for band in 0..BANDS { - let next_band = self.cycle1[band]; - for band2 in band..next_band { - ch_data.mask_wght[band2] += tmp3[band]; + for (band, (&next_band, &add_val)) in self.cycle1.iter().zip(tmp3.iter()).enumerate() { + for el in ch_data.mask_wght[band..next_band].iter_mut() { + *el += add_val; } - tmp2[next_band] += tmp3[band]; + tmp2[next_band] += add_val; } let mut accum = 0.0; - for band in 1..BANDS { - accum = (tmp2[band] + accum) * self.weights1[band - 1]; - ch_data.mask_wght[band] += accum; + for (mask_weight, (&val, &weight)) in ch_data.mask_wght[1..].iter_mut() + .zip(tmp2[1..].iter().zip(self.weights1.iter())) { + accum = (accum + val) * weight; + *mask_weight += accum; } let mut tmp2: [f32; BANDS] = [0.0; BANDS]; tmp2[0] = tmp3[0]; - for band in 1..BANDS { - let prev_band = self.cycle2[band]; + for (band, &prev_band) in self.cycle2.iter().enumerate().skip(1) { for band2 in prev_band+1..band { ch_data.mask_wght[band2] += tmp3[band]; } @@ -519,31 +520,31 @@ impl IMCDecoder { } else { start = 0; } - for i in start..BANDS { - level[i] = br.read_cb(&self.codes[sel_idx][IMC_CB_SELECTOR[sel_idx][i]])? as i8; - if level[i] == 17 { - level[i] += br.read(4)? as i8; + for (i, (level, &code_idx)) in level.iter_mut() + .zip(IMC_CB_SELECTOR[sel_idx].iter()).enumerate().skip(start) { + *level = br.read_cb(&self.codes[sel_idx][code_idx])? as i8; + if *level == 17 { + *level += br.read(4)? as i8; } - self.ba.keep_flag[i] = level[i] == 16; + self.ba.keep_flag[i] = *level == 16; } if reset { let ch_data = &mut self.ch_data[ch]; let (mut c1, mut c2) = calc_maxcoef(f32::from(level[0])); ch_data.new_floor[0] = c1; ch_data.log_floor[0] = c2; - for i in 1..BANDS { - if level[i] == 16 { + for (i, &level) in level.iter().enumerate().skip(1) { + if level == 16 { ch_data.new_floor[i] = 1.0; ch_data.log_floor[i] = 0.0; } else { - let lval; - if level[i] < 17 { - lval = level[i] - 7; - } else if level[i] < 25 { - lval = level[i] - 32; - } else { - lval = level[i] - 16; - } + let lval = if level < 17 { + level - 7 + } else if level < 25 { + level - 32 + } else { + level - 16 + }; c1 *= self.luts.exp_10[(lval + 16) as usize]; c2 += 0.83048 * f32::from(lval); ch_data.new_floor[i] = c1; @@ -552,9 +553,9 @@ impl IMCDecoder { } } else { let ch_data = &mut self.ch_data[ch]; - for i in 0..BANDS { - if level[i] < 16 { - let lval = level[i] - 7; + for (i, &level) in level.iter().enumerate() { + if level < 16 { + let lval = level - 7; ch_data.new_floor[i] = self.luts.exp_10[(lval + 16) as usize] * ch_data.old_floor[i]; ch_data.log_floor[i] += f32::from(lval) * 0.83048; } else { @@ -603,22 +604,20 @@ impl IMCDecoder { ba.skip_flag[i] = true; ba.skip_flag[i + 1] = true; ba.skips_per_band[band] += 2; + } else if br.read_bool()? { + ba.skip_flag_bits[band] += 2; + ba.skip_flag[i] = false; + ba.skip_flag[i + 1] = true; + ba.skips_per_band[band] += 1; } else { - if br.read_bool()? { - ba.skip_flag_bits[band] += 2; - ba.skip_flag[i] = false; - ba.skip_flag[i + 1] = true; + ba.skip_flag_bits[band] += 3; + if !br.read_bool()? { + ba.skip_flag[i] = true; ba.skips_per_band[band] += 1; } else { - ba.skip_flag_bits[band] += 3; - if !br.read_bool()? { - ba.skip_flag[i] = true; - ba.skips_per_band[band] += 1; - } else { - ba.skip_flag[i] = false; - } - ba.skip_flag[i + 1] = false; + ba.skip_flag[i] = false; } + ba.skip_flag[i + 1] = false; } i += 2; } @@ -728,6 +727,7 @@ impl IMCDecoder { } } + #[allow(clippy::collapsible_else_if)] fn decode_block(&mut self, data: &[u8], ch: usize, dst: &mut [f32]) -> DecoderResult<()> { let mut br = BitReader::new(&data[BLOCK_SIZE*ch..][..BLOCK_SIZE], BitReaderMode::LE16MSB); let hdr = br.read(9)?; @@ -761,12 +761,7 @@ impl IMCDecoder { self.ba.cw_len[i] = 5; } for band in 1..4 { - let bits: u8; - if raw_coeffs || !self.ba.keep_flag[band]{ - bits = 5; - } else { - bits = 0; - } + let bits = if raw_coeffs || !self.ba.keep_flag[band] { 5 } else { 0 }; self.ba.band_bits[band] = bits; for i in IMC_BANDS[band]..IMC_BANDS[band + 1] { self.ba.cw_len[i] = bits; diff --git a/nihav-indeo/src/codecs/indeo2.rs b/nihav-indeo/src/codecs/indeo2.rs index a07904e..50af67a 100644 --- a/nihav-indeo/src/codecs/indeo2.rs +++ b/nihav-indeo/src/codecs/indeo2.rs @@ -190,6 +190,7 @@ struct Indeo2Decoder { frmmgr: HAMShuffler, } +#[allow(clippy::identity_op)] impl Indeo2Decoder { fn new() -> Self { let dummy_info = NACodecInfo::new_dummy(); diff --git a/nihav-indeo/src/codecs/indeo3.rs b/nihav-indeo/src/codecs/indeo3.rs index 60b6344..3dd2e78 100644 --- a/nihav-indeo/src/codecs/indeo3.rs +++ b/nihav-indeo/src/codecs/indeo3.rs @@ -295,6 +295,7 @@ impl Indeo3Cell { cell2.depth += 1; (cell1, cell2) } + #[allow(clippy::collapsible_else_if)] fn split_v(&self, stripw: u8) -> (Self, Self) { let w1 = if self.width > stripw { if self.width > stripw * 2 { stripw * 2 } else { stripw } @@ -899,6 +900,7 @@ impl NADecoder for Indeo3Decoder { Err(DecoderError::InvalidData) } } + #[allow(clippy::manual_range_contains)] fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); let mut mr = MemoryReader::new_read(&src); diff --git a/nihav-indeo/src/codecs/indeo3enc/tree.rs b/nihav-indeo/src/codecs/indeo3enc/tree.rs index 921d2d9..d6346d9 100644 --- a/nihav-indeo/src/codecs/indeo3enc/tree.rs +++ b/nihav-indeo/src/codecs/indeo3enc/tree.rs @@ -113,6 +113,7 @@ impl Indeo3Cell { cell2.h = h2; (cell1, cell2) } + #[allow(clippy::collapsible_else_if)] fn split_v(&self, stripw: u8) -> (Self, Self) { let w1 = if self.w > stripw { if self.w > stripw * 2 { stripw * 2 } else { stripw } diff --git a/nihav-indeo/src/codecs/indeo4.rs b/nihav-indeo/src/codecs/indeo4.rs index cc73702..c403313 100644 --- a/nihav-indeo/src/codecs/indeo4.rs +++ b/nihav-indeo/src/codecs/indeo4.rs @@ -38,7 +38,6 @@ impl Indeo4Parser { } impl IndeoXParser for Indeo4Parser { -#[allow(unused_variables,unused_assignments)] fn decode_picture_header(&mut self, br: &mut BitReader) -> DecoderResult { let sync = br.read(18)?; validate!(sync == 0x3FFF8); @@ -47,12 +46,7 @@ impl IndeoXParser for Indeo4Parser { let ftype = INDEO4_FRAME_TYPE[ftype_idx as usize]; let transparent = br.read_bool()?; br.skip(1)?; - let data_size; - if br.read_bool()? { - data_size = br.read(24)? as usize; - } else { - data_size = 0; - } + let _data_size = if br.read_bool()? { br.read(24)? as usize } else { 0 }; if ftype.is_null() { return Ok(PictureHeader::new_null(ftype)); } @@ -99,12 +93,7 @@ impl IndeoXParser for Indeo4Parser { _ => { return Err(DecoderError::InvalidData); } }; let chroma_bands = if sc_idx == 2 { 4 } else { 1 }; - let frame_no; - if br.read_bool()? { - frame_no = br.read(20)?; - } else { - frame_no = 0; - } + let _frame_no = if br.read_bool()? { br.read(20)? } else { 0 }; if br.read_bool()? { br.skip(8)?; // decTimeEst } @@ -112,14 +101,14 @@ impl IndeoXParser for Indeo4Parser { self.mb_cb = br.read_ivi_codebook_desc(true, desc_coded)?; let desc_coded = br.read_bool()?; self.blk_cb = br.read_ivi_codebook_desc(false, desc_coded)?; - let rvmap = if br.read_bool()? { br.read(3)? as usize } else { 8 }; - let in_imf = br.read_bool()?; + let _rvmap = if br.read_bool()? { br.read(3)? as usize } else { 8 }; + let _in_imf = br.read_bool()?; let in_q = br.read_bool()?; - let glob_q = br.read(5)? as u8; + let _glob_q = br.read(5)? as u8; if br.read_bool()? { br.skip(3)?; } - let checksum = if br.read_bool()? { br.read(16)? } else { 0 }; + let _checksum = if br.read_bool()? { br.read(16)? } else { 0 }; if br.read_bool()? { br.skip(8)?; // pic hdr extension } @@ -131,7 +120,7 @@ impl IndeoXParser for Indeo4Parser { Ok(PictureHeader::new(ftype, width, height, slice_w, slice_h, transparent, luma_bands, chroma_bands, in_q)) } -#[allow(unused_variables,unused_assignments)] + #[allow(clippy::manual_range_contains)] fn decode_band_header(&mut self, br: &mut BitReader, pic_hdr: &PictureHeader, plane: usize, band: usize) -> DecoderResult { let plane_no = br.read(2)? as usize; let band_no = br.read(4)? as usize; @@ -141,12 +130,7 @@ impl IndeoXParser for Indeo4Parser { br.align(); return Ok(BandHeader::new_empty(plane_no, band_no)); } - let hdr_size; - if br.read_bool()? { - hdr_size = br.read(16)? as usize; - } else { - hdr_size = 32; - } + let _hdr_size = if br.read_bool()? { br.read(16)? as usize } else { 32 }; let mv_mode = br.read(2)?; validate!(mv_mode < 2); if br.read_bool()? { @@ -196,25 +180,19 @@ impl IndeoXParser for Indeo4Parser { txtype = TxType::None; } - let blk_cb; - if br.read_bool()? { - blk_cb = br.read_ivi_codebook_desc(false, true)?; - } else { - blk_cb = self.blk_cb; - } - let rvmap_idx; - if br.read_bool()? { - rvmap_idx = br.read(3)? as usize; - } else { - rvmap_idx = 8; - } + let blk_cb = if br.read_bool()? { + br.read_ivi_codebook_desc(false, true)? + } else { + self.blk_cb + }; + let rvmap_idx = if br.read_bool()? { br.read(3)? as usize } else { 8 }; let num_corr; let mut corr_map: [u8; CORR_MAP_SIZE] = [0; CORR_MAP_SIZE]; if br.read_bool()? { num_corr = br.read(8)? as usize; validate!(num_corr*2 <= CORR_MAP_SIZE); - for i in 0..num_corr*2 { - corr_map[i] = br.read(8)? as u8; + for el in corr_map[..num_corr*2].iter_mut() { + *el = br.read(8)? as u8; } } else { num_corr = 0; @@ -241,17 +219,15 @@ impl IndeoXParser for Indeo4Parser { } else { return Err(DecoderError::MissingReference); } + } else if !pic_hdr.ftype.is_bidir() { + mb.mtype = if br.read_bool()? { MBType::Inter } else { MBType::Intra }; } else { - if !pic_hdr.ftype.is_bidir() { - mb.mtype = if br.read_bool()? { MBType::Inter } else { MBType::Intra }; - } else { - mb.mtype = match br.read(2)? { - 0 => { MBType::Intra }, - 1 => { MBType::Inter }, - 2 => { MBType::Backward }, - _ => { MBType::Bidir }, - }; - } + mb.mtype = match br.read(2)? { + 0 => { MBType::Intra }, + 1 => { MBType::Inter }, + 2 => { MBType::Backward }, + _ => { MBType::Bidir }, + }; } if band.mb_size == band.blk_size { mb.cbp = br.read(1)? as u8; diff --git a/nihav-indeo/src/codecs/indeo5.rs b/nihav-indeo/src/codecs/indeo5.rs index e4863d3..4f0887d 100644 --- a/nihav-indeo/src/codecs/indeo5.rs +++ b/nihav-indeo/src/codecs/indeo5.rs @@ -61,23 +61,16 @@ fn skip_extension(br: &mut BitReader) -> DecoderResult<()> { } impl IndeoXParser for Indeo5Parser { -#[allow(unused_variables)] -#[allow(unused_assignments)] fn decode_picture_header(&mut self, br: &mut BitReader) -> DecoderResult { let sync = br.read(5)?; validate!(sync == 0x1F); let ftype_idx = br.read(3)?; validate!(ftype_idx < 5); let ftype = INDEO5_FRAME_TYPE[ftype_idx as usize]; - let fnum = br.read(8)?; + let _fnum = br.read(8)?; if ftype == IVIFrameType::Intra { let gop_flags = br.read(8)?; - let hdr_size; - if (gop_flags & 0x01) != 0 { - hdr_size = br.read(16)?; - } else { - hdr_size = 0; - } + let _hdr_size = if (gop_flags & 0x01) != 0 { br.read(16)? } else { 0 }; if (gop_flags & 0x20) != 0 { br.skip(32)?; // lock word } @@ -143,18 +136,8 @@ impl IndeoXParser for Indeo5Parser { return Ok(PictureHeader::new_null(ftype)); } let flags = br.read(8)?; - let size; - if (flags & 0x01) != 0 { - size = br.read(24)?; - } else { - size = 0; - } - let checksum; - if (flags & 0x10) != 0 { - checksum = br.read(16)?; - } else { - checksum = 0; - } + let _size = if (flags & 0x01) != 0 { br.read(24)? } else { 0 }; + let _checksum = if (flags & 0x10) != 0 { br.read(16)? } else { 0 }; if (flags & 0x20) != 0 { skip_extension(br)?; } @@ -166,8 +149,7 @@ impl IndeoXParser for Indeo5Parser { Ok(PictureHeader::new(ftype, self.width, self.height, self.tile_w, self.tile_h, false, self.luma_bands, self.chroma_bands, in_q)) } -#[allow(unused_variables)] - fn decode_band_header(&mut self, br: &mut BitReader, pic_hdr: &PictureHeader, plane_no: usize, band_no: usize) -> DecoderResult { + fn decode_band_header(&mut self, br: &mut BitReader, _pic_hdr: &PictureHeader, plane_no: usize, band_no: usize) -> DecoderResult { let band_flags = br.read(8)?; if (band_flags & 0x01) != 0 { @@ -191,18 +173,13 @@ impl IndeoXParser for Indeo5Parser { if (band_flags & 0x10) != 0 { num_corr = br.read(8)? as usize; validate!(num_corr*2 <= CORR_MAP_SIZE); - for i in 0..num_corr*2 { - corr_map[i] = br.read(8)? as u8; + for el in corr_map[..num_corr*2].iter_mut() { + *el = br.read(8)? as u8; } } else { num_corr = 0; } - let rvmap_idx; - if (band_flags & 0x40) != 0 { - rvmap_idx = br.read(3)? as usize; - } else { - rvmap_idx = 8; - } + let rvmap_idx = if (band_flags & 0x40) != 0 { br.read(3)? as usize } else { 8 }; let blk_cb = br.read_ivi_codebook_desc(false, (band_flags & 0x80) != 0)?; if br.read_bool()? { br.skip(16)?; // checksum @@ -267,6 +244,7 @@ impl IndeoXParser for Indeo5Parser { } #[allow(clippy::cognitive_complexity)] + #[allow(clippy::collapsible_else_if)] fn decode_mb_info(&mut self, br: &mut BitReader, pic_hdr: &PictureHeader, band: &BandHeader, tile: &mut IVITile, ref_tile: Option<&IVITile>, mv_scale: u8) -> DecoderResult<()> { let mut mv_x = 0; let mut mv_y = 0; @@ -389,6 +367,7 @@ impl IndeoXParser for Indeo5Parser { Ok(()) } + #[allow(clippy::identity_op)] fn recombine_plane(&mut self, src: &[i16], sstride: usize, dst: &mut [u8], dstride: usize, w: usize, h: usize) { let mut idx0 = 0; let mut idx1 = w / 2; diff --git a/nihav-indeo/src/codecs/intel263.rs b/nihav-indeo/src/codecs/intel263.rs index 62762bc..9131dba 100644 --- a/nihav-indeo/src/codecs/intel263.rs +++ b/nihav-indeo/src/codecs/intel263.rs @@ -10,13 +10,11 @@ use nihav_codec_support::codecs::h263::code::{H263_INTERP_FUNCS, H263_INTERP_AVG use nihav_codec_support::codecs::h263::decoder::*; use nihav_codec_support::codecs::h263::data::*; -#[allow(dead_code)] struct Tables { intra_mcbpc_cb: Codebook, inter_mcbpc_cb: Codebook, cbpy_cb: Codebook, rl_cb: Codebook, - aic_rl_cb: Codebook, mv_cb: Codebook, } @@ -52,7 +50,6 @@ const W8: i32 = 181; const ROW_SHIFT: u8 = 8; const COL_SHIFT: u8 = 14; -#[allow(clippy::erasing_op)] fn idct_row(row: &mut [i16]) { let in0 = ((i32::from(row[0])) << 11) + (1 << (ROW_SHIFT - 1)); let in1 = (i32::from(row[4])) << 11; @@ -100,6 +97,7 @@ fn idct_row(row: &mut [i16]) { } #[allow(clippy::erasing_op)] +#[allow(clippy::identity_op)] fn idct_col(blk: &mut [i16; 64], off: usize) { let in0 = ((i32::from(blk[off + 0*8])) << 8) + (1 << (COL_SHIFT - 1)); let in1 = (i32::from(blk[off + 4*8])) << 8; @@ -152,6 +150,7 @@ const FILTER_STRENGTH: [u8; 32] = [ ]; #[allow(clippy::erasing_op)] +#[allow(clippy::identity_op)] fn deblock_hor(buf: &mut NAVideoBuffer, comp: usize, strength: u8, off: usize) { let stride = buf.get_stride(comp); let dptr = buf.get_data_mut().unwrap(); @@ -172,6 +171,7 @@ fn deblock_hor(buf: &mut NAVideoBuffer, comp: usize, strength: u8, off: usiz } } +#[allow(clippy::identity_op)] fn deblock_ver(buf: &mut NAVideoBuffer, comp: usize, strength: u8, off: usize) { let stride = buf.get_stride(comp); let dptr = buf.get_data_mut().unwrap(); @@ -210,12 +210,12 @@ impl BlockDSP for I263BlockDSP { fn copy_blocks8x8(&self, dst: &mut NAVideoBuffer, src: NAVideoBufferRef, xpos: usize, ypos: usize, mvs: &[MV; 4]) { let mut dst = NASimpleVideoFrame::from_video_buf(dst).unwrap(); - for i in 0..4 { + for (i, mv) in mvs.iter().enumerate() { let xadd = (i & 1) * 8; let yadd = (i & 2) * 4; - let mode = ((mvs[i].x & 1) + (mvs[i].y & 1) * 2) as usize; + let mode = ((mv.x & 1) + (mv.y & 1) * 2) as usize; - blockdsp::copy_block(&mut dst, src.clone(), 0, xpos + xadd, ypos + yadd, mvs[i].x >> 1, mvs[i].y >> 1, 8, 8, 0, 1, mode, H263_INTERP_FUNCS); + blockdsp::copy_block(&mut dst, src.clone(), 0, xpos + xadd, ypos + yadd, mv.x >> 1, mv.y >> 1, 8, 8, 0, 1, mode, H263_INTERP_FUNCS); } let sum_mv = mvs[0] + mvs[1] + mvs[2] + mvs[3]; @@ -239,12 +239,12 @@ impl BlockDSP for I263BlockDSP { fn avg_blocks8x8(&self, dst: &mut NAVideoBuffer, src: NAVideoBufferRef, xpos: usize, ypos: usize, mvs: &[MV; 4]) { let mut dst = NASimpleVideoFrame::from_video_buf(dst).unwrap(); - for i in 0..4 { + for (i, mv) in mvs.iter().enumerate() { let xadd = (i & 1) * 8; let yadd = (i & 2) * 4; - let mode = ((mvs[i].x & 1) + (mvs[i].y & 1) * 2) as usize; + let mode = ((mv.x & 1) + (mv.y & 1) * 2) as usize; - blockdsp::copy_block(&mut dst, src.clone(), 0, xpos + xadd, ypos + yadd, mvs[i].x >> 1, mvs[i].y >> 1, 8, 8, 0, 1, mode, H263_INTERP_AVG_FUNCS); + blockdsp::copy_block(&mut dst, src.clone(), 0, xpos + xadd, ypos + yadd, mv.x >> 1, mv.y >> 1, 8, 8, 0, 1, mode, H263_INTERP_AVG_FUNCS); } let sum_mv = mvs[0] + mvs[1] + mvs[2] + mvs[3]; @@ -447,8 +447,6 @@ fn decode_b_info(br: &mut BitReader, is_pb: bool, is_ipb: bool, is_intra: bool) impl<'a> BlockDecoder for Intel263BR<'a> { -#[allow(unused_variables)] -#[allow(clippy::unreadable_literal)] fn decode_pichdr(&mut self) -> DecoderResult { let br = &mut self.br; let syncw = br.read(22)?; @@ -504,14 +502,13 @@ impl<'a> BlockDecoder for Intel263BR<'a> { let cpm = br.read_bool()?; validate!(!cpm); - let pbinfo; - if self.is_pb { - let trb = br.read(3)?; - let dbquant = br.read(2)?; - pbinfo = Some(PBInfo::new(trb as u8, dbquant as u8, pbplus)); - } else { - pbinfo = None; - } + let pbinfo = if self.is_pb { + let trb = br.read(3)?; + let dbquant = br.read(2)?; + Some(PBInfo::new(trb as u8, dbquant as u8, pbplus)) + } else { + None + }; while br.read_bool()? { // skip PEI br.read(8)?; } @@ -526,13 +523,12 @@ impl<'a> BlockDecoder for Intel263BR<'a> { Ok(picinfo) } - #[allow(unused_variables)] - fn decode_slice_header(&mut self, info: &PicInfo) -> DecoderResult { + fn decode_slice_header(&mut self, _info: &PicInfo) -> DecoderResult { let br = &mut self.br; let gbsc = br.read(17)?; validate!(gbsc == 1); - let gn = br.read(5)?; - let gfid = br.read(2)?; + let _gn = br.read(5)?; + let _gfid = br.read(2)?; let gquant = br.read(5)?; //println!("GOB gn {:X} id {} q {}", gn, gfid, gquant); let ret = SliceInfo::new_gob(0, self.gob_no, gquant as u8); @@ -540,8 +536,7 @@ impl<'a> BlockDecoder for Intel263BR<'a> { Ok(ret) } - #[allow(unused_variables)] - fn decode_block_header(&mut self, info: &PicInfo, slice: &SliceInfo, sstate: &SliceState) -> DecoderResult { + fn decode_block_header(&mut self, info: &PicInfo, slice: &SliceInfo, _sstate: &SliceState) -> DecoderResult { let br = &mut self.br; let mut q = slice.get_quant(); match info.get_mode() { @@ -622,13 +617,11 @@ impl<'a> BlockDecoder for Intel263BR<'a> { } } - #[allow(unused_variables)] - fn decode_block_intra(&mut self, info: &BlockInfo, sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { + fn decode_block_intra(&mut self, _info: &BlockInfo, _sstate: &SliceState, quant: u8, _no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { self.decode_block(quant, true, coded, blk) } - #[allow(unused_variables)] - fn decode_block_inter(&mut self, info: &BlockInfo, sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { + fn decode_block_inter(&mut self, _info: &BlockInfo, _sstate: &SliceState, quant: u8, _no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> { self.decode_block(quant, false, coded, blk) } @@ -645,8 +638,6 @@ impl Intel263Decoder { let cbpy_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); let mut coderead = H263RLCodeReader::new(H263_RL_CODES); let rl_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); - let mut coderead = H263RLCodeReader::new(H263_RL_CODES_AIC); - let aic_rl_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); let mut coderead = H263ShortCodeReader::new(H263_MV); let mv_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap(); let tables = Tables { @@ -654,7 +645,6 @@ impl Intel263Decoder { inter_mcbpc_cb, cbpy_cb, rl_cb, - aic_rl_cb, mv_cb, }; diff --git a/nihav-indeo/src/codecs/ivi.rs b/nihav-indeo/src/codecs/ivi.rs index ab1c91d..ecfab92 100644 --- a/nihav-indeo/src/codecs/ivi.rs +++ b/nihav-indeo/src/codecs/ivi.rs @@ -107,7 +107,6 @@ impl IVITransformType { } } -#[allow(dead_code)] #[derive(Clone)] pub struct TxParams4x4 { pub quant_intra: &'static [u16; 16], @@ -123,7 +122,6 @@ impl TxParams4x4 { } } -#[allow(dead_code)] #[derive(Clone)] pub struct TxParams8x8 { pub quant_intra: &'static [u16; 64], @@ -167,6 +165,7 @@ pub struct BandHeader { } impl BandHeader { + #[allow(clippy::identity_op)] pub fn new(plane_no: usize, band_no: usize, mb_size: usize, blk_size: usize, halfpel: bool, inherit_mv: bool, has_qdelta: bool, inherit_qd: bool, quant: u32, rvmap_idx: usize, num_corr: usize, corr_map: [u8; CORR_MAP_SIZE], blk_cb: IVICodebook, tr: IVITransformType, ttype: TxType) -> Self { let mut rvmap = IVI_RVMAPS[rvmap_idx].clone(); for i in 0..num_corr { diff --git a/nihav-indeo/src/codecs/ivibr.rs b/nihav-indeo/src/codecs/ivibr.rs index 1383f74..c3722a1 100644 --- a/nihav-indeo/src/codecs/ivibr.rs +++ b/nihav-indeo/src/codecs/ivibr.rs @@ -144,23 +144,22 @@ pub const IVI_BLK_CB: &[IVICodebook; 8] = &[ IVICodebook { len: 9, bits: [ 3, 4, 4, 5, 5, 5, 6, 5, 5, 0, 0, 0, 0, 0, 0, 0 ], offs: [0; 16] } ]; -#[allow(unused_variables)] #[allow(clippy::many_single_char_names)] fn read_trans_band_header(br: &mut BitReader, w: usize, h: usize, dst: &mut [i16], dstride: usize) -> DecoderResult<()> { - let color_plane = br.read(2)?; - let bit_depth = br.read(3)?; + let _color_plane = br.read(2)?; + let _bit_depth = br.read(3)?; let dirty_rects = br.read(8)? as usize; - for i in 0..dirty_rects { - let x = br.read(16)?; - let y = br.read(16)?; - let l = br.read(16)?; - let r = br.read(16)?; + for _ in 0..dirty_rects { + let _x = br.read(16)?; + let _y = br.read(16)?; + let _l = br.read(16)?; + let _r = br.read(16)?; } let has_trans_color = br.read_bool()?; if has_trans_color { - let r = br.read(8)?; - let g = br.read(8)?; - let b = br.read(8)?; + let _r = br.read(8)?; + let _g = br.read(8)?; + let _b = br.read(8)?; } br.skip(1)?; @@ -187,7 +186,7 @@ let tile_end = tile_start + len * 8; let first_val = br.read_bool()?; - let mut dec_size = 0; + let mut _dec_size = 0; let mut x = 0; let mut y = 0; let mut fill = if !first_val { 255-128 } else { 0-128 }; @@ -195,7 +194,7 @@ let tile_end = tile_start + len * 8; while br.tell() < tile_end { let code = br.read_ivi_cb(&cb)? as usize; if code == 0 { - dec_size += 255; + _dec_size += 255; for _ in 0..255 { if (x < w) && (y < h) { dst[x + y * dstride] = fill; @@ -207,7 +206,7 @@ let tile_end = tile_start + len * 8; } } } else { - dec_size += code; + _dec_size += code; for _ in 0..code { if (x < w) && (y < h) { dst[x + y * dstride] = fill; @@ -228,7 +227,7 @@ let tile_end = tile_start + len * 8; Ok(()) } -#[allow(clippy::cast_lossless)] +#[allow(clippy::collapsible_else_if)] fn decode_block8x8(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tables: &TxParams8x8, is_intra: bool, is_2d: bool, prev_dc: &mut i32, quant: u8, coeffs: &mut [i32; 64], transform: TrFunc) -> DecoderResult<()> { let mut idx: isize = -1; let quant_mat = if is_intra { tables.quant_intra } else { tables.quant_inter }; @@ -279,7 +278,8 @@ fn decode_block8x8(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tabl (transform)(coeffs); Ok(()) } -#[allow(clippy::cast_lossless)] + +#[allow(clippy::collapsible_else_if)] fn decode_block4x4(br: &mut BitReader, blk_cb: &IVICodebook, rvmap: &RVMap, tables: &TxParams4x4, is_intra: bool, is_2d: bool, prev_dc: &mut i32, quant: u8, coeffs: &mut [i32; 64], transform: TrFunc) -> DecoderResult<()> { let mut idx: isize = -1; let quant_mat = if is_intra { tables.quant_intra } else { tables.quant_inter }; @@ -610,12 +610,9 @@ impl IVIDecoder { validate!(tile_end <= br.tell() + (br.left() as usize)); { let ref_tile: Option<&IVITile>; - let mv_scale; - if (plane_no == 0) && (band_no == 0) { - mv_scale = 0; - } else { - mv_scale = (((self.bands[0].mb_size >> 3) as i8) - ((band.mb_size >> 3) as i8)) as u8; - } + let mv_scale = if (plane_no == 0) && (band_no == 0) { 0 } else { + (((self.bands[0].mb_size >> 3) as i8) - ((band.mb_size >> 3) as i8)) as u8 + }; let (ref_tiles, cur_tiles) = self.tiles.split_at_mut(tile_no); let tile = &mut cur_tiles[0]; if plane_no != 0 || band_no != 0 { @@ -638,12 +635,9 @@ br.skip(skip_part as u32)?; } else { { let ref_tile: Option<&IVITile>; - let mv_scale; - if (plane_no == 0) && (band_no == 0) { - mv_scale = 0; - } else { - mv_scale = (((self.bands[0].mb_size >> 3) as i8) - ((band.mb_size >> 3) as i8)) as u8; - } + let mv_scale = if (plane_no == 0) && (band_no == 0) { 0 } else { + (((self.bands[0].mb_size >> 3) as i8) - ((band.mb_size >> 3) as i8)) as u8 + }; let (ref_tiles, cur_tiles) = self.tiles.split_at_mut(tile_no); let tile = &mut cur_tiles[0]; if plane_no != 0 || band_no != 0 { @@ -682,6 +676,7 @@ br.skip(skip_part as u32)?; br.align(); Ok(()) } + #[allow(clippy::collapsible_else_if)] fn decode_tile(&mut self, br: &mut BitReader, band: &BandHeader, tile_no: usize, tr: TrFunc, transform_dc: TrFuncDC) -> DecoderResult<()> { let mut mb_idx = 0; let mut prev_dc: i32 = 0; @@ -708,12 +703,7 @@ br.skip(skip_part as u32)?; let boff = (blk_no & 1) * band.blk_size + (blk_no >> 1) * band.blk_size * stride + mb_x * band.mb_size; if !is_intra { if mb.mtype != MBType::Bidir { - let idx; - if mb.mtype != MBType::Backward { - idx = self.prev_frame; - } else { - idx = self.next_frame; - } + let idx = if mb.mtype != MBType::Backward { self.prev_frame } else { self.next_frame }; let pf = &self.frames[idx]; do_mc(&mut dst[dstidx + boff..], stride, &pf.plane_buf[band.plane_no], pf.plane_stride[band.plane_no], @@ -763,12 +753,7 @@ br.skip(skip_part as u32)?; let mut blk: [i32; 64] = [0; 64]; if !is_intra { if mb.mtype != MBType::Bidir { - let idx; - if mb.mtype != MBType::Backward { - idx = self.prev_frame; - } else { - idx = self.next_frame; - } + let idx = if mb.mtype != MBType::Backward { self.prev_frame } else { self.next_frame }; let pf = &self.frames[idx]; do_mc(&mut dst[dstidx + mb_x * band.blk_size..], stride, &pf.plane_buf[band.plane_no], pf.plane_stride[band.plane_no], @@ -926,22 +911,22 @@ br.skip(skip_part as u32)?; } validate!((br.tell() & 31) == 0); - for plane in 0..3 { - for band in 0..num_bands[plane] { - if bands_decoded[plane][band] || br.left() == 0 { + for (plane, &nbands) in num_bands.iter().enumerate() { + for (band, band_decoded) in bands_decoded[plane][..nbands].iter_mut().enumerate() { + if *band_decoded || br.left() == 0 { continue; } self.decode_band(&pic_hdr, dec, br, plane, band)?; - bands_decoded[plane][band] = true; + *band_decoded = true; num_decoded += 1; } } } if let NABufferType::Video(ref mut vb) = buftype { - for plane in 0..3 { + for (plane, &nbands) in num_bands.iter().enumerate() { let mut frame = self.frames[self.cur_frame].clone(); - if num_bands[plane] == 1 { + if nbands == 1 { frame.fill_plane(vb, plane); } else { let dplane = if (plane == 1) || (plane == 2) { plane ^ 3 } else { plane }; diff --git a/nihav-indeo/src/codecs/ividsp.rs b/nihav-indeo/src/codecs/ividsp.rs index b20e155..8a19391 100644 --- a/nihav-indeo/src/codecs/ividsp.rs +++ b/nihav-indeo/src/codecs/ividsp.rs @@ -120,7 +120,7 @@ fn haar8x8_col(blk: &mut[i32; 64]) { } fn haar8x8_dc(blk: &mut[i32; 64], in0: i32) { let dc = in0 >> 3; - for i in 0..64 { blk[i] = dc; } + for el in blk.iter_mut() { *el = dc; } } fn haar4x4_2d(blk: &mut[i32; 64]) { @@ -152,7 +152,7 @@ fn haar4x4_col(blk: &mut[i32; 64]) { } fn haar4x4_dc(blk: &mut[i32; 64], in0: i32) { let dc = in0 >> 3; - for i in 0..16 { blk[i] = dc; } + for el in blk[..16].iter_mut() { *el = dc; } } fn slant8x8_2d(blk: &mut[i32; 64]) { @@ -174,7 +174,7 @@ fn slant8x8_2d(blk: &mut[i32; 64]) { } fn slant8x8_2d_dc(blk: &mut[i32; 64], in0: i32) { let dc = (in0 + 1) >> 1; - for i in 0..64 { blk[i] = dc; } + for el in blk.iter_mut() { *el = dc; } } fn slant8x8_row(blk: &mut[i32; 64]) { let pass = |x: i32| (x + 1) >> 1; @@ -187,8 +187,8 @@ fn slant8x8_row(blk: &mut[i32; 64]) { fn slant8x8_row_dc(blk: &mut[i32; 64], in0: i32) { let dc = (in0 + 1) >> 1; - for i in 0..8 { blk[i] = dc; } - for i in 8..64 { blk[i] = 0; } + for el in blk[0..8].iter_mut() { *el = dc; } + for el in blk[8..].iter_mut() { *el = 0; } } fn slant8x8_col(blk: &mut[i32; 64]) { let pass = |x: i32| (x + 1) >> 1; @@ -221,7 +221,7 @@ fn slant4x4_2d(blk: &mut[i32; 64]) { } fn slant4x4_2d_dc(blk: &mut[i32; 64], in0: i32) { let dc = (in0 + 1) >> 1; - for i in 0..16 { blk[i] = dc; } + for el in blk[..16].iter_mut() { *el = dc; } } fn slant4x4_row(blk: &mut[i32; 64]) { let pass = |x: i32| (x + 1) >> 1; @@ -234,8 +234,8 @@ fn slant4x4_row(blk: &mut[i32; 64]) { fn slant4x4_row_dc(blk: &mut[i32; 64], in0: i32) { let dc = (in0 + 1) >> 1; - for i in 0..4 { blk[i] = dc; } - for i in 4..16 { blk[i] = 0; } + for el in blk[0..4].iter_mut() { *el = dc; } + for el in blk[4..16].iter_mut() { *el = 0; } } fn slant4x4_col(blk: &mut[i32; 64]) { let pass = |x: i32| (x + 1) >> 1; @@ -253,19 +253,17 @@ fn slant4x4_col_dc(blk: &mut[i32; 64], in0: i32) { } } -#[allow(unused_variables)] -fn none8x8(blk: &mut[i32; 64]) { +fn none8x8(_blk: &mut[i32; 64]) { } fn none8x8_dc(blk: &mut[i32; 64], dc: i32) { - for i in 1..8 { blk[i] = dc; } - for i in 8..64 { blk[i] = 0; } + for el in blk[1..8].iter_mut() { *el = dc; } + for el in blk[8..].iter_mut() { *el = 0; } } -#[allow(unused_variables)] -fn none4x4(blk: &mut[i32; 64]) { +fn none4x4(_blk: &mut[i32; 64]) { } fn none4x4_dc(blk: &mut[i32; 64], dc: i32) { - for i in 1..4 { blk[i] = dc; } - for i in 4..16 { blk[i] = 0; } + for el in blk[1..4].iter_mut() { *el = dc; } + for el in blk[4..16].iter_mut() { *el = 0; } } pub fn ivi_get_transform8x8_funcs(ttype: IVITransformType) -> (TrFunc, TrFuncDC) { diff --git a/nihav-indeo/src/codecs/mod.rs b/nihav-indeo/src/codecs/mod.rs index 85523d6..78b8eae 100644 --- a/nihav-indeo/src/codecs/mod.rs +++ b/nihav-indeo/src/codecs/mod.rs @@ -23,16 +23,19 @@ mod indeo4; mod indeo5; #[cfg(any(feature="decoder_indeo4", feature="decoder_indeo5"))] +#[allow(clippy::too_many_arguments)] mod ivi; #[cfg(any(feature="decoder_indeo4", feature="decoder_indeo5"))] +#[allow(clippy::too_many_arguments)] mod ivibr; #[cfg(any(feature="decoder_indeo4", feature="decoder_indeo5"))] #[allow(clippy::erasing_op)] +#[allow(clippy::identity_op)] +#[allow(clippy::too_many_arguments)] mod ividsp; #[cfg(feature="decoder_imc")] #[allow(clippy::excessive_precision)] -#[allow(clippy::unreadable_literal)] mod imc; const INDEO_CODECS: &[DecoderInfo] = &[ diff --git a/nihav-indeo/src/lib.rs b/nihav-indeo/src/lib.rs index a89bd26..a202663 100644 --- a/nihav-indeo/src/lib.rs +++ b/nihav-indeo/src/lib.rs @@ -2,16 +2,7 @@ extern crate nihav_core; extern crate nihav_codec_support; -#[allow(clippy::collapsible_if)] -#[allow(clippy::collapsible_else_if)] -#[allow(clippy::identity_op)] -#[allow(clippy::needless_range_loop)] -#[allow(clippy::needless_late_init)] -#[allow(clippy::too_many_arguments)] -#[allow(clippy::useless_let_if_seq)] -#[allow(clippy::verbose_bit_mask)] #[allow(clippy::upper_case_acronyms)] -#[allow(clippy::manual_range_contains)] mod codecs; pub use crate::codecs::indeo_register_all_decoders;