Skip to content

Commit

Permalink
[sixel] work out restore_band() #2573
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Feb 8, 2022
1 parent 7e00205 commit 759b3b1
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/lib/sixel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1594,30 +1594,43 @@ int sixel_init(int fd){
return sixel_init_core("\e[?8452h", fd);
}

// rebuild the portion of some cell which is within this band, having stored
// the pixels into the auxvec when the cell was wiped (and updated them if we
// loaded another frame). we go through the auxvec to the right and down,
// within the area covered by our band. if the entry is transparent, do
// nothing. otherwise, it is some color; collect other instances of the color,
// marking them transparent as we do so, and update that color's band. in
// the worst case (all pixels different colors), this will be p^2 =\ FIXME.
// .
// returns the number of source-transparent pixels (i.e. pixels which weren't
// restored), which will be used to update the TAM state.
static inline int
restore_band(sixelmap* smap, int band, int startx, int endx,
int starty, int endy, int dimx, int cellpxy, int cellpxx,
int starty, int endy, int cellpxy, int cellpxx,
uint8_t* auxvec){
int restored = 0;
const int sy = band * 6 < starty ? starty - band * 6 : 0;
const int ey = (band + 1) * 6 > endy ? 6 - ((band + 1) * 6 - endy) : 6;
const int width = endx - startx;
const int height = ey - sy;
const int totalpixels = width * height;
fprintf(stderr, "RESTORING band %d (%d->%d (%d->%d), %d->%d) %d pixels\n", band, sy, ey, starty, endy, startx, endx, totalpixels);
int yoff = sy % cellpxy; // we start off on this row of the auxvec
for(int dy = 0 ; sy + dy < ey ; ++dy){
fprintf(stderr, "looking at line %d (auxvec row %d, dy %d)\n", sy + dy, yoff, dy);
}
(void)smap;
(void)band;
(void)startx;
(void)endx;
(void)starty;
(void)endy;
(void)dimx;
(void)cellpxy;
(void)cellpxx;
(void)auxvec;
// FIXME
return 0;
return totalpixels - restored;
}

// only called for cells in SPRIXCELL_ANNIHILATED[_TRANS]. just post to
// wipes_outstanding, so the Sixel gets regenerated the next render cycle,
// just like wiping. this is necessary due to the complex nature of
// modifying a Sixel -- we want to do them all in one batch.
int sixel_rebuild(sprixel* s, int ycell, int xcell, uint8_t* auxvec){
//fprintf(stderr, "REBUILDING %d/%d\n", ycell, xcell);
fprintf(stderr, "REBUILDING %d/%d\n", ycell, xcell);
if(auxvec == NULL){
return -1;
}
Expand All @@ -1641,22 +1654,18 @@ int sixel_rebuild(sprixel* s, int ycell, int xcell, uint8_t* auxvec){
// walk through each color, and wipe the necessary sixels from each band
int w = 0;
for(int b = startband ; b < endband ; ++b){
w += restore_band(smap, b, startx, endx, starty, endy, s->pixx,
w += restore_band(smap, b, startx, endx, starty, endy,
cellpxy, cellpxx, auxvec);
}
s->wipes_outstanding = true;
// FIXME need to set this back up...how? return transparent count from
// restore_band(), and sum them up?
sprixcell_e newstate = SPRIXCELL_OPAQUE_SIXEL; // FIXME incorrect!
/*
if(transparent == cellpxx * cellpxy){
sprixcell_e newstate;
if(w == cellpxx * cellpxy){
newstate = SPRIXCELL_TRANSPARENT;
}else if(transparent){
}else if(w){
newstate = SPRIXCELL_MIXED_SIXEL;
}else{
newstate = SPRIXCELL_OPAQUE_SIXEL;
}
*/
s->n->tam[s->dimx * ycell + xcell].state = newstate;
return 1;
}
Expand Down

0 comments on commit 759b3b1

Please sign in to comment.