- for src in dta.chunks(stride) {
- for x in 0..w {
- let elem = src[x];
- let r = ((elem >> shifts[0]) & masks[0]) << (8 - depths[0]);
- let g = ((elem >> shifts[1]) & masks[1]) << (8 - depths[1]);
- let b = ((elem >> shifts[2]) & masks[2]) << (8 - depths[2]);
- line[x * 3 + 0] = r as u8;
- line[x * 3 + 1] = g as u8;
- line[x * 3 + 2] = b as u8;
+ let flipped = buf.get_info().is_flipped();
+ if !flipped {
+ for src in dta.chunks(stride) {
+ for x in 0..w {
+ let elem = src[x];
+ let r = ((elem >> shifts[0]) & masks[0]) << (8 - depths[0]);
+ let g = ((elem >> shifts[1]) & masks[1]) << (8 - depths[1]);
+ let b = ((elem >> shifts[2]) & masks[2]) << (8 - depths[2]);
+ line[x * 3 + 0] = r as u8;
+ line[x * 3 + 1] = g as u8;
+ line[x * 3 + 2] = b as u8;
+ }
+ ofile.write_all(line.as_slice()).unwrap();
+ }
+ } else {
+ for src in dta[..h * stride].chunks(stride).rev() {
+ for x in 0..w {
+ let elem = src[x];
+ let r = ((elem >> shifts[0]) & masks[0]) << (8 - depths[0]);
+ let g = ((elem >> shifts[1]) & masks[1]) << (8 - depths[1]);
+ let b = ((elem >> shifts[2]) & masks[2]) << (8 - depths[2]);
+ line[x * 3 + 0] = r as u8;
+ line[x * 3 + 1] = g as u8;
+ line[x * 3 + 2] = b as u8;
+ }
+ ofile.write_all(line.as_slice()).unwrap();