frmwriter: fix handling of flipped paletted images
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 24 May 2020 13:23:37 +0000 (15:23 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 24 May 2020 13:23:37 +0000 (15:23 +0200)
src/frmwriter.rs

index 71ad491abc60e8bc008c8c6a7b874c79e166c644..f882a7fa266f9bcd5dac659c134f23929b347125 100644 (file)
@@ -112,9 +112,12 @@ pub fn write_palppm(pfx: &str, strno: usize, num: u64, frm: NAFrameRef) {
             buf.get_info().get_format().get_chromaton(2).unwrap().get_offset() as usize
         ];
     let flipped = buf.get_info().is_flipped();
             buf.get_info().get_format().get_chromaton(2).unwrap().get_offset() as usize
         ];
     let flipped = buf.get_info().is_flipped();
-    let mut idx  = if !flipped { 0 } else { ls * (h - 1) };
+    let mut idx  = if !flipped { 0 } else { ls * h };
     let mut line: Vec<u8> = vec![0; w * 3];
     for _ in 0..h {
     let mut line: Vec<u8> = vec![0; w * 3];
     for _ in 0..h {
+        if flipped {
+            idx -= ls;
+        }
         let src = &dta[idx..(idx+w)];
         for x in 0..w {
             let pix = src[x] as usize;
         let src = &dta[idx..(idx+w)];
         for x in 0..w {
             let pix = src[x] as usize;
@@ -125,8 +128,6 @@ pub fn write_palppm(pfx: &str, strno: usize, num: u64, frm: NAFrameRef) {
         ofile.write_all(line.as_slice()).unwrap();
         if !flipped {
             idx += ls;
         ofile.write_all(line.as_slice()).unwrap();
         if !flipped {
             idx += ls;
-        } else {
-            idx -= ls;
         }
     }
 }
         }
     }
 }