]> git.nihav.org Git - nihav.git/commitdiff
codec_support/imgwrite: flip alpha plane too
authorKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 22 Sep 2021 16:39:32 +0000 (18:39 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 22 Sep 2021 16:43:12 +0000 (18:43 +0200)
nihav-codec-support/src/imgwrite/mod.rs

index 78e55cda0d668487248920833137d7e245daa701..e41e20c81ad3bd8a38d6ab43fdab29304fb2bffc 100644 (file)
@@ -84,13 +84,16 @@ pub fn write_pgmyuv(name: &str, frm: NAFrameRef) -> std::io::Result<()> {
     }
     if has_alpha {
         let ls = buf.get_stride(3);
-        let mut idx = buf.get_offset(3);
-        let mut idx2 = idx + w;
-        for _ in 0..h {
-            let line = &dta[idx..idx2];
-            ofile.write_all(line)?;
-            idx  += ls;
-            idx2 += ls;
+        if !is_flipped {
+            let alines = dta[buf.get_offset(3)..].chunks(ls).take(h);
+            for line in alines {
+                ofile.write_all(&line[..w])?;
+            }
+        } else {
+            let alines = dta[buf.get_offset(3)..].chunks(ls).take(h).rev();
+            for line in alines {
+                ofile.write_all(&line[..w])?;
+            }
         }
     }
     Ok(())