mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
[kitty] finish sprite_kitty_cell_wipe
This commit is contained in:
parent
c067c2bfd9
commit
07594606fd
@ -61,9 +61,17 @@ base64_rgba3(const uint32_t* pixels, size_t pcount, char* b64){
|
|||||||
// null out part of a triplet (a triplet is 3 pixels, which map to 12 bytes, which map to
|
// null out part of a triplet (a triplet is 3 pixels, which map to 12 bytes, which map to
|
||||||
// 16 bytes when base64 encoded). skip the initial |skip| pixels, and null out a maximum
|
// 16 bytes when base64 encoded). skip the initial |skip| pixels, and null out a maximum
|
||||||
// of |max| pixels after that. returns the number of pixels nulled out. |max| must be
|
// of |max| pixels after that. returns the number of pixels nulled out. |max| must be
|
||||||
// positive. |skip| must be non-negative, and less than 3.
|
// positive. |skip| must be non-negative, and less than 3. |pleft| is the number of pixels
|
||||||
|
// available in the chunk.
|
||||||
static inline int
|
static inline int
|
||||||
kitty_null(char* triplet, int skip, int max){
|
kitty_null(char* triplet, int skip, int max, int pleft){
|
||||||
|
if(pleft > 3){
|
||||||
|
pleft = 3;
|
||||||
|
}
|
||||||
|
if(max + skip > pleft){
|
||||||
|
max = pleft - skip;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "alpha-nulling up to %d after %d\n", max, skip);
|
||||||
(void)triplet;
|
(void)triplet;
|
||||||
(void)max;
|
(void)max;
|
||||||
(void)skip;
|
(void)skip;
|
||||||
@ -79,6 +87,7 @@ int sprite_kitty_cell_wipe(notcurses* nc, sprixel* s, int ycell, int xcell){
|
|||||||
if(xcell >= s->dimx){
|
if(xcell >= s->dimx){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
const int totalpixels = s->pixy * s->pixx;
|
||||||
const int xpixels = nc->tcache.cellpixx;
|
const int xpixels = nc->tcache.cellpixx;
|
||||||
const int ypixels = nc->tcache.cellpixy;
|
const int ypixels = nc->tcache.cellpixy;
|
||||||
// if the cell is on the right or bottom borders, it might only be partially
|
// if the cell is on the right or bottom borders, it might only be partially
|
||||||
@ -96,16 +105,20 @@ fprintf(stderr, "TARGET AREA: %d x %d\n", targy, targx);
|
|||||||
// every pixel was 4 source bytes, 32 bits, 6.33 base64 bytes. every 3 input pixels is
|
// every pixel was 4 source bytes, 32 bits, 6.33 base64 bytes. every 3 input pixels is
|
||||||
// 12 bytes (96 bits), an even 16 base64 bytes. there is chunking to worry about. there
|
// 12 bytes (96 bits), an even 16 base64 bytes. there is chunking to worry about. there
|
||||||
// are up to 768 pixels in a chunk.
|
// are up to 768 pixels in a chunk.
|
||||||
int nextpixel = s->dimx * xpixels * ycell + xpixels * xcell;
|
int nextpixel = (s->pixx * ycell * ypixels) + (xpixels * xcell);
|
||||||
int nextend = nextpixel + targx - 1;
|
|
||||||
fprintf(stderr, "NEXTPIXEL: %d\n", nextpixel);
|
fprintf(stderr, "NEXTPIXEL: %d\n", nextpixel);
|
||||||
int curpixel = 0;
|
|
||||||
int thisrow = targx;
|
int thisrow = targx;
|
||||||
|
int chunkedhandled = 0;
|
||||||
while(targy){ // need to null out |targy| rows of |targx| pixels, track with |thisrow|
|
while(targy){ // need to null out |targy| rows of |targx| pixels, track with |thisrow|
|
||||||
while(*c != ';'){
|
while(*c != ';'){
|
||||||
++c;
|
++c;
|
||||||
}
|
}
|
||||||
++c;
|
++c;
|
||||||
|
int inchunk = totalpixels - chunkedhandled * RGBA_MAXLEN;
|
||||||
|
if(inchunk > RGBA_MAXLEN){
|
||||||
|
inchunk = RGBA_MAXLEN;
|
||||||
|
}
|
||||||
|
const int curpixel = chunkedhandled * RGBA_MAXLEN;
|
||||||
while(nextpixel - curpixel < RGBA_MAXLEN && thisrow){
|
while(nextpixel - curpixel < RGBA_MAXLEN && thisrow){
|
||||||
// our next pixel is within this chunk. find the pixel offset of the
|
// our next pixel is within this chunk. find the pixel offset of the
|
||||||
// first pixel (within the chunk).
|
// first pixel (within the chunk).
|
||||||
@ -115,19 +128,22 @@ fprintf(stderr, "NEXTPIXEL: %d\n", nextpixel);
|
|||||||
// we start within a 16-byte chunk |tripbytes| into the chunk. determine
|
// we start within a 16-byte chunk |tripbytes| into the chunk. determine
|
||||||
// the number of bits.
|
// the number of bits.
|
||||||
int tripskip = pixoffset - triples * 3;
|
int tripskip = pixoffset - triples * 3;
|
||||||
int chomped = kitty_null(c + tripbytes, tripskip, thisrow);
|
fprintf(stderr, "pixoffset: %d next: %d tripbytes: %d tripskip: %d thisrow: %d\n", pixoffset, nextpixel, tripbytes, tripskip, thisrow);
|
||||||
|
// the maximum number of pixels we can convert is the minimum of the
|
||||||
|
// pixels remaining in the target row, and the pixels left in the chunk.
|
||||||
|
int chomped = kitty_null(c + tripbytes, tripskip, thisrow, inchunk - triples * 3);
|
||||||
thisrow -= chomped;
|
thisrow -= chomped;
|
||||||
nextpixel += chomped;
|
nextpixel += chomped;
|
||||||
fprintf(stderr, "pixoffset: %d next: %d tripbytes: %d tripskip: %d\n", pixoffset, nextpixel, tripbytes, tripskip);
|
|
||||||
if(thisrow == 0){
|
if(thisrow == 0){
|
||||||
if(--targy == 0){
|
if(--targy == 0){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
thisrow = targx;
|
thisrow = targx;
|
||||||
nextpixel += s->dimx - xpixels;
|
nextpixel += s->dimx * xpixels - targx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c += RGBA_MAXLEN * 4 * 4 / 3; // 4bpp * 4/3 for base64, 4096b per chunk
|
c += RGBA_MAXLEN * 4 * 4 / 3; // 4bpp * 4/3 for base64, 4096b per chunk
|
||||||
|
++chunkedhandled;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -58,19 +58,15 @@ TEST_CASE("Pixel") {
|
|||||||
auto s = n->sprite;
|
auto s = n->sprite;
|
||||||
REQUIRE(nullptr != s);
|
REQUIRE(nullptr != s);
|
||||||
CHECK(0 == notcurses_render(nc_));
|
CHECK(0 == notcurses_render(nc_));
|
||||||
sleep(3);
|
|
||||||
CHECK(0 == nc_->tcache.pixel_cell_wipe(nc_, s, 0, 0));
|
CHECK(0 == nc_->tcache.pixel_cell_wipe(nc_, s, 0, 0));
|
||||||
CHECK(0 == notcurses_render(nc_));
|
CHECK(0 == notcurses_render(nc_));
|
||||||
sleep(3);
|
|
||||||
CHECK(0 == nc_->tcache.pixel_cell_wipe(nc_, s, 1, 1));
|
CHECK(0 == nc_->tcache.pixel_cell_wipe(nc_, s, 1, 1));
|
||||||
CHECK(0 == notcurses_render(nc_));
|
CHECK(0 == notcurses_render(nc_));
|
||||||
sleep(3);
|
sleep(1);
|
||||||
CHECK(0 == nc_->tcache.pixel_cell_wipe(nc_, s, 1, 0));
|
CHECK(0 == nc_->tcache.pixel_cell_wipe(nc_, s, 1, 0));
|
||||||
CHECK(0 == notcurses_render(nc_));
|
CHECK(0 == notcurses_render(nc_));
|
||||||
sleep(3);
|
|
||||||
CHECK(0 == nc_->tcache.pixel_cell_wipe(nc_, s, 0, 1));
|
CHECK(0 == nc_->tcache.pixel_cell_wipe(nc_, s, 0, 1));
|
||||||
CHECK(0 == notcurses_render(nc_));
|
CHECK(0 == notcurses_render(nc_));
|
||||||
sleep(3);
|
|
||||||
ncplane_destroy(n);
|
ncplane_destroy(n);
|
||||||
ncvisual_destroy(ncv);
|
ncvisual_destroy(ncv);
|
||||||
CHECK(0 == notcurses_render(nc_));
|
CHECK(0 == notcurses_render(nc_));
|
||||||
|
Loading…
Reference in New Issue
Block a user