core/formats: fix offsets in YUV pixel format parsing
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 30 Sep 2021 13:52:42 +0000 (15:52 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 30 Sep 2021 16:13:05 +0000 (18:13 +0200)
nihav-core/src/formats.rs

index 713a3e5662b3e30fb342569a2f5e047ee3f59eac..99370f9ab4c370f5cc155e1865b4ab71f2b7cafd 100644 (file)
@@ -1065,8 +1065,8 @@ fn parse_yuv_format(s: &str) -> Result<NAPixelFormaton, FormatParseError> {
             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,