From 3e0783593d715364748197f9d78333b2fb1695a3 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 24 Apr 2021 22:44:56 -0400 Subject: [PATCH] add sprixel_rebuild interface, kitty + sixel skeletons #1440 --- src/lib/internal.h | 11 ++++++++++- src/lib/kitty.c | 8 ++++++++ src/lib/render.c | 3 +-- src/lib/sixel.c | 8 ++++++++ src/lib/terminfo.c | 2 ++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/lib/internal.h b/src/lib/internal.h index ed47ea867..13ab65a2f 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -450,6 +450,8 @@ typedef struct tinfo { // means leaving out the pixels (and likely resizes the string). for kitty, // this means dialing down their alpha to 0 (in equivalent space). int (*pixel_cell_wipe)(const struct notcurses* nc, sprixel* s, int y, int x); + // perform the inverse of pixel_cell_wipe, restoring an annihilated sprixcell. + int (*pixel_rebuild)(const struct notcurses* nc, sprixel* s, int y, int x); int (*pixel_remove)(int id, FILE* out); // kitty only, issue actual delete command int (*pixel_init)(int fd); // called when support is detected int (*pixel_draw)(const struct notcurses* n, const struct ncpile* p, sprixel* s, FILE* out); @@ -922,7 +924,9 @@ int sixel_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell); // nulls out a cell from a kitty bitmap via changing the alpha value // throughout to 0. the same trick doesn't work on sixel, but there we // can just print directly over the bitmap. -int kitty_wipe(const notcurses* nc, sprixel* s, int y, int x); +int kitty_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell); +int sixel_rebuild(const notcurses* nc, sprixel* s, int ycell, int xcell); +int kitty_rebuild(const notcurses* nc, sprixel* s, int ycell, int xcell); void sprixel_free(sprixel* s); void sprixel_hide(sprixel* s); @@ -960,6 +964,11 @@ sprite_destroy(const notcurses* nc, const ncpile* p, FILE* out, sprixel* s){ return nc->tcache.pixel_destroy(nc, p, out, s); } +static inline int +sprite_rebuild(const notcurses* nc, sprixel* s, int ycell, int xcell){ + return nc->tcache.pixel_rebuild(nc, s, ycell, xcell); +} + static inline void clamp_to_sixelmax(const tinfo* t, int* y, int* x){ if(t->sixel_maxy && *y > t->sixel_maxy){ diff --git a/src/lib/kitty.c b/src/lib/kitty.c index 04c3cd884..39ad48c5d 100644 --- a/src/lib/kitty.c +++ b/src/lib/kitty.c @@ -153,6 +153,14 @@ kitty_null(char* triplet, int skip, int max, int pleft){ } #define RGBA_MAXLEN 768 // 768 base64-encoded pixels in 4096 bytes +int kitty_rebuild(const notcurses* nc, sprixel* s, int ycell, int xcell){ + (void)nc; + (void)s; + (void)ycell; + (void)xcell; + return 0; +} + int kitty_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell){ if(s->n->tacache[s->dimx * ycell + xcell] == SPRIXCELL_ANNIHILATED){ //fprintf(stderr, "CACHED WIPE %d %d/%d\n", s->id, ycell, xcell); diff --git a/src/lib/render.c b/src/lib/render.c index e2bebbb61..72893a87a 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -178,8 +178,7 @@ paint_sprixel(ncplane* p, struct crender* rvec, int starty, int startx, crender->sprixel = s; } if(sprixel_state(s, absy, absx) == SPRIXCELL_ANNIHILATED){ - // FIXME rebuild! -fprintf(stderr, "annihilation UNDONE at %d/%d\n", y, x); + sprite_rebuild(nc, s, y, x); } } } diff --git a/src/lib/sixel.c b/src/lib/sixel.c index bbf2e18e5..49182d459 100644 --- a/src/lib/sixel.c +++ b/src/lib/sixel.c @@ -746,6 +746,14 @@ int sixel_init(int fd){ return tty_emit("\e[?80;8452h", fd); } +int sixel_rebuild(const notcurses* nc, sprixel* s, int ycell, int xcell){ + (void)nc; + (void)s; + (void)ycell; + (void)xcell; + return 0; +} + // we return -1 because we're not doing a proper wipe -- that's not possible // using sixel. we just mark it as partially transparent, so that if it's // redrawn, it's redrawn using P2=1. diff --git a/src/lib/terminfo.c b/src/lib/terminfo.c index 15f490473..159b30d00 100644 --- a/src/lib/terminfo.c +++ b/src/lib/terminfo.c @@ -15,6 +15,7 @@ setup_sixel_bitmaps(tinfo* ti){ ti->pixel_destroy = sixel_destroy; ti->pixel_cell_wipe = sixel_wipe; ti->pixel_shutdown = sixel_shutdown; + ti->pixel_rebuild = sixel_rebuild; ti->sprixel_height_factor = 6; } @@ -27,6 +28,7 @@ setup_kitty_bitmaps(tinfo* ti){ ti->pixel_draw = kitty_draw; ti->pixel_shutdown = kitty_shutdown; ti->sprixel_height_factor = 1; + ti->pixel_rebuild = kitty_rebuild; set_pixel_blitter(kitty_blit); }