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)
}
}
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)
}
}
/// 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 {
/// 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
}
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()) {
let end = if self.be { "BE" } else { "LE" };
let palstr = if self.palette { "palette " } else { "" };
let astr = if self.alpha { "alpha " } else { "" };
- let mut str = format!("Formaton for {} ({}{}elem {} size {}): ", self.model, palstr, astr,end, self.elem_size);
+ let mut string = format!("Formaton for {} ({}{}elem {} size {}): ", self.model, palstr, astr,end, self.elem_size);
for i in 0..self.comp_info.len() {
if let Some(chr) = self.comp_info[i] {
- str = format!("{} {}", str, chr);
+ string = format!("{} {}", string, chr);
}
}
- write!(f, "[{}]", str)
+ write!(f, "[{}]", string)
}
}
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 ch.is_ascii_digit() {
format = format * 10 + u32::from((ch as u8) - b'0');
if format > 444 { return Err(FormatParseError {}); }
} else {
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 ch.is_ascii_digit() {
val = val * 10 + ((ch as u8) - b'0');
if val > 16 { return Err(FormatParseError {}); }
} else {
444 => [[0, 0], [0, 0], [0, 0], [0, 0]],
_ => return Err(FormatParseError {}),
};
- for (chro, ss) in chromatons.iter_mut().take(components as usize).zip(subsamp.iter()) {
- *chro = Some(NAPixelChromaton{ h_ss: ss[0], v_ss: ss[1], packed: !is_planar, depth, shift: 0, comp_offs: next_elem, next_elem });
+ for (i, (chro, ss)) in chromatons.iter_mut().take(components as usize).zip(subsamp.iter()).enumerate() {
+ *chro = Some(NAPixelChromaton{ h_ss: ss[0], v_ss: ss[1], packed: !is_planar, depth, shift: 0, comp_offs: if is_planar { i as u8 } else { next_elem }, next_elem });
}
Ok(NAPixelFormaton { model: ColorModel::YUV(YUVSubmodel::YUVJ),
components,