dump sprixel_auxiliary_vector, save 50% of kitty/fbcon auxvec space

This commit is contained in:
nick black 2021-10-20 02:09:41 -04:00
parent d857fedf16
commit 9483278ba1
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
5 changed files with 40 additions and 20 deletions

View File

@ -649,12 +649,6 @@ void sprixel_movefrom(sprixel* s, int y, int x);
void sprixel_debug(const sprixel* s, FILE* out); void sprixel_debug(const sprixel* s, FILE* out);
void sixelmap_free(struct sixelmap *s); void sixelmap_free(struct sixelmap *s);
// create an auxiliary vector suitable for a sprixcell, and zero it out. there
// are two bytes per pixel in the cell. kitty uses only one (for an alpha
// value). sixel uses both (for palette index, and transparency). FIXME fold
// the transparency vector up into 1/8th as many bytes.
uint8_t* sprixel_auxiliary_vector(const sprixel* s);
// update any necessary cells underneath the sprixel pursuant to its removal. // update any necessary cells underneath the sprixel pursuant to its removal.
// for sixel, this *achieves* the removal, and is performed on every cell. // for sixel, this *achieves* the removal, and is performed on every cell.
// returns 1 if the graphic can be immediately freed (which is equivalent to // returns 1 if the graphic can be immediately freed (which is equivalent to

View File

@ -445,9 +445,21 @@ sprixel* kitty_recycle(ncplane* n){
return sprixel_alloc(&ncplane_notcurses_const(n)->tcache, n, dimy, dimx); return sprixel_alloc(&ncplane_notcurses_const(n)->tcache, n, dimy, dimx);
} }
// for pre-animation kitty (NCPIXEL_KITTY_STATIC), we need a byte per pixel,
// in which we stash the alpha.
static inline uint8_t*
kitty_auxiliary_vector(const sprixel* s){
int pixels = s->cellpxy * s->cellpxx;
uint8_t* ret = malloc(sizeof(*ret) * pixels);
if(ret){
memset(ret, 0, sizeof(*ret) * pixels);
}
return ret;
}
int kitty_wipe(sprixel* s, int ycell, int xcell){ int kitty_wipe(sprixel* s, int ycell, int xcell){
//fprintf(stderr, "NEW WIPE %d %d/%d\n", s->id, ycell, xcell); //fprintf(stderr, "NEW WIPE %d %d/%d\n", s->id, ycell, xcell);
uint8_t* auxvec = sprixel_auxiliary_vector(s); uint8_t* auxvec = kitty_auxiliary_vector(s);
if(auxvec == NULL){ if(auxvec == NULL){
return -1; return -1;
} }

View File

@ -3,8 +3,18 @@
// auxvecs for framebuffer are 1B each for s->cellpxx * s->cellpxy elements, // auxvecs for framebuffer are 1B each for s->cellpxx * s->cellpxy elements,
// and store the original alpha value. // and store the original alpha value.
static inline uint8_t*
fbcon_auxiliary_vector(const sprixel* s){
int pixels = s->cellpxy * s->cellpxx;
uint8_t* ret = malloc(sizeof(*ret) * pixels);
if(ret){
memset(ret, 0, sizeof(*ret) * pixels);
}
return ret;
}
int fbcon_wipe(sprixel* s, int ycell, int xcell){ int fbcon_wipe(sprixel* s, int ycell, int xcell){
uint8_t* auxvec = sprixel_auxiliary_vector(s); uint8_t* auxvec = fbcon_auxiliary_vector(s);
if(auxvec == NULL){ if(auxvec == NULL){
return -1; return -1;
} }

View File

@ -20,6 +20,21 @@ sixelcount(int dimy, int dimx){
return (dimy + 5) / 6 * dimx; return (dimy + 5) / 6 * dimx;
} }
// create an auxiliary vector suitable for a Sixel sprixcell, and zero it out.
// there are two bytes per pixel in the cell: a contiguous set of palette
// indices (yet another reason that we work with 256 colors), and a contiguous
// set of two-value transparencies (these could be folded down to bits from
// bytes, saving 7/8 of the space FIXME).
static inline uint8_t*
sixel_auxiliary_vector(const sprixel* s){
int pixels = s->cellpxy * s->cellpxx;
uint8_t* ret = malloc(sizeof(*ret) * pixels * 2);
if(ret){
memset(ret, 0, sizeof(*ret) * pixels);
}
return ret;
}
// we keep a color-indexed set of sixels (a single-row column of six pixels, // we keep a color-indexed set of sixels (a single-row column of six pixels,
// encoded as a byte) across the life of the sprixel. This provides a good // encoded as a byte) across the life of the sprixel. This provides a good
// combination of easy-to-edit (for wipes and restores) -- you can index by // combination of easy-to-edit (for wipes and restores) -- you can index by
@ -210,7 +225,7 @@ wipe_color(sixelmap* smap, int color, int sband, int eband,
// redrawn, it's redrawn using P2=1. // redrawn, it's redrawn using P2=1.
int sixel_wipe(sprixel* s, int ycell, int xcell){ int sixel_wipe(sprixel* s, int ycell, int xcell){
//fprintf(stderr, "WIPING %d/%d\n", ycell, xcell); //fprintf(stderr, "WIPING %d/%d\n", ycell, xcell);
uint8_t* auxvec = sprixel_auxiliary_vector(s); uint8_t* auxvec = sixel_auxiliary_vector(s);
if(auxvec == NULL){ if(auxvec == NULL){
return -1; return -1;
} }

View File

@ -224,14 +224,3 @@ int sprite_init(const tinfo* t, int fd){
} }
return t->pixel_init(fd); return t->pixel_init(fd);
} }
uint8_t* sprixel_auxiliary_vector(const sprixel* s){
int pixels = s->cellpxy * s->cellpxx;
// for now we just do two bytes per pixel. we ought squeeze the transparency
// vector down to a bit per pixel, rather than a byte FIXME.
uint8_t* ret = malloc(sizeof(*ret) * pixels * 2);
if(ret){
memset(ret, 0, sizeof(*ret) * pixels);
}
return ret;
}