core/formats: fix grayscale format returned by NAPixelFormaton::from_str()
[nihav.git] / nihav-core / src / formats.rs
index 6d7f1a152caba62dfa1c78c402c963c933109483..586fa6f7ad8420a53b413e1b607aab9516ceb1ba 100644 (file)
@@ -216,9 +216,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 +247,8 @@ impl ToString for NAChannelType {
             NAChannelType::Rt   => "Rt".to_string(),
             NAChannelType::Lo   => "Lo".to_string(),
             NAChannelType::Ro   => "Ro".to_string(),
-        }
+        };
+        write!(f, "{}", name)
     }
 }
 
@@ -768,7 +769,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 +779,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)
             },
@@ -960,18 +961,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 {