diff --git a/src/pixels.cpp b/src/pixels.cpp index 5e808c8..0a78381 100644 --- a/src/pixels.cpp +++ b/src/pixels.cpp @@ -16,17 +16,24 @@ static void write(std::ostream& os, FILE* in) { std::unique_ptr row1 {pnm_allocpamrow(&info), pm_freerow}; std::unique_ptr row2 {pnm_allocpamrow(&info), pm_freerow}; for (int y = 0; y < info.height; y += 2) { + tuple* t1 {row1.get()}; + tuple* t2 {row2.get()}; pnm_readpamrow(&info, row1.get()); - pnm_readpamrow(&info, row2.get()); + if (y < info.height - 1) { + pnm_readpamrow(&info, row2.get()); + } else { + // fill second row with terminal background color + for (int col = 0; col < info.width; ++col) { + t2[col][0] = t2[col][1] = t2[col][2] = 0; + } + } for (int x = 0; x < info.width; ++x) { if (info.depth == 3) { // assume RGB, 1 byte per sample - tuple* t1 {row1.get()}; if (has_truecolor) { os << sc::io::truecolorb(t1[x][0], t1[x][1], t1[x][2]); } else { os << sc::io::rgbb(t2p(t1[x][0]), t2p(t1[x][1]), t2p(t1[x][2])); } - tuple* t2 {row2.get()}; if (has_truecolor) { os << sc::io::truecolorf(t2[x][0], t2[x][1], t2[x][2]); } else {