X-Git-Url: https://git.nihav.org/?p=nihav.git;a=blobdiff_plain;f=nihav-core%2Fsrc%2Fformats.rs;h=fdb7a1b7640a303d17a7552970ec3ad2fc2d151f;hp=810fff25ddc1a0de03896ac659df1fbf6737e6a9;hb=e6aaad5c5273cd814b5748b7faf3751835a37217;hpb=625751036014b099fd9c126397bc973cb0543130 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 {