ncvisual_render: direct cell_load into framebuffer

Saves about 10% of wall clock time on 'eagle', nice.
pull/217/head
nick black 5 years ago
parent 046d0314b9
commit 0b8eb20811

@ -128,6 +128,7 @@ typedef struct notcurses {
char* italoff; // CELL_STYLE_ITALIC (disable)
char* smkx; // enter keypad transmit mode (keypad_xmit)
char* rmkx; // leave keypad transmit mode (keypad_local)
char* getm; // get mouse events
bool RGBflag; // terminfo-reported "RGB" flag for 24bpc directcolor
bool CCCflag; // terminfo-reported "CCC" flag for palette set capability
@ -227,6 +228,8 @@ extended_gcluster(const ncplane* n, const cell* c){
return egcpool_extended_gcluster(&n->pool, c);
}
cell* ncplane_cell_ref_yx(ncplane* n, int y, int x);
#define NANOSECS_IN_SEC 1000000000
#ifdef __cplusplus

@ -319,39 +319,36 @@ int ncvisual_render(const ncvisual* ncv, int begy, int begx, int leny, int lenx)
const unsigned char* rgbbase_down = data + (linesize * (visy + 1)) + (visx * bpp / CHAR_BIT);
/*fprintf(stderr, "[%04d/%04d] %p bpp: %d lsize: %d %02x %02x %02x %02x\n",
y, x, rgbbase, bpp, linesize, rgbbase[0], rgbbase[1], rgbbase[2], rgbbase[3]);*/
cell c = CELL_TRIVIAL_INITIALIZER;
cell* c = ncplane_cell_ref_yx(ncv->ncp, y, x);
// use the default for the background, as that's the only way it's
// effective in that case anyway
c->channels = 0;
c->attrword = 0;
if(!rgbbase_up[3] || !rgbbase_down[3]){
cell_set_bg_alpha(&c, CELL_ALPHA_TRANSPARENT);
cell_set_bg_alpha(c, CELL_ALPHA_TRANSPARENT);
if(!rgbbase_up[3] && !rgbbase_down[3]){
if(cell_load(ncv->ncp, &c, " ") <= 0){
if(cell_load(ncv->ncp, c, " ") <= 0){
return -1;
}
cell_set_fg_alpha(&c, CELL_ALPHA_TRANSPARENT);
cell_set_fg_alpha(c, CELL_ALPHA_TRANSPARENT);
}else if(!rgbbase_up[3]){ // down has the color
if(cell_load(ncv->ncp, &c, "\u2584") <= 0){ // lower half block
if(cell_load(ncv->ncp, c, "\u2584") <= 0){ // lower half block
return -1;
}
cell_set_fg_rgb(&c, rgbbase_down[0], rgbbase_down[1], rgbbase_down[2]);
cell_set_fg_rgb(c, rgbbase_down[0], rgbbase_down[1], rgbbase_down[2]);
}else{ // up has the color
if(cell_load(ncv->ncp, &c, "\u2580") <= 0){ // upper half block
if(cell_load(ncv->ncp, c, "\u2580") <= 0){ // upper half block
return -1;
}
cell_set_fg_rgb(&c, rgbbase_up[0], rgbbase_up[1], rgbbase_up[2]);
cell_set_fg_rgb(c, rgbbase_up[0], rgbbase_up[1], rgbbase_up[2]);
}
}else{
cell_set_fg_rgb(&c, rgbbase_up[0], rgbbase_up[1], rgbbase_up[2]);
cell_set_bg_rgb(&c, rgbbase_down[0], rgbbase_down[1], rgbbase_down[2]);
if(cell_load(ncv->ncp, &c, "\u2580") <= 0){ // upper half block
cell_set_fg_rgb(c, rgbbase_up[0], rgbbase_up[1], rgbbase_up[2]);
cell_set_bg_rgb(c, rgbbase_down[0], rgbbase_down[1], rgbbase_down[2]);
if(cell_load(ncv->ncp, c, "\u2580") <= 0){ // upper half block
return -1;
}
}
if(ncplane_putc(ncv->ncp, &c) <= 0){
cell_release(ncv->ncp, &c);
return -1;
}
cell_release(ncv->ncp, &c);
}
}
return 0;

@ -213,6 +213,10 @@ int ncplane_at_yx(ncplane* n, int y, int x, cell* c){
return cell_duplicate(n, c, &n->fb[fbcellidx(n, y, x)]);
}
cell* ncplane_cell_ref_yx(ncplane* n, int y, int x){
return &n->fb[fbcellidx(n, y, x)];
}
void ncplane_dim_yx(const ncplane* n, int* rows, int* cols){
if(rows){
*rows = n->leny;

Loading…
Cancel
Save