diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2022-09-22 17:53:58 +0200 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2022-09-22 17:53:58 +0200 |
commit | 6f2630992fe340ad1a122ec10c649f756e478185 (patch) | |
tree | c8c95d46546cd71e2cd5e15faef02ca9acd2b70b /nihav-core/src | |
parent | f44bddc9b5520507c7571b89763de668238d790a (diff) | |
download | nihav-6f2630992fe340ad1a122ec10c649f756e478185.tar.gz |
fix some clippy warnings
Diffstat (limited to 'nihav-core/src')
-rw-r--r-- | nihav-core/src/compr/deflate.rs | 7 | ||||
-rw-r--r-- | nihav-core/src/formats.rs | 54 | ||||
-rw-r--r-- | nihav-core/src/frame.rs | 23 | ||||
-rw-r--r-- | nihav-core/src/io/codebook.rs | 8 | ||||
-rw-r--r-- | nihav-core/src/options.rs | 4 | ||||
-rw-r--r-- | nihav-core/src/scale/mod.rs | 40 | ||||
-rw-r--r-- | nihav-core/src/scale/palette/mod.rs | 2 | ||||
-rw-r--r-- | nihav-core/src/soundcvt/mod.rs | 30 |
8 files changed, 67 insertions, 101 deletions
diff --git a/nihav-core/src/compr/deflate.rs b/nihav-core/src/compr/deflate.rs index b126661..71e0dfe 100644 --- a/nihav-core/src/compr/deflate.rs +++ b/nihav-core/src/compr/deflate.rs @@ -366,10 +366,7 @@ impl Inflate { } ///! Reports whether decoder has finished decoding the input. pub fn is_finished(&self) -> bool { - match self.state { - InflateState::End => true, - _ => false, - } + matches!(self.state, InflateState::End) } ///! Reports the current amount of bytes output into the destination buffer after the last run. pub fn get_current_output_size(&self) -> usize { self.output_idx } @@ -624,7 +621,7 @@ impl Inflate { let (lit_lengths, dist_lengths) = self.all_lengths.split_at(self.hlit); let mut lit_codes = [ShortCodebookDesc { code: 0, bits: 0 }; NUM_LITERALS]; - lengths_to_codes(&lit_lengths, &mut lit_codes)?; + lengths_to_codes(lit_lengths, &mut lit_codes)?; let mut cr = ShortCodebookDescReader::new(lit_codes.to_vec()); let ret = Codebook::new(&mut cr, CodebookMode::LSB); if ret.is_err() { return Err(DecompressError::InvalidHeader); } diff --git a/nihav-core/src/formats.rs b/nihav-core/src/formats.rs index 99370f9..c0027ec 100644 --- a/nihav-core/src/formats.rs +++ b/nihav-core/src/formats.rs @@ -148,35 +148,29 @@ pub enum NAChannelType { impl NAChannelType { /// Reports whether this is some center channel. pub fn is_center(self) -> bool { - match self { - NAChannelType::C => true, NAChannelType::Ch => true, - NAChannelType::Cl => true, NAChannelType::Ov => true, - NAChannelType::LFE => true, NAChannelType::LFE2 => true, - NAChannelType::Cs => true, NAChannelType::Chs => true, - _ => false, - } + matches!(self, + NAChannelType::C | NAChannelType::Ch | + NAChannelType::Cl | NAChannelType::Ov | + NAChannelType::LFE | NAChannelType::LFE2 | + NAChannelType::Cs | NAChannelType::Chs) } /// Reports whether this is some left channel. pub fn is_left(self) -> bool { - match self { - NAChannelType::L => true, NAChannelType::Ls => true, - NAChannelType::Lss => true, NAChannelType::Lc => true, - NAChannelType::Lh => true, NAChannelType::Lw => true, - NAChannelType::Lhs => true, NAChannelType::Ll => true, - NAChannelType::Lt => true, NAChannelType::Lo => true, - _ => false, - } + matches!(self, + NAChannelType::L | NAChannelType::Ls | + NAChannelType::Lss | NAChannelType::Lc | + NAChannelType::Lh | NAChannelType::Lw | + NAChannelType::Lhs | NAChannelType::Ll | + NAChannelType::Lt | NAChannelType::Lo) } /// Reports whether this is some right channel. pub fn is_right(self) -> bool { - match self { - NAChannelType::R => true, NAChannelType::Rs => true, - NAChannelType::Rss => true, NAChannelType::Rc => true, - NAChannelType::Rh => true, NAChannelType::Rw => true, - NAChannelType::Rhs => true, NAChannelType::Rl => true, - NAChannelType::Rt => true, NAChannelType::Ro => true, - _ => false, - } + matches!(self, + NAChannelType::R | NAChannelType::Rs | + NAChannelType::Rss | NAChannelType::Rc | + NAChannelType::Rh | NAChannelType::Rw | + NAChannelType::Rhs | NAChannelType::Rl | + NAChannelType::Rt | NAChannelType::Ro) } } @@ -400,17 +394,11 @@ impl ColorModel { } /// Reports whether the current colour model is RGB. pub fn is_rgb(self) -> bool { - match self { - ColorModel::RGB(_) => true, - _ => false, - } + matches!(self, ColorModel::RGB(_)) } /// Reports whether the current colour model is YUV. pub fn is_yuv(self) -> bool { - match self { - ColorModel::YUV(_) => true, - _ => false, - } + matches!(self, ColorModel::YUV(_)) } /// Returns short name for the current colour mode. pub fn get_short_name(self) -> &'static str { @@ -1029,7 +1017,7 @@ fn parse_yuv_format(s: &str) -> Result<NAPixelFormaton, FormatParseError> { let mut parse_end = components as usize; for ch in s.chars().skip(components as usize) { parse_end += 1; - if ch >= '0' && ch <= '9' { + if ('0'..='9').contains(&ch) { format = format * 10 + u32::from((ch as u8) - b'0'); if format > 444 { return Err(FormatParseError {}); } } else { @@ -1041,7 +1029,7 @@ fn parse_yuv_format(s: &str) -> Result<NAPixelFormaton, FormatParseError> { let depth = if s.len() == parse_end { 8 } else { let mut val = 0; for ch in s.chars().skip(parse_end) { - if ch >= '0' && ch <= '9' { + if ('0'..='9').contains(&ch) { 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 7a09be4..fbdbdf5 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -112,17 +112,11 @@ impl NACodecTypeInfo { } /// Reports whether the current stream is video stream. pub fn is_video(&self) -> bool { - match *self { - NACodecTypeInfo::Video(_) => true, - _ => false, - } + matches!(*self, NACodecTypeInfo::Video(_)) } /// Reports whether the current stream is audio stream. pub fn is_audio(&self) -> bool { - match *self { - NACodecTypeInfo::Audio(_) => true, - _ => false, - } + matches!(*self, NACodecTypeInfo::Audio(_)) } } @@ -560,10 +554,7 @@ pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result<NABufferType, } max_depth = max(max_depth, chr.get_depth()); } - let unfit_elem_size = match fmt.get_elem_size() { - 2 | 4 => false, - _ => true, - }; + let unfit_elem_size = !matches!(fmt.get_elem_size(), 2 | 4); //todo semi-packed like NV12 if fmt.is_paletted() { @@ -827,11 +818,7 @@ pub type NACodecInfoRef = Arc<NACodecInfo>; impl NACodecInfo { /// Constructs a new instance of `NACodecInfo`. pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self { - let extradata = match edata { - None => None, - Some(vec) => Some(Arc::new(vec)), - }; - NACodecInfo { name, properties: p, extradata } + NACodecInfo { name, properties: p, extradata: edata.map(Arc::new) } } /// Constructs a new reference-counted instance of `NACodecInfo`. pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option<Arc<Vec<u8>>>) -> Self { @@ -1145,7 +1132,7 @@ impl FromStr for NATimePoint { let mut mval = 0; let mut base = 0; for ch in val.chars() { - if ch >= '0' && ch <= '9' { + if ('0'..='9').contains(&ch) { mval = mval * 10 + u64::from((ch as u8) - b'0'); base += 1; if base > 3 { break; } diff --git a/nihav-core/src/io/codebook.rs b/nihav-core/src/io/codebook.rs index 0ec8883..6ea3b1e 100644 --- a/nihav-core/src/io/codebook.rs +++ b/nihav-core/src/io/codebook.rs @@ -144,7 +144,7 @@ pub trait CodebookReader<S> { pub const TABLE_FILL_VALUE: u32 = 0x7F; const MAX_LUT_BITS: u8 = 10; -fn fill_lut_msb(table: &mut Vec<u32>, off: usize, +fn fill_lut_msb(table: &mut [u32], off: usize, code: u32, bits: u8, lut_bits: u8, symidx: u32, esc: bool) -> CodebookResult<()> { if !esc { let fill_len = lut_bits - bits; @@ -164,7 +164,7 @@ fn fill_lut_msb(table: &mut Vec<u32>, off: usize, Ok(()) } -fn fill_lut_lsb(table: &mut Vec<u32>, off: usize, +fn fill_lut_lsb(table: &mut [u32], off: usize, code: u32, bits: u8, lut_bits: u8, symidx: u32, esc: bool) -> CodebookResult<()> { if !esc { let fill_len = lut_bits - bits; @@ -184,7 +184,7 @@ fn fill_lut_lsb(table: &mut Vec<u32>, off: usize, Ok(()) } -fn fill_lut(table: &mut Vec<u32>, mode: CodebookMode, +fn fill_lut(table: &mut [u32], mode: CodebookMode, off: usize, code: u32, bits: u8, lut_bits: u8, symidx: u32, esc: bool) -> CodebookResult<bool> { match mode { CodebookMode::MSB => fill_lut_msb(table, off, code, bits, lut_bits, symidx, esc)?, @@ -346,7 +346,7 @@ impl<S: Copy> Codebook<S> { } for bucket in escape_list.values() { - build_esc_lut(&mut table, mode, &bucket)?; + build_esc_lut(&mut table, mode, bucket)?; } for i in 0..cb.len() { diff --git a/nihav-core/src/options.rs b/nihav-core/src/options.rs index d3d8be8..4e4c7aa 100644 --- a/nihav-core/src/options.rs +++ b/nihav-core/src/options.rs @@ -183,7 +183,7 @@ impl NAOptionDefinition { Ok(()) }, NAValue::String(ref cur_str) => { - if let NAOptionDefinitionType::String(Some(ref strings)) = self.opt_type { + if let NAOptionDefinitionType::String(Some(strings)) = self.opt_type { for str in strings.iter() { if cur_str == str { return Ok(()); @@ -205,7 +205,7 @@ impl fmt::Display for NAOptionDefinition { NAOptionDefinitionType::None => write!(f, "{}: {}", self.name, self.description), NAOptionDefinitionType::Bool => write!(f, "[no]{}: {}", self.name, self.description), NAOptionDefinitionType::String(ref str_list) => { - if let Some(ref opts) = str_list { + if let Some(opts) = str_list { write!(f, "{} {}: {}", self.name, opts.join("|"), self.description) } else { write!(f, "{} <string>: {}", self.name, self.description) diff --git a/nihav-core/src/scale/mod.rs b/nihav-core/src/scale/mod.rs index 6bf6e27..6c1daa9 100644 --- a/nihav-core/src/scale/mod.rs +++ b/nihav-core/src/scale/mod.rs @@ -263,7 +263,7 @@ fn fmt_needs_scale(ifmt: &NAPixelFormaton, ofmt: &NAPixelFormaton) -> bool { fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, options: &[(String, String)]) -> ScaleResult<Option<Stage>> { let mut debug = false; for (name, value) in options.iter() { - if name == "debug" && (value == "" || value == "true") { + if name == "debug" && (value.is_empty() || value == "true") { debug = true; break; } @@ -283,7 +283,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option let needs_unpack = !ifmt.fmt.is_unpacked(); let needs_pack = !ofmt.fmt.is_unpacked(); let needs_convert = inname != outname; - let scale_before_cvt = is_better_fmt(&ifmt, &ofmt) && needs_convert + let scale_before_cvt = is_better_fmt(ifmt, ofmt) && needs_convert && (ofmt.fmt.get_max_subsampling() == 0); let needs_palettise = ofmt.fmt.palette; //todo stages for model and gamma conversion @@ -296,9 +296,9 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option println!("[adding unpack]"); } let new_stage = if !cur_fmt.fmt.is_paletted() { - Stage::new("unpack", &cur_fmt, &ofmt, options)? + Stage::new("unpack", &cur_fmt, ofmt, options)? } else { - Stage::new("depal", &cur_fmt, &ofmt, options)? + Stage::new("depal", &cur_fmt, ofmt, options)? }; cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); @@ -307,7 +307,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option if debug { println!("[adding scale]"); } - let new_stage = Stage::new("scale", &cur_fmt, &ofmt, options)?; + let new_stage = Stage::new("scale", &cur_fmt, ofmt, options)?; cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); } @@ -319,7 +319,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option if debug { println!("[{}]", cvtname); } - let new_stage = Stage::new(&cvtname, &cur_fmt, &ofmt, options)?; + let new_stage = Stage::new(&cvtname, &cur_fmt, ofmt, options)?; //todo if fails try converting via RGB or YUV cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); @@ -329,7 +329,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option if debug { println!("[adding scale]"); } - let new_stage = Stage::new("scale", &cur_fmt, &ofmt, options)?; + let new_stage = Stage::new("scale", &cur_fmt, ofmt, options)?; cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); } @@ -337,7 +337,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option if debug { println!("[adding pack]"); } - let new_stage = Stage::new("pack", &cur_fmt, &ofmt, options)?; + let new_stage = Stage::new("pack", &cur_fmt, ofmt, options)?; //cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); } @@ -345,7 +345,7 @@ fn build_pipeline(ifmt: &ScaleInfo, ofmt: &ScaleInfo, just_convert: bool, option if debug { println!("[adding palettise]"); } - let new_stage = Stage::new("palette", &cur_fmt, &ofmt, options)?; + let new_stage = Stage::new("palette", &cur_fmt, ofmt, options)?; //cur_fmt = new_stage.fmt_out; add_stage!(stages, new_stage); } @@ -438,24 +438,22 @@ pub fn flip_picture(pic: &mut NABufferType) -> ScaleResult<()> { impl NAScale { /// Constructs a new `NAScale` instance. pub fn new(fmt_in: ScaleInfo, fmt_out: ScaleInfo) -> ScaleResult<Self> { - let pipeline; let just_convert = (fmt_in.width == fmt_out.width) && (fmt_in.height == fmt_out.height); - if fmt_in != fmt_out { - pipeline = build_pipeline(&fmt_in, &fmt_out, just_convert, &[])?; - } else { - pipeline = None; - } + let pipeline = if fmt_in != fmt_out { + build_pipeline(&fmt_in, &fmt_out, just_convert, &[])? + } else { + None + }; Ok(Self { fmt_in, fmt_out, just_convert, pipeline }) } /// Constructs a new `NAScale` instance taking into account provided options. pub fn new_with_options(fmt_in: ScaleInfo, fmt_out: ScaleInfo, options: &[(String, String)]) -> ScaleResult<Self> { - let pipeline; let just_convert = (fmt_in.width == fmt_out.width) && (fmt_in.height == fmt_out.height); - if fmt_in != fmt_out { - pipeline = build_pipeline(&fmt_in, &fmt_out, just_convert, options)?; - } else { - pipeline = None; - } + let pipeline = if fmt_in != fmt_out { + build_pipeline(&fmt_in, &fmt_out, just_convert, options)? + } else { + None + }; Ok(Self { fmt_in, fmt_out, just_convert, pipeline }) } /// Checks whether requested conversion operation is needed at all. diff --git a/nihav-core/src/scale/palette/mod.rs b/nihav-core/src/scale/palette/mod.rs index ce673ee..f70300f 100644 --- a/nihav-core/src/scale/palette/mod.rs +++ b/nihav-core/src/scale/palette/mod.rs @@ -14,7 +14,7 @@ impl Pixel { fn new(src: &[u8]) -> Self { Self { r: src[0], g: src[1], b: src[2] } } - fn to_rgb(&self) -> [u8; 3] { + fn to_rgb(self) -> [u8; 3] { [self.r, self.g, self.b] } fn dist(&self, pix: Pixel) -> u32 { diff --git a/nihav-core/src/soundcvt/mod.rs b/nihav-core/src/soundcvt/mod.rs index 891a58a..a9f16c6 100644 --- a/nihav-core/src/soundcvt/mod.rs +++ b/nihav-core/src/soundcvt/mod.rs @@ -29,15 +29,11 @@ enum ChannelOp { impl ChannelOp { fn is_remix(&self) -> bool { - match *self { - ChannelOp::Remix(_) => true, - ChannelOp::DupMono(_) => true, - _ => false, - } + matches! (*self, ChannelOp::Remix(_) | ChannelOp::DupMono(_)) } } -fn apply_channel_op<T:Copy>(ch_op: &ChannelOp, src: &[T], dst: &mut Vec<T>) { +fn apply_channel_op<T:Copy>(ch_op: &ChannelOp, src: &[T], dst: &mut [T]) { match *ch_op { ChannelOp::Passthrough => { dst.copy_from_slice(src); @@ -51,7 +47,7 @@ fn apply_channel_op<T:Copy>(ch_op: &ChannelOp, src: &[T], dst: &mut Vec<T>) { }; } -fn remix_i32(ch_op: &ChannelOp, src: &[i32], dst: &mut Vec<i32>) { +fn remix_i32(ch_op: &ChannelOp, src: &[i32], dst: &mut [i32]) { if let ChannelOp::Remix(ref remix_mat) = ch_op { let sch = src.len(); for (out, coeffs) in dst.iter_mut().zip(remix_mat.chunks(sch)) { @@ -70,7 +66,7 @@ fn remix_i32(ch_op: &ChannelOp, src: &[i32], dst: &mut Vec<i32>) { } } -fn remix_f32(ch_op: &ChannelOp, src: &[f32], dst: &mut Vec<f32>) { +fn remix_f32(ch_op: &ChannelOp, src: &[f32], dst: &mut [f32]) { if let ChannelOp::Remix(ref remix_mat) = ch_op { let sch = src.len(); for (out, coeffs) in dst.iter_mut().zip(remix_mat.chunks(sch)) { @@ -164,8 +160,8 @@ impl<T:Copy, U:Copy> IntoFmt<U> for T where U: FromFmt<T> { trait SampleReader { - fn get_samples_i32(&self, pos: usize, dst: &mut Vec<i32>); - fn get_samples_f32(&self, pos: usize, dst: &mut Vec<f32>); + fn get_samples_i32(&self, pos: usize, dst: &mut [i32]); + fn get_samples_f32(&self, pos: usize, dst: &mut [f32]); } struct GenericSampleReader<'a, T:Copy> { @@ -174,14 +170,14 @@ struct GenericSampleReader<'a, T:Copy> { } impl<'a, T:Copy+IntoFmt<i32>+IntoFmt<f32>> SampleReader for GenericSampleReader<'a, T> { - fn get_samples_i32(&self, pos: usize, dst: &mut Vec<i32>) { + fn get_samples_i32(&self, pos: usize, dst: &mut [i32]) { let mut off = pos; for el in dst.iter_mut() { *el = self.data[off].cvt_into(); off += self.stride; } } - fn get_samples_f32(&self, pos: usize, dst: &mut Vec<f32>) { + fn get_samples_f32(&self, pos: usize, dst: &mut [f32]) { let mut off = pos; for el in dst.iter_mut() { *el = self.data[off].cvt_into(); @@ -196,14 +192,14 @@ struct S8SampleReader<'a> { } impl<'a> SampleReader for S8SampleReader<'a> { - fn get_samples_i32(&self, pos: usize, dst: &mut Vec<i32>) { + fn get_samples_i32(&self, pos: usize, dst: &mut [i32]) { let mut off = pos; for el in dst.iter_mut() { *el = (self.data[off] ^ 0x80).cvt_into(); off += self.stride; } } - fn get_samples_f32(&self, pos: usize, dst: &mut Vec<f32>) { + fn get_samples_f32(&self, pos: usize, dst: &mut [f32]) { let mut off = pos; for el in dst.iter_mut() { *el = (self.data[off] ^ 0x80).cvt_into(); @@ -224,7 +220,7 @@ impl<'a> PackedSampleReader<'a> { let bpp = (fmt.bits >> 3) as usize; Self { data, fmt, bpp } } - fn get_samples<T:Copy>(&self, pos: usize, dst: &mut Vec<T>) where u8: IntoFmt<T>, i16: IntoFmt<T>, i32: IntoFmt<T>, f32: IntoFmt<T> { + fn get_samples<T:Copy>(&self, pos: usize, dst: &mut [T]) where u8: IntoFmt<T>, i16: IntoFmt<T>, i32: IntoFmt<T>, f32: IntoFmt<T> { let mut offset = pos * self.bpp * dst.len(); for el in dst.iter_mut() { @@ -255,10 +251,10 @@ impl<'a> PackedSampleReader<'a> { } impl SampleReader for PackedSampleReader<'_> { - fn get_samples_i32(&self, pos: usize, dst: &mut Vec<i32>) { + fn get_samples_i32(&self, pos: usize, dst: &mut [i32]) { self.get_samples(pos, dst); } - fn get_samples_f32(&self, pos: usize, dst: &mut Vec<f32>) { + fn get_samples_f32(&self, pos: usize, dst: &mut [f32]) { self.get_samples(pos, dst); } } |