From e6aaad5c5273cd814b5748b7faf3751835a37217 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Wed, 26 Jul 2023 19:03:18 +0200 Subject: [PATCH] fix clippy warnings --- nihav-codec-support/src/codecs/mod.rs | 36 +++------------- nihav-codec-support/src/test/dec_video.rs | 4 +- nihav-codec-support/src/test/wavwriter.rs | 2 +- nihav-commonfmt/src/codecs/clearvideo.rs | 2 +- nihav-commonfmt/src/codecs/jpeg.rs | 4 +- nihav-commonfmt/src/codecs/mod.rs | 1 + nihav-commonfmt/src/codecs/pcm.rs | 6 +-- nihav-commonfmt/src/demuxers/mov.rs | 8 ++-- nihav-commonfmt/src/demuxers/y4m.rs | 6 +-- nihav-commonfmt/src/lib.rs | 3 ++ nihav-core/src/codecs/mod.rs | 9 +--- nihav-core/src/compr/deflate.rs | 11 ++--- nihav-core/src/compr/mod.rs | 3 +- nihav-core/src/demuxers/mod.rs | 28 +++--------- nihav-core/src/formats.rs | 42 +++++++----------- nihav-core/src/frame.rs | 43 +++++++++---------- nihav-core/src/io/bitreader.rs | 6 +-- nihav-core/src/io/bitwriter.rs | 1 + nihav-core/src/io/byteio.rs | 8 ++-- nihav-core/src/io/codebook.rs | 6 +-- nihav-core/src/lib.rs | 2 + nihav-core/src/muxers/mod.rs | 7 +-- nihav-core/src/reorder.rs | 3 +- nihav-core/src/scale/mod.rs | 8 ++-- nihav-core/src/scale/palette/mediancut.rs | 2 +- nihav-core/src/scale/palette/mod.rs | 16 +++---- nihav-core/src/scale/scale/mod.rs | 4 +- nihav-duck/src/codecs/on2avc.rs | 8 ++-- nihav-duck/src/codecs/truemotion1enc.rs | 20 +++------ nihav-duck/src/codecs/vp3.rs | 16 +++---- nihav-duck/src/codecs/vp56.rs | 18 ++++---- nihav-duck/src/codecs/vp6.rs | 1 - nihav-duck/src/codecs/vp6enc/coder.rs | 16 +++---- nihav-duck/src/codecs/vp6enc/dsp.rs | 4 +- nihav-duck/src/codecs/vp6enc/mb.rs | 6 +-- nihav-duck/src/codecs/vp7.rs | 1 + nihav-duck/src/codecs/vp78.rs | 7 +-- nihav-duck/src/codecs/vp78dsp.rs | 6 +-- nihav-duck/src/codecs/vp7dsp.rs | 2 +- nihav-duck/src/codecs/vp7enc/blocks.rs | 2 +- nihav-duck/src/codecs/vp7enc/rdo.rs | 2 +- nihav-duck/src/codecs/vp8.rs | 25 +++-------- nihav-duck/src/codecs/vp8dsp.rs | 4 +- nihav-duck/src/codecs/vpcommon.rs | 19 ++------ nihav-duck/src/codecs/vpenc/motion_est.rs | 7 +-- nihav-duck/src/lib.rs | 5 +++ nihav-flash/src/codecs/flashsv.rs | 10 +---- nihav-game/src/codecs/gremlinvideo.rs | 2 +- nihav-game/src/codecs/lhst500f22.rs | 2 +- nihav-game/src/codecs/midivid3.rs | 4 +- nihav-game/src/codecs/q.rs | 4 +- nihav-game/src/codecs/smush/v1.rs | 2 +- nihav-game/src/codecs/vmd.rs | 4 +- nihav-game/src/demuxers/q.rs | 2 +- nihav-game/src/demuxers/smush.rs | 2 +- nihav-game/src/lib.rs | 6 +++ nihav-indeo/src/codecs/imc.rs | 8 ++-- nihav-indeo/src/codecs/indeo2.rs | 4 +- nihav-indeo/src/codecs/indeo3enc/cell.rs | 16 +++---- nihav-indeo/src/codecs/indeo3enc/mod.rs | 2 +- nihav-indeo/src/codecs/indeo5.rs | 2 +- nihav-indeo/src/codecs/ivibr.rs | 13 +++--- nihav-indeo/src/demuxers/ivf.rs | 10 +++-- nihav-indeo/src/lib.rs | 4 ++ nihav-itu/src/codecs/h264/cabac.rs | 14 +++--- nihav-itu/src/codecs/h264/cavlc.rs | 10 ++--- nihav-itu/src/codecs/h264/decoder_mt.rs | 6 +-- nihav-itu/src/codecs/h264/decoder_st.rs | 8 ++-- nihav-itu/src/codecs/h264/pic_ref.rs | 8 ++-- nihav-itu/src/codecs/h264/types.rs | 28 ++++-------- nihav-itu/src/codecs/mod.rs | 1 + nihav-llaudio/src/codecs/ape.rs | 2 +- nihav-llaudio/src/codecs/flac.rs | 2 +- nihav-llaudio/src/codecs/wavpack.rs | 1 + nihav-llaudio/src/demuxers/flac.rs | 2 +- nihav-llaudio/src/demuxers/flacraw.rs | 2 +- nihav-llaudio/src/demuxers/wavpack.rs | 1 + nihav-mpeg/src/codecs/aac/coeff_read.rs | 10 ++--- nihav-mpeg/src/codecs/aac/mod.rs | 4 +- nihav-mpeg/src/codecs/aac/sbr/bs.rs | 2 +- nihav-mpeg/src/codecs/aac/sbr/synth.rs | 8 ++-- nihav-mpeg/src/codecs/mpegaudio/mod.rs | 2 +- nihav-mpeg/src/lib.rs | 4 ++ nihav-ms/src/codecs/imaadpcmenc.rs | 2 - nihav-ms/src/codecs/mod.rs | 1 + nihav-ms/src/codecs/msadpcm.rs | 1 - nihav-ms/src/codecs/msvideo1enc.rs | 12 +++--- nihav-ms/src/lib.rs | 1 + nihav-qt/src/codecs/qdm2qmf.rs | 2 +- nihav-qt/src/codecs/qdmcommon.rs | 4 +- nihav-qt/src/codecs/rpza.rs | 2 +- nihav-qt/src/codecs/smc.rs | 2 +- nihav-qt/src/codecs/svq3.rs | 10 ++--- nihav-qt/src/lib.rs | 3 ++ nihav-rad/src/codecs/binkaud.rs | 4 +- nihav-rad/src/codecs/binkvid.rs | 2 +- nihav-rad/src/codecs/smacker.rs | 6 +-- nihav-rad/src/demuxers/smacker.rs | 6 +-- nihav-rad/src/lib.rs | 3 ++ nihav-realmedia/src/codecs/cook.rs | 2 +- nihav-realmedia/src/codecs/rv20.rs | 6 +-- .../src/codecs/rv40enc/bitstream.rs | 2 +- nihav-realmedia/src/codecs/rv40enc/mod.rs | 4 +- .../src/codecs/rv40enc/motion_est.rs | 11 ++--- nihav-realmedia/src/codecs/rv60.rs | 23 +++------- nihav-realmedia/src/codecs/rv60codes.rs | 4 +- nihav-realmedia/src/demuxers/realmedia.rs | 15 ++++--- nihav-realmedia/src/lib.rs | 7 +++ .../src/muxers/rmvb/audiostream.rs | 10 ++--- nihav-realmedia/src/muxers/rmvb/mod.rs | 4 +- .../src/muxers/rmvb/videostream.rs | 2 +- nihav-registry/src/register.rs | 7 +-- nihav-vivo/src/codecs/g723_1.rs | 14 +++--- nihav-vivo/src/lib.rs | 2 + 114 files changed, 353 insertions(+), 473 deletions(-) diff --git a/nihav-codec-support/src/codecs/mod.rs b/nihav-codec-support/src/codecs/mod.rs index 2bac7e2..63810ad 100644 --- a/nihav-codec-support/src/codecs/mod.rs +++ b/nihav-codec-support/src/codecs/mod.rs @@ -56,10 +56,7 @@ impl HAMShuffler { /// Returns the original saved reference frame or `None` if it is not present. #[allow(dead_code)] pub fn get_output_frame(&mut self) -> Option> { - match self.lastframe { - Some(ref frm) => Some(frm.clone()), - None => None, - } + self.lastframe.as_ref().cloned() } } @@ -102,11 +99,7 @@ impl IPShuffler { /// Returns the original saved reference frame or `None` if it is not present. #[allow(dead_code)] pub fn get_ref(&mut self) -> Option> { - if let Some(ref frm) = self.lastframe { - Some(frm.clone()) - } else { - None - } + self.lastframe.as_ref().cloned() } } @@ -162,38 +155,22 @@ impl IPBShuffler { /// Returns the previous reference frame or `None` if it is not present. #[allow(dead_code)] pub fn get_lastref(&mut self) -> Option> { - if let Some(ref frm) = self.lastframe { - Some(frm.clone()) - } else { - None - } + self.lastframe.as_ref().cloned() } /// Returns second last reference frame or `None` if it is not present. #[allow(dead_code)] pub fn get_nextref(&mut self) -> Option> { - if let Some(ref frm) = self.nextframe { - Some(frm.clone()) - } else { - None - } + self.nextframe.as_ref().cloned() } /// Returns the temporally following reference for B-frame or `None` if it is not present. #[allow(dead_code)] pub fn get_b_fwdref(&mut self) -> Option> { - if let Some(ref frm) = self.nextframe { - Some(frm.clone()) - } else { - None - } + self.nextframe.as_ref().cloned() } /// Returns the temporally preceeding reference for B-frame or `None` if it is not present. #[allow(dead_code)] pub fn get_b_bwdref(&mut self) -> Option> { - if let Some(ref frm) = self.lastframe { - Some(frm.clone()) - } else { - None - } + self.lastframe.as_ref().cloned() } } @@ -219,6 +196,7 @@ pub struct MV { #[allow(clippy::many_single_char_names)] #[allow(clippy::collapsible_if)] +#[allow(clippy::collapsible_else_if)] impl MV { /// Creates a new motion vector instance. pub fn new(x: i16, y: i16) -> Self { MV{ x, y } } diff --git a/nihav-codec-support/src/test/dec_video.rs b/nihav-codec-support/src/test/dec_video.rs index 035e89d..8915a73 100644 --- a/nihav-codec-support/src/test/dec_video.rs +++ b/nihav-codec-support/src/test/dec_video.rs @@ -486,8 +486,7 @@ println!("stream {} codec {} / {}", i, info.get_name(), dec_name); } } - 'tail_loop: for dentry in decs.iter_mut() { - if let Some((_, ref mut dec)) = dentry { + 'tail_loop: for (_, ref mut dec) in decs.iter_mut().flatten() { loop { match dec.get_frame() { (Ok(frm), id) => { @@ -507,7 +506,6 @@ println!("stream {} codec {} / {}", i, info.get_name(), dec_name); break; } } - } } if let ExpectedTestResult::MD5(ref ref_hash) = test { md5.finish(); diff --git a/nihav-codec-support/src/test/wavwriter.rs b/nihav-codec-support/src/test/wavwriter.rs index 061abfa..3d41108 100644 --- a/nihav-codec-support/src/test/wavwriter.rs +++ b/nihav-codec-support/src/test/wavwriter.rs @@ -124,7 +124,7 @@ impl<'a> Drop for WavWriter<'a> { let res = self.io.seek(SeekFrom::Start(4)); let res = self.io.write_u32le((size - 8) as u32); let res = self.io.seek(SeekFrom::Start(self.data_pos - 4)); - let res = self.io.write_u32le(((size as u64) - self.data_pos) as u32); + let res = self.io.write_u32le((size - self.data_pos) as u32); } } } diff --git a/nihav-commonfmt/src/codecs/clearvideo.rs b/nihav-commonfmt/src/codecs/clearvideo.rs index 52bfe2b..50794ab 100644 --- a/nihav-commonfmt/src/codecs/clearvideo.rs +++ b/nihav-commonfmt/src/codecs/clearvideo.rs @@ -572,7 +572,7 @@ fn decode_dct_block(br: &mut BitReader, blk: &mut [i32; 64], ac_quant: i32, has_ } else { eob = br.read_bool()?; let run = br.read(6)? as usize; - let lev = br.read_s(8)? as i32; + let lev = br.read_s(8)?; (lev, run) }; idx += skip; diff --git a/nihav-commonfmt/src/codecs/jpeg.rs b/nihav-commonfmt/src/codecs/jpeg.rs index 957104c..08f30a7 100644 --- a/nihav-commonfmt/src/codecs/jpeg.rs +++ b/nihav-commonfmt/src/codecs/jpeg.rs @@ -637,9 +637,7 @@ impl NADecoder for JPEGDecoder { std::mem::swap(&mut self.buf, &mut data); let ret = self.decode_scan(&data, buf, &ci[..ns], ss, se); std::mem::swap(&mut self.buf, &mut data); - if let Err(err) = ret { - return Err(err); - } + ret?; } else { unreachable!(); } }, JPEGType::Progressive => { diff --git a/nihav-commonfmt/src/codecs/mod.rs b/nihav-commonfmt/src/codecs/mod.rs index 4c6569e..ad8a8c6 100644 --- a/nihav-commonfmt/src/codecs/mod.rs +++ b/nihav-commonfmt/src/codecs/mod.rs @@ -30,6 +30,7 @@ mod atrac3; mod pcm; #[cfg(feature="decoder_sipro")] #[allow(clippy::collapsible_if)] +#[allow(clippy::collapsible_else_if)] #[allow(clippy::identity_op)] #[allow(clippy::manual_memcpy)] mod sipro; diff --git a/nihav-commonfmt/src/codecs/pcm.rs b/nihav-commonfmt/src/codecs/pcm.rs index b2dd817..c0ef5d3 100644 --- a/nihav-commonfmt/src/codecs/pcm.rs +++ b/nihav-commonfmt/src/codecs/pcm.rs @@ -79,12 +79,12 @@ fn get_default_chmap(nch: u8) -> NAChannelMap { #[cfg(feature="decoder_pcm")] fn get_duration(ainfo: &NAAudioInfo, duration: Option, data_size: usize) -> u64 { - if duration == None { + if let Some(dur) = duration { + dur + } else { let size_bits = (data_size as u64) * 8; let blk_size = u64::from(ainfo.get_channels()) * u64::from(ainfo.get_format().get_bits()); size_bits / blk_size - } else { - duration.unwrap() } } diff --git a/nihav-commonfmt/src/demuxers/mov.rs b/nihav-commonfmt/src/demuxers/mov.rs index 54a6c52..87eb2f1 100644 --- a/nihav-commonfmt/src/demuxers/mov.rs +++ b/nihav-commonfmt/src/demuxers/mov.rs @@ -573,6 +573,7 @@ fn parse_audio_edata(br: &mut ByteReader, start_pos: u64, size: u64) -> DemuxerR } } +#[allow(clippy::neg_cmp_op_on_partial_ord)] fn read_stsd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult { const KNOWN_STSD_SIZE: u64 = 24; validate!(size >= KNOWN_STSD_SIZE); @@ -625,12 +626,12 @@ fn read_stsd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult match depth & 0x1F { 2 => { let mut pal = [0; 1024]; - (&mut pal[..4 * 4]).copy_from_slice(&MOV_DEFAULT_PAL_2BIT); + pal[..4 * 4].copy_from_slice(&MOV_DEFAULT_PAL_2BIT); track.pal = Some(Arc::new(pal)); }, 4 => { let mut pal = [0; 1024]; - (&mut pal[..16 * 4]).copy_from_slice(&MOV_DEFAULT_PAL_4BIT); + pal[..16 * 4].copy_from_slice(&MOV_DEFAULT_PAL_4BIT); track.pal = Some(Arc::new(pal)); }, 8 => { @@ -1276,7 +1277,7 @@ impl Track { for kf_time in self.keyframes.iter() { let pts = tsearch.map_time(*kf_time - 1, &self.time_to_sample); let time = NATimeInfo::ts_to_time(pts, 1000, self.tb_num, self.tb_den); - seek_index.add_entry(self.track_no as u32, SeekEntry { time, pts: u64::from(*kf_time - 1), pos: 0 }); + seek_index.add_entry(self.track_no, SeekEntry { time, pts: u64::from(*kf_time - 1), pos: 0 }); } } fn calculate_chunk_size(&self, nsamp: usize) -> usize { @@ -1409,6 +1410,7 @@ impl Track { } } #[allow(clippy::collapsible_if)] + #[allow(clippy::collapsible_else_if)] fn seek(&mut self, pts: u64, tpoint: NATimePoint) -> DemuxerResult { self.cur_sample = pts as usize; self.samples_left = 0; diff --git a/nihav-commonfmt/src/demuxers/y4m.rs b/nihav-commonfmt/src/demuxers/y4m.rs index 89bf933..3571ea9 100644 --- a/nihav-commonfmt/src/demuxers/y4m.rs +++ b/nihav-commonfmt/src/demuxers/y4m.rs @@ -151,10 +151,8 @@ impl<'a> Y4MDemuxer<'a> { } validate!(self.width > 0 && self.height > 0); self.frame_size = 0; - for chromaton in format.comp_info.iter() { - if let Some(ref chr) = chromaton { - self.frame_size += chr.get_data_size(self.width, self.height); - } + for chr in format.comp_info.iter().flatten() { + self.frame_size += chr.get_data_size(self.width, self.height); } validate!(self.frame_size > 0); diff --git a/nihav-commonfmt/src/lib.rs b/nihav-commonfmt/src/lib.rs index 528b8b7..cdd2cd9 100644 --- a/nihav-commonfmt/src/lib.rs +++ b/nihav-commonfmt/src/lib.rs @@ -9,6 +9,9 @@ extern crate nihav_registry; #[allow(clippy::unreadable_literal)] #[allow(clippy::too_many_arguments)] #[allow(clippy::excessive_precision)] +#[allow(clippy::upper_case_acronyms)] +#[allow(clippy::manual_range_contains)] +#[allow(clippy::collapsible_else_if)] mod codecs; #[cfg(feature="decoders")] diff --git a/nihav-core/src/codecs/mod.rs b/nihav-core/src/codecs/mod.rs index 04d480a..37857d9 100644 --- a/nihav-core/src/codecs/mod.rs +++ b/nihav-core/src/codecs/mod.rs @@ -203,9 +203,10 @@ impl RegisteredMTDecoders { } /// Frame skipping mode for decoders. -#[derive(Clone,Copy,PartialEq,Debug)] +#[derive(Clone,Copy,PartialEq,Debug,Default)] pub enum FrameSkipMode { /// Decode all frames. + #[default] None, /// Decode all key frames. KeyframesOnly, @@ -213,12 +214,6 @@ pub enum FrameSkipMode { IntraOnly, } -impl Default for FrameSkipMode { - fn default() -> Self { - FrameSkipMode::None - } -} - impl FromStr for FrameSkipMode { type Err = DecoderError; diff --git a/nihav-core/src/compr/deflate.rs b/nihav-core/src/compr/deflate.rs index 09e9d8f..9277731 100644 --- a/nihav-core/src/compr/deflate.rs +++ b/nihav-core/src/compr/deflate.rs @@ -210,7 +210,7 @@ impl<'a, S: Copy> CodebookReader for CurrentSource<'a> { let mut lut_bits = cb.lut_bits; let orig_br = self.br; while esc { - let lut_idx = (self.peek(lut_bits) as usize) + (idx as usize); + let lut_idx = (self.peek(lut_bits) as usize) + idx; if cb.table[lut_idx] == TABLE_FILL_VALUE { return Err(CodebookError::InvalidCode); } let bits = cb.table[lut_idx] & 0x7F; esc = (cb.table[lut_idx] & 0x80) != 0; @@ -221,7 +221,7 @@ impl<'a, S: Copy> CodebookReader for CurrentSource<'a> { self.refill(); return Err(CodebookError::MemoryError); } - self.skip(skip_bits as u32).unwrap(); + self.skip(skip_bits).unwrap(); lut_bits = bits as u8; } Ok(cb.syms[idx]) @@ -1918,22 +1918,19 @@ impl LZParse for OptimalParser { } ///! Deflate compression mode. -#[derive(Clone,Copy,Debug,PartialEq)] +#[derive(Clone,Copy,Debug,PartialEq,Default)] pub enum DeflateMode { ///! No compression. NoCompr, ///! Fast compression. Fast, ///! Still fast but better compression. + #[default] Better, ///! Slow but the best compression. Best, } -impl Default for DeflateMode { - fn default() -> Self { DeflateMode::Better } -} - pub const DEFLATE_MODE_DESCRIPTION: &str = "Deflate compression level."; ///! Deflate option for no compression. pub const DEFLATE_MODE_NONE: &str = "none"; diff --git a/nihav-core/src/compr/mod.rs b/nihav-core/src/compr/mod.rs index c8069b5..106b03a 100644 --- a/nihav-core/src/compr/mod.rs +++ b/nihav-core/src/compr/mod.rs @@ -1,5 +1,6 @@ //! Various compression formats support. #[cfg(feature="deflate")] +#[allow(clippy::manual_range_contains)] pub mod deflate; use crate::io::byteio::ByteIOError; @@ -64,7 +65,7 @@ pub fn lz_copy(buf: &mut [u8], dst_pos: usize, offset: usize, len: usize) { let buf = &mut buf[ipos..]; if ipos + len <= dst_pos { let (src, dst) = buf.split_at_mut(offset); - (&mut dst[..len]).copy_from_slice(&src[..len]); + dst[..len].copy_from_slice(&src[..len]); } else { for i in 0..len { buf[offset + i] = buf[i]; diff --git a/nihav-core/src/demuxers/mod.rs b/nihav-core/src/demuxers/mod.rs index 300b6af..08bf8f7 100644 --- a/nihav-core/src/demuxers/mod.rs +++ b/nihav-core/src/demuxers/mod.rs @@ -181,9 +181,10 @@ impl<'a> Iterator for StreamIter<'a> { } /// Seeking modes. -#[derive(Clone,Copy,PartialEq)] +#[derive(Clone,Copy,PartialEq,Default)] pub enum SeekIndexMode { /// No seeking index present. + #[default] None, /// Seeking index is present. Present, @@ -191,10 +192,6 @@ pub enum SeekIndexMode { Automatic, } -impl Default for SeekIndexMode { - fn default() -> Self { SeekIndexMode::None } -} - /// A structure holding seeking information. #[derive(Clone,Copy,Default)] pub struct SeekEntry { @@ -309,12 +306,7 @@ impl SeekIndex { } /// Returns stream reference for provided stream ID. pub fn get_stream_index(&mut self, id: u32) -> Option<&mut StreamSeekInfo> { - for stream in self.seek_info.iter_mut() { - if stream.id == id { - return Some(stream); - } - } - None + self.seek_info.iter_mut().find(|stream| stream.id == id) } /// Adds seeking information to the index. pub fn add_entry(&mut self, id: u32, entry: SeekEntry) { @@ -498,12 +490,7 @@ impl RegisteredDemuxers { } /// Searches for a demuxer that supports requested container format. pub fn find_demuxer(&self, name: &str) -> Option<&dyn DemuxerCreator> { - for &dmx in self.dmxs.iter() { - if dmx.get_name() == name { - return Some(dmx); - } - } - None + self.dmxs.iter().find(|&&dmx| dmx.get_name() == name).copied() } /// Provides an iterator over currently registered demuxers. pub fn iter(&self) -> std::slice::Iter<&dyn DemuxerCreator> { @@ -674,12 +661,7 @@ impl RegisteredRawDemuxers { } /// Searches for a demuxer that supports requested container format. pub fn find_demuxer(&self, name: &str) -> Option<&dyn RawDemuxerCreator> { - for &dmx in self.dmxs.iter() { - if dmx.get_name() == name { - return Some(dmx); - } - } - None + self.dmxs.iter().find(|&&dmx| dmx.get_name() == name).copied() } /// Provides an iterator over currently registered demuxers. pub fn iter(&self) -> std::slice::Iter<&dyn RawDemuxerCreator> { diff --git a/nihav-core/src/formats.rs b/nihav-core/src/formats.rs index 810fff2..fdb7a1b 100644 --- a/nihav-core/src/formats.rs +++ b/nihav-core/src/formats.rs @@ -315,7 +315,7 @@ impl fmt::Display for NAChannelMap { let mut map = String::new(); for el in self.ids.iter() { if !map.is_empty() { map.push(','); } - map.push_str(&*el.to_string()); + map.push_str(&el.to_string()); } write!(f, "{}", map) } @@ -660,41 +660,33 @@ impl NAPixelFormaton { /// Reports whether the format is not packed. pub fn is_unpacked(&self) -> bool { if self.palette { return false; } - for chr in self.comp_info.iter() { - if let Some(ref chromaton) = chr { - if chromaton.is_packed() { return false; } - } + for chromaton in self.comp_info.iter().flatten() { + if chromaton.is_packed() { return false; } } true } /// Returns the maximum component bit depth. pub fn get_max_depth(&self) -> u8 { let mut mdepth = 0; - for chr in self.comp_info.iter() { - if let Some(ref chromaton) = chr { - mdepth = mdepth.max(chromaton.depth); - } + for chromaton in self.comp_info.iter().flatten() { + mdepth = mdepth.max(chromaton.depth); } mdepth } /// Returns the total amount of bits needed for components. pub fn get_total_depth(&self) -> u8 { let mut depth = 0; - for chr in self.comp_info.iter() { - if let Some(ref chromaton) = chr { - depth += chromaton.depth; - } + for chromaton in self.comp_info.iter().flatten() { + depth += chromaton.depth; } depth } /// Returns the maximum component subsampling. pub fn get_max_subsampling(&self) -> u8 { let mut ssamp = 0; - for chr in self.comp_info.iter() { - if let Some(ref chromaton) = chr { - let (ss_v, ss_h) = chromaton.get_subsampling(); - ssamp = ssamp.max(ss_v).max(ss_h); - } + for chromaton in self.comp_info.iter().flatten() { + let (ss_v, ss_h) = chromaton.get_subsampling(); + ssamp = ssamp.max(ss_v).max(ss_h); } ssamp } @@ -716,12 +708,10 @@ impl NAPixelFormaton { let mut start_off = 0; let mut start_shift = 0; let mut use_shift = true; - for comp in self.comp_info.iter() { - if let Some(comp) = comp { - start_off = start_off.min(comp.comp_offs); - start_shift = start_shift.min(comp.shift); - if comp.comp_offs != 0 { use_shift = false; } - } + for comp in self.comp_info.iter().flatten() { + start_off = start_off.min(comp.comp_offs); + start_shift = start_shift.min(comp.shift); + if comp.comp_offs != 0 { use_shift = false; } } for component in 0..(self.components as usize) { for (comp, cname) in self.comp_info.iter().zip(b"rgba".iter()) { @@ -1017,7 +1007,7 @@ fn parse_yuv_format(s: &str) -> Result { let mut parse_end = components as usize; for ch in s.chars().skip(components as usize) { parse_end += 1; - if ('0'..='9').contains(&ch) { + if ch.is_ascii_digit() { format = format * 10 + u32::from((ch as u8) - b'0'); if format > 444 { return Err(FormatParseError {}); } } else { @@ -1029,7 +1019,7 @@ fn parse_yuv_format(s: &str) -> Result { let depth = if s.len() == parse_end { 8 } else { let mut val = 0; for ch in s.chars().skip(parse_end) { - if ('0'..='9').contains(&ch) { + if ch.is_ascii_digit() { val = val * 10 + ((ch as u8) - b'0'); if val > 16 { return Err(FormatParseError {}); } } else { diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index 10db18d..1bf5dec 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -65,9 +65,9 @@ impl NAVideoInfo { NAVideoInfo { width: w, height: h, flipped: flip, format: fmt, bits } } /// Returns picture width. - pub fn get_width(&self) -> usize { self.width as usize } + pub fn get_width(&self) -> usize { self.width } /// Returns picture height. - pub fn get_height(&self) -> usize { self.height as usize } + pub fn get_height(&self) -> usize { self.height } /// Returns picture orientation. pub fn is_flipped(&self) -> bool { self.flipped } /// Returns picture pixel format. @@ -535,12 +535,12 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result = Vec::new(); for i in 0..fmt.get_num_comp() { - if fmt.get_chromaton(i) == None { return Err(AllocatorError::FormatError); } + if fmt.get_chromaton(i).is_none() { return Err(AllocatorError::FormatError); } } let align_mod = ((1 << align) as usize) - 1; - let width = ((vinfo.width as usize) + align_mod) & !align_mod; - let height = ((vinfo.height as usize) + align_mod) & !align_mod; + let width = (vinfo.width + align_mod) & !align_mod; + let height = (vinfo.height + align_mod) & !align_mod; let mut max_depth = 0; let mut all_packed = true; let mut all_bytealigned = true; @@ -562,10 +562,10 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result Result Result = vec![0; new_size]; strides.push(line_sz.unwrap()); @@ -614,7 +614,7 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result { @@ -636,11 +636,12 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result Result { let mut offs: Vec = Vec::new(); if ainfo.format.is_planar() || ((ainfo.format.get_bits() % 8) == 0) { let len = nsamples.checked_mul(ainfo.channels as usize); - if len == None { return Err(AllocatorError::TooLargeDimensions); } + if len.is_none() { return Err(AllocatorError::TooLargeDimensions); } let length = len.unwrap(); let stride; let step; @@ -684,7 +685,7 @@ pub fn alloc_audio_buffer(ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelM } } else { let len = nsamples.checked_mul(ainfo.channels as usize); - if len == None { return Err(AllocatorError::TooLargeDimensions); } + if len.is_none() { return Err(AllocatorError::TooLargeDimensions); } let length = ainfo.format.get_audio_size(len.unwrap() as u64); let data: Vec = vec![0; length]; let buf: NAAudioBuffer = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples, stride: 0, step: 0 }; @@ -957,6 +958,7 @@ impl NATimeInfo { /// Converts time in given scale into timestamp in given base. #[allow(clippy::collapsible_if)] + #[allow(clippy::collapsible_else_if)] pub fn time_to_ts(time: u64, base: u64, tb_num: u32, tb_den: u32) -> u64 { let tb_num = u64::from(tb_num); let tb_den = u64::from(tb_den); @@ -1032,22 +1034,17 @@ impl NATimeInfo { } /// Time information for specifying durations or seek positions. -#[derive(Clone,Copy,Debug,PartialEq)] +#[derive(Clone,Copy,Debug,PartialEq,Default)] pub enum NATimePoint { /// Time in milliseconds. Milliseconds(u64), /// Stream timestamp. PTS(u64), /// No time information present. + #[default] None, } -impl Default for NATimePoint { - fn default() -> Self { - NATimePoint::None - } -} - impl fmt::Display for NATimePoint { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { @@ -1149,7 +1146,7 @@ impl FromStr for NATimePoint { let mut mval = 0; let mut base = 0; for ch in val.chars() { - if ('0'..='9').contains(&ch) { + if ch.is_ascii_digit() { mval = mval * 10 + u64::from((ch as u8) - b'0'); base += 1; if base > 3 { break; } diff --git a/nihav-core/src/io/bitreader.rs b/nihav-core/src/io/bitreader.rs index c4f9f6c..b5f8de6 100644 --- a/nihav-core/src/io/bitreader.rs +++ b/nihav-core/src/io/bitreader.rs @@ -227,7 +227,7 @@ impl<'a> BitReader<'a> { if nbits == 0 { return Ok(0) } if nbits > 32 { return Err(TooManyBitsRequested) } if self.bits < nbits { - if let Err(err) = self.refill() { return Err(err) } + self.refill()?; if self.bits < nbits { return Err(BitstreamEnd) } } let res = self.read_cache(nbits); @@ -243,7 +243,7 @@ impl<'a> BitReader<'a> { pub fn read_s(&mut self, nbits: u8) -> BitReaderResult { if nbits == 0 || nbits > 32 { return Err(TooManyBitsRequested) } if self.bits < nbits { - if let Err(err) = self.refill() { return Err(err) } + self.refill()?; if self.bits < nbits { return Err(BitstreamEnd) } } let res = self.read_cache_s(nbits); @@ -255,7 +255,7 @@ impl<'a> BitReader<'a> { #[inline(always)] pub fn read_bool(&mut self) -> BitReaderResult { if self.bits < 1 { - if let Err(err) = self.refill() { return Err(err) } + self.refill()?; if self.bits < 1 { return Err(BitstreamEnd) } } let res = self.read_cache(1); diff --git a/nihav-core/src/io/bitwriter.rs b/nihav-core/src/io/bitwriter.rs index 4447567..4f3c39c 100644 --- a/nihav-core/src/io/bitwriter.rs +++ b/nihav-core/src/io/bitwriter.rs @@ -77,6 +77,7 @@ impl BitWriter { } /// Writes `bits` bits of `val` value to the output. #[allow(clippy::collapsible_if)] + #[allow(clippy::collapsible_else_if)] pub fn write(&mut self, val: u32, bits: u8) { if bits == 0 { return; diff --git a/nihav-core/src/io/byteio.rs b/nihav-core/src/io/byteio.rs index 0ff54cb..61b8816 100644 --- a/nihav-core/src/io/byteio.rs +++ b/nihav-core/src/io/byteio.rs @@ -624,7 +624,7 @@ impl ByteIO for FileReader { } fn tell(&mut self) -> u64 { - self.file.seek(SeekFrom::Current(0)).unwrap() + self.file.stream_position().unwrap() } fn seek(&mut self, pos: SeekFrom) -> ByteIOResult { @@ -681,7 +681,7 @@ impl BoundedFileReader { /// Destroys the reader and releases the reader resource for a further use. pub fn finish(self) -> Box { self.file } fn real_tell(&mut self) -> u64 { - self.file.seek(SeekFrom::Current(0)).unwrap() + self.file.stream_position().unwrap() } fn max_read_len(&mut self, len: usize) -> usize { if let Some(epos) = self.end { @@ -779,7 +779,7 @@ impl ByteIO for BoundedFileReader { } fn tell(&mut self) -> u64 { - self.file.seek(SeekFrom::Current(0)).unwrap() - self.start + self.file.stream_position().unwrap() - self.start } fn seek(&mut self, pos: SeekFrom) -> ByteIOResult { @@ -1188,7 +1188,7 @@ impl ByteIO for FileWriter { } fn tell(&mut self) -> u64 { - self.file.seek(SeekFrom::Current(0)).unwrap() + self.file.stream_position().unwrap() } fn seek(&mut self, pos: SeekFrom) -> ByteIOResult { diff --git a/nihav-core/src/io/codebook.rs b/nihav-core/src/io/codebook.rs index 6ea3b1e..f533cb2 100644 --- a/nihav-core/src/io/codebook.rs +++ b/nihav-core/src/io/codebook.rs @@ -271,7 +271,7 @@ fn build_esc_lut(table: &mut Vec, let cur_offset = bucket.offset; for (ckey, sec_bucket) in &mut escape_list { - let key = *ckey as u32; + let key = *ckey; let maxlen = min(sec_bucket.maxlen, MAX_LUT_BITS); let new_off = resize_table(table, maxlen)?; fill_lut(table, mode, cur_offset, key, maxlen, @@ -366,7 +366,7 @@ impl<'a, S: Copy> CodebookReader for BitReader<'a> { let mut idx = 0; let mut lut_bits = cb.lut_bits; while esc { - let lut_idx = (self.peek(lut_bits) as usize) + (idx as usize); + let lut_idx = (self.peek(lut_bits) as usize) + idx; if cb.table[lut_idx] == TABLE_FILL_VALUE { return Err(CodebookError::InvalidCode); } let bits = cb.table[lut_idx] & 0x7F; esc = (cb.table[lut_idx] & 0x80) != 0; @@ -375,7 +375,7 @@ impl<'a, S: Copy> CodebookReader for BitReader<'a> { if (skip_bits as isize) > self.left() { return Err(CodebookError::InvalidCode); } - self.skip(skip_bits as u32).unwrap(); + self.skip(skip_bits).unwrap(); lut_bits = bits as u8; } Ok(cb.syms[idx]) diff --git a/nihav-core/src/lib.rs b/nihav-core/src/lib.rs index d9eab81..b6e1690 100644 --- a/nihav-core/src/lib.rs +++ b/nihav-core/src/lib.rs @@ -1,5 +1,6 @@ //! Core functionality of NihAV intended to be used by both crates implementing format support and users. #[cfg(feature="decoders")] +#[allow(clippy::upper_case_acronyms)] #[allow(clippy::cast_lossless)] #[allow(clippy::identity_op)] #[allow(clippy::too_many_arguments)] @@ -26,6 +27,7 @@ pub mod io; pub mod options; pub mod refs; pub mod reorder; +#[allow(clippy::upper_case_acronyms)] #[allow(clippy::collapsible_if)] #[allow(clippy::many_single_char_names)] #[allow(clippy::needless_range_loop)] diff --git a/nihav-core/src/muxers/mod.rs b/nihav-core/src/muxers/mod.rs index e8334e5..eb71df5 100644 --- a/nihav-core/src/muxers/mod.rs +++ b/nihav-core/src/muxers/mod.rs @@ -157,12 +157,7 @@ impl RegisteredMuxers { } /// Searches for a muxer that supports requested container format. pub fn find_muxer(&self, name: &str) -> Option<&dyn MuxerCreator> { - for &mux in self.muxes.iter() { - if mux.get_name() == name { - return Some(mux); - } - } - None + self.muxes.iter().find(|&&mux| mux.get_name() == name).copied() } /// Provides an iterator over currently registered muxers. pub fn iter(&self) -> std::slice::Iter<&dyn MuxerCreator> { diff --git a/nihav-core/src/reorder.rs b/nihav-core/src/reorder.rs index 8f02afd..9337b9a 100644 --- a/nihav-core/src/reorder.rs +++ b/nihav-core/src/reorder.rs @@ -226,6 +226,7 @@ impl MTFrameReorderer { } /// Gets the next frame to be displayed (or `None` if that is not possible). #[allow(clippy::collapsible_if)] + #[allow(clippy::collapsible_else_if)] pub fn get_frame(&mut self) -> Option { // check if we have consequent timestamps that we can output if !self.frames.is_empty() { @@ -255,7 +256,7 @@ impl MTFrameReorderer { } let end = self.ids.iter().position(|&id| id == kf_id).unwrap(); for ref_id in self.ids[..end].iter() { - if self.frames.iter().position(|(id, _)| id == ref_id).is_none() { + if !self.frames.iter().any(|(id, _)| id == ref_id) { return None; } } diff --git a/nihav-core/src/scale/mod.rs b/nihav-core/src/scale/mod.rs index a79232d..4fbf3e6 100644 --- a/nihav-core/src/scale/mod.rs +++ b/nihav-core/src/scale/mod.rs @@ -187,7 +187,7 @@ fn copy(pic_in: &NABufferType, pic_out: &mut NABufferType) let dst = &mut ddata[doff..]; let copy_size = sstride.min(dstride); for (dline, sline) in dst.chunks_exact_mut(dstride).take(h).zip(src.chunks_exact(sstride)) { - (&mut dline[..copy_size]).copy_from_slice(&sline[..copy_size]); + dline[..copy_size].copy_from_slice(&sline[..copy_size]); } } } @@ -220,7 +220,7 @@ fn copy(pic_in: &NABufferType, pic_out: &mut NABufferType) let dst = &mut ddata[doff..]; let copy_size = sstride.min(dstride); for (dline, sline) in dst.chunks_exact_mut(dstride).take(h).zip(src.chunks_exact(sstride)) { - (&mut dline[..copy_size]).copy_from_slice(&sline[..copy_size]); + dline[..copy_size].copy_from_slice(&sline[..copy_size]); } } } @@ -363,8 +363,8 @@ fn swap_plane(data: &mut [T], stride: usize, h: usize, line0: &mut [T], for _ in 0..h/2 { line0.copy_from_slice(&data[doff0..][..stride]); line1.copy_from_slice(&data[doff1..][..stride]); - (&mut data[doff1..][..stride]).copy_from_slice(line0); - (&mut data[doff0..][..stride]).copy_from_slice(line1); + data[doff1..][..stride].copy_from_slice(line0); + data[doff0..][..stride].copy_from_slice(line1); doff0 += stride; doff1 -= stride; } diff --git a/nihav-core/src/scale/palette/mediancut.rs b/nihav-core/src/scale/palette/mediancut.rs index 64281ef..b8fb7d6 100644 --- a/nihav-core/src/scale/palette/mediancut.rs +++ b/nihav-core/src/scale/palette/mediancut.rs @@ -47,7 +47,7 @@ impl<'a> VQBox<'a> { pivot = start + end; cand1 = start; } - (&mut arr[start..][..end]).copy_from_slice(bucket.as_slice()); + arr[start..][..end].copy_from_slice(bucket.as_slice()); start += end; } for bucket in buckets.iter() { diff --git a/nihav-core/src/scale/palette/mod.rs b/nihav-core/src/scale/palette/mod.rs index f70300f..12c2947 100644 --- a/nihav-core/src/scale/palette/mod.rs +++ b/nihav-core/src/scale/palette/mod.rs @@ -45,12 +45,13 @@ mod palettise; //use mediancut::quantise_median_cut; //use neuquant::NeuQuantQuantiser; -#[derive(Clone,Copy,Debug,PartialEq)] +#[derive(Clone,Copy,Debug,PartialEq,Default)] /// Palette quantisation algorithms. pub enum QuantisationMode { /// Median cut approach proposed by Paul Heckbert. /// /// This is moderately fast and moderately good. + #[default] MedianCut, /// Enhanced LBG algorithm proposed by Giuseppe Patane and Marco Russo. /// @@ -63,25 +64,18 @@ pub enum QuantisationMode { NeuQuant(u8), } -impl Default for QuantisationMode { - fn default() -> Self { QuantisationMode::MedianCut } -} - -#[derive(Clone,Copy,Debug,PartialEq)] +#[derive(Clone,Copy,Debug,PartialEq,Default)] /// Algorithms for seaching an appropriate palette entry for a given pixel. pub enum PaletteSearchMode { /// Full search (slowest). Full, /// Local search (faster but may be not so good). + #[default] Local, /// k-d tree based one (the fastest but not so accurate). KDTree, } -impl Default for PaletteSearchMode { - fn default() -> Self { PaletteSearchMode::Local } -} - use crate::scale::palette::elbg::ELBG; use crate::scale::palette::mediancut::quantise_median_cut; use crate::scale::palette::neuquant::NeuQuantQuantiser; @@ -146,7 +140,7 @@ fn palettise_frame_internal(pic_in: &NABufferType, pic_out: &mut NABufferType, q }; let esize = ofmt.elem_size as usize; let coffs = [ofmt.comp_info[0].unwrap().comp_offs as usize, ofmt.comp_info[1].unwrap().comp_offs as usize, ofmt.comp_info[2].unwrap().comp_offs as usize]; - for (dpal, spal) in (&mut dst[paloff..]).chunks_mut(esize).zip(pal.iter()) { + for (dpal, spal) in dst[paloff..].chunks_mut(esize).zip(pal.iter()) { dpal[coffs[0]] = spal[0]; dpal[coffs[1]] = spal[1]; dpal[coffs[2]] = spal[2]; diff --git a/nihav-core/src/scale/scale/mod.rs b/nihav-core/src/scale/scale/mod.rs index ae39ef3..5d0776d 100644 --- a/nihav-core/src/scale/scale/mod.rs +++ b/nihav-core/src/scale/scale/mod.rs @@ -221,8 +221,8 @@ impl LanczosResize { let a = order as f32; for i in 0..(order * 2) { let x = frac - ((i as f32) + 1.0 - a); - let fp = std::f32::consts::PI * (x as f32); - coeffs[i] = a * fp.sin() * (fp / a).sin() / (norm * (x as f32) * (x as f32)); + let fp = std::f32::consts::PI * x; + coeffs[i] = a * fp.sin() * (fp / a).sin() / (norm * x * x); } } fn create_cache(order: usize, den: usize) -> Vec> { diff --git a/nihav-duck/src/codecs/on2avc.rs b/nihav-duck/src/codecs/on2avc.rs index 8a34655..9a0e0cd 100644 --- a/nihav-duck/src/codecs/on2avc.rs +++ b/nihav-duck/src/codecs/on2avc.rs @@ -355,7 +355,7 @@ impl AVCDecoder { 0 | 1 => { self.imdct_long.imdct_half(coeffs, &mut self.tmp); overlap_half(dst, &self.tmp, delay, self.win_long); - (&mut delay[0..COEFFS/2]).copy_from_slice(&self.tmp[COEFFS/2..COEFFS]); + delay[0..COEFFS/2].copy_from_slice(&self.tmp[COEFFS/2..COEFFS]); for i in COEFFS/2..COEFFS { delay[i] = delay[COEFFS - 1 - i]; } @@ -657,12 +657,12 @@ fn synth_recursive(dst: &mut [f32], tmp: &mut [f32], size: usize, order: &[u8], let idx = if !dir { i } else { bands - 1 - i }; synth_filter(src, tmp, size, step, bands, idx); } - (&mut dst[..size]).copy_from_slice(&tmp[..size]); + dst[..size].copy_from_slice(&tmp[..size]); } fn synth_generic(src: &[f32], dst: &mut [f32], tmpbuf: &mut [f32; COEFFS * 2], is_40khz: bool, size: usize) { let order = if is_40khz { MERGE_ORDER_40K } else { MERGE_ORDER_44K }; - (&mut dst[..size]).copy_from_slice(&src[..size]); + dst[..size].copy_from_slice(&src[..size]); let mut order_idx = 0; synth_recursive(dst, tmpbuf, size, order, &mut order_idx, false); for el in dst.iter_mut().take(COEFFS) { *el *= 0.125; } @@ -908,7 +908,7 @@ fn dequant(val: i16, qtab: &[f32; QTAB_SIZE], scale: f32) -> f32 { if val >= 0 { qtab[val as usize] * scale } else { - -qtab[val.abs() as usize] * scale + -qtab[val.unsigned_abs() as usize] * scale } } diff --git a/nihav-duck/src/codecs/truemotion1enc.rs b/nihav-duck/src/codecs/truemotion1enc.rs index 72553b5..d582d1e 100644 --- a/nihav-duck/src/codecs/truemotion1enc.rs +++ b/nihav-duck/src/codecs/truemotion1enc.rs @@ -3,20 +3,15 @@ use nihav_core::codecs::*; use nihav_core::io::byteio::*; use super::truemotion1data::*; -#[derive(Clone,Copy,PartialEq)] +#[derive(Clone,Copy,PartialEq,Default)] enum BlockMode { FourByFour, + #[default] TwoByTwo, FourByTwo, TwoByFour, } -impl Default for BlockMode { - fn default() -> Self { - BlockMode::TwoByTwo - } -} - impl FromStr for BlockMode { type Err = (); fn from_str(s: &str) -> Result { @@ -41,19 +36,14 @@ impl ToString for BlockMode { } } -#[derive(Clone,Copy,PartialEq)] +#[derive(Clone,Copy,PartialEq,Default)] enum OptionMode { Off, On, + #[default] Auto, } -impl Default for OptionMode { - fn default() -> Self { - OptionMode::Auto - } -} - impl FromStr for OptionMode { type Err = (); fn from_str(s: &str) -> Result { @@ -518,7 +508,7 @@ impl TM1Encoder { pair[1] = self.prev_frame[x * 2 + 1 + y * self.width]; hpred[0] = pair[0] - vpred[0]; hpred[1] = pair[1] - vpred[1]; - vpred.copy_from_slice(&pair); + vpred.copy_from_slice(pair); continue; } let pval = [vpred[0] + hpred[0], vpred[1] + hpred[1]]; diff --git a/nihav-duck/src/codecs/vp3.rs b/nihav-duck/src/codecs/vp3.rs index cf59b14..08bfd1a 100644 --- a/nihav-duck/src/codecs/vp3.rs +++ b/nihav-duck/src/codecs/vp3.rs @@ -1141,8 +1141,8 @@ impl VP34Decoder { if let Some(ref codes) = self.aux_codes { for _ in 0..self.y_blocks/4 { if self.blocks[self.blk_addr[cur_blk] >> 2].btype == VPMBType::InterFourMV { - let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.abs() as usize]]; - let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.abs() as usize]]; + let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.unsigned_abs() as usize]]; + let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.unsigned_abs() as usize]]; let x_sign = last_mv.x < 0; let y_sign = last_mv.y < 0; last2_mv = last_mv; @@ -1167,8 +1167,8 @@ impl VP34Decoder { cur_mv = ZERO_MV; }, VPMBType::InterMV => { - let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.abs() as usize]]; - let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.abs() as usize]]; + let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv.x.unsigned_abs() as usize]]; + let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv.y.unsigned_abs() as usize]]; let x_sign = last_mv.x < 0; let y_sign = last_mv.y < 0; let x = i16::from(br.read_cb(x_cb)?); @@ -1185,8 +1185,8 @@ impl VP34Decoder { std::mem::swap(&mut last_mv, &mut last2_mv); }, _ => { // GoldenMV - let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv_g.x.abs() as usize]]; - let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv_g.y.abs() as usize]]; + let x_cb = &codes.mv_x_cb[VP40_MV_LUT_INDEX[last_mv_g.x.unsigned_abs() as usize]]; + let y_cb = &codes.mv_y_cb[VP40_MV_LUT_INDEX[last_mv_g.y.unsigned_abs() as usize]]; let x_sign = last_mv_g.x < 0; let y_sign = last_mv_g.y < 0; let x = i16::from(br.read_cb(x_cb)?); @@ -1466,7 +1466,7 @@ impl VP34Decoder { let mut pred = 0i32; for i in 0..4 { if (pp & (1 << i)) != 0 { - pred += (preds[i] as i32) * i32::from(VP31_DC_WEIGHTS[pp][i]); + pred += preds[i] * i32::from(VP31_DC_WEIGHTS[pp][i]); } } pred /= i32::from(VP31_DC_WEIGHTS[pp][4]); @@ -1501,7 +1501,7 @@ impl VP34Decoder { let mut npred = 0; for i in 0..4 { if (pp & (1 << i)) != 0 { - pred += preds[i] as i32; + pred += preds[i]; npred += 1; if npred == 2 { return (pred / 2) as i16; diff --git a/nihav-duck/src/codecs/vp56.rs b/nihav-duck/src/codecs/vp56.rs index 2ab474b..5abea84 100644 --- a/nihav-duck/src/codecs/vp56.rs +++ b/nihav-duck/src/codecs/vp56.rs @@ -531,9 +531,7 @@ impl VP56Decoder { std::mem::swap(&mut self.models, &mut self.amodels); let ret = self.decode_planes(br, &mut dframe, &mut bc, &ahdr, asrc, true); std::mem::swap(&mut self.models, &mut self.amodels); - if let Err(err) = ret { - return Err(err); - } + ret?; match (hdr.is_golden, ahdr.is_golden) { (true, true) => { self.shuf.add_golden_frame(buf.clone()); }, (true, false) => { @@ -699,16 +697,16 @@ impl VP56Decoder { 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); - let gold_mv0_weight = (cnt[5] as u32) + (cnt[6] as u32); - let gold_mv1_weight = (cnt[8] as u32) + (cnt[9] as u32); - let mix_weight = (cnt[1] as u32) + (cnt[7] as u32); + let inter_mv0_weight = cnt[0] + cnt[2]; + let inter_mv1_weight = cnt[3] + cnt[4]; + let gold_mv0_weight = cnt[5] + cnt[6]; + let gold_mv1_weight = cnt[8] + cnt[9]; + let mix_weight = cnt[1] + cnt[7]; mdl.probs[0] = 1 + rescale_mb_mode_prob(inter_mv0_weight + inter_mv1_weight, total); mdl.probs[1] = 1 + rescale_mb_mode_prob(inter_mv0_weight, inter_mv0_weight + inter_mv1_weight); mdl.probs[2] = 1 + rescale_mb_mode_prob(mix_weight, mix_weight + gold_mv0_weight + gold_mv1_weight); - mdl.probs[3] = 1 + rescale_mb_mode_prob(cnt[0] as u32, inter_mv0_weight); - mdl.probs[4] = 1 + rescale_mb_mode_prob(cnt[3] as u32, inter_mv1_weight); + mdl.probs[3] = 1 + rescale_mb_mode_prob(cnt[0], inter_mv0_weight); + mdl.probs[4] = 1 + rescale_mb_mode_prob(cnt[3], inter_mv1_weight); mdl.probs[5] = 1 + rescale_mb_mode_prob(cnt[1], mix_weight); mdl.probs[6] = 1 + rescale_mb_mode_prob(gold_mv0_weight, gold_mv0_weight + gold_mv1_weight); mdl.probs[7] = 1 + rescale_mb_mode_prob(cnt[5], gold_mv0_weight); diff --git a/nihav-duck/src/codecs/vp6.rs b/nihav-duck/src/codecs/vp6.rs index 4bbf4c9..916711c 100644 --- a/nihav-duck/src/codecs/vp6.rs +++ b/nihav-duck/src/codecs/vp6.rs @@ -54,7 +54,6 @@ impl VP56Parser for VP6BR { hdr.multistream = true; } let bytes = br.tell() >> 3; - std::mem::drop(br); bc.skip_bytes(bytes); self.loop_mode = 0; if hdr.is_intra { diff --git a/nihav-duck/src/codecs/vp6enc/coder.rs b/nihav-duck/src/codecs/vp6enc/coder.rs index cb0904f..a88b0e2 100644 --- a/nihav-duck/src/codecs/vp6enc/coder.rs +++ b/nihav-duck/src/codecs/vp6enc/coder.rs @@ -199,16 +199,16 @@ fn calc_mb_model_probs(prob_xmitted: &[u8; 20], mbtype_models: &mut [VP56MBTypeM 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); - let gold_mv0_weight = (cnt[5] as u32) + (cnt[6] as u32); - let gold_mv1_weight = (cnt[8] as u32) + (cnt[9] as u32); - let mix_weight = (cnt[1] as u32) + (cnt[7] as u32); + let inter_mv0_weight = cnt[0] + cnt[2]; + let inter_mv1_weight = cnt[3] + cnt[4]; + let gold_mv0_weight = cnt[5] + cnt[6]; + let gold_mv1_weight = cnt[8] + cnt[9]; + let mix_weight = cnt[1] + cnt[7]; mdl.probs[0] = 1 + rescale_mb_mode_prob(inter_mv0_weight + inter_mv1_weight, total); mdl.probs[1] = 1 + rescale_mb_mode_prob(inter_mv0_weight, inter_mv0_weight + inter_mv1_weight); mdl.probs[2] = 1 + rescale_mb_mode_prob(mix_weight, mix_weight + gold_mv0_weight + gold_mv1_weight); - mdl.probs[3] = 1 + rescale_mb_mode_prob(cnt[0] as u32, inter_mv0_weight); - mdl.probs[4] = 1 + rescale_mb_mode_prob(cnt[3] as u32, inter_mv1_weight); + mdl.probs[3] = 1 + rescale_mb_mode_prob(cnt[0], inter_mv0_weight); + mdl.probs[4] = 1 + rescale_mb_mode_prob(cnt[3], inter_mv1_weight); mdl.probs[5] = 1 + rescale_mb_mode_prob(cnt[1], mix_weight); mdl.probs[6] = 1 + rescale_mb_mode_prob(gold_mv0_weight, gold_mv0_weight + gold_mv1_weight); mdl.probs[7] = 1 + rescale_mb_mode_prob(cnt[5], gold_mv0_weight); @@ -341,7 +341,7 @@ pub fn encode_mode_prob_models(bc: &mut BoolEncoder, models: &mut VP56Models, pm bc.put_bool(diff < 0, 128)?; bc.write_el(d0, MODE_TREE_DIFF, MODE_TREE_DIFF_PROBS)?; if d0 == 7 { - bc.put_bits(diff.abs() as u32, 7)?; + bc.put_bits(u32::from(diff.unsigned_abs()), 7)?; } tprob[i ^ 1] = (i16::from(tprob[i ^ 1]) + deltas[i ^ 1]) as u8; } diff --git a/nihav-duck/src/codecs/vp6enc/dsp.rs b/nihav-duck/src/codecs/vp6enc/dsp.rs index 2651458..90c76b9 100644 --- a/nihav-duck/src/codecs/vp6enc/dsp.rs +++ b/nihav-duck/src/codecs/vp6enc/dsp.rs @@ -326,7 +326,7 @@ impl MVEstimator { fn sad(src1: &[u8; 64], src2: &[u8; 64]) -> u32 { let mut sum = 0; for (&p1, &p2) in src1.iter().zip(src2.iter()) { - sum += (i32::from(p1) - i32::from(p2)).abs() as u32; + sum += (i32::from(p1) - i32::from(p2)).unsigned_abs(); } sum } @@ -341,7 +341,7 @@ pub fn calc_mb_dist(mb1: &ResidueMB, mb2: &ResidueMB) -> u32 { let mut sum = 0; for (blk1, blk2) in mb1.coeffs.iter().zip(mb2.coeffs.iter()) { for (&c1, &c2) in blk1.iter().zip(blk2.iter()) { - sum += (i32::from(c1) - i32::from(c2)).abs() as u32; + sum += (i32::from(c1) - i32::from(c2)).unsigned_abs(); } } sum diff --git a/nihav-duck/src/codecs/vp6enc/mb.rs b/nihav-duck/src/codecs/vp6enc/mb.rs index cd33f12..cece9d1 100644 --- a/nihav-duck/src/codecs/vp6enc/mb.rs +++ b/nihav-duck/src/codecs/vp6enc/mb.rs @@ -341,7 +341,7 @@ impl FrameEncoder { } } pub fn estimate_mvs(&mut self, ref_frame: NAVideoBufferRef, mc_buf: NAVideoBufferRef, golden: bool) { - let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant as usize]); + let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant]); let inter_mbs = if !golden { &mut self.inter_mbs } else { &mut self.golden_mbs }; @@ -384,7 +384,7 @@ impl FrameEncoder { } } fn estimate_fourmv(&mut self, ref_frame: NAVideoBufferRef, mc_buf: NAVideoBufferRef, mb_x: usize, mb_y: usize) -> bool { - let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant as usize]); + let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant]); if self.fourmv_mbs.is_empty() { for _ in 0..self.mb_w * self.mb_h { @@ -526,7 +526,7 @@ impl FrameEncoder { } } pub fn select_inter_blocks_fast(&mut self, ref_frame: NAVideoBufferRef, gold_frame: Option>, mc_buf: NAVideoBufferRef, lambda: f32) { - let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant as usize]); + let loop_thr = i16::from(VP56_FILTER_LIMITS[self.quant]); if self.inter_mbs.is_empty() { for _ in 0..self.mb_w * self.mb_h { diff --git a/nihav-duck/src/codecs/vp7.rs b/nihav-duck/src/codecs/vp7.rs index 5ca88c0..3b2d854 100644 --- a/nihav-duck/src/codecs/vp7.rs +++ b/nihav-duck/src/codecs/vp7.rs @@ -204,6 +204,7 @@ impl VP7Decoder { self.pcache.resize(self.mb_w); } + #[allow(clippy::field_reassign_with_default)] fn read_features(&mut self, bc: &mut BoolCoder) -> DecoderResult<()> { for (i, feat) in self.dstate.features.iter_mut().enumerate() { if bc.read_bool() { diff --git a/nihav-duck/src/codecs/vp78.rs b/nihav-duck/src/codecs/vp78.rs index b0b7672..4ec79d1 100644 --- a/nihav-duck/src/codecs/vp78.rs +++ b/nihav-duck/src/codecs/vp78.rs @@ -25,8 +25,9 @@ impl<'a> VPTreeReader for BoolCoder<'a> { } #[repr(u8)] -#[derive(Clone,Copy,PartialEq,Debug)] +#[derive(Clone,Copy,PartialEq,Debug,Default)] pub enum PredMode { + #[default] DCPred, HPred, VPred, @@ -44,10 +45,6 @@ pub enum PredMode { Inter, } -impl Default for PredMode { - fn default() -> Self { PredMode::DCPred } -} - impl PredMode { pub fn to_b_mode(self) -> Self { if self == PredMode::DCPred { diff --git a/nihav-duck/src/codecs/vp78dsp.rs b/nihav-duck/src/codecs/vp78dsp.rs index e69a5ab..9d68616 100644 --- a/nihav-duck/src/codecs/vp78dsp.rs +++ b/nihav-duck/src/codecs/vp78dsp.rs @@ -396,7 +396,7 @@ fn mc_block_common(dst: &mut [u8], mut doff: usize, dstride: usize, src: &[u8], let dst = &mut dst[doff..]; let src = &src[EDGE_PRE + EDGE_PRE * sstride..]; for (out, src) in dst.chunks_mut(dstride).take(size).zip(src.chunks(sstride)) { - (&mut out[0..size]).copy_from_slice(&src[0..size]); + out[..size].copy_from_slice(&src[..size]); } } else if my == 0 { let src = &src[EDGE_PRE * sstride..]; @@ -439,7 +439,7 @@ fn mc_block(dst: &mut [u8], doff: usize, dstride: usize, xpos: usize, ypos: usiz let src = &reffrm.get_data(); let src = &src[srcoff..]; for (out, src) in dst.chunks_mut(dstride).take(size).zip(src.chunks(sstride)) { - (&mut out[0..size]).copy_from_slice(&src[0..size]); + out[..size].copy_from_slice(&src[..size]); } return; } @@ -512,7 +512,7 @@ pub fn mc_block_special(dst: &mut [u8], doff: usize, dstride: usize, xpos: usize (&data[off + (start_x as usize) + (start_y as usize) * stride..], ((stride as isize) + xstep) as usize) } else { - let add = (size + EDGE_PRE + EDGE_POST) * (xstep.abs() as usize); + let add = (size + EDGE_PRE + EDGE_POST) * xstep.unsigned_abs(); let bw = size + EDGE_PRE + EDGE_POST + add; let bh = (end_y - start_y) as usize; let bo = if xstep >= 0 { 0 } else { add }; diff --git a/nihav-duck/src/codecs/vp7dsp.rs b/nihav-duck/src/codecs/vp7dsp.rs index d4c06c6..090eada 100644 --- a/nihav-duck/src/codecs/vp7dsp.rs +++ b/nihav-duck/src/codecs/vp7dsp.rs @@ -172,7 +172,7 @@ pub fn fade_frame(srcfrm: NAVideoBufferRef, dstfrm: &mut NASimpleVideoFrame< let dstride = dstfrm.stride[plane]; let dst = &mut dstfrm.data[dstfrm.offset[plane]..]; for (src, dst) in src.chunks(sstride).zip(dst.chunks_mut(dstride)).take(ha) { - (&mut dst[0..wa]).copy_from_slice(&src[0..wa]); + dst[..wa].copy_from_slice(&src[..wa]); } } } diff --git a/nihav-duck/src/codecs/vp7enc/blocks.rs b/nihav-duck/src/codecs/vp7enc/blocks.rs index 2276382..7a18d48 100644 --- a/nihav-duck/src/codecs/vp7enc/blocks.rs +++ b/nihav-duck/src/codecs/vp7enc/blocks.rs @@ -270,7 +270,7 @@ impl SrcBlock { } pub fn apply_ipred_luma(&self, mode: PredMode, ipred: &IPredContext, dst: &mut Residue) { let mut tmp = [0; 256]; - (&mut tmp).ipred16(16, mode, ipred); + tmp.ipred16(16, mode, ipred); dst.set_luma_from_diff(&self.luma, &tmp); } pub fn fill_ipred_luma(&mut self, mode: PredMode, ipred: &IPredContext) { diff --git a/nihav-duck/src/codecs/vp7enc/rdo.rs b/nihav-duck/src/codecs/vp7enc/rdo.rs index 88f7456..d91cee4 100644 --- a/nihav-duck/src/codecs/vp7enc/rdo.rs +++ b/nihav-duck/src/codecs/vp7enc/rdo.rs @@ -136,7 +136,7 @@ impl BitRateControl { } pub fn get_frame_quant(&self, is_intra: bool) -> usize { if let Some(q) = self.force_q { - q as usize + q } else { let expected_size = self.get_target_size(is_intra); let nits_per_mb = ((expected_size * 8) as f32) / (self.num_mb as f32); diff --git a/nihav-duck/src/codecs/vp8.rs b/nihav-duck/src/codecs/vp8.rs index 791788a..6e34f59 100644 --- a/nihav-duck/src/codecs/vp8.rs +++ b/nihav-duck/src/codecs/vp8.rs @@ -7,18 +7,15 @@ use super::vp78data::*; use super::vp78dsp::*; use super::vp8dsp::*; -#[derive(Clone,Copy,PartialEq,Debug)] +#[derive(Clone,Copy,PartialEq,Debug,Default)] enum VP8Ref { + #[default] Intra, Last, Golden, AltRef, } -impl Default for VP8Ref { - fn default() -> Self { VP8Ref::Intra } -} - #[derive(Default)] pub struct VP8Shuffler { lastframe: Option>, @@ -43,25 +40,13 @@ impl VP8Shuffler { self.altframe = Some(buf); } pub fn get_last(&mut self) -> Option> { - if let Some(ref frm) = self.lastframe { - Some(frm.clone()) - } else { - None - } + self.lastframe.as_ref().cloned() } pub fn get_golden(&mut self) -> Option> { - if let Some(ref frm) = self.goldframe { - Some(frm.clone()) - } else { - None - } + self.goldframe.as_ref().cloned() } pub fn get_altref(&mut self) -> Option> { - if let Some(ref frm) = self.altframe { - Some(frm.clone()) - } else { - None - } + self.altframe.as_ref().cloned() } pub fn has_refs(&self) -> bool { self.lastframe.is_some() diff --git a/nihav-duck/src/codecs/vp8dsp.rs b/nihav-duck/src/codecs/vp8dsp.rs index c097a3c..fa7aa09 100644 --- a/nihav-duck/src/codecs/vp8dsp.rs +++ b/nihav-duck/src/codecs/vp8dsp.rs @@ -177,7 +177,7 @@ fn mc_block_common(dst: &mut [u8], mut doff: usize, dstride: usize, src: &[u8], if (mx == 0) && (my == 0) { let dst = &mut dst[doff..]; for (out, src) in dst.chunks_mut(dstride).take(size).zip(src.chunks(sstride)) { - (&mut out[0..size]).copy_from_slice(&src[0..size]); + out[..size].copy_from_slice(&src[..size]); } } else if my == 0 { for src in src.chunks(sstride).take(size) { @@ -218,7 +218,7 @@ fn mc_block(dst: &mut [u8], doff: usize, dstride: usize, xpos: usize, ypos: usiz let src = &reffrm.get_data(); let src = &src[srcoff..]; for (out, src) in dst.chunks_mut(dstride).take(size).zip(src.chunks(sstride)) { - (&mut out[0..size]).copy_from_slice(&src[0..size]); + out[..size].copy_from_slice(&src[..size]); } return; } diff --git a/nihav-duck/src/codecs/vpcommon.rs b/nihav-duck/src/codecs/vpcommon.rs index 8474dc6..eb84f4e 100644 --- a/nihav-duck/src/codecs/vpcommon.rs +++ b/nihav-duck/src/codecs/vpcommon.rs @@ -17,9 +17,10 @@ pub const VP_YUVA420_FORMAT: NAPixelFormaton = NAPixelFormaton{ palette: false }; -#[derive(Clone,Copy,Debug,PartialEq)] +#[derive(Clone,Copy,Debug,PartialEq,Default)] #[allow(dead_code)] pub enum VPMBType { + #[default] Intra, InterNoMV, InterMV, @@ -51,10 +52,6 @@ impl VPMBType { } } -impl Default for VPMBType { - fn default() -> Self { VPMBType::Intra } -} - #[derive(Default)] pub struct VPShuffler { lastframe: Option>, @@ -71,18 +68,10 @@ impl VPShuffler { self.goldframe = Some(buf); } pub fn get_last(&mut self) -> Option> { - if let Some(ref frm) = self.lastframe { - Some(frm.clone()) - } else { - None - } + self.lastframe.as_ref().cloned() } pub fn get_golden(&mut self) -> Option> { - if let Some(ref frm) = self.goldframe { - Some(frm.clone()) - } else { - None - } + self.goldframe.as_ref().cloned() } pub fn has_refs(&self) -> bool { self.lastframe.is_some() diff --git a/nihav-duck/src/codecs/vpenc/motion_est.rs b/nihav-duck/src/codecs/vpenc/motion_est.rs index 005780c..31d2989 100644 --- a/nihav-duck/src/codecs/vpenc/motion_est.rs +++ b/nihav-duck/src/codecs/vpenc/motion_est.rs @@ -2,20 +2,17 @@ use nihav_codec_support::codecs::{MV, ZERO_MV}; use std::str::FromStr; -#[derive(Debug,Clone,Copy,PartialEq)] +#[derive(Debug,Clone,Copy,PartialEq,Default)] #[allow(dead_code)] pub enum MVSearchMode { Full, SEA, Diamond, + #[default] Hexagon, EPZS, } -impl Default for MVSearchMode { - fn default() -> Self { MVSearchMode::Hexagon } -} - pub struct ParseError{} impl FromStr for MVSearchMode { diff --git a/nihav-duck/src/lib.rs b/nihav-duck/src/lib.rs index bb290cd..76dfbf4 100644 --- a/nihav-duck/src/lib.rs +++ b/nihav-duck/src/lib.rs @@ -3,11 +3,16 @@ extern crate nihav_core; extern crate nihav_codec_support; #[allow(clippy::collapsible_if)] +#[allow(clippy::collapsible_else_if)] #[allow(clippy::comparison_chain)] #[allow(clippy::excessive_precision)] #[allow(clippy::identity_op)] +#[allow(clippy::needless_late_init)] #[allow(clippy::unreadable_literal)] +#[allow(clippy::upper_case_acronyms)] #[allow(clippy::verbose_bit_mask)] +#[allow(clippy::manual_range_contains)] +#[allow(clippy::wrong_self_convention)] mod codecs; mod demuxers; diff --git a/nihav-flash/src/codecs/flashsv.rs b/nihav-flash/src/codecs/flashsv.rs index 91d5825..47f660f 100644 --- a/nihav-flash/src/codecs/flashsv.rs +++ b/nihav-flash/src/codecs/flashsv.rs @@ -33,16 +33,10 @@ impl FSVShuffler { } fn has_last_frame(&self) -> bool { self.lastframe.is_some() } fn get_key_frame(&mut self) -> Option> { - match self.keyframe { - Some(ref frm) => Some(frm.clone()), - None => None, - } + self.keyframe.as_ref().cloned() } fn get_last_frame(&mut self) -> Option> { - match self.lastframe { - Some(ref frm) => Some(frm.clone()), - None => None, - } + self.lastframe.as_ref().cloned() } } diff --git a/nihav-game/src/codecs/gremlinvideo.rs b/nihav-game/src/codecs/gremlinvideo.rs index 624f513..ad63796 100644 --- a/nihav-game/src/codecs/gremlinvideo.rs +++ b/nihav-game/src/codecs/gremlinvideo.rs @@ -453,7 +453,7 @@ impl GremlinVideoDecoder { let top = (bits.read_bits(br, 4)? as usize) << 8; let offs = top + (br.read_byte()? as usize); if (subtag != 0) || (offs <= 0xF80) { - let len = (subtag as usize) + 3; + let len = subtag + 3; self.lz_copy(idx, (offs as isize) - 4096, len)?; idx += len; } else { diff --git a/nihav-game/src/codecs/lhst500f22.rs b/nihav-game/src/codecs/lhst500f22.rs index 8129b5e..8590492 100644 --- a/nihav-game/src/codecs/lhst500f22.rs +++ b/nihav-game/src/codecs/lhst500f22.rs @@ -191,7 +191,7 @@ impl NADecoder for LHDecoder { let abuf = alloc_audio_buffer(self.ainfo, daudio.len(), self.chmap.clone())?; let mut adata = abuf.get_abuf_f32().unwrap(); let buf = adata.get_data_mut().unwrap(); - (&mut buf[..daudio.len()]).copy_from_slice(daudio.as_slice()); + buf[..daudio.len()].copy_from_slice(daudio.as_slice()); let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), abuf); frm.set_duration(Some(CODEC_SAMPLES as u64)); diff --git a/nihav-game/src/codecs/midivid3.rs b/nihav-game/src/codecs/midivid3.rs index 7878f2b..aebd118 100644 --- a/nihav-game/src/codecs/midivid3.rs +++ b/nihav-game/src/codecs/midivid3.rs @@ -211,7 +211,7 @@ impl Midivid3Decoder { let src = &ref_frm.get_data()[ref_frm.get_offset(0) + (src_x as usize) + (src_y as usize) * sstride..]; let dst = &mut frm.data[ydst + x..]; for (dst, src) in dst.chunks_mut(frm.stride[0]).zip(src.chunks(sstride)).take(16) { - (&mut dst[..16]).copy_from_slice(&src[..16]); + dst[..16].copy_from_slice(&src[..16]); } let xoff = (src_x as usize) >> 1; let yoff = (src_y as usize) >> 1; @@ -220,7 +220,7 @@ impl Midivid3Decoder { let src = &ref_frm.get_data()[ref_frm.get_offset(plane) + xoff + yoff * sstride..]; let dst = &mut frm.data[if plane == 1 { udst } else { vdst } + x / 2..]; for (dst, src) in dst.chunks_mut(frm.stride[plane]).zip(src.chunks(sstride)).take(8) { - (&mut dst[..8]).copy_from_slice(&src[..8]); + dst[..8].copy_from_slice(&src[..8]); } } if has_residue { diff --git a/nihav-game/src/codecs/q.rs b/nihav-game/src/codecs/q.rs index 9e51832..b282a47 100644 --- a/nihav-game/src/codecs/q.rs +++ b/nihav-game/src/codecs/q.rs @@ -161,8 +161,8 @@ impl QVideoDecoder { const MV_PART: [i8; 16] = [ 0, 4, 8, 12, 16, 20, 24, 28, -32, -4, -8, -12, -16, -20, -24, -28 ]; let idx = br.read_byte()? as usize; - let x = MV_PART[(idx & 0xF) as usize] as isize; - let y = MV_PART[(idx >> 4) as usize] as isize; + let x = MV_PART[idx & 0xF] as isize; + let y = MV_PART[idx >> 4] as isize; let src_off = (tile_off as isize) + x + y * (self.w as isize); validate!(src_off >= 0); validate!((src_off as usize) + self.tile_w + (self.tile_h - 1) * self.w <= self.w * self.h); diff --git a/nihav-game/src/codecs/smush/v1.rs b/nihav-game/src/codecs/smush/v1.rs index 6731a29..40e6008 100644 --- a/nihav-game/src/codecs/smush/v1.rs +++ b/nihav-game/src/codecs/smush/v1.rs @@ -1051,7 +1051,7 @@ impl NADecoder for Smush1Decoder { self.pic.fpal[i] = self.pic.fpal[i].wrapping_add(self.pic.pdelta[i]); self.pic.pal[i] = (self.pic.fpal[i] >> 7) as u8; } - br.read_skip((size as usize) - 4)?; + br.read_skip(size - 4)?; }, 2 => { validate!(size == 0x904); diff --git a/nihav-game/src/codecs/vmd.rs b/nihav-game/src/codecs/vmd.rs index f3a1d87..9492c62 100644 --- a/nihav-game/src/codecs/vmd.rs +++ b/nihav-game/src/codecs/vmd.rs @@ -308,10 +308,10 @@ impl NADecoder for VMDVideoDecoder { let paloff = buf.get_offset(1); let data = buf.get_data_mut().unwrap(); for (inrow, outrow) in self.framebuf.chunks(self.width).zip(data.chunks_mut(stride)) { - (&mut outrow[..self.width]).copy_from_slice(inrow); + outrow[..self.width].copy_from_slice(inrow); } if !self.is_24bit { - (&mut data[paloff..][..768]).copy_from_slice(&self.pal); + data[paloff..][..768].copy_from_slice(&self.pal); } videobuf = if !self.is_24bit { NABufferType::Video(buf) } else { NABufferType::VideoPacked(buf) }; } else { diff --git a/nihav-game/src/demuxers/q.rs b/nihav-game/src/demuxers/q.rs index 071f00f..ebd93b2 100644 --- a/nihav-game/src/demuxers/q.rs +++ b/nihav-game/src/demuxers/q.rs @@ -61,7 +61,7 @@ impl<'a> DemuxCore<'a> for QDemuxer<'a> { validate!(abits == 8 || abits == 16); self.bps = (channels as usize) * abits / 8; let bsize = read_u16le(&buf[32..])? as usize; - let ahdr = NAAudioInfo::new(arate, channels as u8, if abits == 16 { SND_S16_FORMAT } else { SND_U8_FORMAT }, bsize); + let ahdr = NAAudioInfo::new(arate, channels, if abits == 16 { SND_S16_FORMAT } else { SND_U8_FORMAT }, bsize); let ainfo = NACodecInfo::new("pcm", NACodecTypeInfo::Audio(ahdr), None); self.a_id = strmgr.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, arate, 2)); } diff --git a/nihav-game/src/demuxers/smush.rs b/nihav-game/src/demuxers/smush.rs index 6132d9c..3cc5fbc 100644 --- a/nihav-game/src/demuxers/smush.rs +++ b/nihav-game/src/demuxers/smush.rs @@ -531,7 +531,7 @@ impl<'a> DemuxCore<'a> for MCMPDemuxer<'a> { let hdr_size = self.src.read_u32be()?; validate!(cmp == 0 && size1 == hdr_size); - let size = (nframes - 1) as usize; + let size = nframes - 1; self.offsets = Vec::with_capacity(size); self.sizes = Vec::with_capacity(size); self.samples = Vec::with_capacity(size); diff --git a/nihav-game/src/lib.rs b/nihav-game/src/lib.rs index 5682ef0..e0187ae 100644 --- a/nihav-game/src/lib.rs +++ b/nihav-game/src/lib.rs @@ -3,14 +3,20 @@ extern crate nihav_core; extern crate nihav_codec_support; #[allow(clippy::collapsible_if)] +#[allow(clippy::collapsible_else_if)] #[allow(clippy::excessive_precision)] #[allow(clippy::needless_range_loop)] +#[allow(clippy::manual_range_contains)] #[allow(clippy::unreadable_literal)] #[allow(clippy::useless_let_if_seq)] +#[allow(clippy::upper_case_acronyms)] +#[allow(clippy::needless_late_init)] mod codecs; pub use crate::codecs::game_register_all_decoders; #[allow(clippy::collapsible_if)] #[allow(clippy::needless_range_loop)] #[allow(clippy::unreadable_literal)] +#[allow(clippy::manual_range_contains)] +#[allow(clippy::upper_case_acronyms)] mod demuxers; pub use crate::demuxers::game_register_all_demuxers; diff --git a/nihav-indeo/src/codecs/imc.rs b/nihav-indeo/src/codecs/imc.rs index 98f97eb..ea4d0b0 100644 --- a/nihav-indeo/src/codecs/imc.rs +++ b/nihav-indeo/src/codecs/imc.rs @@ -161,7 +161,7 @@ impl BitAlloc { if len < 0 { len = 0; } if len > 6 { len = 6; } self.band_bits[band] = len as u8; - cur_bits += (self.band_width[band] as i32) * (len as i32); + cur_bits += (self.band_width[band] as i32) * len; if len > 0 { acc += self.band_width[band] as i32; } @@ -643,7 +643,7 @@ impl IMCDecoder { } if self.ba.band_present[band] { let band_w = IMC_BANDS[band + 1] - IMC_BANDS[band]; - let bitsum = self.ba.band_bitsum[band] as usize; + let bitsum = self.ba.band_bitsum[band]; if (bitsum > 0) && (((band_w * 3) >> 1) > bitsum) { self.ba.band_skip[band] = true; } @@ -903,8 +903,8 @@ impl NADecoder for IMCDecoder { let channels = self.ainfo.get_channels() as usize; for chunk in pktbuf.chunks(BLOCK_SIZE * channels) { for ch in 0..channels { - let off = abuf.get_offset(ch as usize) + start; - self.decode_block(chunk, ch as usize, &mut dst[off..off+COEFFS])?; + let off = abuf.get_offset(ch) + start; + self.decode_block(chunk, ch, &mut dst[off..off+COEFFS])?; } if (channels == 2) && ((chunk[1] & 0x20) != 0) { let off1 = abuf.get_offset(0) + start; diff --git a/nihav-indeo/src/codecs/indeo2.rs b/nihav-indeo/src/codecs/indeo2.rs index 3213388..a07904e 100644 --- a/nihav-indeo/src/codecs/indeo2.rs +++ b/nihav-indeo/src/codecs/indeo2.rs @@ -223,8 +223,8 @@ impl Indeo2Decoder { } x += run; } else { - framebuf[base + x + 0] = table[(idx * 2 + 0) as usize]; - framebuf[base + x + 1] = table[(idx * 2 + 1) as usize]; + framebuf[base + x + 0] = table[idx * 2]; + framebuf[base + x + 1] = table[idx * 2 + 1]; x += 2; } } diff --git a/nihav-indeo/src/codecs/indeo3enc/cell.rs b/nihav-indeo/src/codecs/indeo3enc/cell.rs index 582293b..b4e30f9 100644 --- a/nihav-indeo/src/codecs/indeo3enc/cell.rs +++ b/nihav-indeo/src/codecs/indeo3enc/cell.rs @@ -132,7 +132,7 @@ impl CodebookSuggester { if delta == 0 { continue; } - let delta = delta.abs() as u8; + let delta = delta.unsigned_abs(); self.add_delta(delta); } } @@ -141,7 +141,7 @@ impl CodebookSuggester { if delta == 0 { continue; } - let delta = delta.abs() as u8; + let delta = delta.unsigned_abs(); self.add_delta(delta); } } @@ -253,9 +253,9 @@ impl CellEncoder { fn determine_mode(&self, intra: bool, mut mode_hint: u8) -> (u8, [u8; 2]) { if let Some(qmode) = self.quant { if intra { - return (mode_hint, [qmode as u8, qmode as u8]); + return (mode_hint, [qmode, qmode]); } else { - let qmode = (qmode & 7) as u8; + let qmode = qmode & 7; return (mode_hint, [qmode, qmode]); } } @@ -646,7 +646,7 @@ fn compress_intra_cell(iwriter: &mut IndexWriter, cell4: &mut [u8; 20], cbs: &[& let (prev, cur) = cell4.split_at_mut(pivot); let prev = &prev[prev.len() - 4..]; let cur = &mut cur[..4]; - let (idx0, idx1) = find_quad(&cb.data, prev, cur); + let (idx0, idx1) = find_quad(cb.data, prev, cur); cur[0] = ((prev[0] as i8) + cb.data[usize::from(idx1) * 2]) as u8; cur[1] = ((prev[1] as i8) + cb.data[usize::from(idx1) * 2 + 1]) as u8; @@ -665,7 +665,7 @@ fn compress_inter_cell(iwriter: &mut IndexWriter, ccell4: &mut [u8; 20], pcell: let cb = cbs[y]; let esc_val = esc_vals[y]; - let (idx0, idx1) = find_quad(&cb.data, prev, cur); + let (idx0, idx1) = find_quad(cb.data, prev, cur); cur[0] = ((prev[0] as i8) + cb.data[usize::from(idx1) * 2]) as u8; cur[1] = ((prev[1] as i8) + cb.data[usize::from(idx1) * 2 + 1]) as u8; @@ -780,8 +780,8 @@ fn compress_inter_cell_mode11(iwriter: &mut IndexWriter, cell: &mut [u8; 32], di } fn pair_dist(src: &[i8], pair: &[i8]) -> u32 { - let d0 = (i32::from(src[0]) - i32::from(pair[0])).abs() as u32; - let d1 = (i32::from(src[1]) - i32::from(pair[1])).abs() as u32; + let d0 = (i32::from(src[0]) - i32::from(pair[0])).unsigned_abs(); + let d1 = (i32::from(src[1]) - i32::from(pair[1])).unsigned_abs(); d0 * d0 + d1 * d1 } diff --git a/nihav-indeo/src/codecs/indeo3enc/mod.rs b/nihav-indeo/src/codecs/indeo3enc/mod.rs index eefa3d7..762f8a2 100644 --- a/nihav-indeo/src/codecs/indeo3enc/mod.rs +++ b/nihav-indeo/src/codecs/indeo3enc/mod.rs @@ -148,7 +148,7 @@ impl Indeo3Encoder { } let mut iw = Indeo3Writer::new(dbuf); - self.cframe.plane[planeno].encode_tree(&mut iw, &tree, &mut self.cenc, ref_plane); + self.cframe.plane[planeno].encode_tree(&mut iw, tree, &mut self.cenc, ref_plane); drop(iw); while (dbuf.len() & 3) != 0 { dbuf.push(0); diff --git a/nihav-indeo/src/codecs/indeo5.rs b/nihav-indeo/src/codecs/indeo5.rs index b5030de..e4863d3 100644 --- a/nihav-indeo/src/codecs/indeo5.rs +++ b/nihav-indeo/src/codecs/indeo5.rs @@ -7,7 +7,7 @@ use super::ivi::*; use super::ivibr::*; fn calc_quant(glob_q: u32, qd: i16) -> usize { - let qq = (glob_q as i16) + (qd as i16); + let qq = (glob_q as i16) + qd; if qq < 0 { 0 } else if qq > 23 { diff --git a/nihav-indeo/src/codecs/ivibr.rs b/nihav-indeo/src/codecs/ivibr.rs index d544085..1383f74 100644 --- a/nihav-indeo/src/codecs/ivibr.rs +++ b/nihav-indeo/src/codecs/ivibr.rs @@ -836,7 +836,7 @@ br.skip(skip_part as u32)?; unreachable!(); } - fn decode_single_frame<'a>(&mut self, dec: &mut dyn IndeoXParser, br: &mut BitReader<'a>) -> DecoderResult { + fn decode_single_frame(&mut self, dec: &mut dyn IndeoXParser, br: &mut BitReader) -> DecoderResult { let pic_hdr = dec.decode_picture_header(br)?; self.ftype = pic_hdr.ftype; if pic_hdr.ftype.is_null() { @@ -978,9 +978,8 @@ br.skip(skip_part as u32)?; Ok(buftype) } - pub fn decode_frame<'a>(&mut self, dec: &mut dyn IndeoXParser, br: &mut BitReader<'a>) -> DecoderResult { - let res = self.decode_single_frame(dec, br); - if res.is_err() { return res; } + pub fn decode_frame(&mut self, dec: &mut dyn IndeoXParser, br: &mut BitReader) -> DecoderResult { + let res = self.decode_single_frame(dec, br)?; if (self.ftype == IVIFrameType::Intra) && (br.left() > 16) { loop { if br.left() < 8 { break; } @@ -1003,11 +1002,11 @@ br.skip(skip_part as u32)?; } } if self.bref.is_some() && self.ftype == IVIFrameType::Inter { - let mut bref: Option = Some(res.unwrap()); + let mut bref: Option = Some(res); mem::swap(&mut bref, &mut self.bref); return Ok(bref.unwrap()); } - if let Ok(NABufferType::None) = res { + if let NABufferType::None = res { if self.bref.is_some() { let mut bref: Option = None; mem::swap(&mut bref, &mut self.bref); @@ -1015,7 +1014,7 @@ br.skip(skip_part as u32)?; return Ok(bref.unwrap()); } } - res + Ok(res) } pub fn flush(&mut self) { diff --git a/nihav-indeo/src/demuxers/ivf.rs b/nihav-indeo/src/demuxers/ivf.rs index cccb5ab..4e55d91 100644 --- a/nihav-indeo/src/demuxers/ivf.rs +++ b/nihav-indeo/src/demuxers/ivf.rs @@ -40,9 +40,9 @@ impl<'a> DemuxCore<'a> for IVFDemuxer<'a> { fn open(&mut self, strmgr: &mut StreamManager, _seek_index: &mut SeekIndex) -> DemuxerResult<()> { let mut guid = [0; 16]; self.src.read_buf(&mut guid)?; - let version = match &guid { - &IVF_GUID_0 => 0, - &IVF_GUID_1 => 1, + let version = match guid { + IVF_GUID_0 => 0, + IVF_GUID_1 => 1, _ => return Err(DemuxerError::InvalidData), }; let flags = self.src.read_u32le()?; @@ -85,7 +85,7 @@ impl<'a> DemuxCore<'a> for IVFDemuxer<'a> { let fcc = self.src.read_tag()?; self.src.read_skip(20)?; - let mut vhdr = NAVideoInfo::new(width, height.abs() as usize, height < 0, YUV420_FORMAT); + let mut vhdr = NAVideoInfo::new(width, height.unsigned_abs() as usize, height < 0, YUV420_FORMAT); vhdr.bits = (planes as u8) * (bitcount as u8); let cname = match &fcc { b"IV31" | b"IV32" => "indeo3", @@ -243,6 +243,7 @@ const DEMUXER_OPTS: &[NAOptionDefinition] = &[ impl<'a> NAOptionHandler for IVFDemuxer<'a> { fn get_supported_options(&self) -> &[NAOptionDefinition] { DEMUXER_OPTS } + #[allow(clippy::single_match)] fn set_options(&mut self, options: &[NAOption]) { for option in options.iter() { for opt_def in DEMUXER_OPTS.iter() { @@ -259,6 +260,7 @@ impl<'a> NAOptionHandler for IVFDemuxer<'a> { } } } + #[allow(clippy::single_match)] fn query_option_value(&self, name: &str) -> Option { match name { PASSES => Some(NAValue::Int(i64::from(self.passes))), diff --git a/nihav-indeo/src/lib.rs b/nihav-indeo/src/lib.rs index 22ef878..a89bd26 100644 --- a/nihav-indeo/src/lib.rs +++ b/nihav-indeo/src/lib.rs @@ -3,11 +3,15 @@ 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; diff --git a/nihav-itu/src/codecs/h264/cabac.rs b/nihav-itu/src/codecs/h264/cabac.rs index 01d46af..ae0d435 100644 --- a/nihav-itu/src/codecs/h264/cabac.rs +++ b/nihav-itu/src/codecs/h264/cabac.rs @@ -287,7 +287,7 @@ pub fn decode_mb_pred_cabac(cabac: &mut CABAC, slice_hdr: &SliceHeader, mb_type: } else { new_mode }; } mb_info.ipred[x + y * 4] = pred_mode.into(); - sstate.get_cur_blk4(x + y * 4).ipred = (pred_mode as u8).into(); + sstate.get_cur_blk4(x + y * 4).ipred = pred_mode.into(); } let mut ctx = 0; if sstate.get_left_mb().cmode != 0 { @@ -329,10 +329,10 @@ pub fn decode_mb_pred_cabac(cabac: &mut CABAC, slice_hdr: &SliceHeader, mb_type: mb_info.ipred[blk4 + 1] = pred_mode.into(); mb_info.ipred[blk4 + 4] = pred_mode.into(); mb_info.ipred[blk4 + 5] = pred_mode.into(); - sstate.get_cur_blk4(blk4).ipred = (pred_mode as u8).into(); - sstate.get_cur_blk4(blk4 + 1).ipred = (pred_mode as u8).into(); - sstate.get_cur_blk4(blk4 + 4).ipred = (pred_mode as u8).into(); - sstate.get_cur_blk4(blk4 + 5).ipred = (pred_mode as u8).into(); + sstate.get_cur_blk4(blk4).ipred = pred_mode.into(); + sstate.get_cur_blk4(blk4 + 1).ipred = pred_mode.into(); + sstate.get_cur_blk4(blk4 + 4).ipred = pred_mode.into(); + sstate.get_cur_blk4(blk4 + 5).ipred = pred_mode.into(); } let mut ctx = 0; if sstate.get_left_mb().cmode != 0 { @@ -589,9 +589,9 @@ pub fn decode_mb_qp_delta_cabac(cabac: &mut CABAC, ctx: usize) -> i32 { val += 1; } if (val & 1) != 0 { - ((val >> 1) as i32) + 2 + (val >> 1) + 2 } else { - -((val >> 1) as i32) - 1 + -(val >> 1) - 1 } } } diff --git a/nihav-itu/src/codecs/h264/cavlc.rs b/nihav-itu/src/codecs/h264/cavlc.rs index adc28ab..af98aa5 100644 --- a/nihav-itu/src/codecs/h264/cavlc.rs +++ b/nihav-itu/src/codecs/h264/cavlc.rs @@ -130,7 +130,7 @@ pub fn decode_mb_pred_cavlc(br: &mut BitReader, slice_hdr: &SliceHeader, mb_type } else { new_mode }; } mb_info.ipred[x + y * 4] = pred_mode.into(); - sstate.get_cur_blk4(x + y * 4).ipred = (pred_mode as u8).into(); + sstate.get_cur_blk4(x + y * 4).ipred = pred_mode.into(); } mb_info.chroma_ipred = br.read_ue_lim(3)? as u8; }, @@ -154,10 +154,10 @@ pub fn decode_mb_pred_cavlc(br: &mut BitReader, slice_hdr: &SliceHeader, mb_type mb_info.ipred[blk4 + 1] = pred_mode.into(); mb_info.ipred[blk4 + 4] = pred_mode.into(); mb_info.ipred[blk4 + 5] = pred_mode.into(); - sstate.get_cur_blk4(blk4).ipred = (pred_mode as u8).into(); - sstate.get_cur_blk4(blk4 + 1).ipred = (pred_mode as u8).into(); - sstate.get_cur_blk4(blk4 + 4).ipred = (pred_mode as u8).into(); - sstate.get_cur_blk4(blk4 + 5).ipred = (pred_mode as u8).into(); + sstate.get_cur_blk4(blk4).ipred = pred_mode.into(); + sstate.get_cur_blk4(blk4 + 1).ipred = pred_mode.into(); + sstate.get_cur_blk4(blk4 + 4).ipred = pred_mode.into(); + sstate.get_cur_blk4(blk4 + 5).ipred = pred_mode.into(); } mb_info.chroma_ipred = br.read_ue_lim(3)? as u8; }, diff --git a/nihav-itu/src/codecs/h264/decoder_mt.rs b/nihav-itu/src/codecs/h264/decoder_mt.rs index 27570e5..a69cf33 100644 --- a/nihav-itu/src/codecs/h264/decoder_mt.rs +++ b/nihav-itu/src/codecs/h264/decoder_mt.rs @@ -61,7 +61,7 @@ impl FrameDecoder { 17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41 ]; - let mut mb_idx = slice_hdr.first_mb_in_slice as usize; + let mut mb_idx = slice_hdr.first_mb_in_slice; let mut mb_info = CurrentMBInfo { qp_y: slice_hdr.slice_qp, ..Default::default() }; let skip_type = if slice_hdr.slice_type.is_p() { MBType::PSkip } else { MBType::BSkip }; while br.tell() < full_size && mb_idx < self.num_mbs { @@ -155,7 +155,7 @@ impl FrameDecoder { Ok(mb_idx) } fn decode_slice_cabac(&mut self, cabac: &mut CABAC, slice_hdr: &SliceHeader, refs: &SliceRefs) -> DecoderResult { - let mut mb_idx = slice_hdr.first_mb_in_slice as usize; + let mut mb_idx = slice_hdr.first_mb_in_slice; let mut prev_mb_skipped = false; let skip_type = if slice_hdr.slice_type.is_p() { MBType::PSkip } else { MBType::BSkip }; let mut last_qp_diff = false; @@ -777,7 +777,7 @@ impl NADecoderMT for H264MTDecoder { } let num_bufs = if !self.sps.is_empty() { - self.sps[0].num_ref_frames as usize + 1 + self.sps[0].num_ref_frames + 1 } else { 3 }.max(16 + 1); diff --git a/nihav-itu/src/codecs/h264/decoder_st.rs b/nihav-itu/src/codecs/h264/decoder_st.rs index 85deab9..13fe1bd 100644 --- a/nihav-itu/src/codecs/h264/decoder_st.rs +++ b/nihav-itu/src/codecs/h264/decoder_st.rs @@ -222,7 +222,7 @@ println!("PAFF?"); self.has_pic = self.decode_slice_cavlc(&mut br, &slice_hdr, full_size)?; } else { br.align(); - let start = (br.tell() / 8) as usize; + let start = br.tell() / 8; let csrc = &src[start..]; validate!(csrc.len() >= 2); let mut cabac = CABAC::new(csrc, slice_hdr.slice_type, slice_hdr.slice_qp, slice_hdr.cabac_init_idc as usize)?; @@ -482,7 +482,7 @@ _ => {}, 17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41 ]; - let mut mb_idx = slice_hdr.first_mb_in_slice as usize; + let mut mb_idx = slice_hdr.first_mb_in_slice; let mut mb_info = CurrentMBInfo { qp_y: slice_hdr.slice_qp, ..Default::default() }; let skip_type = if slice_hdr.slice_type.is_p() { MBType::PSkip } else { MBType::BSkip }; while br.tell() < full_size && mb_idx < self.num_mbs { @@ -576,7 +576,7 @@ _ => {}, Ok(mb_idx == self.num_mbs) } fn decode_slice_cabac(&mut self, cabac: &mut CABAC, slice_hdr: &SliceHeader) -> DecoderResult { - let mut mb_idx = slice_hdr.first_mb_in_slice as usize; + let mut mb_idx = slice_hdr.first_mb_in_slice; let mut prev_mb_skipped = false; let skip_type = if slice_hdr.slice_type.is_p() { MBType::PSkip } else { MBType::BSkip }; let mut last_qp_diff = false; @@ -763,7 +763,7 @@ impl NADecoder for H264Decoder { } let num_bufs = if !self.sps.is_empty() { - self.sps[0].num_ref_frames as usize + 1 + self.sps[0].num_ref_frames + 1 } else { 3 }.max(16 + 1); diff --git a/nihav-itu/src/codecs/h264/pic_ref.rs b/nihav-itu/src/codecs/h264/pic_ref.rs index a047216..a24e9d0 100644 --- a/nihav-itu/src/codecs/h264/pic_ref.rs +++ b/nihav-itu/src/codecs/h264/pic_ref.rs @@ -188,11 +188,9 @@ impl FrameRefs { dst.push(pic.full_id); } } - for ltpic in self.long_term.iter() { - if let Some(ref pic) = ltpic { - if !dst.contains(&pic.full_id) { - dst.push(pic.full_id); - } + for pic in self.long_term.iter().flatten() { + if !dst.contains(&pic.full_id) { + dst.push(pic.full_id); } } } diff --git a/nihav-itu/src/codecs/h264/types.rs b/nihav-itu/src/codecs/h264/types.rs index 9df866e..6fe5aea 100644 --- a/nihav-itu/src/codecs/h264/types.rs +++ b/nihav-itu/src/codecs/h264/types.rs @@ -12,8 +12,9 @@ pub enum BMode { Bi, } -#[derive(Clone,Copy,Debug,PartialEq)] +#[derive(Clone,Copy,Debug,PartialEq,Default)] pub enum MBType { + #[default] Intra4x4, Intra8x8, Intra16x16(u8, u8, u8), @@ -106,16 +107,13 @@ impl MBType { } } -impl Default for MBType { - fn default() -> Self { MBType::Intra4x4 } -} - -#[derive(Clone,Copy,Debug,PartialEq)] +#[derive(Clone,Copy,Debug,PartialEq,Default)] pub enum SubMBType { P8x8, P8x4, P4x8, P4x4, + #[default] Direct8x8, B8x8(BMode), B8x4(BMode), @@ -159,12 +157,8 @@ impl SubMBType { } } -impl Default for SubMBType { - fn default() -> Self { SubMBType::Direct8x8 } -} - #[repr(u8)] -#[derive(Clone,Copy,Debug,PartialEq)] +#[derive(Clone,Copy,Debug,PartialEq,Default)] pub enum CompactMBType { Intra4x4, Intra8x8, @@ -185,6 +179,7 @@ pub enum CompactMBType { B8x8, BSkip, + #[default] None, } @@ -215,10 +210,6 @@ impl CompactMBType { } } -impl Default for CompactMBType { - fn default() -> Self { CompactMBType::None } -} - impl From for CompactMBType { fn from(mbtype: MBType) -> Self { match mbtype { @@ -243,7 +234,7 @@ impl From for CompactMBType { } #[repr(u8)] -#[derive(Clone,Copy,Debug,PartialEq)] +#[derive(Clone,Copy,Debug,PartialEq,Default)] pub enum IntraPredMode { Vertical, Horizontal, @@ -254,6 +245,7 @@ pub enum IntraPredMode { HorDown, VerLeft, HorUp, + #[default] None, } @@ -268,10 +260,6 @@ impl IntraPredMode { } } -impl Default for IntraPredMode { - fn default() -> Self { IntraPredMode::None } -} - impl From for IntraPredMode { fn from(val: u8) -> Self { match val { diff --git a/nihav-itu/src/codecs/mod.rs b/nihav-itu/src/codecs/mod.rs index a3873bf..2014f0a 100644 --- a/nihav-itu/src/codecs/mod.rs +++ b/nihav-itu/src/codecs/mod.rs @@ -10,6 +10,7 @@ macro_rules! validate { } #[allow(clippy::collapsible_else_if)] +#[allow(clippy::manual_range_contains)] #[allow(clippy::too_many_arguments)] #[allow(clippy::upper_case_acronyms)] #[cfg(feature="decoder_h264")] diff --git a/nihav-llaudio/src/codecs/ape.rs b/nihav-llaudio/src/codecs/ape.rs index 1bcd62e..7b02c94 100644 --- a/nihav-llaudio/src/codecs/ape.rs +++ b/nihav-llaudio/src/codecs/ape.rs @@ -107,7 +107,7 @@ impl NADecoder for APEDecoder { } else { return Err(DecoderError::NotImplemented); }; - self.ainfo = NAAudioInfo::new(srate, channels as u8, SND_S16P_FORMAT, 4602); + self.ainfo = NAAudioInfo::new(srate, channels, SND_S16P_FORMAT, 4602); Ok(()) } else { Err(DecoderError::InvalidData) diff --git a/nihav-llaudio/src/codecs/flac.rs b/nihav-llaudio/src/codecs/flac.rs index e0b407d..6d71981 100644 --- a/nihav-llaudio/src/codecs/flac.rs +++ b/nihav-llaudio/src/codecs/flac.rs @@ -263,7 +263,7 @@ impl NADecoder for FlacDecoder { _ => return Err(DecoderError::NotImplemented), }; - self.ainfo = NAAudioInfo::new(self.srate, self.channels as u8, fmt, self.max_blk_size.max(1)); + self.ainfo = NAAudioInfo::new(self.srate, self.channels, fmt, self.max_blk_size.max(1)); Ok(()) } else { Err(DecoderError::InvalidData) diff --git a/nihav-llaudio/src/codecs/wavpack.rs b/nihav-llaudio/src/codecs/wavpack.rs index 31629e7..d8f2302 100644 --- a/nihav-llaudio/src/codecs/wavpack.rs +++ b/nihav-llaudio/src/codecs/wavpack.rs @@ -38,6 +38,7 @@ struct WVHeader { const WV_HEADER_SIZE: usize = 32; impl WVHeader { + #[allow(clippy::field_reassign_with_default)] fn parse(src: &[u8]) -> DecoderResult { let mut mr = MemoryReader::new_read(src); let mut br = ByteReader::new(&mut mr); diff --git a/nihav-llaudio/src/demuxers/flac.rs b/nihav-llaudio/src/demuxers/flac.rs index 215a1e9..4fb6c4c 100644 --- a/nihav-llaudio/src/demuxers/flac.rs +++ b/nihav-llaudio/src/demuxers/flac.rs @@ -212,7 +212,7 @@ impl<'a> DemuxCore<'a> for FLACDemuxer<'a> { self.srate = srate; let base = if self.blk_samples != 0 { u32::from(self.blk_samples) } else { 1 }; - let ahdr = NAAudioInfo::new(srate, channels as u8, SND_S16P_FORMAT, base as usize); + let ahdr = NAAudioInfo::new(srate, channels, SND_S16P_FORMAT, base as usize); let ainfo = NACodecInfo::new("flac", NACodecTypeInfo::Audio(ahdr), Some(streaminfo)); strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, base, srate, 0)).unwrap(); diff --git a/nihav-llaudio/src/demuxers/flacraw.rs b/nihav-llaudio/src/demuxers/flacraw.rs index c04f1f0..dcdd5a5 100644 --- a/nihav-llaudio/src/demuxers/flacraw.rs +++ b/nihav-llaudio/src/demuxers/flacraw.rs @@ -90,7 +90,7 @@ impl<'a> RawDemuxCore<'a> for FLACDemuxer<'a> { self.srate = srate; let base = if self.blk_samples != 0 { u32::from(self.blk_samples) } else { 1 }; - let ahdr = NAAudioInfo::new(srate, channels as u8, SND_S16P_FORMAT, base as usize); + let ahdr = NAAudioInfo::new(srate, channels, SND_S16P_FORMAT, base as usize); let ainfo = NACodecInfo::new("flac", NACodecTypeInfo::Audio(ahdr), Some(streaminfo)); strmgr.add_stream(NAStream::new(StreamType::Audio, 0, ainfo, base, srate, 0)).unwrap(); diff --git a/nihav-llaudio/src/demuxers/wavpack.rs b/nihav-llaudio/src/demuxers/wavpack.rs index 2d92e7b..6c5f8dd 100644 --- a/nihav-llaudio/src/demuxers/wavpack.rs +++ b/nihav-llaudio/src/demuxers/wavpack.rs @@ -36,6 +36,7 @@ struct WVHeader { const WV_HEADER_SIZE: usize = 32; impl WVHeader { + #[allow(clippy::field_reassign_with_default)] fn parse(src: &[u8]) -> DemuxerResult { let mut mr = MemoryReader::new_read(src); let mut br = ByteReader::new(&mut mr); diff --git a/nihav-mpeg/src/codecs/aac/coeff_read.rs b/nihav-mpeg/src/codecs/aac/coeff_read.rs index 63a86aa..81a1d36 100644 --- a/nihav-mpeg/src/codecs/aac/coeff_read.rs +++ b/nihav-mpeg/src/codecs/aac/coeff_read.rs @@ -43,7 +43,7 @@ pub fn get_scale(scale: u8) -> f32 { 2.0f32.powf(0.25 * (f32::from(scale) - 100.0 - 56.0)) } fn iquant(val: i16) -> f32 { - let idx = val.abs() as usize; + let idx = val.unsigned_abs() as usize; if idx < CBRT_TAB.len() { if val < 0 { -CBRT_TAB[idx] @@ -83,9 +83,9 @@ fn decode_quads(br: &mut BitReader, cb: &Codebook, unsigned: bool, scale: f for i in 0..4 { let val = AAC_QUADS[cw][i] - 1; if val < 0 { - out[i] = -CBRT_TAB[val.abs() as usize] * scale; + out[i] = -CBRT_TAB[val.unsigned_abs() as usize] * scale; } else { - out[i] = CBRT_TAB[val.abs() as usize] * scale; + out[i] = CBRT_TAB[val.unsigned_abs() as usize] * scale; } } } @@ -118,8 +118,8 @@ fn decode_pairs(br: &mut BitReader, cb: &Codebook, unsigned: bool, escape: out[0] = iquant(x) * scale; out[1] = iquant(y) * scale; } else { - out[0] = scale * if x < 0 { -CBRT_TAB[x.abs() as usize] } else { CBRT_TAB[x as usize] }; - out[1] = scale * if y < 0 { -CBRT_TAB[y.abs() as usize] } else { CBRT_TAB[y as usize] }; + out[0] = scale * if x < 0 { -CBRT_TAB[x.unsigned_abs() as usize] } else { CBRT_TAB[x as usize] }; + out[1] = scale * if y < 0 { -CBRT_TAB[y.unsigned_abs() as usize] } else { CBRT_TAB[y as usize] }; } } Ok(()) diff --git a/nihav-mpeg/src/codecs/aac/mod.rs b/nihav-mpeg/src/codecs/aac/mod.rs index ea262b9..179134c 100644 --- a/nihav-mpeg/src/codecs/aac/mod.rs +++ b/nihav-mpeg/src/codecs/aac/mod.rs @@ -628,8 +628,8 @@ impl AACDecoder { 4 => { // ID_DSE let _id = br.read(4)?; let align = br.read_bool()?; - let mut count = br.read(8)? as u32; - if count == 255 { count += br.read(8)? as u32; } + let mut count = br.read(8)?; + if count == 255 { count += br.read(8)?; } if align { br.align(); } br.skip(count * 8)?; // no SBR payload or such }, diff --git a/nihav-mpeg/src/codecs/aac/sbr/bs.rs b/nihav-mpeg/src/codecs/aac/sbr/bs.rs index f12e9d9..dbce727 100644 --- a/nihav-mpeg/src/codecs/aac/sbr/bs.rs +++ b/nihav-mpeg/src/codecs/aac/sbr/bs.rs @@ -159,7 +159,7 @@ fn read_grid(br: &mut BitReader, chan: &mut SBRChannel) -> DecoderResult<()> { let var_bord_1 = br.read(2)? as u8; let num_rel_0 = br.read(2)? as usize; let num_rel_1 = br.read(2)? as usize; - chan.num_env = (num_rel_0 as usize) + (num_rel_1 as usize) + 1; + chan.num_env = num_rel_0 + num_rel_1 + 1; let mut rel_bord_0 = [0u8; NUM_ENVELOPES]; let mut rel_bord_1 = [0u8; NUM_ENVELOPES]; for el in rel_bord_0[..num_rel_0].iter_mut() { diff --git a/nihav-mpeg/src/codecs/aac/sbr/synth.rs b/nihav-mpeg/src/codecs/aac/sbr/synth.rs index 75c808e..42a5ba0 100644 --- a/nihav-mpeg/src/codecs/aac/sbr/synth.rs +++ b/nihav-mpeg/src/codecs/aac/sbr/synth.rs @@ -447,15 +447,15 @@ impl SBRChannel { let mut e_o_sum = EPS0; let mut e_c_sum = EPS0; for k in start..end { - e_o_sum += e_orig_mapped[env][k] as f32; + e_o_sum += e_orig_mapped[env][k]; e_c_sum += e_curr[env][k]; } *dst = (e_o_sum / e_c_sum).sqrt() * LIM_GAIN[hdr.limiter_gains as usize]; start = end; } for k in kx..km { - let e_orig = e_orig_mapped[env][k] as f32; - let q_orig = q_mapped[env][k] as f32; + let e_orig = e_orig_mapped[env][k]; + let q_orig = q_mapped[env][k]; let e_curr = e_curr[env][k]; q_m[k] = (e_orig * q_orig / (1.0 + q_orig)).sqrt(); @@ -485,7 +485,7 @@ impl SBRChannel { let mut nsum = EPS0; let mut dsum = EPS0; for k in start..end { - nsum += e_orig_mapped[env][k] as f32; + nsum += e_orig_mapped[env][k]; dsum += e_curr[env][k] * g_lim[k] * g_lim[k]; if s_m[k] != 0.0 || (env as i8) == l_a || (env as i8) == la_prev { dsum += s_m[k] * s_m[k]; diff --git a/nihav-mpeg/src/codecs/mpegaudio/mod.rs b/nihav-mpeg/src/codecs/mpegaudio/mod.rs index 99b5772..677e81b 100644 --- a/nihav-mpeg/src/codecs/mpegaudio/mod.rs +++ b/nihav-mpeg/src/codecs/mpegaudio/mod.rs @@ -81,7 +81,7 @@ impl MPADecoder { ctx.mpeg1 = self.sf_idx < 3; ctx.sf_idx = self.sf_idx; ctx.read_mp3_side_data(br, channels)?; - let hdr_size = (br.tell() / 8) as usize; + let hdr_size = br.tell() / 8; let add_len = src.len() - hdr_size; if self.bytebuf.len() + add_len > BYTEBUF_SIZE { self.bytebuf.drain(..self.bytebuf.len() + add_len - BYTEBUF_SIZE); diff --git a/nihav-mpeg/src/lib.rs b/nihav-mpeg/src/lib.rs index a40decf..5e16125 100644 --- a/nihav-mpeg/src/lib.rs +++ b/nihav-mpeg/src/lib.rs @@ -4,7 +4,11 @@ extern crate nihav_codec_support; #[cfg(feature="decoders")] #[allow(clippy::collapsible_if)] +#[allow(clippy::collapsible_else_if)] #[allow(clippy::needless_range_loop)] +#[allow(clippy::needless_late_init)] +#[allow(clippy::manual_range_contains)] +#[allow(clippy::upper_case_acronyms)] mod codecs; #[cfg(feature="decoders")] diff --git a/nihav-ms/src/codecs/imaadpcmenc.rs b/nihav-ms/src/codecs/imaadpcmenc.rs index a113d5d..f2a2223 100644 --- a/nihav-ms/src/codecs/imaadpcmenc.rs +++ b/nihav-ms/src/codecs/imaadpcmenc.rs @@ -96,7 +96,6 @@ impl IMAADPCMEncoder { nw.write(nib)?; } } - drop(nw); } else { self.nodes.reserve(self.block_len); self.nibs.resize(self.channels, Vec::new()); @@ -164,7 +163,6 @@ impl IMAADPCMEncoder { nw.write(self.nibs[ch][i])?; } } - drop(nw); } self.samples.drain(..self.block_len * self.channels); diff --git a/nihav-ms/src/codecs/mod.rs b/nihav-ms/src/codecs/mod.rs index 739315b..736884b 100644 --- a/nihav-ms/src/codecs/mod.rs +++ b/nihav-ms/src/codecs/mod.rs @@ -43,6 +43,7 @@ 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 179b097..23769de 100644 --- a/nihav-ms/src/codecs/msadpcm.rs +++ b/nihav-ms/src/codecs/msadpcm.rs @@ -267,7 +267,6 @@ impl MSADPCMEncoder { } } self.samples.drain(..len * self.channels); - drop(bw); let ts = NATimeInfo::new(None, None, Some(1), 1, self.srate); Ok(NAPacket::new(self.stream.clone().unwrap(), ts, true, dbuf)) } diff --git a/nihav-ms/src/codecs/msvideo1enc.rs b/nihav-ms/src/codecs/msvideo1enc.rs index 4507e08..f457dfc 100644 --- a/nihav-ms/src/codecs/msvideo1enc.rs +++ b/nihav-ms/src/codecs/msvideo1enc.rs @@ -316,7 +316,7 @@ impl BlockState { self.clr2.swap(0, 1); } } else { - let (clrs, mask, dist) = quant2_16pix(&buf); + let (clrs, mask, dist) = quant2_16pix(buf); self.clr2 = clrs; self.clr2_flags = mask; self.clr2_dist = dist; @@ -581,7 +581,7 @@ impl MSVideo1Encoder { let dst = cur_frm.get_data_mut().unwrap(); let mut skip_run = 0; let bpainter = BlockPainter15::new(); - for ((sstrip, rstrip), dstrip) in (&src[soff..]).chunks(sstride * 4).take(h / 4).zip((&rsrc[roff..]).chunks(rstride * 4)).zip((&mut dst[doff..]).chunks_mut(dstride * 4)) { + for ((sstrip, rstrip), dstrip) in src[soff..].chunks(sstride * 4).take(h / 4).zip(rsrc[roff..].chunks(rstride * 4)).zip(dst[doff..].chunks_mut(dstride * 4)) { for x in (0..w).step_by(4) { let mut buf = [UnpackedPixel::default(); 16]; let mut refbuf = [UnpackedPixel::default(); 16]; @@ -662,7 +662,7 @@ impl MSVideo1Encoder { let doff = cur_frm.get_offset(0); let dst = cur_frm.get_data_mut().unwrap(); let bpainter = BlockPainter15::new(); - for (sstrip, dstrip) in (&src[soff..]).chunks(sstride * 4).take(h / 4).zip((&mut dst[doff..]).chunks_mut(dstride * 4)) { + for (sstrip, dstrip) in src[soff..].chunks(sstride * 4).take(h / 4).zip(dst[doff..].chunks_mut(dstride * 4)) { for x in (0..w).step_by(4) { let mut buf = [UnpackedPixel::default(); 16]; Self::get_block(&sstrip[x..], sstride, &mut buf); @@ -701,7 +701,7 @@ impl MSVideo1Encoder { let dst = cur_frm.get_data_mut().unwrap(); let mut skip_run = 0; let bpainter = BlockPainterPal::new(ls); - for ((sstrip, rstrip), dstrip) in (&src[soff..]).chunks(sstride * 4).take(h / 4).zip((&rsrc[roff..]).chunks(rstride * 4)).zip((&mut dst[doff..]).chunks_mut(dstride * 4)) { + for ((sstrip, rstrip), dstrip) in src[soff..].chunks(sstride * 4).take(h / 4).zip(rsrc[roff..].chunks(rstride * 4)).zip(dst[doff..].chunks_mut(dstride * 4)) { for x in (0..w).step_by(4) { let mut buf = [UnpackedPixel::default(); 16]; let mut refbuf = [UnpackedPixel::default(); 16]; @@ -782,7 +782,7 @@ impl MSVideo1Encoder { let doff = cur_frm.get_offset(0); let dst = cur_frm.get_data_mut().unwrap(); let bpainter = BlockPainterPal::new(ls); - for (sstrip, dstrip) in (&src[soff..]).chunks(sstride * 4).take(h / 4).zip((&mut dst[doff..]).chunks_mut(dstride * 4)) { + for (sstrip, dstrip) in src[soff..].chunks(sstride * 4).take(h / 4).zip(dst[doff..].chunks_mut(dstride * 4)) { for x in (0..w).step_by(4) { let mut buf = [UnpackedPixel::default(); 16]; Self::get_block8(&sstrip[x..], sstride, &mut buf, pal); @@ -932,7 +932,7 @@ impl NAEncoder for MSVideo1Encoder { for (cur_pal, new_pal) in self.pal.iter_mut().zip(pal.chunks_exact(3)) { let (cur_clr, luma) = cur_pal.split_at_mut(3); let new_clr = [u16::from(new_pal[0]), u16::from(new_pal[1]), u16::from(new_pal[2])]; - if cur_clr != &new_clr { + if cur_clr != new_clr { pal_changed = true; cur_clr.copy_from_slice(&new_clr); luma[0] = rgb2y(cur_clr[0], cur_clr[1], cur_clr[2]); diff --git a/nihav-ms/src/lib.rs b/nihav-ms/src/lib.rs index 2274a20..7eec3c2 100644 --- a/nihav-ms/src/lib.rs +++ b/nihav-ms/src/lib.rs @@ -3,6 +3,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; diff --git a/nihav-qt/src/codecs/qdm2qmf.rs b/nihav-qt/src/codecs/qdm2qmf.rs index 214f7af..d8cafa2 100644 --- a/nihav-qt/src/codecs/qdm2qmf.rs +++ b/nihav-qt/src/codecs/qdm2qmf.rs @@ -359,7 +359,7 @@ unimplemented!(); } q = q.wrapping_sub(self.grid_3_quant[ch][band - 4]); } - self.tone_idx[ch][band][i] = q as i8; + self.tone_idx[ch][band][i] = q; if q > 0 || (self.is_intra && q == 0) { self.tone_scale[ch][band][i] = TONE_SCALES[0][(q & 0x3F) as usize]; } else { diff --git a/nihav-qt/src/codecs/qdmcommon.rs b/nihav-qt/src/codecs/qdmcommon.rs index 6011140..17ce03f 100644 --- a/nihav-qt/src/codecs/qdmcommon.rs +++ b/nihav-qt/src/codecs/qdmcommon.rs @@ -93,13 +93,13 @@ impl<'a, S: Copy> CodebookReader for QdmBitReader<'a> { let mut idx = 0; let mut lut_bits = cb.lut_bits; while esc { - let lut_idx = (self.peek(lut_bits) as usize) + (idx as usize); + let lut_idx = (self.peek(lut_bits) as usize) + idx; if cb.table[lut_idx] == TABLE_FILL_VALUE { return Err(CodebookError::InvalidCode); } let bits = cb.table[lut_idx] & 0x7F; esc = (cb.table[lut_idx] & 0x80) != 0; idx = (cb.table[lut_idx] >> 8) as usize; let skip_bits = if esc { u32::from(lut_bits) } else { bits }; - self.skip(skip_bits as u32); + self.skip(skip_bits); lut_bits = bits as u8; } Ok(cb.syms[idx]) diff --git a/nihav-qt/src/codecs/rpza.rs b/nihav-qt/src/codecs/rpza.rs index e0efd26..7eb1d8b 100644 --- a/nihav-qt/src/codecs/rpza.rs +++ b/nihav-qt/src/codecs/rpza.rs @@ -25,7 +25,7 @@ impl RpzaDecoder { } fn put_block(dst: &mut [u16], dstride: usize, block: &[u16; 16]) { for (line, src) in dst.chunks_mut(dstride).take(4).zip(block.chunks(4)) { - (&mut line[..4]).copy_from_slice(src); + line[..4].copy_from_slice(src); } } } diff --git a/nihav-qt/src/codecs/smc.rs b/nihav-qt/src/codecs/smc.rs index b53ca5c..7b01097 100644 --- a/nihav-qt/src/codecs/smc.rs +++ b/nihav-qt/src/codecs/smc.rs @@ -26,7 +26,7 @@ impl SmcDecoder { } fn put_block(dst: &mut [u8], dstride: usize, block: &[u8; 16]) { for (line, src) in dst.chunks_mut(dstride).take(4).zip(block.chunks(4)) { - (&mut line[..4]).copy_from_slice(src); + line[..4].copy_from_slice(src); } } fn put_blocks(&self, dst: &mut [u8], stride: usize, doff: &mut usize, x: &mut usize, len: usize, block: &[u8; 16]) { diff --git a/nihav-qt/src/codecs/svq3.rs b/nihav-qt/src/codecs/svq3.rs index 3852d6d..1a87ca6 100644 --- a/nihav-qt/src/codecs/svq3.rs +++ b/nihav-qt/src/codecs/svq3.rs @@ -261,7 +261,7 @@ fn decode_alt_slice(br: &mut BitReader, blk: &mut [i16; 16], mut idx: usize, end SVQ3_RUNLEVEL_ALT[val as usize] } else { let run = (val & 0x7) as usize; - (run, ((val >> 3) as i16) + RUN_ADD_ALT[(run as usize).min(RUN_ADD_ALT.len() - 1)]) + (run, ((val >> 3) as i16) + RUN_ADD_ALT[run.min(RUN_ADD_ALT.len() - 1)]) }; idx += run; validate!(idx < end); @@ -289,7 +289,7 @@ fn decode_block(br: &mut BitReader, blk: &mut [i16; 16], start: usize, alt: bool SVQ3_RUNLEVEL[val as usize] } else { let run = (val & 0xF) as usize; - (run, ((val >> 4) as i16) + RUN_ADD[(run as usize).min(RUN_ADD.len() - 1)]) + (run, ((val >> 4) as i16) + RUN_ADD[run.min(RUN_ADD.len() - 1)]) }; idx += run; validate!(idx < blk.len()); @@ -674,7 +674,7 @@ unimplemented!(); } else { MCMode::Pixel }; - let (bw, bh) = SVQ3_PART_SIZES[mb_type as usize]; + let (bw, bh) = SVQ3_PART_SIZES[mb_type]; let bw = (bw >> 2) as usize; let bh = (bh >> 2) as usize; @@ -1167,9 +1167,7 @@ impl NADecoder for SVQ3Decoder { } let ret = self.decode_slice(&mut br, &hdr, &mut dframe); std::mem::swap(&mut sbuf, &mut self.slice_buf); - if let Err(err) = ret { - return Err(err); - } + ret?; slice_prepared = false; off += slice_len; } diff --git a/nihav-qt/src/lib.rs b/nihav-qt/src/lib.rs index 2c2e792..59c415c 100644 --- a/nihav-qt/src/lib.rs +++ b/nihav-qt/src/lib.rs @@ -4,5 +4,8 @@ extern crate nihav_codec_support; #[allow(clippy::comparison_chain)] #[allow(clippy::single_match)] +#[allow(clippy::field_reassign_with_default)] +#[allow(clippy::upper_case_acronyms)] +#[allow(clippy::collapsible_else_if)] mod codecs; pub use crate::codecs::qt_register_all_decoders; diff --git a/nihav-rad/src/codecs/binkaud.rs b/nihav-rad/src/codecs/binkaud.rs index 039e441..7848e7e 100644 --- a/nihav-rad/src/codecs/binkaud.rs +++ b/nihav-rad/src/codecs/binkaud.rs @@ -45,8 +45,8 @@ fn read_bink_float(br: &mut BitReader) -> DecoderResult { Ok(v) }*/ let exp = br.read(5)? as u8; - let mant = br.read(23)? as u32; - let sign = br.read(1)? as u32; + let mant = br.read(23)?; + let sign = br.read(1)?; let nexp = exp.wrapping_add(0x7E) as u32; let nmant = (mant << 1) & ((1 << 23) - 1); Ok(f32::from_bits((sign << 31) | (nexp << 23) | nmant)) diff --git a/nihav-rad/src/codecs/binkvid.rs b/nihav-rad/src/codecs/binkvid.rs index 65ab3cf..7a31486 100644 --- a/nihav-rad/src/codecs/binkvid.rs +++ b/nihav-rad/src/codecs/binkvid.rs @@ -227,7 +227,7 @@ impl Bundle { last = col_hi[last as usize].read_sym(br, trees)?; let lo = self.tree.read_sym(br, trees)?; let val = Self::cvt_color(lo, last, new_bink); - for i in 0..len { self.data[self.dec_pos + i] = val as u8; } + for i in 0..len { self.data[self.dec_pos + i] = val; } self.dec_pos += len; } else { while self.dec_pos < end { diff --git a/nihav-rad/src/codecs/smacker.rs b/nihav-rad/src/codecs/smacker.rs index c1b9fd6..d834c7e 100644 --- a/nihav-rad/src/codecs/smacker.rs +++ b/nihav-rad/src/codecs/smacker.rs @@ -138,7 +138,7 @@ impl SmackerTree16 { let mut esc: [u32; 3] = [0; 3]; for i in 0..esc.len() { - esc[i] = br.read(16)? as u32; + esc[i] = br.read(16)?; } let nsyms = (((size + 3) >> 2) + 4) as usize; @@ -573,7 +573,7 @@ impl NADecoder for SmackerAudioDecoder { let mut pred: [u8; 2] = [ pred1, pred0 ]; for ch in 0..2 { dst[ch] = pred[ch]; } for i in 2..unp_size { - let diff = br.read_tree8(&trees[i & 1])? as u8; + let diff = br.read_tree8(&trees[i & 1])?; pred[i & 1] = pred[i & 1].wrapping_add(diff); dst[i] = pred[i & 1]; } @@ -583,7 +583,7 @@ impl NADecoder for SmackerAudioDecoder { let mut pred = br.read(8)? as u8; dst[0] = pred; for i in 1..unp_size { - let diff = br.read_tree8(&tree)? as u8; + let diff = br.read_tree8(&tree)?; pred = pred.wrapping_add(diff); dst[i] = pred; } diff --git a/nihav-rad/src/demuxers/smacker.rs b/nihav-rad/src/demuxers/smacker.rs index fe64191..00724cf 100644 --- a/nihav-rad/src/demuxers/smacker.rs +++ b/nihav-rad/src/demuxers/smacker.rs @@ -252,11 +252,7 @@ impl<'a> DemuxCore<'a> for SmackerVideoDemuxer<'a> { Ok(pkt) } fn seek(&mut self, time: NATimePoint, _seek_idx: &SeekIndex) -> DemuxerResult<()> { - let seek_to_start = match time { - NATimePoint::Milliseconds(0) => true, - NATimePoint::PTS(0) => true, - _ => false, - }; + let seek_to_start = matches!(time, NATimePoint::Milliseconds(0) | NATimePoint::PTS(0)); if seek_to_start { let start = self.start; self.src.seek(SeekFrom::Start(start))?; diff --git a/nihav-rad/src/lib.rs b/nihav-rad/src/lib.rs index d407fa7..f7bce33 100644 --- a/nihav-rad/src/lib.rs +++ b/nihav-rad/src/lib.rs @@ -5,12 +5,15 @@ extern crate nihav_codec_support; #[cfg(feature="decoders")] #[allow(clippy::cast_lossless)] #[allow(clippy::collapsible_if)] +#[allow(clippy::collapsible_else_if)] #[allow(clippy::excessive_precision)] #[allow(clippy::identity_op)] #[allow(clippy::needless_range_loop)] +#[allow(clippy::needless_late_init)] #[allow(clippy::too_many_arguments)] #[allow(clippy::unreadable_literal)] #[allow(clippy::useless_let_if_seq)] +#[allow(clippy::upper_case_acronyms)] mod codecs; #[cfg(feature="decoders")] pub use crate::codecs::rad_register_all_decoders; diff --git a/nihav-realmedia/src/codecs/cook.rs b/nihav-realmedia/src/codecs/cook.rs index 48bdb0a..1afe246 100644 --- a/nihav-realmedia/src/codecs/cook.rs +++ b/nihav-realmedia/src/codecs/cook.rs @@ -292,7 +292,7 @@ impl CookChannelPair { for _ in 0..num_vectors { let idx = tcat[tcat_idx2]; tcat_idx2 += 1; - self.category[idx] = (self.category[idx] + 1).min((NUM_CATEGORIES - 1) as u8) as u8; + self.category[idx] = (self.category[idx] + 1).min((NUM_CATEGORIES - 1) as u8); } } fn decode_channel_data(&mut self, dsp: &mut CookDSP, rnd: &mut RND, codebooks: &Codebooks, src: &[u8], buf: &mut [u8], channel: usize) -> DecoderResult<()> { diff --git a/nihav-realmedia/src/codecs/rv20.rs b/nihav-realmedia/src/codecs/rv20.rs index f25df6b..333e91a 100644 --- a/nihav-realmedia/src/codecs/rv20.rs +++ b/nihav-realmedia/src/codecs/rv20.rs @@ -257,7 +257,7 @@ impl<'a> RealVideo20BR<'a> { let rl_cb = if sstate.is_iframe { &self.tables.aic_rl_cb } else { &self.tables.rl_cb }; let q = if plane_no == 0 { (quant * 2) as i16 } else { (H263_CHROMA_QUANT[quant as usize] * 2) as i16 }; - let q_add = if q == 0 || sstate.is_iframe { 0i16 } else { (((q >> 1) - 1) | 1) as i16 }; + let q_add = if q == 0 || sstate.is_iframe { 0i16 } else { ((q >> 1) - 1) | 1 }; while idx < 64 { let code = br.read_cb(rl_cb)?; let run; @@ -593,7 +593,7 @@ impl RealVideo20Decoder { h: 0, minor_ver: 0, rpr: RPRInfo { present: false, bits: 0, widths: [0; 8], heights: [0; 8] }, - bdsp: Box::new(RV20BlockDSP::default()), + bdsp: Box::::default(), base_ts: 0, last_ts: 0, next_ts: 0, @@ -626,7 +626,7 @@ impl NADecoder for RealVideo20Decoder { self.rpr.present = false; } else { self.rpr.present = true; - self.rpr.bits = ((rprb >> 1) + 1).min(3) as u8; + self.rpr.bits = ((rprb >> 1) + 1).min(3); let num_dim = ((src.len() - 8) / 2).min(self.rpr.widths.len() - 1); for i in 0..num_dim { self.rpr.widths [i] = (src[i * 2 + 8] as usize) * 4; diff --git a/nihav-realmedia/src/codecs/rv40enc/bitstream.rs b/nihav-realmedia/src/codecs/rv40enc/bitstream.rs index bd0bacc..892b7ff 100644 --- a/nihav-realmedia/src/codecs/rv40enc/bitstream.rs +++ b/nihav-realmedia/src/codecs/rv40enc/bitstream.rs @@ -432,7 +432,7 @@ impl CodeSets { } } pub fn init(&mut self, quant: usize, subset: usize) { - let mut idx = quant as usize; + let mut idx = quant; if (subset == 2) && (idx < 19) { idx += 10; } else if (subset != 0) && (idx < 26) { diff --git a/nihav-realmedia/src/codecs/rv40enc/mod.rs b/nihav-realmedia/src/codecs/rv40enc/mod.rs index 9adecfb..071a7ae 100644 --- a/nihav-realmedia/src/codecs/rv40enc/mod.rs +++ b/nihav-realmedia/src/codecs/rv40enc/mod.rs @@ -631,7 +631,7 @@ impl RV40Encoder { } if self.debug_log.is_set(DEBUG_BIT_PSNR) { - let psnr = calc_psnr(&vbuf, &rvbuf); + let psnr = calc_psnr(vbuf, &rvbuf); println!(" encoded frame PSNR {} size {}", psnr, dvec.len()); } @@ -675,7 +675,7 @@ fn calc_psnr(pic1: &NAVideoBuffer, pic2: &NAVideoBuffer) -> f64 { for (line1, line2) in data1[pic1.get_offset(comp)..].chunks(pic1.get_stride(comp)).zip( data2[pic2.get_offset(comp)..].chunks(pic2.get_stride(comp))).take(h) { for (&pix1, &pix2) in line1[..w].iter().zip(line2.iter()) { - let diff = (i32::from(pix1) - i32::from(pix2)).abs() as u32; + let diff = (i32::from(pix1) - i32::from(pix2)).unsigned_abs(); sum += u64::from(diff * diff); } } diff --git a/nihav-realmedia/src/codecs/rv40enc/motion_est.rs b/nihav-realmedia/src/codecs/rv40enc/motion_est.rs index 63d4663..9fa18e9 100644 --- a/nihav-realmedia/src/codecs/rv40enc/motion_est.rs +++ b/nihav-realmedia/src/codecs/rv40enc/motion_est.rs @@ -3,10 +3,11 @@ use nihav_codec_support::codecs::{MV, ZERO_MV}; use std::str::FromStr; use super::dsp::{RefMBData, luma_mc, chroma_mc}; -#[derive(Clone,Copy,PartialEq)] +#[derive(Clone,Copy,PartialEq,Default)] pub enum MVSearchMode { Dummy, Diamond, + #[default] Hexagon, UMH, } @@ -25,10 +26,6 @@ impl MVSearchMode { } } -impl Default for MVSearchMode { - fn default() -> Self { MVSearchMode::Hexagon } -} - impl std::fmt::Display for MVSearchMode { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match *self { @@ -878,7 +875,7 @@ impl FrameComplexityEstimate { hadamard!(diffs[i], diffs[i + 4], diffs[i + 8], diffs[i + 12], diffs[i], diffs[i + 4], diffs[i + 8], diffs[i + 12]); } - diffs.iter().fold(0u32, |acc, x| acc + (x.abs() as u32)) + diffs.iter().fold(0u32, |acc, x| acc + (x.unsigned_abs() as u32)) } fn satd(src0: &[u8], src1: &[u8], stride: usize) -> u32 { let mut diffs = [0; 16]; @@ -894,7 +891,7 @@ impl FrameComplexityEstimate { hadamard!(diffs[i], diffs[i + 4], diffs[i + 8], diffs[i + 12], diffs[i], diffs[i + 4], diffs[i + 8], diffs[i + 12]); } - diffs.iter().fold(0u32, |acc, x| acc + (x.abs() as u32)) + diffs.iter().fold(0u32, |acc, x| acc + (x.unsigned_abs() as u32)) } fn downscale(dst: &mut NAVideoBuffer, src: &NAVideoBuffer) { let dst = NASimpleVideoFrame::from_video_buf(dst).unwrap(); diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index 844e1ab..befe7a6 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -233,22 +233,20 @@ const RV60_AVAIL_MASK: [u8; 64] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; -#[derive(Clone,Copy,PartialEq,Debug)] +#[derive(Clone,Copy,PartialEq,Debug,Default)] enum CUType { + #[default] Intra, InterMV, Skip, InterNoMV, } -impl Default for CUType { - fn default() -> Self { CUType::Intra } -} - const RV60_CU_TYPES: [CUType; 4] = [ CUType::Intra, CUType::InterMV, CUType::Skip, CUType::InterNoMV ]; -#[derive(Clone,Copy,PartialEq,Debug)] +#[derive(Clone,Copy,PartialEq,Debug,Default)] enum PUType { + #[default] Full, N2Hor, N2Ver, @@ -317,10 +315,6 @@ impl PUType { } } -impl Default for PUType { - fn default() -> Self { PUType::Full } -} - #[derive(Clone,Copy,Debug)] enum IntraMode { Index(u8), @@ -329,18 +323,15 @@ enum IntraMode { Plane64, } -#[derive(Clone,Copy,PartialEq,Debug)] +#[derive(Clone,Copy,PartialEq,Debug,Default)] enum TransformType { + #[default] None, T4X4, T8X8, T16X16, } -impl Default for TransformType { - fn default() -> Self { TransformType::None } -} - #[derive(Clone,Copy,PartialEq,Debug)] enum MVRef { None, @@ -1502,7 +1493,7 @@ impl NADecoder for RealVideo60Decoder { if hdr.deblock { self.dblk.reinit(hdr.awidth, hdr.aheight); } - let mut off = hsize + ((br.tell() >> 3) as usize); + let mut off = hsize + (br.tell() >> 3); let mut dframe = NASimpleVideoFrame::from_video_buf(&mut buf).unwrap(); for (cu_y, size) in slices.into_iter().enumerate() { self.decode_cu_line(&mut dframe, &hdr, &src[off..][..size], cu_y)?; diff --git a/nihav-realmedia/src/codecs/rv60codes.rs b/nihav-realmedia/src/codecs/rv60codes.rs index 8effbb5..390458c 100644 --- a/nihav-realmedia/src/codecs/rv60codes.rs +++ b/nihav-realmedia/src/codecs/rv60codes.rs @@ -169,7 +169,7 @@ fn quant(val: i16, q: i16) -> i16 { (val * q + 8) >> 4 } fn decode_2x2_dc(br: &mut BitReader, cb: &Codebook, coeffs: &mut [i16], stride: usize, block2: bool, dsc: usize, q_dc: i16, q_ac: i16) -> DecoderResult<()> { if dsc == 0 { return Ok(()); } - let lx = RV60_DSC_TO_LX[dsc as usize]; + let lx = RV60_DSC_TO_LX[dsc]; let l0 = ((lx >> 0) & 0xFF) as i16; let l1 = ((lx >> 8) & 0xFF) as i16; let l2 = ((lx >> 16) & 0xFF) as i16; @@ -187,7 +187,7 @@ fn decode_2x2_dc(br: &mut BitReader, cb: &Codebook, coeffs: &mut [i16], str } fn decode_2x2(br: &mut BitReader, cb: &Codebook, coeffs: &mut [i16], stride: usize, block2: bool, dsc: usize, q_ac: i16) -> DecoderResult<()> { if dsc == 0 { return Ok(()); } - let lx = RV60_DSC_TO_LX[dsc as usize]; + let lx = RV60_DSC_TO_LX[dsc]; let l0 = ((lx >> 0) & 0xFF) as i16; let l1 = ((lx >> 8) & 0xFF) as i16; let l2 = ((lx >> 16) & 0xFF) as i16; diff --git a/nihav-realmedia/src/demuxers/realmedia.rs b/nihav-realmedia/src/demuxers/realmedia.rs index 6335c6d..7f94cdc 100644 --- a/nihav-realmedia/src/demuxers/realmedia.rs +++ b/nihav-realmedia/src/demuxers/realmedia.rs @@ -398,7 +398,7 @@ fn read_14or30(src: &mut ByteReader) -> DemuxerResult<(bool, u32)> { } fn read_video_buf(src: &mut ByteReader, stream: NAStreamRef, ts: u32, keyframe: bool, frame_size: usize) -> DemuxerResult { - let size = (frame_size as usize) + 9; + let size = frame_size + 9; let mut vec: Vec = vec![0; size]; //v[0] = 0; // 1 slice vec[4] = 1; @@ -444,7 +444,7 @@ impl RMDemuxCommon { let soniton = NASoniton::new(samp_size as u8, SONITON_FLAG_SIGNED); let ahdr = NAAudioInfo::new(sample_rate, channels as u8, soniton, 1); let nainfo = NACodecInfo::new("ralf", NACodecTypeInfo::Audio(ahdr), extradata); - let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no as u32, nainfo, 1, 1000, u64::from(duration))); + let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no, nainfo, 1, 1000, u64::from(duration))); if res.is_none() { return Err(MemoryError); } let astr = RMAudioStream::new(None); str_data.streams.push(RMStreamType::Audio(astr)); @@ -530,7 +530,7 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); }; let duration = if duration == 0 { ainfo.get_duration(1000) } else { u64::from(duration) }; let nainfo = NACodecInfo::new(cname, NACodecTypeInfo::Audio(ahdr), extradata); - let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no as u32, nainfo, 1, 1000, duration)); + let res = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_no, nainfo, 1, 1000, duration)); if res.is_none() { return Err(MemoryError); } let astr = RMAudioStream::new(ainfo.ileave_info); @@ -563,7 +563,7 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); let vhdr = NAVideoInfo::new(width, height, false, RGB24_FORMAT); let vinfo = NACodecInfo::new(cname, NACodecTypeInfo::Video(vhdr), extradata); - let res = strmgr.add_stream(NAStream::new(StreamType::Video, stream_no as u32, vinfo, 1, 1000, u64::from(duration))); + let res = strmgr.add_stream(NAStream::new(StreamType::Video, stream_no, vinfo, 1, 1000, u64::from(duration))); if res.is_none() { return Err(DemuxerError::MemoryError); } let vstr = RMVideoStream::new(); @@ -571,6 +571,7 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); Ok(()) } #[allow(unused_variables)] + #[allow(clippy::question_mark)] fn parse_packet_payload(src: &mut ByteReader, rmstream: &mut RMStreamType, stream: NAStreamRef, slice_buf: &mut Vec, queued_pkts: &mut Vec, keyframe: bool, ts: u32, payload_size: usize) -> DemuxerResult { match rmstream { RMStreamType::Video(ref mut vstr) => { @@ -588,7 +589,7 @@ println!("unknown MLTI substream {:08X} / {:08X}", tag, tag2); let seq_no = src.read_byte()?; let hdr_skip = (src.tell() - pos) as usize; - let slice_size = (payload_size - hdr_skip) as usize; + let slice_size = payload_size - hdr_skip; slice_buf.resize(slice_size, 0); src.read_buf(slice_buf.as_mut_slice())?; if packet_num == 1 { @@ -714,7 +715,7 @@ impl<'a> DemuxCore<'a> for RealMediaDemuxer<'a> { let payload_size = len - (hdr_size as usize); - let stream_id = self.str_data.get_stream_id(str_no as u32, pkt_grp); + let stream_id = self.str_data.get_stream_id(str_no, pkt_grp); let sr = self.str_data.find_stream(stream_id); if sr.is_none() { self.src.read_skip(payload_size)?; @@ -1502,7 +1503,7 @@ impl RecordDemuxer { validate!(sr.is_some()); let str_no = self.start_str + (sr.unwrap() as u32); let pkt_grp = ((flags >> 8) & 0xFF) as u16; - let stream_id = str_data.get_stream_id(str_no as u32, pkt_grp); + let stream_id = str_data.get_stream_id(str_no, pkt_grp); let sr = str_data.find_stream(stream_id); if sr.is_none() { src.read_skip(payload_size)?; diff --git a/nihav-realmedia/src/lib.rs b/nihav-realmedia/src/lib.rs index 9cacc28..a5083c0 100644 --- a/nihav-realmedia/src/lib.rs +++ b/nihav-realmedia/src/lib.rs @@ -5,6 +5,7 @@ extern crate nihav_codec_support; #[cfg(any(feature="decoders", feature="encoders"))] #[allow(clippy::cast_lossless)] #[allow(clippy::collapsible_if)] +#[allow(clippy::collapsible_else_if)] #[allow(clippy::comparison_chain)] #[allow(clippy::excessive_precision)] #[allow(clippy::identity_op)] @@ -13,6 +14,10 @@ extern crate nihav_codec_support; #[allow(clippy::too_many_arguments)] #[allow(clippy::unreadable_literal)] #[allow(clippy::useless_let_if_seq)] +#[allow(clippy::needless_late_init)] +#[allow(clippy::upper_case_acronyms)] +#[allow(clippy::manual_range_contains)] +#[allow(clippy::wrong_self_convention)] mod codecs; #[cfg(feature="decoders")] pub use crate::codecs::realmedia_register_all_decoders; @@ -24,6 +29,8 @@ pub use crate::codecs::realmedia_register_all_encoders; #[allow(clippy::too_many_arguments)] #[allow(clippy::unreadable_literal)] #[allow(clippy::useless_let_if_seq)] +#[allow(clippy::needless_late_init)] +#[allow(clippy::upper_case_acronyms)] mod demuxers; #[cfg(feature="demuxers")] pub use crate::demuxers::realmedia_register_all_demuxers; diff --git a/nihav-realmedia/src/muxers/rmvb/audiostream.rs b/nihav-realmedia/src/muxers/rmvb/audiostream.rs index 0e174a2..bd8d34e 100644 --- a/nihav-realmedia/src/muxers/rmvb/audiostream.rs +++ b/nihav-realmedia/src/muxers/rmvb/audiostream.rs @@ -57,11 +57,7 @@ impl Interleaver for NoInterleaver { fn get_packet(&mut self) -> Option<(Vec, bool)> { let mut ret = None; std::mem::swap(&mut self.pkt, &mut ret); - if let Some(pkt) = ret { - Some((pkt, true)) - } else { - None - } + ret.map(|pkt| (pkt, true)) } fn flush(&mut self) {} } @@ -117,7 +113,7 @@ impl Interleaver for Int4Interleaver { return false; } let pos = self.map[self.cur_frame]; - self.buf[pos * self.frame_size..][..self.frame_size].copy_from_slice(&src); + self.buf[pos * self.frame_size..][..self.frame_size].copy_from_slice(src); self.cur_frame += 1; true } @@ -217,7 +213,7 @@ impl Interleaver for GenericInterleaver { return false; } let pos = self.map[self.cur_frame]; - self.buf[pos * self.frame_size..][..self.frame_size].copy_from_slice(&src); + self.buf[pos * self.frame_size..][..self.frame_size].copy_from_slice(src); self.cur_frame += 1; true } diff --git a/nihav-realmedia/src/muxers/rmvb/mod.rs b/nihav-realmedia/src/muxers/rmvb/mod.rs index 661e59a..1d08f4d 100644 --- a/nihav-realmedia/src/muxers/rmvb/mod.rs +++ b/nihav-realmedia/src/muxers/rmvb/mod.rs @@ -89,7 +89,7 @@ impl RMStream { self.mdpr_pos = bw.tell(); bw.write_chunk(b"MDPR", 0, 0)?; - bw.write_u16be(self.stream_id as u16)?; + bw.write_u16be(self.stream_id)?; bw.write_u32be(0)?; //max br bw.write_u32be(0)?; //avg br bw.write_u32be(0)?; //max ps @@ -453,7 +453,7 @@ impl<'a> MuxCore<'a> for RAMuxer<'a> { } fn end(&mut self) -> MuxerResult<()> { if let Some(ref mut sw) = self.sw { - sw.finish(&mut self.bw)?; + sw.finish(self.bw)?; } Ok(()) } diff --git a/nihav-realmedia/src/muxers/rmvb/videostream.rs b/nihav-realmedia/src/muxers/rmvb/videostream.rs index b6ed1a7..2d561e6 100644 --- a/nihav-realmedia/src/muxers/rmvb/videostream.rs +++ b/nihav-realmedia/src/muxers/rmvb/videostream.rs @@ -249,7 +249,7 @@ fn write_16_or_32(dst: &mut Vec, val: u32) { fn write_multiple_frame(dst: &mut Vec, frm: &VideoData) { dst.push(0xC0); // 0x3 = multiple frame write_16_or_32(dst, frm.data.len() as u32); - write_16_or_32(dst, frm.pts as u32); + write_16_or_32(dst, frm.pts); dst.push(frm.seq_no); dst.extend_from_slice(&frm.data); } diff --git a/nihav-registry/src/register.rs b/nihav-registry/src/register.rs index c8d3b60..7bfd172 100644 --- a/nihav-registry/src/register.rs +++ b/nihav-registry/src/register.rs @@ -147,12 +147,7 @@ macro_rules! desc { /// Returns codec description for the provided codec short name if it is found. pub fn get_codec_description(name: &str) -> Option<&'static CodecDescription> { - for reg in CODEC_REGISTER { - if reg.name == name { - return Some(reg); - } - } - None + CODEC_REGISTER.iter().find(|®| reg.name == name) } static CODEC_REGISTER: &[CodecDescription] = &[ diff --git a/nihav-vivo/src/codecs/g723_1.rs b/nihav-vivo/src/codecs/g723_1.rs index da00042..89d694d 100644 --- a/nihav-vivo/src/codecs/g723_1.rs +++ b/nihav-vivo/src/codecs/g723_1.rs @@ -396,7 +396,7 @@ impl G7231Decoder { Self::inverse_quant(&self.prev_lsp, &mut cur_lsp, &self.lsp_index, bad_frame); Self::interpolate_lsp(&mut self.lpc, &cur_lsp, &self.prev_lsp); self.prev_lsp.copy_from_slice(&cur_lsp); - (&mut self.excitation[..MAX_PITCH]).copy_from_slice(&self.prev_excitation); + self.excitation[..MAX_PITCH].copy_from_slice(&self.prev_excitation); if self.erased_frames == 0 { let mut acb_vector = [0; SUBFRAME_LEN]; self.interp_gain = FIXED_CB_GAIN[(self.subframe[2].amp_index + self.subframe[3].amp_index) >> 1]; @@ -562,15 +562,15 @@ impl G7231Decoder { } } - (&mut self.synth_buf[LPC_ORDER..][..MAX_PITCH]).copy_from_slice(&self.prev_excitation); + self.synth_buf[LPC_ORDER..][..MAX_PITCH].copy_from_slice(&self.prev_excitation); let mut acb_vec = [0; SUBFRAME_LEN]; let mut tmp = [0; SUBFRAME_LEN * 2]; for i in (0..SUBFRAMES).step_by(2) { let buf = &mut self.synth_buf[LPC_ORDER + SUBFRAME_LEN * i..]; self.subframe[i].gen_acb_excitation(&mut acb_vec, buf, self.is_6300); - (&mut buf[..SUBFRAME_LEN]).copy_from_slice(&acb_vec); + buf[..SUBFRAME_LEN].copy_from_slice(&acb_vec); self.subframe[i + 1].gen_acb_excitation(&mut acb_vec, &buf[SUBFRAME_LEN..], self.is_6300); - (&mut buf[SUBFRAME_LEN..][..SUBFRAME_LEN]).copy_from_slice(&acb_vec); + buf[SUBFRAME_LEN..][..SUBFRAME_LEN].copy_from_slice(&acb_vec); let mut max = 0; for j in 0..SUBFRAME_LEN*2 { @@ -783,9 +783,9 @@ impl G7231Decoder { } } fn formant_postfilter(&mut self, dst: &mut [i16]) { - (&mut self.synth_buf[..LPC_ORDER]).copy_from_slice(&self.fir_mem); + self.synth_buf[..LPC_ORDER].copy_from_slice(&self.fir_mem); let mut filter_data = [0; LPC_ORDER + SAMPLES]; - (&mut filter_data[..LPC_ORDER]).copy_from_slice(&self.iir_mem); + filter_data[..LPC_ORDER].copy_from_slice(&self.iir_mem); let mut filter_coef = [[0; LPC_ORDER]; 2]; for i in 0..SUBFRAMES { @@ -945,7 +945,7 @@ impl NADecoder for G7231Decoder { self.synth_frame_other(); } self.prev_ftype = self.cur_ftype; - (&mut self.synth_buf[..LPC_ORDER]).copy_from_slice(&self.filt_mem); + self.synth_buf[..LPC_ORDER].copy_from_slice(&self.filt_mem); for i in 0..SUBFRAMES { Self::do_lpc(&mut self.synth_buf, LPC_ORDER + i * SUBFRAME_LEN, &self.lpc[i]); } diff --git a/nihav-vivo/src/lib.rs b/nihav-vivo/src/lib.rs index b5fdfad..469babe 100644 --- a/nihav-vivo/src/lib.rs +++ b/nihav-vivo/src/lib.rs @@ -2,6 +2,8 @@ extern crate nihav_core; extern crate nihav_codec_support; +#[allow(clippy::upper_case_acronyms)] +#[allow(clippy::needless_late_init)] mod codecs; mod demuxers; -- 2.30.2