From beb254ec90f6136a8e8d040426f591efa49ebc41 Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 23 Mar 2021 21:17:00 -0400 Subject: [PATCH] [sixel] use parse_start to optimize wiping --- src/lib/sixel.c | 98 +++++++++++++++++++++++----------------------- src/lib/terminfo.c | 2 +- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/lib/sixel.c b/src/lib/sixel.c index f0c9d7571..1afca09c5 100644 --- a/src/lib/sixel.c +++ b/src/lib/sixel.c @@ -51,60 +51,60 @@ int sprite_sixel_cell_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell ++c; } row += 6; - } - unsigned mask = 0; - if(row < top){ - for(int i = 0 ; i < top - row ; ++i){ - mask |= (1 << i); - } - } - // make masks containing only pixels which we will *not* be turning off - // (on the top or bottom), if any. go through each entry and if it - // occupies our target columns, scrub scrub scrub! - while(*c == '#' || isdigit(*c)){ - while(*c == '#' || isdigit(*c)){ - ++c; - } - int column = 0; - int rle = 0; - // here begins the substance, concluded by '-', '$', or '\e'. '!' indicates rle. - while(*c != '-' && *c != '$' && *c != '\e'){ - if(*c == '!'){ - rle = 0; - }else if(isdigit(*c)){ - rle *= 10; - rle += (*c - '0'); - }else{ - if(rle){ - // FIXME this can skip over the starting column - column += (rle - 1); - rle = 0; - } - if(column >= left && column < right){ // zorch it -//fprintf(stderr, "STARTED WITH %d %c\n", *c, *c); - *c = ((*c - 63) & mask) + 63; -//fprintf(stderr, "CHANGED TO %d %c\n", *c, *c); - } - ++column; + unsigned mask = 0; + if(row < top){ + for(int i = 0 ; i < top - row ; ++i){ + mask |= (1 << i); } - ++c; } - if(*c == '-'){ - row += 6; - if(row >= bottom){ + // make masks containing only pixels which we will *not* be turning off + // (on the top or bottom), if any. go through each entry and if it + // occupies our target columns, scrub scrub scrub! + while(*c == '#' || isdigit(*c)){ + while(*c == '#' || isdigit(*c)){ + ++c; + } + int column = 0; + int rle = 0; + // here begins the substance, concluded by '-', '$', or '\e'. '!' indicates rle. + while(*c != '-' && *c != '$' && *c != '\e'){ + if(*c == '!'){ + rle = 0; + }else if(isdigit(*c)){ + rle *= 10; + rle += (*c - '0'); + }else{ + if(rle){ + // FIXME this can skip over the starting column + column += (rle - 1); + rle = 0; + } + if(column >= left && column < right){ // zorch it +//fprintf(stderr, "STARTED WITH %d %c\n", *c, *c); + *c = ((*c - 63) & mask) + 63; +//fprintf(stderr, "CHANGED TO %d %c\n", *c, *c); + } + ++column; + } + ++c; + } + if(*c == '-'){ + row += 6; + if(row >= bottom){ + return 0; + } + mask = 0; + if(bottom - row < 6){ + for(int i = 0 ; i < bottom - row ; ++i){ + mask |= (1 << (6 - i)); + } + } + }else if(*c == '\e'){ return 0; } - mask = 0; - if(bottom - row < 6){ - for(int i = 0 ; i < bottom - row ; ++i){ - mask |= (1 << (6 - i)); - } - } - }else if(*c == '\e'){ - return 0; + column = 0; + ++c; } - column = 0; - ++c; } return 0; } diff --git a/src/lib/terminfo.c b/src/lib/terminfo.c index 363c91bf5..66c753da9 100644 --- a/src/lib/terminfo.c +++ b/src/lib/terminfo.c @@ -348,7 +348,7 @@ query_sixel(tinfo* ti, int fd){ ti->color_registers = 256; // assumed default [shrug] ti->pixel_destroy = sprite_sixel_annihilate; ti->pixel_init = sprite_sixel_init; - //ti->pixel_cell_wipe = sprite_sixel_cell_wipe; + ti->pixel_cell_wipe = sprite_sixel_cell_wipe; ti->sixel_maxx = ti->sixel_maxy = 0; } }