fix clippy warnings for update to rustc 1.46
[nihav.git] / nihav-core / src / formats.rs
index 6d7f1a152caba62dfa1c78c402c963c933109483..713a3e5662b3e30fb342569a2f5e047ee3f59eac 100644 (file)
@@ -62,6 +62,8 @@ pub const SND_U8_FORMAT: NASoniton = NASoniton { bits: 8, be: false, packed: fal
 pub const SND_S16_FORMAT: NASoniton = NASoniton { bits: 16, be: false, packed: false, planar: false, float: false, signed: true };
 /// Predefined format for planar 16-bit signed audio.
 pub const SND_S16P_FORMAT: NASoniton = NASoniton { bits: 16, be: false, packed: false, planar: true, float: false, signed: true };
+/// Predefined format for planar 32-bit signed audio.
+pub const SND_S32P_FORMAT: NASoniton = NASoniton { bits: 32, be: false, packed: false, planar: true, float: false, signed: true };
 /// Predefined format for planar 32-bit floating point audio.
 pub const SND_F32P_FORMAT: NASoniton = NASoniton { bits: 32, be: false, packed: false, planar: true, float: true, signed: true };
 
@@ -101,7 +103,7 @@ impl NASoniton {
     }
 
     /// Returns soniton description as a short string.
-    pub fn to_short_string(&self) -> String {
+    pub fn to_short_string(self) -> String {
         let ltype = if self.float { 'f' } else if self.signed { 's' } else { 'u' };
         let endianness = if self.bits == 8 { "" } else if self.be { "be" } else { "le" };
         let planar = if self.planar { "p" } else { "" };
@@ -114,7 +116,7 @@ impl fmt::Display for NASoniton {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         let fmt = if self.float { "float" } else if self.signed { "int" } else { "uint" };
         let end = if self.be { "BE" } else { "LE" };
-        write!(f, "({} bps, {} planar: {} packed: {} {})", self.bits, end, self.packed, self.planar, fmt)
+        write!(f, "({} bps, {} planar: {} packed: {} {})", self.bits, end, self.planar, self.packed, fmt)
     }
 }
 
@@ -216,9 +218,9 @@ impl FromStr for NAChannelType {
     }
 }
 
-impl ToString for NAChannelType {
-    fn to_string(&self) -> String {
-        match *self {
+impl fmt::Display for NAChannelType {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        let name = match *self {
             NAChannelType::C    => "C".to_string(),
             NAChannelType::L    => "L".to_string(),
             NAChannelType::R    => "R".to_string(),
@@ -247,7 +249,8 @@ impl ToString for NAChannelType {
             NAChannelType::Rt   => "Rt".to_string(),
             NAChannelType::Lo   => "Lo".to_string(),
             NAChannelType::Ro   => "Ro".to_string(),
-        }
+        };
+        write!(f, "{}", name)
     }
 }
 
@@ -425,8 +428,8 @@ impl ColorModel {
 impl fmt::Display for ColorModel {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         let name = match *self {
-            ColorModel::RGB(fmt) => format!("RGB({})", fmt).to_string(),
-            ColorModel::YUV(fmt) => format!("YUV({})", fmt).to_string(),
+            ColorModel::RGB(fmt) => format!("RGB({})", fmt),
+            ColorModel::YUV(fmt) => format!("YUV({})", fmt),
             ColorModel::CMYK     => "CMYK".to_string(),
             ColorModel::HSV      => "HSV".to_string(),
             ColorModel::LAB      => "LAB".to_string(),
@@ -707,6 +710,7 @@ impl NAPixelFormaton {
         }
         ssamp
     }
+    #[allow(clippy::cognitive_complexity)]
     /// Returns a short string description of the format if possible.
     pub fn to_short_string(&self) -> Option<String> {
         match self.model {
@@ -768,7 +772,7 @@ impl NAPixelFormaton {
                             break;
                         }
                     }
-                    name += if self.be { "be" } else { "le" };                   
+                    name += if self.be { "be" } else { "le" };
                     return Some(name);
                 }
                 if depth == 24 || depth != 8 * self.components {
@@ -778,7 +782,7 @@ impl NAPixelFormaton {
                     name.push('p');
                 }
                 if self.get_max_depth() > 8 {
-                    name += if self.be { "be" } else { "le" };                   
+                    name += if self.be { "be" } else { "le" };
                 }
                 Some(name)
             },
@@ -856,7 +860,7 @@ fn parse_rgb_format(s: &str) -> Result<NAPixelFormaton, FormatParseError> {
                     'A' | 'a' => { order[3] = i; has_alpha = true; },
                     '0'..='9' => {
                         pstate = 1; bits_start = i;
-                        bits = ((ch as u8) - b'0') as u32;
+                        bits = u32::from((ch as u8) - b'0');
                     },
                     _ => return Err(FormatParseError {}),
                 };
@@ -865,7 +869,7 @@ fn parse_rgb_format(s: &str) -> Result<NAPixelFormaton, FormatParseError> {
                 if i > 4 + bits_start { return Err(FormatParseError {}); }
                 match ch {
                     '0'..='9' => {
-                        bits = (bits * 10) + (((ch as u8) - b'0') as u32);
+                        bits = (bits * 10) + u32::from((ch as u8) - b'0');
                     },
                     'B' | 'b' => { pstate = 2; }
                     'L' | 'l' => { pstate = 2; is_be = false; }
@@ -960,18 +964,18 @@ fn parse_yuv_format(s: &str) -> Result<NAPixelFormaton, FormatParseError> {
             return Ok(NAPixelFormaton {
                     model: ColorModel::YUV(YUVSubmodel::YUVJ), components: 1,
                     comp_info: [
-                        Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: true, depth: 8, shift: 0, comp_offs: 0, next_elem: 1 }),
+                        Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: false, depth: 8, shift: 0, comp_offs: 0, next_elem: 1 }),
                         None, None, None, None],
-                    elem_size: 1, be: false, alpha: false, palette: false });
+                    elem_size: 1, be: true, alpha: false, palette: false });
         },
         "y8a" | "y400a" | "graya" => {
             return Ok(NAPixelFormaton {
                     model: ColorModel::YUV(YUVSubmodel::YUVJ), components: 2,
                     comp_info: [
-                        Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: true, depth: 8, shift: 0, comp_offs: 0, next_elem: 2 }),
-                        Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: true, depth: 8, shift: 0, comp_offs: 1, next_elem: 2 }),
+                        Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: false, depth: 8, shift: 0, comp_offs: 0, next_elem: 2 }),
+                        Some(NAPixelChromaton{ h_ss: 0, v_ss: 0, packed: false, depth: 8, shift: 0, comp_offs: 1, next_elem: 2 }),
                         None, None, None],
-                    elem_size: 1, be: false, alpha: true, palette: false });
+                    elem_size: 1, be: true, alpha: true, palette: false });
         },
         "uyvy" | "y422" => {
             return Ok(NAPixelFormaton {
@@ -1026,7 +1030,7 @@ fn parse_yuv_format(s: &str) -> Result<NAPixelFormaton, FormatParseError> {
     for ch in s.chars().skip(components as usize) {
         parse_end += 1;
         if ch >= '0' && ch <= '9' {
-            format = format * 10 + (((ch as u8) - b'0') as u32);
+            format = format * 10 + u32::from((ch as u8) - b'0');
             if format > 444 { return Err(FormatParseError {}); }
         } else {
             is_planar = ch == 'p';
@@ -1074,6 +1078,7 @@ fn parse_yuv_format(s: &str) -> Result<NAPixelFormaton, FormatParseError> {
 impl FromStr for NAPixelFormaton {
     type Err = FormatParseError;
 
+    #[allow(clippy::single_match)]
     fn from_str(s: &str) -> Result<Self, Self::Err> {
         match s {
             "pal8" => return Ok(PAL8_FORMAT),