Skip to content

Commit

Permalink
continuing down the kitty animations road #1439
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Jun 30, 2021
1 parent fcca453 commit b8f6e8d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
74 changes: 38 additions & 36 deletions src/lib/kitty.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,36 @@ kitty_restore(char* triplet, int skip, int max, int pleft,
return max;
}

// if there is no mstreamfp open, create one, using glyph and glyphlen as the
// base. we're blowing away the glyph.
static int
init_sprixel_animation(sprixel* s){
if(s->mstreamfp){
return 0;
}
free(s->glyph);
s->glyph = NULL;
s->glyphlen = 0;
if((s->mstreamfp = open_memstream(&s->glyph, &s->glyphlen)) == NULL){
loginfo("Opened animation buffer for sprixel %u\n", s->id);
return -1;
}
return 0;
}

// this just needs to delete the animation block that was lain atop the
// original bitmap.
int kitty_rebuild_animation(sprixel* s, int ycell, int xcell, uint8_t* auxvec){
if(init_sprixel_animation(s)){
return -1;
}
uint32_t blockid;
memcpy(&blockid, auxvec, sizeof(blockid));
(void)ycell;
(void)xcell;
return -1; // FIXME
}

#define RGBA_MAXLEN 768 // 768 base64-encoded pixels in 4096 bytes
// restore an annihilated sprixcell by copying the alpha values from the
// auxiliary vector back into the actual data. we then free the auxvector.
Expand Down Expand Up @@ -336,23 +366,6 @@ int kitty_rebuild(sprixel* s, int ycell, int xcell, uint8_t* auxvec){
return -1;
}

// if there is no mstreamfp open, create one, using glyph and glyphlen as the
// base. we're blowing away the glyph.
static int
init_sprixel_animation(sprixel* s){
if(s->mstreamfp){
return 0;
}
free(s->glyph);
s->glyph = NULL;
s->glyphlen = 0;
if((s->mstreamfp = open_memstream(&s->glyph, &s->glyphlen)) == NULL){
loginfo("Opened animation buffer for sprixel %u\n", s->id);
return -1;
}
return 0;
}

// we lay a cell-sixed animation block atop the graphic, giving it a
// cell id with which we can delete it in O(1) for a rebuild. this
// way, we needn't delete and redraw the entire sprixel.
Expand Down Expand Up @@ -399,19 +412,6 @@ sprixel* kitty_recycle(ncplane* n){
return sprixel_alloc(n, dimy, dimx);
}

// this just needs to delete the animation block that was lain atop the
// original bitmap.
int kitty_rebuild_animation(sprixel* s, int ycell, int xcell, uint8_t* auxvec){
if(init_sprixel_animation(s)){
return -1;
}
uint32_t blockid;
memcpy(&blockid, auxvec, sizeof(blockid));
(void)ycell;
(void)xcell;
return -1; // FIXME
}

