From: Kostya Shishkov Date: Wed, 11 Nov 2026 20:41:05 +0000 (+0100) Subject: janitorial: fix some clippy warnings X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=904a660eca4a646b4618d11bb6ef025a6e50f725;p=nihav.git janitorial: fix some clippy warnings --- diff --git a/nihav-commonfmt/src/muxers/mov/videotrack.rs b/nihav-commonfmt/src/muxers/mov/videotrack.rs index ded1415..3710e58 100644 --- a/nihav-commonfmt/src/muxers/mov/videotrack.rs +++ b/nihav-commonfmt/src/muxers/mov/videotrack.rs @@ -24,7 +24,7 @@ impl VideoTrackHandler { "pal8" | "rgb24" | "rgb555be" => {}, other => { println!("Raw format {other} is not supported!"); - return Err(MuxerError::UnsupportedFormat)?; + return Err(MuxerError::UnsupportedFormat); } } } diff --git a/nihav-game/src/codecs/vmd.rs b/nihav-game/src/codecs/vmd.rs index fd0de8f..75a1aae 100644 --- a/nihav-game/src/codecs/vmd.rs +++ b/nihav-game/src/codecs/vmd.rs @@ -271,7 +271,7 @@ impl NADecoder for VMDVideoDecoder { } (self.width / 2, RGB555_FORMAT) }; - self.framebuf = vec!(0; self.width * self.height); + self.framebuf = vec![0; self.width * self.height]; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(disp_width, self.height, false, fmt)); self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); diff --git a/nihav-game/src/codecs/vx.rs b/nihav-game/src/codecs/vx.rs index ae85702..2a078fe 100644 --- a/nihav-game/src/codecs/vx.rs +++ b/nihav-game/src/codecs/vx.rs @@ -85,7 +85,7 @@ macro_rules! mc { let mut doff = $xpos + $ypos * 256; for _y in 0..$h { for x in 0..$w { - $bufs[$dst_id][doff + x] = (i32::from($bufs[$src_id][soff + x]) + $ydelta).max(0).min(255) as u8; + $bufs[$dst_id][doff + x] = (i32::from($bufs[$src_id][soff + x]) + $ydelta).clamp(0, 255) as u8; } soff += 256; doff += 256; @@ -94,8 +94,8 @@ macro_rules! mc { let mut doff = CHROMA_OFF + $xpos / 2 + $ypos / 2 * 256; for _y in 0..$h / 2 { for x in 0..$w / 2 { - $bufs[$dst_id][doff + x] = (i32::from($bufs[$src_id][soff + x]) + $udelta).max(0).min(255) as u8; - $bufs[$dst_id][doff + x + 128] = (i32::from($bufs[$src_id][soff + x + 128]) + $vdelta).max(0).min(255) as u8; + $bufs[$dst_id][doff + x] = (i32::from($bufs[$src_id][soff + x]) + $udelta).clamp(0, 255) as u8; + $bufs[$dst_id][doff + x + 128] = (i32::from($bufs[$src_id][soff + x + 128]) + $vdelta).clamp(0, 255) as u8; } soff += 256; doff += 256; @@ -492,7 +492,7 @@ fn idct_add(qmat: &[i32; 8], blk: &mut [i32; 16], dst: &mut [u8]) { for (dline, row) in dst.chunks_mut(256).zip(blk.chunks_mut(4)) { transform!(row[0], row[1], row[2], row[3], 1, 1); for (out, coef) in dline.iter_mut().zip(row.iter_mut()) { - *out = (i32::from(*out) + ((*coef + 0x20) >> 6)).max(0).min(255) as u8; + *out = (i32::from(*out) + ((*coef + 0x20) >> 6)).clamp(0, 255) as u8; } } } @@ -555,12 +555,10 @@ fn decode_coeffs(br: &mut BitReader, codebooks: &Codebooks, qmat: &[i32; 8], ctx if num_zero > 0 && coef_left > 0 { let run = if num_zero < 7 { br.read_cb(&codebooks.zero_run_cb[num_zero as usize - 1])? + } else if br.peek(3) != 0 { + 7 - (br.read(3)? as u8) } else { - if br.peek(3) != 0 { - 7 - (br.read(3)? as u8) - } else { - (br.read_unary()? as u8) + 4 - } + (br.read_unary()? as u8) + 4 }; validate!(run <= num_zero); idx -= run; @@ -827,7 +825,7 @@ impl VXVideoDecoder { self.decode_block(br, xpos, ypos + hh, w, hh)?; }, 3 => { self.do_mc_bias(br, xpos, ypos, w, h)?; }, - 4 | 5 | 6 => { + 4..=6 => { let ref_id = (mode - 4) as usize; self.do_mc(br, xpos, ypos, w, h, ref_id)?; }, @@ -864,7 +862,7 @@ impl VXVideoDecoder { self.intra_pred4x4(br, xpos, ypos, w, h)?; } }, - 16 | 17 | 18 => { + 16..=18 => { let ref_id = (mode - 16) as usize; self.do_mc(br, xpos, ypos, w, h, ref_id)?; self.decode_residue(br, xpos, ypos, w, h)?; @@ -913,7 +911,7 @@ impl NADecoder for VXVideoDecoder { self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); if let Some(edata) = info.get_extradata() { - validate!(edata.len() > 0); + validate!(!edata.is_empty()); let fps = edata[0] as usize; validate!(fps <= 60); let base = &QUANTISERS[(fps % 6) * 8..][..8]; diff --git a/nihav-indeo/src/codecs/indeo3enc/cell.rs b/nihav-indeo/src/codecs/indeo3enc/cell.rs index 4372dcf..93e6288 100644 --- a/nihav-indeo/src/codecs/indeo3enc/cell.rs +++ b/nihav-indeo/src/codecs/indeo3enc/cell.rs @@ -397,7 +397,7 @@ impl CellEncoder { let mut cell4 = [0; 20]; match mode { - 0 | 1 | 2 => { + 0..=2 => { for y in (0..self.cell.get_height()).step_by(4) { for x in (0..self.cell.get_width()).step_by(4) { Self::get_cell4(&self.buf, x, y, stride, &mut cell4); @@ -489,7 +489,7 @@ impl CellEncoder { let mut ccell4 = [0; 20]; let mut pcell4 = [0; 20]; match mode { - 0 | 1 | 2 => { + 0..=2 => { for y in (0..self.cell.get_height()).step_by(4) { for x in (0..self.cell.get_width()).step_by(4) { Self::get_cell4(&self.buf, x, y, stride, &mut ccell4); diff --git a/nihav-indeo/src/codecs/indeo3enc/mv.rs b/nihav-indeo/src/codecs/indeo3enc/mv.rs index d234e94..c6994df 100644 --- a/nihav-indeo/src/codecs/indeo3enc/mv.rs +++ b/nihav-indeo/src/codecs/indeo3enc/mv.rs @@ -119,7 +119,7 @@ fn calc_mv_score(cur: &Plane, prev: &Plane, cell: Indeo3Cell, mv: MV) -> u32 { } pub fn compact_mvs(mvs: &mut Vec<(MV, u16)>) { - mvs.sort_by(|a, b| b.1.cmp(&a.1)); + mvs.sort_by_key(|a| std::cmp::Reverse(a.1)); mvs.truncate(256); } diff --git a/nihav-indeo/src/codecs/indeo3enc/tree.rs b/nihav-indeo/src/codecs/indeo3enc/tree.rs index b359c65..a4e5ef0 100644 --- a/nihav-indeo/src/codecs/indeo3enc/tree.rs +++ b/nihav-indeo/src/codecs/indeo3enc/tree.rs @@ -368,7 +368,7 @@ impl Plane { Indeo3PrimaryTree::RelFill(ref mv, ref _sec) => { if find_mv(*mv, &self.mvs).is_none() { let sec = self.split_sec(cell); - *tree = Box::new(Indeo3PrimaryTree::AbsFill(sec)); + **tree = Indeo3PrimaryTree::AbsFill(sec); } }, } diff --git a/nihav-itu/src/codecs/h264/baseline/decoder_mt.rs b/nihav-itu/src/codecs/h264/baseline/decoder_mt.rs index be5f37e..275e371 100644 --- a/nihav-itu/src/codecs/h264/baseline/decoder_mt.rs +++ b/nihav-itu/src/codecs/h264/baseline/decoder_mt.rs @@ -874,10 +874,8 @@ impl NADecoderMT for H264MTDecoder { FrameSkipMode::IntraOnly => { skip_decoding = pic_type != FrameType::I; }, - FrameSkipMode::KeyframesOnly => { - if !is_ref { - skip_decoding = true; - } + FrameSkipMode::KeyframesOnly if !is_ref => { + skip_decoding = true; }, _ => {}, }; diff --git a/nihav-itu/src/codecs/h264/baseline/decoder_st.rs b/nihav-itu/src/codecs/h264/baseline/decoder_st.rs index cf48f61..7ef007b 100644 --- a/nihav-itu/src/codecs/h264/baseline/decoder_st.rs +++ b/nihav-itu/src/codecs/h264/baseline/decoder_st.rs @@ -853,10 +853,8 @@ impl NADecoder for H264Decoder { FrameSkipMode::IntraOnly => { skip_decoding = pic_type != FrameType::I; }, - FrameSkipMode::KeyframesOnly => { - if !is_ref { - skip_decoding = true; - } + FrameSkipMode::KeyframesOnly if !is_ref => { + skip_decoding = true; }, _ => {}, }; diff --git a/nihav-itu/src/codecs/h264/high/decoder_mt.rs b/nihav-itu/src/codecs/h264/high/decoder_mt.rs index b88e378..1389cb8 100644 --- a/nihav-itu/src/codecs/h264/high/decoder_mt.rs +++ b/nihav-itu/src/codecs/h264/high/decoder_mt.rs @@ -892,10 +892,8 @@ impl NADecoderMT for H264MTDecoder { FrameSkipMode::IntraOnly => { skip_decoding = pic_type != FrameType::I; }, - FrameSkipMode::KeyframesOnly => { - if !is_ref { - skip_decoding = true; - } + FrameSkipMode::KeyframesOnly if !is_ref => { + skip_decoding = true; }, _ => {}, }; diff --git a/nihav-itu/src/codecs/h264/high/decoder_st.rs b/nihav-itu/src/codecs/h264/high/decoder_st.rs index 37ac395..27b09cb 100644 --- a/nihav-itu/src/codecs/h264/high/decoder_st.rs +++ b/nihav-itu/src/codecs/h264/high/decoder_st.rs @@ -870,10 +870,8 @@ impl NADecoder for H264Decoder { FrameSkipMode::IntraOnly => { skip_decoding = pic_type != FrameType::I; }, - FrameSkipMode::KeyframesOnly => { - if !is_ref { - skip_decoding = true; - } + FrameSkipMode::KeyframesOnly if !is_ref => { + skip_decoding = true; }, _ => {}, }; diff --git a/nihav-llaudio/src/codecs/tta.rs b/nihav-llaudio/src/codecs/tta.rs index 9508a0f..759bb02 100644 --- a/nihav-llaudio/src/codecs/tta.rs +++ b/nihav-llaudio/src/codecs/tta.rs @@ -281,7 +281,7 @@ impl NADecoder for TTADecoder { _ => return Err(DecoderError::NotImplemented), }; self.ainfo.block_len = self.framelen as usize; - self.bpp = (ainfo.format.bits / 8) as u8; + self.bpp = ainfo.format.bits / 8; self.ch_dec = Vec::with_capacity(usize::from(ainfo.channels)); for _ in 0..ainfo.channels { self.ch_dec.push(ChannelDecoder::new());