From: Kostya Shishkov <kostya.shishkov@gmail.com>
Date: Wed, 22 Sep 2021 16:39:32 +0000 (+0200)
Subject: codec_support/imgwrite: flip alpha plane too
X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=62578014e7cc82336bbaed69120e5047d178161d;p=nihav.git

codec_support/imgwrite: flip alpha plane too
---

diff --git a/nihav-codec-support/src/imgwrite/mod.rs b/nihav-codec-support/src/imgwrite/mod.rs
index 78e55cd..e41e20c 100644
--- a/nihav-codec-support/src/imgwrite/mod.rs
+++ b/nihav-codec-support/src/imgwrite/mod.rs
@@ -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(())