From 0574a3a479c1820d55d5d33f91d1d1e872db0053 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 13 Jun 2021 15:07:17 -0400 Subject: [PATCH] hook up sixel discovery through new one-shot query #1469 --- src/lib/input.c | 9 +++------ src/lib/termdesc.c | 28 +++++----------------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/src/lib/input.c b/src/lib/input.c index f7df3504e..21784d4d3 100644 --- a/src/lib/input.c +++ b/src/lib/input.c @@ -806,8 +806,7 @@ pump_control_read(init_state* inits, unsigned char c){ break; case STATE_SIXEL_CREGS: if(c == 'S'){ -fprintf(stderr, "%d color registers!\n", inits->numeric); - // FIXME set color register count + inits->tcache->color_registers = inits->numeric; inits->state = STATE_NULL; }else if(ruts_numeric(&inits->numeric, c)){ return -1; @@ -851,8 +850,7 @@ fprintf(stderr, "%d color registers!\n", inits->numeric); break; case STATE_SIXEL_WIDTH: if(c == ';'){ -fprintf(stderr, "%d max sixel width!\n", inits->numeric); - // FIXME set width + inits->tcache->sixel_maxx = inits->numeric; inits->state = STATE_SIXEL_HEIGHT; inits->numeric = 0; }else if(ruts_numeric(&inits->numeric, c)){ @@ -861,8 +859,7 @@ fprintf(stderr, "%d max sixel width!\n", inits->numeric); break; case STATE_SIXEL_HEIGHT: if(c == 'S'){ -fprintf(stderr, "%d max sixel height!\n", inits->numeric); - // FIXME set height + inits->tcache->sixel_maxy = inits->numeric; inits->state = STATE_NULL; }else if(ruts_numeric(&inits->numeric, c)){ return -1; diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index 9b64dcecd..1eb7c1fe9 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -6,11 +6,8 @@ static inline void setup_sixel_bitmaps(tinfo* ti){ ti->bitmap_supported = true; - ti->color_registers = 256; // assumed default [shrug] ti->pixel_init = sixel_init; ti->pixel_draw = sixel_draw; - ti->sixel_maxx = 4096; // whee! - ti->sixel_maxy = 4096; ti->pixel_remove = NULL; ti->pixel_destroy = sixel_destroy; ti->pixel_wipe = sixel_wipe; @@ -212,26 +209,6 @@ init_terminfo_esc(tinfo* ti, const char* name, escape_e idx, // ⇒ CSI ? 6 4 ; Ps c ("VT420") #define ESC_DA "\e[c" -/* -// query for Sixel details including the number of color registers and, one day -// perhaps, maximum geometry. xterm binds its return by the current geometry, -// making it useless for a one-time query. -static int -query_sixel_details(tinfo* ti, int fd){ - if(query_xtsmgraphics(fd, "\x1b[?2;1;0S" ESC_DA, &ti->sixel_maxx, &ti->sixel_maxy)){ - return -1; - } - if(query_xtsmgraphics(fd, "\x1b[?1;1;0S" ESC_DA, &ti->color_registers, NULL)){ - return -1; - } -//fprintf(stderr, "Sixel ColorRegs: %d Max_x: %d Max_y: %d\n", ti->color_registers, ti->sixel_maxx, ti->sixel_maxy); - if(ti->color_registers < 64){ // FIXME try to drive it higher - return -1; - } - return 0; -} -*/ - // we send an XTSMGRAPHICS to set up 256 color registers (the most we can // currently take advantage of; we need at least 64 to use sixel at all. // maybe that works, maybe it doesn't. then query both color registers @@ -424,6 +401,11 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8, if(ncinputlayer_init(ti, stdin)){ return -1; } + // our current sixel quantization algorithm requires at least 64 color + // registers. we make use of no more than 256. + if(ti->color_registers >= 64){ + setup_sixel_bitmaps(ti); + } if(apply_term_heuristics(ti, termname, fd)){ goto err; }