From: Kostya Shishkov Date: Fri, 8 Nov 2024 18:52:23 +0000 (+0100) Subject: nihav_ms: fix or update clippy warnings X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=33e30dc2a9da6724325f9606858b13b03312d91b;p=nihav.git nihav_ms: fix or update clippy warnings --- diff --git a/nihav-ms/src/codecs/imaadpcmenc.rs b/nihav-ms/src/codecs/imaadpcmenc.rs index f2a2223..f5c6df0 100644 --- a/nihav-ms/src/codecs/imaadpcmenc.rs +++ b/nihav-ms/src/codecs/imaadpcmenc.rs @@ -106,12 +106,12 @@ impl IMAADPCMEncoder { let mut state = [TrellisNode::default(); 16]; for ch in 0..self.channels { self.nodes.clear(); - for i in 0..16 { + for (i, state) in state.iter_mut().enumerate() { let step = (((self.first[ch].step + i) as isize) - 8).max(0).min(IMA_MAX_STEP as isize) as usize; - state[i].state.predictor = self.first[ch].predictor; - state[i].state.step = step; - state[i].error = 0; - state[i].nib = step as u8; + state.state.predictor = self.first[ch].predictor; + state.state.step = step; + state.error = 0; + state.nib = step as u8; } self.nodes.push(state); let mut sidx = ch + step; diff --git a/nihav-ms/src/codecs/mod.rs b/nihav-ms/src/codecs/mod.rs index 736884b..739315b 100644 --- a/nihav-ms/src/codecs/mod.rs +++ b/nihav-ms/src/codecs/mod.rs @@ -43,7 +43,6 @@ pub fn ms_register_all_decoders(rd: &mut RegisteredDecoders) { } #[cfg(feature="encoder_msvideo1")] -#[allow(clippy::collapsible_else_if)] pub mod msvideo1enc; const MS_ENCODERS: &[EncoderInfo] = &[ diff --git a/nihav-ms/src/codecs/msadpcm.rs b/nihav-ms/src/codecs/msadpcm.rs index f95a691..7896614 100644 --- a/nihav-ms/src/codecs/msadpcm.rs +++ b/nihav-ms/src/codecs/msadpcm.rs @@ -113,22 +113,22 @@ impl NADecoder for MSADPCMDecoder { for blk in pktbuf.chunks(self.block_len) { let mut mr = MemoryReader::new_read(blk); let mut br = ByteReader::new(&mut mr); - for ch in 0..channels { + for p in pred[..channels].iter_mut() { let coef_idx = br.read_byte()? as usize; validate!(coef_idx < self.adapt_coeffs.len()); - pred[ch].coef1 = self.adapt_coeffs[coef_idx][0]; - pred[ch].coef2 = self.adapt_coeffs[coef_idx][1]; + p.coef1 = self.adapt_coeffs[coef_idx][0]; + p.coef2 = self.adapt_coeffs[coef_idx][1]; } - for ch in 0..channels { - pred[ch].delta = i32::from(br.read_u16le()?); + for p in pred[..channels].iter_mut() { + p.delta = i32::from(br.read_u16le()?); } - for ch in 0..channels { + for p in pred[..channels].iter_mut() { let samp = br.read_u16le()? as i16; - pred[ch].sample1 = i32::from(samp); + p.sample1 = i32::from(samp); } - for ch in 0..channels { + for p in pred[..channels].iter_mut() { let samp = br.read_u16le()? as i16; - pred[ch].sample2 = i32::from(samp); + p.sample2 = i32::from(samp); } for ch in 0..channels { dst[off[ch]] = pred[ch].sample2 as i16; @@ -212,16 +212,16 @@ impl MSADPCMEncoder { let mut bw = ByteWriter::new(&mut mw); let mut best_idx = [0usize; 2]; - for ch in 0..self.channels { + for (ch, best_idx) in best_idx[..self.channels].iter_mut().enumerate() { let mut best_dist = std::i64::MAX; for i in 0..ADAPT_COEFFS.len() { let dist = self.calc_dist(ch, i, len); if dist < best_dist { best_dist = dist; - best_idx[ch] = i; + *best_idx = i; } } - bw.write_byte(best_idx[ch] as u8)?; + bw.write_byte(*best_idx as u8)?; } let mut dec = [Predictor::default(), Predictor::default()]; for ch in 0..self.channels { @@ -236,14 +236,14 @@ impl MSADPCMEncoder { dec[ch].delta = 16; } } - for ch in 0..self.channels { - bw.write_u16le(dec[ch].delta as u16)?; + for d in dec[..self.channels].iter() { + bw.write_u16le(d.delta as u16)?; } - for ch in 0..self.channels { - bw.write_u16le(dec[ch].sample1 as u16)?; + for d in dec[..self.channels].iter() { + bw.write_u16le(d.sample1 as u16)?; } - for ch in 0..self.channels { - bw.write_u16le(dec[ch].sample2 as u16)?; + for d in dec[..self.channels].iter() { + bw.write_u16le(d.sample2 as u16)?; } if self.channels == 1 { for samps in self.samples.chunks(2).skip(1).take(len/2 - 1) { diff --git a/nihav-ms/src/codecs/msrle.rs b/nihav-ms/src/codecs/msrle.rs index 8637e03..5953a37 100644 --- a/nihav-ms/src/codecs/msrle.rs +++ b/nihav-ms/src/codecs/msrle.rs @@ -200,7 +200,6 @@ impl NADecoder for RleDecoder { let mut mr = MemoryReader::new_read(src.as_slice()); let mut br = ByteReader::new(&mut mr); - let ftype; let bufret = self.hams.clone_ref(); let mut buf; if let Some(bbuf) = bufret { @@ -212,11 +211,11 @@ impl NADecoder for RleDecoder { buf = self.hams.get_output_frame().unwrap(); } let mut frm = NASimpleVideoFrame::from_video_buf(&mut buf).unwrap(); - if !self.is_4bit { - ftype = self.decode_8bit(&mut br, &mut frm)?; - } else { - ftype = self.decode_4bit(&mut br, &mut frm)?; - } + let ftype = if !self.is_4bit { + self.decode_8bit(&mut br, &mut frm)? + } else { + self.decode_4bit(&mut br, &mut frm)? + }; let paloff = frm.offset[1]; let dpal = &mut frm.data[paloff..]; for sd in pkt.side_data.iter() { diff --git a/nihav-ms/src/codecs/msvideo1enc.rs b/nihav-ms/src/codecs/msvideo1enc.rs index f457dfc..d1074e0 100644 --- a/nihav-ms/src/codecs/msvideo1enc.rs +++ b/nihav-ms/src/codecs/msvideo1enc.rs @@ -354,21 +354,21 @@ impl<'a> BlockPainterPal<'a> { fn find_index(&self, pix: UnpackedPixel) -> u8 { self.ls.search(pix) as u8 } fn put_fill(&self, bstate: &BlockState, dst: &mut [u8], dstride: usize) -> u8 { let fill_val = self.find_index(bstate.fill_val); - for line in dst.chunks_mut(dstride) { - for i in 0..4 { - line[i] = fill_val; + for line in dst.chunks_mut(dstride).take(4) { + for pix in line[..4].iter_mut() { + *pix = fill_val; } } fill_val } fn put_clr2(&self, bstate: &BlockState, dst: &mut [u8], dstride: usize) -> [u8; 2] { let clr2 = [self.find_index(bstate.clr2[0]), self.find_index(bstate.clr2[1])]; - for j in 0..4 { - for i in 0..4 { + for (j, dline) in dst.chunks_mut(dstride).take(4).enumerate() { + for (i, pix) in dline[..4].iter_mut().enumerate() { if (bstate.clr2_flags & (1 << (i + j * 4))) == 0 { - dst[i + j * dstride] = clr2[0]; + *pix = clr2[0]; } else { - dst[i + j * dstride] = clr2[1]; + *pix = clr2[1]; } } } @@ -445,20 +445,20 @@ impl BlockPainter15 { fn put_fill(&self, bstate: &BlockState, dst: &mut [u16], dstride: usize) -> u16 { let fill_val = pack_rgb555(bstate.fill_val); for line in dst.chunks_mut(dstride) { - for i in 0..4 { - line[i] = fill_val; + for pix in line[..4].iter_mut() { + *pix = fill_val; } } fill_val } fn put_clr2(&self, bstate: &BlockState, dst: &mut [u16], dstride: usize) -> [u16; 2] { let clr2 = [pack_rgb555(bstate.clr2[0]), pack_rgb555(bstate.clr2[1])]; - for j in 0..4 { - for i in 0..4 { + for (j, dline) in dst.chunks_mut(dstride).take(4).enumerate() { + for (i, pix) in dline[..4].iter_mut().enumerate() { if (bstate.clr2_flags & (1 << (i + j * 4))) == 0 { - dst[i + j * dstride] = clr2[0]; + *pix = clr2[0]; } else { - dst[i + j * dstride] = clr2[1]; + *pix = clr2[1]; } } } @@ -836,6 +836,7 @@ impl NAEncoder for MSVideo1Encoder { } } fn get_capabilities(&self) -> u64 { ENC_CAPS_SKIPFRAME } + #[allow(clippy::collapsible_else_if)] fn init(&mut self, stream_id: u32, encinfo: EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => Err(EncoderError::FormatError), diff --git a/nihav-ms/src/lib.rs b/nihav-ms/src/lib.rs index 7eec3c2..7cf1318 100644 --- a/nihav-ms/src/lib.rs +++ b/nihav-ms/src/lib.rs @@ -2,10 +2,7 @@ extern crate nihav_core; extern crate nihav_codec_support; -#[allow(clippy::needless_range_loop)] -#[allow(clippy::needless_late_init)] #[allow(clippy::single_match)] -#[allow(clippy::verbose_bit_mask)] mod codecs; pub use crate::codecs::ms_register_all_decoders; pub use crate::codecs::ms_register_all_encoders;