Skip to content

Commit

Permalink
kitty: tripartite blit implementation #1900
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Jul 26, 2021
1 parent 57f9623 commit e399687
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
19 changes: 19 additions & 0 deletions src/lib/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ int kitty_rebuild(sprixel* s, int ycell, int xcell, uint8_t* auxvec);
int iterm_rebuild(sprixel* s, int ycell, int xcell, uint8_t* auxvec);
int fbcon_rebuild(sprixel* s, int ycell, int xcell, uint8_t* auxvec);
int kitty_rebuild_animation(sprixel* s, int ycell, int xcell, uint8_t* auxvec);
int kitty_rebuild_selfref(sprixel* s, int ycell, int xcell, uint8_t* auxvec);
int sixel_draw(const tinfo* ti, const struct ncpile *p, sprixel* s,
FILE* out, int y, int x);
int kitty_draw(const tinfo* ti, const struct ncpile *p, sprixel* s,
Expand Down Expand Up @@ -199,11 +200,29 @@ int iterm_blit(struct ncplane* nc, int linesize, const void* data,
int leny, int lenx, const struct blitterargs* bargs);
int kitty_blit_animated(struct ncplane* n, int linesize, const void* data,
int leny, int lenx, const struct blitterargs* bargs);
int kitty_blit_selfref(struct ncplane* nc, int linesize, const void* data,
int leny, int lenx, const struct blitterargs* bargs);
int fbcon_blit(struct ncplane* nc, int linesize, const void* data,
int leny, int lenx, const struct blitterargs* bargs);
int fbcon_draw(const tinfo* ti, const struct ncpile *p, sprixel* s,
FILE* out, int y, int x);

typedef enum {
// C=1 (disabling scrolling) was only introduced in 0.20.0, at the same
// time as animation. prior to this, graphics had to be entirely redrawn
// on any change, and it wasn't possible to use the bottom line.
KITTY_ALWAYS_SCROLLS,
// until 0.21.3's introduction of 't=z' for self-reference, we had to
// keep a complete copy of the RGBA data, in case a wiped cell needed to
// be rebuilt. we'd otherwise have to unpack the glyph and store it into
// the auxvec on the fly.
KITTY_ANIMATION,
// with 0.21.3, we only ever write transparent cells after writing the
// original image (which we now deflate, since we needn't unpack it later).
// the only data we need keep is the auxvecs.
KITTY_SELFREF,
} kitty_graphics_e;

#ifdef __cplusplus
}
#endif
Expand Down
27 changes: 17 additions & 10 deletions src/lib/termdesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,32 @@ setup_iterm_bitmaps(tinfo* ti, int fd){
}

// kitty 0.19.3 didn't have C=1, and thus needs sixel_maxy_pristine. it also
// lacked animation, and thus requires the older interface.
// lacked animation, and must thus redraw the complete image every time it
// changes. requires the older interface.
static inline void
setup_kitty_bitmaps(tinfo* ti, int fd, int sixel_maxy_pristine){
setup_kitty_bitmaps(tinfo* ti, int fd, kitty_graphics_e level){
ti->pixel_scrub = kitty_scrub;
ti->pixel_remove = kitty_remove;
ti->pixel_draw = kitty_draw;
ti->pixel_commit = kitty_commit;
ti->pixel_move = kitty_move;
ti->pixel_shutdown = kitty_shutdown;
ti->pixel_clear_all = kitty_clear_all;
ti->sixel_maxy_pristine = sixel_maxy_pristine;
if(sixel_maxy_pristine){
if(level == KITTY_ALWAYS_SCROLLS){
ti->pixel_wipe = kitty_wipe;
ti->pixel_trans_auxvec = kitty_trans_auxvec;
ti->pixel_rebuild = kitty_rebuild;
ti->sixel_maxy_pristine = INT_MAX;
set_pixel_blitter(kitty_blit);
}else{
ti->pixel_wipe = kitty_wipe_animation;
ti->pixel_rebuild = kitty_rebuild_animation;
set_pixel_blitter(kitty_blit_animated);
if(level == KITTY_ANIMATION){
ti->pixel_rebuild = kitty_rebuild_animation;
set_pixel_blitter(kitty_blit_animated);
}else{
ti->pixel_rebuild = kitty_rebuild_selfref;
set_pixel_blitter(kitty_blit_selfref);
}
}
sprite_init(ti, fd);
}
Expand Down Expand Up @@ -501,11 +507,12 @@ apply_term_heuristics(tinfo* ti, const char* termname, int fd,
if(add_smulx_escapes(ti, tablelen, tableused)){
return -1;
}
// kitty only introduced C=1 in 0.20.0
if(compare_versions(ti->termversion, "0.20.0") < 0){
setup_kitty_bitmaps(ti, fd, INT_MAX);
if(compare_versions(ti->termversion, "0.21.3") >= 0){
setup_kitty_bitmaps(ti, fd, KITTY_SELFREF);
}else if(compare_versions(ti->termversion, "0.20.0") >= 0){
setup_kitty_bitmaps(ti, fd, KITTY_ANIMATION);
}else{
setup_kitty_bitmaps(ti, fd, 0);
setup_kitty_bitmaps(ti, fd, KITTY_ALWAYS_SCROLLS);
}
if(add_pushcolors_escapes(ti, tablelen, tableused)){
return -1;
Expand Down

0 comments on commit e399687

Please sign in to comment.