render: don't send unnecessary color change sequences #47

pull/85/head
nick black 5 years ago committed by Nick Black
parent 4cc0ce037d
commit 5e35e05151

@ -213,7 +213,12 @@ int main(int argc, char** argv){
fprintf(stderr, "Couldn't get standard plane\n");
goto err;
}
nanosleep(&demodelay, NULL);
// no one cares about the leaderscreen. 1s max.
if(demodelay.tv_sec >= 1){
sleep(1);
}else{
nanosleep(&demodelay, NULL);
}
if(ext_demos(nc, demos)){
goto err;
}

@ -42,7 +42,7 @@ message(struct ncplane* n, int maxy, int maxx, int num, int total){
cell_load(n, &ur, "");
ncplane_putc(n, &ur);
ncplane_cursor_move_yx(n, 2, 5);
ncplane_printf(n, " %dx%d (%d/%d) ", maxx, maxy, num, total);
ncplane_printf(n, " %dx%d (%d/%d) ", maxx, maxy, num + 1, total);
ncplane_cursor_move_yx(n, 4, 2);
ncplane_styles_off(n, CELL_STYLE_BOLD);
ncplane_fg_rgb8(n, 200, 20, 200);

@ -988,6 +988,14 @@ int notcurses_render(notcurses* nc){
uint32_t curattr = 0; // current attributes set (does not include colors)
term_emit(nc->clear, out, false);
unsigned lastr, lastg, lastb;
unsigned lastbr, lastbg, lastbb;
// we can elide a color escape iff the color has not changed between the two
// cells and the current cell uses no defaults, or if both the current and
// the last used both defaults.
bool fgelidable = false, bgelidable = false, defaultelidable = false;
uint64_t fgelisions = 0, fgemissions = 0;
uint64_t bgelisions = 0, bgemissions = 0;
uint64_t defaultelisions = 0, defaultemissions = 0;
for(y = 0 ; y < nc->stdscr->leny ; ++y){
// FIXME previous line could have ended halfway through multicol. what happens?
// FIXME also must explicitly move to next line if we're to deal with
@ -1000,16 +1008,45 @@ int notcurses_render(notcurses* nc){
// them both via the 'op' capability. unless we want to generate the 'op'
// escapes ourselves, if either is set to default, we first send op, and
// then a turnon for whichever aren't default.
// we can elide the default set iff the previous used both defaults
if(cell_fg_default_p(c) || cell_bg_default_p(c)){
term_emit(nc->op, out, false);
if(!defaultelidable){
++defaultemissions;
term_emit(nc->op, out, false);
}else{
++defaultelisions;
}
// if either is not default, this will get turned off
defaultelidable = true;
fgelidable = false;
bgelidable = false;
}
// we can elide the foreground set iff the previous used fg and matched
if(!cell_fg_default_p(c)){
cell_get_fg(c, &r, &g, &b);
term_fg_rgb8(nc, out, r, g, b);
if(!fgelidable || lastr != r || lastg != g || lastb != b){
term_fg_rgb8(nc, out, r, g, b);
++fgemissions;
fgelidable = true;
}else{
++fgelisions;
}
lastr = r; lastg = g; lastb = b;
defaultelidable = false;
}
if(!cell_bg_default_p(c)){
cell_get_bg(c, &br, &bg, &bb);
term_bg_rgb8(nc, out, br, bg, bb);
if(!bgelidable || lastbr != br || lastbg != bg || lastbb != bb){
term_bg_rgb8(nc, out, br, bg, bb);
++bgemissions;
bgelidable = true;
}else{
++bgelisions;
}
lastbr = br; lastbg = bg; lastbb = bb;
defaultelidable = false;
}
term_setstyles(nc, out, &curattr, c);
// FIXME what to do if we're at the last cell, and it's wide?
@ -1026,6 +1063,8 @@ int notcurses_render(notcurses* nc){
if(w < 0 || (size_t)w != buflen){
ret = -1;
}
/*fprintf(stderr, "%lu/%lu %lu/%lu %lu/%lu\n", defaultelisions, defaultemissions,
fgelisions, fgemissions, bgelisions, bgemissions);*/
if(nc->renderfp){
fprintf(nc->renderfp, "%s\n", buf);
}

Loading…
Cancel
Save