int kitty_wipe(sprixel* s, int ycell, int xcell){
//fprintf(stderr, "NEW WIPE %d %d/%d\n", s->id, ycell, xcell);
uint8_t* auxvec = kitty_trans_auxvec(s);
Expand Down Expand Up @@ -556,14 +556,16 @@ write_kitty_data(FILE* fp, int linesize, int leny, int lenx, int cols,
int ycell = y / cdimy;
int tyx = xcell + ycell * cols;
//fprintf(stderr, "Tyx: %d y: %d (%d) * %d x: %d (%d) state %d %p\n", tyx, y, y / cdimy, cols, x, x / cdimx, tam[tyx].state, tam[tyx].auxvector);
// this pixel is part of a cell which is currently wiped (alpha-nulled
// out, to present a glyph "atop" it). we will continue to mark it
// transparent, but we need to update the auxiliary vector.
const int vyx = (y % cdimy) * cdimx + (x % cdimx);
if(tam[tyx].state == SPRIXCELL_ANNIHILATED || tam[tyx].state == SPRIXCELL_ANNIHILATED_TRANS){
// this pixel is part of a cell which is currently wiped (alpha-nulled
// out, to present a glyph "atop" it). we will continue to mark it
// transparent, but we need to update the auxiliary vector.
const int vyx = (y % cdimy) * cdimx + (x % cdimx);
// FIXME NO DOES NOT WORK FOR ANIMATED AUXVEC
// tam[tyx].auxvector[vyx] = ncpixel_a(source[e]);
tam[tyx].auxvector[vyx] = ncpixel_a(source[e]);
wipe[e] = 1;
}else if(tam[tyx].state == SPRIXCELL_ANIMATED || tam[tyx].state == SPRIXCELL_ANIMATED_TRANS){
fprintf(stderr, "ANIMATED AUXVEC CONSULT %d/%d\n", y, x);
// FIXME NO DOES NOT WORK FOR ANIMATED AUXVEC
}else{
wipe[e] = 0;
if(rgba_trans_p(source[e], transcolor)){
Expand Down
2 changes: 1 addition & 1 deletion src/lib/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ paint_sprixel(ncplane* p, struct crender* rvec, int starty, int startx,
if(crender->sprixel == NULL){
crender->sprixel = s;
}
if(state == SPRIXCELL_ANNIHILATED || state == SPRIXCELL_ANNIHILATED_TRANS){
if(state >= SPRIXCELL_ANNIHILATED){
//fprintf(stderr, "REBUILDING AT %d/%d\n", y, x);
sprite_rebuild(nc, s, y, x);
//fprintf(stderr, "damaging due to rebuild [%s] %d/%d\n", nccell_extended_gcluster(crender->p, &crender->c), absy, absx);
Expand Down
9 changes: 3 additions & 6 deletions src/lib/sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void sprixel_debug(FILE* out, const sprixel* s){
idx = 0;
for(int y = 0 ; y < s->dimy ; ++y){
for(int x = 0 ; x < s->dimx ; ++x){
if(s->n->tam[idx].state == SPRIXCELL_ANNIHILATED){
if(s->n->tam[idx].state >= SPRIXCELL_ANNIHILATED){
if(s->n->tam[idx].auxvector){
fprintf(out, "%03d] ", idx);
for(int p = 0 ; p < s->cellpxx * s->cellpxy ; ++p){
Expand Down Expand Up @@ -101,8 +101,7 @@ void sprixel_invalidate(sprixel* s, int y, int x){
int localx = x - s->n->absx;
//fprintf(stderr, "INVALIDATING AT %d/%d (%d/%d) TAM: %d\n", y, x, localy, localx, s->n->tam[localy * s->dimx + localx].state);
if(s->n->tam[localy * s->dimx + localx].state != SPRIXCELL_TRANSPARENT &&
s->n->tam[localy * s->dimx + localx].state != SPRIXCELL_ANNIHILATED &&
s->n->tam[localy * s->dimx + localx].state != SPRIXCELL_ANNIHILATED_TRANS){
s->n->tam[localy * s->dimx + localx].state < SPRIXCELL_ANNIHILATED){
s->invalidated = SPRIXEL_INVALIDATED;
}
}
Expand Down Expand Up @@ -179,8 +178,7 @@ int sprite_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell){
s->n->tam[idx].state = SPRIXCELL_ANNIHILATED_TRANS;
return 1;
}
if(s->n->tam[idx].state == SPRIXCELL_ANNIHILATED_TRANS ||
s->n->tam[idx].state == SPRIXCELL_ANNIHILATED){
if(s->n->tam[idx].state >= SPRIXCELL_ANNIHILATED){
//fprintf(stderr, "CACHED WIPE %d %d/%d\n", s->id, ycell, xcell);
return 0;
}
Expand All @@ -189,7 +187,6 @@ int sprite_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell){
//fprintf(stderr, "WIPED %d %d/%d ret=%d\n", s->id, ycell, xcell, r);
// mark the cell as annihilated whether we actually scrubbed it or not,
// so that we use this fact should we move to another frame
s->n->tam[idx].state = SPRIXCELL_ANNIHILATED;
return r;
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ typedef enum {
SPRIXCELL_TRANSPARENT, // all pixels are naturally transparent
SPRIXCELL_ANNIHILATED, // this cell has been wiped (all trans)
SPRIXCELL_ANNIHILATED_TRANS, // this transparent cell is covered
SPRIXCELL_ANIMATED, // this cell has been nuked via animation
SPRIXCELL_ANIMATED_TRANS, // this transparent cell is animated out
} sprixcell_e;

// a sprixel represents a bitmap, using whatever local protocol is available.
Expand Down

0 comments on commit b8f6e8d

Please sign in to comment.