[pixel] beginning of transparency-annihilation cache #1388

This commit is contained in:
nick black 2021-03-20 15:09:49 -04:00 committed by Nick Black
parent ca84f96f9c
commit ef380fe768
4 changed files with 21 additions and 3 deletions

View File

@ -63,6 +63,7 @@ typedef struct sprixel {
int y, x;
int dimy, dimx; // cell geometry
int pixy, pixx; // pixel geometry (might be smaller than cell geo)
int* tacache; // transparency-annihilatin cache (dimy * dimx)
} sprixel;
// A plane is memory for some rectilinear virtual window, plus current cursor
@ -703,7 +704,7 @@ void sprixel_hide(sprixel* s);
// dimy and dimx are cell geometry, not pixel
sprixel* sprixel_create(ncplane* n, const char* s, int bytes, int sprixelid,
int dimy, int dimx, int pixy, int pixx);
int sprite_wipe_cell(const notcurses* nc, sprixel* s, int y, int x);
API int sprite_wipe_cell(const notcurses* nc, sprixel* s, int y, int x);
int sprite_kitty_annihilate(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s);
int sprite_sixel_annihilate(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s);

View File

@ -971,6 +971,7 @@ rasterize_sprixels(notcurses* nc, const ncpile* p, FILE* out){
if(s->invalidated == SPRIXEL_INVALIDATED){
int y, x;
ncplane_yx(s->n, &y, &x);
//fprintf(stderr, "DRAWING BITMAP AT %d/%d\n", y, x);
if(goto_location(nc, out, y + nc->stdplane->absy, x + nc->stdplane->absx)){
return -1;
}

View File

@ -2,6 +2,7 @@
void sprixel_free(sprixel* s){
if(s){
free(s->tacache);
free(s->glyph);
free(s);
}
@ -24,6 +25,15 @@ sprixel* sprixel_create(ncplane* n, const char* s, int bytes, int sprixelid,
free(ret);
return NULL;
}
const size_t tasize = sizeof(*ret->tacache) * dimy * dimx;
if((ret->tacache = malloc(tasize)) == NULL){
free(ret->glyph);
free(ret);
return NULL;
}
// FIXME set up transparency cache when generating sprixel;
// we manage only annihilation cache
memset(ret->tacache, 0, tasize);
ret->invalidated = SPRIXEL_INVALIDATED;
ret->n = n;
ret->dimy = dimy;
@ -41,13 +51,19 @@ sprixel* sprixel_create(ncplane* n, const char* s, int bytes, int sprixelid,
}
int sprite_wipe_cell(const notcurses* nc, sprixel* s, int ycell, int xcell){
if(!nc->tcache.pixel_cell_wipe){
return 0;
}
if(ycell >= s->dimy){
return -1;
}
if(xcell >= s->dimx){
return -1;
}
// FIXME transparency-annihilation cache!
if(s->tacache[s->dimx * ycell + xcell] == 2){
return 0; // already annihilated
}
s->tacache[s->dimx * ycell + xcell] = 2;
int r = nc->tcache.pixel_cell_wipe(nc, s, ycell, xcell);
if(r == 0){
s->invalidated = SPRIXEL_INVALIDATED;

View File

@ -347,7 +347,7 @@ query_sixel(tinfo* ti, int fd){
ti->sixel_supported = true;
ti->color_registers = 256; // assumed default [shrug]
ti->pixel_destroy = sprite_sixel_annihilate;
ti->pixel_cell_wipe = sprite_sixel_cell_wipe;
//ti->pixel_cell_wipe = sprite_sixel_cell_wipe;
ti->sixel_maxx = ti->sixel_maxy = 0;
}
}