diff --git a/src/lib/internal.h b/src/lib/internal.h index 61877dbd6..5a830dc5b 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -649,12 +649,6 @@ void sprixel_movefrom(sprixel* s, int y, int x); void sprixel_debug(const sprixel* s, FILE* out); 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. // 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 diff --git a/src/lib/kitty.c b/src/lib/kitty.c index 6e8afca83..7f66f93af 100644 --- a/src/lib/kitty.c +++ b/src/lib/kitty.c @@ -445,9 +445,21 @@ sprixel* kitty_recycle(ncplane* n){ 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){ //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){ return -1; } diff --git a/src/lib/linux.c b/src/lib/linux.c index dab57abf2..c4a04f4bb 100644 --- a/src/lib/linux.c +++ b/src/lib/linux.c @@ -3,8 +3,18 @@ // auxvecs for framebuffer are 1B each for s->cellpxx * s->cellpxy elements, // 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){ - uint8_t* auxvec = sprixel_auxiliary_vector(s); + uint8_t* auxvec = fbcon_auxiliary_vector(s); if(auxvec == NULL){ return -1; } diff --git a/src/lib/sixel.c b/src/lib/sixel.c index 5261bdfdd..99215dab0 100644 --- a/src/lib/sixel.c +++ b/src/lib/sixel.c @@ -20,6 +20,21 @@ sixelcount(int dimy, int 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, // 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 @@ -210,7 +225,7 @@ wipe_color(sixelmap* smap, int color, int sband, int eband, // redrawn, it's redrawn using P2=1. int sixel_wipe(sprixel* s, int ycell, int 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){ return -1; } diff --git a/src/lib/sprite.c b/src/lib/sprite.c index 53bfccd03..1483da386 100644 --- a/src/lib/sprite.c +++ b/src/lib/sprite.c @@ -224,14 +224,3 @@ int sprite_init(const tinfo* t, int 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; -}