From 62578014e7cc82336bbaed69120e5047d178161d Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Wed, 22 Sep 2021 18:39:32 +0200 Subject: [PATCH] codec_support/imgwrite: flip alpha plane too --- nihav-codec-support/src/imgwrite/mod.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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(()) -- 2.39.5