raster: don't print colors in pixel mode

pull/1377/head
nick black 4 years ago committed by Nick Black
parent 37623d86e0
commit a1776d950b

@ -288,6 +288,8 @@ typedef struct tinfo {
uint32_t bg_collides_default; uint32_t bg_collides_default;
bool sextants; // do we have (good, vetted) Unicode 13 sextant support? bool sextants; // do we have (good, vetted) Unicode 13 sextant support?
bool braille; // do we have Braille support? (linux console does not) bool braille; // do we have Braille support? (linux console does not)
char* pixelon; // enter pixel graphics mode
char* pixeloff; // leave pixel graphics mode
bool sixel; // do we have Sixel support? bool sixel; // do we have Sixel support?
} tinfo; } tinfo;
@ -621,9 +623,14 @@ plane_debug(const ncplane* n, bool details){
} }
} }
static inline unsigned
channels_pixel_p(uint64_t channels){
return channels & CELL_PIXEL_GRAPHICS;
}
static inline unsigned static inline unsigned
cell_pixels_p(const nccell* c){ cell_pixels_p(const nccell* c){
return c->channels & CELL_PIXEL_GRAPHICS; return channels_pixel_p(c->channels);
} }
static inline nccell* static inline nccell*

@ -582,7 +582,7 @@ ncfputc(char c, FILE* out){
static int static int
enter_pixel_mode(notcurses* nc, FILE* out){ enter_pixel_mode(notcurses* nc, FILE* out){
if(!nc->rstate.pixelmode){ if(!nc->rstate.pixelmode){
if(term_emit("\ePq", out, false)){ if(term_emit(nc->tcache.pixelon, out, false)){
return -1; return -1;
} }
} }
@ -592,7 +592,7 @@ enter_pixel_mode(notcurses* nc, FILE* out){
static int static int
leave_pixel_mode(notcurses* nc, FILE* out){ leave_pixel_mode(notcurses* nc, FILE* out){
if(term_emit("\e\\", out, false)){ if(term_emit(nc->tcache.pixeloff, out, false)){
return -1; return -1;
} }
nc->rstate.pixelmode = false; nc->rstate.pixelmode = false;
@ -971,96 +971,98 @@ notcurses_rasterize_inner(notcurses* nc, const ncpile* p, FILE* out){
if(goto_location(nc, out, y, x)){ if(goto_location(nc, out, y, x)){
return -1; return -1;
} }
// set the style. this can change the color back to the default; if it if(!cell_pixels_p(srccell)){
// does, we need update our elision possibilities. // set the style. this can change the color back to the default; if it
if(term_setstyles(out, &nc->rstate, srccell, // does, we need update our elision possibilities.
nc->tcache.sgr0, nc->tcache.sgr, if(term_setstyles(out, &nc->rstate, srccell,
nc->tcache.italics, nc->tcache.italoff, nc->tcache.sgr0, nc->tcache.sgr,
nc->tcache.struck, nc->tcache.struckoff)){ nc->tcache.italics, nc->tcache.italoff,
return -1; nc->tcache.struck, nc->tcache.struckoff)){
}
// if our cell has a default foreground *or* background, we can elide
// the default set iff one of:
// * we are a partial glyph, and the previous was default on both, or
// * we are a no-foreground glyph, and the previous was default background, or
// * we are a no-background glyph, and the previous was default foreground
bool nobackground = cell_nobackground_p(srccell);
if((cell_fg_default_p(srccell)) || (!nobackground && cell_bg_default_p(srccell))){
if(raster_defaults(nc, cell_fg_default_p(srccell),
!nobackground && cell_bg_default_p(srccell), out)){
return -1; return -1;
} }
} // if our cell has a default foreground *or* background, we can elide
// if our cell has a non-default foreground, we can elide the // the default set iff one of:
// non-default foreground set iff either: // * we are a partial glyph, and the previous was default on both, or
// * the previous was non-default, and matches what we have now, or // * we are a no-foreground glyph, and the previous was default background, or
// * we are a no-foreground glyph (iswspace() is true) // * we are a no-background glyph, and the previous was default foreground
if(cell_fg_palindex_p(srccell)){ // palette-indexed foreground bool nobackground = cell_nobackground_p(srccell);
palfg = cell_fg_palindex(srccell); if((cell_fg_default_p(srccell)) || (!nobackground && cell_bg_default_p(srccell))){
// we overload lastr for the palette index; both are 8 bits if(raster_defaults(nc, cell_fg_default_p(srccell),
if(nc->rstate.fgpalelidable && nc->rstate.lastr == palfg){ !nobackground && cell_bg_default_p(srccell), out)){
++nc->stats.fgelisions;
}else{
if(term_fg_palindex(nc, out, palfg)){
return -1; return -1;
} }
++nc->stats.fgemissions;
nc->rstate.fgpalelidable = true;
} }
nc->rstate.lastr = palfg; // if our cell has a non-default foreground, we can elide the
nc->rstate.fgdefelidable = false; // non-default foreground set iff either:
nc->rstate.fgelidable = false; // * the previous was non-default, and matches what we have now, or
}else if(!cell_fg_default_p(srccell)){ // rgb foreground // * we are a no-foreground glyph (iswspace() is true)
cell_fg_rgb8(srccell, &r, &g, &b); if(cell_fg_palindex_p(srccell)){ // palette-indexed foreground
if(nc->rstate.fgelidable && nc->rstate.lastr == r && nc->rstate.lastg == g && nc->rstate.lastb == b){ palfg = cell_fg_palindex(srccell);
++nc->stats.fgelisions; // we overload lastr for the palette index; both are 8 bits
}else{ if(nc->rstate.fgpalelidable && nc->rstate.lastr == palfg){
if(term_fg_rgb8(nc->tcache.RGBflag, nc->tcache.setaf, nc->tcache.colors, out, r, g, b)){ ++nc->stats.fgelisions;
return -1; }else{
if(term_fg_palindex(nc, out, palfg)){
return -1;
}
++nc->stats.fgemissions;
nc->rstate.fgpalelidable = true;
} }
++nc->stats.fgemissions; nc->rstate.lastr = palfg;
nc->rstate.fgelidable = true; nc->rstate.fgdefelidable = false;
} nc->rstate.fgelidable = false;
nc->rstate.lastr = r; nc->rstate.lastg = g; nc->rstate.lastb = b; }else if(!cell_fg_default_p(srccell)){ // rgb foreground
nc->rstate.fgdefelidable = false; cell_fg_rgb8(srccell, &r, &g, &b);
nc->rstate.fgpalelidable = false; if(nc->rstate.fgelidable && nc->rstate.lastr == r && nc->rstate.lastg == g && nc->rstate.lastb == b){
} ++nc->stats.fgelisions;
// if our cell has a non-default background, we can elide the }else{
// non-default background set iff either: if(term_fg_rgb8(nc->tcache.RGBflag, nc->tcache.setaf, nc->tcache.colors, out, r, g, b)){
// * we do not use the background, because the cell is all-foreground, return -1;
// * the previous was non-default, and matches what we have now, or }
if(nobackground){ ++nc->stats.fgemissions;
++nc->stats.bgelisions; nc->rstate.fgelidable = true;
}else if(cell_bg_palindex_p(srccell)){ // palette-indexed background
palbg = cell_bg_palindex(srccell);
if(nc->rstate.bgpalelidable && nc->rstate.lastbr == palbg){
++nc->stats.bgelisions;
}else{
if(term_bg_palindex(nc, out, palbg)){
return -1;
} }
++nc->stats.bgemissions; nc->rstate.lastr = r; nc->rstate.lastg = g; nc->rstate.lastb = b;
nc->rstate.bgpalelidable = true; nc->rstate.fgdefelidable = false;
nc->rstate.fgpalelidable = false;
} }
nc->rstate.lastr = palbg; // if our cell has a non-default background, we can elide the
nc->rstate.bgdefelidable = false; // non-default background set iff either:
nc->rstate.bgelidable = false; // * we do not use the background, because the cell is all-foreground,
}else if(!cell_bg_default_p(srccell)){ // rgb background // * the previous was non-default, and matches what we have now, or
cell_bg_rgb8(srccell, &br, &bg, &bb); if(nobackground){
if(nc->rstate.bgelidable && nc->rstate.lastbr == br && nc->rstate.lastbg == bg && nc->rstate.lastbb == bb){
++nc->stats.bgelisions; ++nc->stats.bgelisions;
}else{ }else if(cell_bg_palindex_p(srccell)){ // palette-indexed background
if(term_bg_rgb8(nc->tcache.RGBflag, nc->tcache.setab, palbg = cell_bg_palindex(srccell);
nc->tcache.colors, out, br, bg, bb, if(nc->rstate.bgpalelidable && nc->rstate.lastbr == palbg){
nc->tcache.bg_collides_default)){ ++nc->stats.bgelisions;
return -1; }else{
if(term_bg_palindex(nc, out, palbg)){
return -1;
}
++nc->stats.bgemissions;
nc->rstate.bgpalelidable = true;
}
nc->rstate.lastr = palbg;
nc->rstate.bgdefelidable = false;
nc->rstate.bgelidable = false;
}else if(!cell_bg_default_p(srccell)){ // rgb background
cell_bg_rgb8(srccell, &br, &bg, &bb);
if(nc->rstate.bgelidable && nc->rstate.lastbr == br && nc->rstate.lastbg == bg && nc->rstate.lastbb == bb){
++nc->stats.bgelisions;
}else{
if(term_bg_rgb8(nc->tcache.RGBflag, nc->tcache.setab,
nc->tcache.colors, out, br, bg, bb,
nc->tcache.bg_collides_default)){
return -1;
}
++nc->stats.bgemissions;
nc->rstate.bgelidable = true;
} }
++nc->stats.bgemissions; nc->rstate.lastbr = br; nc->rstate.lastbg = bg; nc->rstate.lastbb = bb;
nc->rstate.bgelidable = true; nc->rstate.bgdefelidable = false;
nc->rstate.bgpalelidable = false;
} }
nc->rstate.lastbr = br; nc->rstate.lastbg = bg; nc->rstate.lastbb = bb;
nc->rstate.bgdefelidable = false;
nc->rstate.bgpalelidable = false;
} }
//fprintf(stderr, "RAST %08x [%s] to %d/%d cols: %u %016lx\n", srccell->gcluster, pool_extended_gcluster(&nc->pool, srccell), y, x, srccell->width, srccell->channels); //fprintf(stderr, "RAST %08x [%s] to %d/%d cols: %u %016lx\n", srccell->gcluster, pool_extended_gcluster(&nc->pool, srccell), y, x, srccell->width, srccell->channels);
if(term_putc(nc, out, &nc->pool, srccell)){ if(term_putc(nc, out, &nc->pool, srccell)){

@ -228,7 +228,10 @@ query_sixel(tinfo* ti, int fd){
if(in == 'c'){ if(in == 'c'){
state = DONE; state = DONE;
}else if(in == '4'){ }else if(in == '4'){
ti->sixel = true; if(!ti->pixelon){
ti->pixelon = strdup("\ePq");
ti->pixeloff = strdup("\e\\");
} // FIXME else warning?
} }
break; break;
case DONE: case DONE:

@ -27,8 +27,8 @@ void usage(std::ostream& o, const char* name, int exitcode){
o << " -L: loop frames\n"; o << " -L: loop frames\n";
o << " -t seconds: delay t seconds after each file\n"; o << " -t seconds: delay t seconds after each file\n";
o << " -l loglevel: integer between 0 and 9, goes to stderr'\n"; o << " -l loglevel: integer between 0 and 9, goes to stderr'\n";
o << " -s scaletype: one of 'none', 'hires', 'scale', 'scalehi', or 'stretch'\n"; o << " -s 'none', 'hires', 'scale', 'scalehi', or 'stretch'\n";
o << " -b blitter: 'ascii', 'halfblock', 'quadblitter', 'sexblitter', or 'braille'\n"; o << " -b 'ascii', 'halfblock', 'quadblitter', 'sexblitter', 'braille', or 'pixel'\n";
o << " -m margins: margin, or 4 comma-separated margins\n"; o << " -m margins: margin, or 4 comma-separated margins\n";
o << " -d mult: non-negative floating point scale for frame time" << std::endl; o << " -d mult: non-negative floating point scale for frame time" << std::endl;
exit(exitcode); exit(exitcode);

Loading…
Cancel
Save