[pixels] unify sprixel nonce

pull/1418/head
nick black 4 years ago committed by Nick Black
parent cd48c78eb2
commit 2eff848061

@ -527,6 +527,7 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
.celldimx = n->tcache.cellpixx,
.celldimy = n->tcache.cellpixy,
.colorregs = n->tcache.color_registers,
.sprixelid = n->tcache.sprixelnonce++,
},
};
if(ncvisual_blit(ncv, disprows, dispcols, ncdv, bset,

@ -313,6 +313,7 @@ typedef struct tinfo {
int color_registers; // sixel color registers (post pixel_query_done)
int sixel_maxx, sixel_maxy; // sixel size maxima (post pixel_query_done)
bool sixel_supported; // do we support sixel (post pixel_query_done)?
int sprixelnonce; // next sprixel id
int (*pixel_destroy)(struct notcurses* nc, const struct ncpile* p, FILE* out, sprixel* s);
bool pixel_query_done; // have we yet performed pixel query?
bool sextants; // do we have (good, vetted) Unicode 13 sextant support?
@ -396,7 +397,6 @@ typedef struct notcurses {
bool suppress_banner; // from notcurses_options
sprixel* sprixelcache; // list of pixel graphics currently displayed
int sprixelnonce; // next sprixel id FIXME ought be atomic
// desired margins (best-effort only), copied in from notcurses_options
int margin_t, margin_b, margin_r, margin_l;
@ -417,6 +417,7 @@ typedef union {
int celldimx; // horizontal pixels per cell
int celldimy; // vertical pixels per cell
int colorregs; // number of color registers
int sprixelid; // unqie 24-bit id into sprixel cache
} pixel; // for pixels
} blitterargs;
@ -694,7 +695,7 @@ plane_debug(const ncplane* n, bool details){
void sprixel_free(sprixel* s);
void sprixel_hide(sprixel* s);
sprixel* sprixel_create(ncplane* n, const char* s, int bytes);
sprixel* sprixel_create(ncplane* n, const char* s, int bytes, int sprixelid);
int sprite_kitty_annihilate(notcurses* nc, const ncpile* p, FILE* out, sprixel* s);
int sprite_sixel_annihilate(notcurses* nc, const ncpile* p, FILE* out, sprixel* s);
@ -1090,8 +1091,9 @@ egc_rtl(const char* egc, int* bytes){
// a reference to the context-wide sprixel cache. this ought be an entirely
// new, purpose-specific plane.
static inline int
plane_blit_sixel(ncplane* n, const char* s, int bytes, int leny, int lenx){
sprixel* spx = sprixel_create(n, s, bytes);
plane_blit_sixel(ncplane* n, const char* s, int bytes, int leny, int lenx,
int sprixelid){
sprixel* spx = sprixel_create(n, s, bytes, sprixelid);
if(spx == NULL){
return -1;
}

@ -951,7 +951,6 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
ret->margin_r = opts->margin_r;
ret->cursory = ret->cursorx = -1;
ret->sprixelcache = NULL;
ret->sprixelnonce = 1;
memset(&ret->stats, 0, sizeof(ret->stats));
memset(&ret->stashed_stats, 0, sizeof(ret->stashed_stats));
reset_stats(&ret->stats);

@ -971,7 +971,7 @@ rasterize_sprixels(notcurses* nc, const ncpile* p, FILE* out){
nc->rstate.hardcursorpos = true;
parent = &s->next;
}else if(s->invalidated == SPRIXEL_HIDE){
//fprintf(stderr, "OUGHT HIDE [%dx%d @ %d/%d] %p\n", s->dimy, s->dimx, s->y, s->x, s);
//fprintf(stderr, "OUGHT HIDE %d [%dx%d @ %d/%d] %p\n", s->id, s->dimy, s->dimx, s->y, s->x, s);
int r = nc->tcache.pixel_destroy(nc, p, out, s);
if(r < 0){
return -1;

@ -258,7 +258,7 @@ int sixel_blit_inner(ncplane* nc, int leny, int lenx, sixeltable* stab,
}
unsigned cols = lenx / bargs->pixel.celldimx + !!(lenx % bargs->pixel.celldimx);
unsigned rows = leny / bargs->pixel.celldimy + !!(leny % bargs->pixel.celldimx);
if(plane_blit_sixel(nc, buf, size, rows, cols) < 0){
if(plane_blit_sixel(nc, buf, size, rows, cols, bargs->pixel.sprixelid) < 0){
free(buf);
return -1;
}

@ -15,7 +15,7 @@ void sprixel_hide(sprixel* s){
s->n = NULL;
}
sprixel* sprixel_create(ncplane* n, const char* s, int bytes){
sprixel* sprixel_create(ncplane* n, const char* s, int bytes, int sprixelid){
sprixel* ret = malloc(sizeof(sprixel));
if(ret){
if((ret->glyph = memdup(s, bytes + 1)) == NULL){
@ -28,7 +28,7 @@ sprixel* sprixel_create(ncplane* n, const char* s, int bytes){
notcurses* nc = ncplane_notcurses(n);
ret->next = nc->sprixelcache;
nc->sprixelcache = ret;
ret->id = nc->sprixelnonce++; // FIXME should be atomic
ret->id = sprixelid;
}
}
return ret;

@ -200,6 +200,7 @@ int interrogate_terminfo(tinfo* ti, const char* termname, unsigned utf8){
if(apply_term_heuristics(ti, termname)){
return -1;
}
ti->sprixelnonce = 1;
return 0;
}

@ -529,6 +529,7 @@ auto ncvisual_render_pixels(tinfo* tcache, ncvisual* ncv, const blitset* bset,
bargs.pixel.celldimx = ncplane_notcurses(stdn)->tcache.cellpixx;
bargs.pixel.celldimy = ncplane_notcurses(stdn)->tcache.cellpixy;
bargs.pixel.colorregs = ncplane_notcurses(stdn)->tcache.color_registers;
bargs.pixel.sprixelid = tcache->sprixelnonce++;
if(ncvisual_blit(ncv, disprows, dispcols, n, bset,
begy, begx, disprows, dispcols, &bargs)){
ncplane_destroy(n);

Loading…
Cancel
Save