blitting: place utf8 in tcache #1334

pull/1338/head
nick black 4 years ago
parent fdd1785ff0
commit 568e83e4f6
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -902,8 +902,8 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v
blitter = vopts->blitter; blitter = vopts->blitter;
} }
const bool degrade = !(vopts->flags & NCVISUAL_OPTION_NODEGRADE); const bool degrade = !(vopts->flags & NCVISUAL_OPTION_NODEGRADE);
const struct blitset* bset = lookup_blitset(notcurses_canutf8(ncplane_notcurses(nc)), const notcurses* notc = ncplane_notcurses(nc);
blitter, degrade); const struct blitset* bset = lookup_blitset(&notc->tcache, blitter, degrade);
if(bset == NULL){ if(bset == NULL){
return -1; return -1;
} }
@ -913,5 +913,5 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v
} }
ncblitter_e ncvisual_media_defblitter(const notcurses* nc, ncscale_e scale){ ncblitter_e ncvisual_media_defblitter(const notcurses* nc, ncscale_e scale){
return rgba_blitter_default(nc->utf8, scale, nc->tcache.sextants); return rgba_blitter_default(nc->tcache.utf8, scale, nc->tcache.sextants);
} }

@ -4,12 +4,12 @@
#include "notcurses/notcurses.h" #include "notcurses/notcurses.h"
static inline const struct blitset* static inline const struct blitset*
lookup_blitset(unsigned utf8, ncblitter_e setid, bool may_degrade) { lookup_blitset(const tinfo* tcache, ncblitter_e setid, bool may_degrade) {
if(setid == NCBLIT_DEFAULT){ // ought have resolved NCBLIT_DEFAULT before now if(setid == NCBLIT_DEFAULT){ // ought have resolved NCBLIT_DEFAULT before now
return NULL; return NULL;
} }
// the only viable blitter in ASCII is NCBLIT_1x1 // the only viable blitter in ASCII is NCBLIT_1x1
if(!utf8 && setid != NCBLIT_1x1){ if(!tcache->utf8 && setid != NCBLIT_1x1){
if(may_degrade){ if(may_degrade){
setid = NCBLIT_1x1; setid = NCBLIT_1x1;
}else{ }else{
@ -54,14 +54,12 @@ rgba_blitter_default(bool utf8, ncscale_e scale, bool sextants){
} }
static inline const struct blitset* static inline const struct blitset*
rgba_blitter_low(bool utf8, bool sextants, ncscale_e scale, bool maydegrade, rgba_blitter_low(const tinfo* tcache, bool sextants, ncscale_e scale, bool maydegrade,
ncblitter_e blitrec) { ncblitter_e blitrec) {
const struct blitset* bset; if(blitrec == NCBLIT_DEFAULT){
if(blitrec != NCBLIT_DEFAULT){ blitrec = rgba_blitter_default(tcache->utf8, scale, sextants);
bset = lookup_blitset(utf8, blitrec, maydegrade);
}else{
bset = lookup_blitset(utf8, rgba_blitter_default(utf8, scale, sextants), maydegrade);
} }
const struct blitset* bset = lookup_blitset(tcache, blitrec, maydegrade);
if(bset && !bset->blit){ // FIXME remove this once all blitters are enabled if(bset && !bset->blit){ // FIXME remove this once all blitters are enabled
bset = NULL; bset = NULL;
} }
@ -74,7 +72,7 @@ static inline const struct blitset*
rgba_blitter(const struct notcurses* nc, const struct ncvisual_options* opts) { rgba_blitter(const struct notcurses* nc, const struct ncvisual_options* opts) {
const bool maydegrade = !(opts && (opts->flags & NCVISUAL_OPTION_NODEGRADE)); const bool maydegrade = !(opts && (opts->flags & NCVISUAL_OPTION_NODEGRADE));
const ncscale_e scale = opts ? opts->scaling : NCSCALE_NONE; const ncscale_e scale = opts ? opts->scaling : NCSCALE_NONE;
return rgba_blitter_low(notcurses_canutf8(nc), notcurses_cansextant(nc), return rgba_blitter_low(&nc->tcache, notcurses_cansextant(nc),
scale, maydegrade, opts ? opts->blitter : NCBLIT_DEFAULT); scale, maydegrade, opts ? opts->blitter : NCBLIT_DEFAULT);
} }

@ -485,7 +485,7 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
return nullptr; return nullptr;
} }
//fprintf(stderr, "render %d/%d to %d+%d scaling: %d\n", ncv->rows, ncv->cols, leny, lenx, scale); //fprintf(stderr, "render %d/%d to %d+%d scaling: %d\n", ncv->rows, ncv->cols, leny, lenx, scale);
auto bset = rgba_blitter_low(n->utf8, n->tcache.sextants, scale, true, blitter); auto bset = rgba_blitter_low(&n->tcache, n->tcache.sextants, scale, true, blitter);
if(!bset){ if(!bset){
ncvisual_destroy(ncv); ncvisual_destroy(ncv);
return nullptr; return nullptr;
@ -638,7 +638,7 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
} }
const char* encoding = nl_langinfo(CODESET); const char* encoding = nl_langinfo(CODESET);
if(encoding && strcmp(encoding, "UTF-8") == 0){ if(encoding && strcmp(encoding, "UTF-8") == 0){
ret->utf8 = true; ret->tcache.utf8 = true;
} }
if(setup_signals(ret, (flags & NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS), if(setup_signals(ret, (flags & NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS),
true, ncdirect_stop_minimal)){ true, ncdirect_stop_minimal)){
@ -1066,7 +1066,7 @@ bool ncdirect_canopen_images(const ncdirect* n __attribute__ ((unused))){
// Is our encoding UTF-8? Requires LANG being set to a UTF8 locale. // Is our encoding UTF-8? Requires LANG being set to a UTF8 locale.
bool ncdirect_canutf8(const ncdirect* n){ bool ncdirect_canutf8(const ncdirect* n){
return n->utf8; return n->tcache.utf8;
} }
int ncdirect_flush(const ncdirect* nc){ int ncdirect_flush(const ncdirect* nc){

@ -268,6 +268,7 @@ typedef struct tinfo {
bool CCCflag; // "CCC" flag for palette set capability bool CCCflag; // "CCC" flag for palette set capability
bool BCEflag; // "BCE" flag for erases with background color bool BCEflag; // "BCE" flag for erases with background color
bool AMflag; // "AM" flag for automatic movement to next line bool AMflag; // "AM" flag for automatic movement to next line
bool utf8; // are we using utf-8 encoding, as hoped?
char* smcup; // enter alternate mode char* smcup; // enter alternate mode
char* rmcup; // restore primary mode char* rmcup; // restore primary mode
@ -304,7 +305,6 @@ typedef struct ncdirect {
uint64_t channels; // current channels uint64_t channels; // current channels
uint16_t stylemask; // current styles uint16_t stylemask; // current styles
ncinputlayer input; // input layer; we're in cbreak mode ncinputlayer input; // input layer; we're in cbreak mode
bool utf8; // are we using utf-8 encoding, as hoped?
struct termios tpreserved; // terminal state upon entry struct termios tpreserved; // terminal state upon entry
// some terminals (e.g. kmscon) return cursor coordinates inverted from the // some terminals (e.g. kmscon) return cursor coordinates inverted from the
// typical order. we detect it the first time ncdirect_cursor_yx() is called. // typical order. we detect it the first time ncdirect_cursor_yx() is called.
@ -360,7 +360,6 @@ typedef struct notcurses {
int loglevel; int loglevel;
palette256 palette; // 256-indexed palette can be used instead of/with RGB palette256 palette; // 256-indexed palette can be used instead of/with RGB
bool palette_damage[NCPALETTESIZE]; bool palette_damage[NCPALETTESIZE];
bool utf8; // are we using utf-8 encoding, as hoped?
bool libsixel; // do we have Sixel support? bool libsixel; // do we have Sixel support?
} notcurses; } notcurses;

@ -945,10 +945,11 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
init_lang(ret); init_lang(ret);
} }
const char* encoding = nl_langinfo(CODESET); const char* encoding = nl_langinfo(CODESET);
bool utf8;
if(encoding && !strcmp(encoding, "UTF-8")){ if(encoding && !strcmp(encoding, "UTF-8")){
ret->utf8 = true; utf8 = true;
}else if(encoding && (!strcmp(encoding, "ANSI_X3.4-1968") || !strcmp(encoding, "US-ASCII"))){ }else if(encoding && (!strcmp(encoding, "ANSI_X3.4-1968") || !strcmp(encoding, "US-ASCII"))){
ret->utf8 = false; utf8 = false;
}else{ }else{
fprintf(stderr, "Encoding (\"%s\") was neither ANSI_X3.4-1968 nor UTF-8, refusing to start\n Did you call setlocale()?\n", fprintf(stderr, "Encoding (\"%s\") was neither ANSI_X3.4-1968 nor UTF-8, refusing to start\n Did you call setlocale()?\n",
encoding ? encoding : "none found"); encoding ? encoding : "none found");
@ -1028,6 +1029,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
if(interrogate_terminfo(&ret->tcache, shortname_term)){ if(interrogate_terminfo(&ret->tcache, shortname_term)){
goto err; goto err;
} }
ret->tcache.utf8 = utf8;
warn_terminfo(ret, &ret->tcache); warn_terminfo(ret, &ret->tcache);
reset_term_attributes(ret); reset_term_attributes(ret);
if(ncinputlayer_init(&ret->input, stdin)){ if(ncinputlayer_init(&ret->input, stdin)){
@ -2044,11 +2046,11 @@ int notcurses_mouse_disable(notcurses* n){
} }
bool notcurses_canutf8(const notcurses* nc){ bool notcurses_canutf8(const notcurses* nc){
return nc->utf8; return nc->tcache.utf8;
} }
bool notcurses_cansextant(const notcurses* nc){ bool notcurses_cansextant(const notcurses* nc){
return nc->tcache.sextants && nc->utf8; return nc->tcache.sextants && nc->tcache.utf8;
} }
bool notcurses_canfade(const notcurses* nc){ bool notcurses_canfade(const notcurses* nc){

@ -42,6 +42,7 @@ class ncppplot {
ncplane_destroy(n); ncplane_destroy(n);
return false; return false;
} }
const notcurses* notc = ncplane_notcurses(n);
ncblitter_e blitter = opts ? opts->gridtype : NCBLIT_DEFAULT; ncblitter_e blitter = opts ? opts->gridtype : NCBLIT_DEFAULT;
if(blitter == NCBLIT_DEFAULT){ if(blitter == NCBLIT_DEFAULT){
if(notcurses_canutf8(ncplane_notcurses(n))){ if(notcurses_canutf8(ncplane_notcurses(n))){
@ -51,8 +52,7 @@ class ncppplot {
} }
} }
bool degrade_blitter = !(opts && (opts->flags & NCPLOT_OPTION_NODEGRADE)); bool degrade_blitter = !(opts && (opts->flags & NCPLOT_OPTION_NODEGRADE));
auto bset = lookup_blitset(notcurses_canutf8(ncplane_notcurses(n)), auto bset = lookup_blitset(&notc->tcache, blitter, degrade_blitter);
blitter, degrade_blitter);
if(bset == nullptr){ if(bset == nullptr){
ncplane_destroy(n); ncplane_destroy(n);
return false; return false;

@ -79,8 +79,7 @@ auto ncvisual_geom(const notcurses* nc, const ncvisual* n,
blitter = vopts->blitter; blitter = vopts->blitter;
} }
const bool maydegrade = !(vopts && (vopts->flags & NCVISUAL_OPTION_NODEGRADE)); const bool maydegrade = !(vopts && (vopts->flags & NCVISUAL_OPTION_NODEGRADE));
const struct blitset* bset = lookup_blitset(notcurses_canutf8(nc), const struct blitset* bset = lookup_blitset(&nc->tcache, blitter, maydegrade);
blitter, maydegrade);
if(!bset){ if(!bset){
return -1; return -1;
} }

Loading…
Cancel
Save