From ef5a3200de3e531ccdd757574c958e6aa384cde6 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 7 Mar 2021 19:50:55 -0500 Subject: [PATCH] pull pixelon/pixeloff out of tinfo struct --- src/demo/keller.c | 2 +- src/lib/blit.c | 29 ++++++++++++----------------- src/lib/direct.cpp | 4 ++-- src/lib/internal.h | 24 +++++++++++------------- src/lib/notcurses.c | 4 ++-- src/lib/sixel.c | 24 ++++++++++++++---------- src/lib/terminfo.c | 10 ++-------- src/lib/visual.cpp | 21 ++++++++++----------- src/media/ffmpeg.cpp | 8 ++++---- src/media/oiio.cpp | 12 ++++++------ 10 files changed, 64 insertions(+), 74 deletions(-) diff --git a/src/demo/keller.c b/src/demo/keller.c index eac342520..4170c68de 100644 --- a/src/demo/keller.c +++ b/src/demo/keller.c @@ -23,7 +23,7 @@ visualize(struct notcurses* nc, struct ncvisual* ncv){ .y = 1, }; if(vopts.blitter == NCBLIT_PIXEL){ - vopts.scaling = NCSCALE_NONE; + vopts.scaling = NCSCALE_SCALE; } if(ncvisual_render(nc, ncv, &vopts) == NULL){ return -1; diff --git a/src/lib/blit.c b/src/lib/blit.c index dc56e50b7..3bed2d528 100644 --- a/src/lib/blit.c +++ b/src/lib/blit.c @@ -33,11 +33,10 @@ trilerp(uint32_t c0, uint32_t c1, uint32_t c2){ // Retarded RGBA blitter (ASCII only). static inline int -tria_blit_ascii(const tinfo* tcache, ncplane* nc, int placey, int placex, - int linesize, const void* data, int begy, int begx, +tria_blit_ascii(ncplane* nc, int placey, int placex, int linesize, + const void* data, int begy, int begx, int leny, int lenx, unsigned blendcolors){ //fprintf(stderr, "ASCII %d X %d @ %d X %d (%p) place: %d X %d\n", leny, lenx, begy, begx, data, placey, placex); - (void)tcache; const int bpp = 32; int dimy, dimx, x, y; int total = 0; // number of cells written @@ -83,10 +82,9 @@ tria_blit_ascii(const tinfo* tcache, ncplane* nc, int placey, int placex, // RGBA half-block blitter. Best for most images/videos. Full fidelity // combined with 1:1 pixel aspect ratio. static inline int -tria_blit(const tinfo* tcache, ncplane* nc, int placey, int placex, - int linesize, const void* data, int begy, int begx, +tria_blit(ncplane* nc, int placey, int placex, int linesize, + const void* data, int begy, int begx, int leny, int lenx, unsigned blendcolors){ - (void)tcache; //fprintf(stderr, "HALF %d X %d @ %d X %d (%p) place: %d X %d\n", leny, lenx, begy, begx, data, placey, placex); const int bpp = 32; int dimy, dimx, x, y; @@ -418,10 +416,9 @@ qtrans_check(nccell* c, unsigned blendcolors, // quadrant blitter. maps 2x2 to each cell. since we only have two colors at // our disposal (foreground and background), we lose some fidelity. static inline int -quadrant_blit(const tinfo* tcache, ncplane* nc, int placey, int placex, - int linesize, const void* data, int begy, int begx, +quadrant_blit(ncplane* nc, int placey, int placex, int linesize, + const void* data, int begy, int begx, int leny, int lenx, unsigned blendcolors){ - (void)tcache; const int bpp = 32; int dimy, dimx, x, y; int total = 0; // number of cells written @@ -642,10 +639,9 @@ sex_trans_check(cell* c, const uint32_t rgbas[6], unsigned blendcolors){ // sextant blitter. maps 3x2 to each cell. since we only have two colors at // our disposal (foreground and background), we lose some fidelity. static inline int -sextant_blit(const tinfo* tcache, ncplane* nc, int placey, int placex, - int linesize, const void* data, int begy, int begx, +sextant_blit(ncplane* nc, int placey, int placex, int linesize, + const void* data, int begy, int begx, int leny, int lenx, unsigned blendcolors){ - (void)tcache; const int bpp = 32; int dimy, dimx, x, y; int total = 0; // number of cells written @@ -712,10 +708,9 @@ fold_rgb8(unsigned* restrict r, unsigned* restrict g, unsigned* restrict b, // visuals with only two colors in a given area, as it packs lots of // resolution. always transparent background. static inline int -braille_blit(const tinfo* tcache, ncplane* nc, int placey, int placex, - int linesize, const void* data, int begy, int begx, +braille_blit(ncplane* nc, int placey, int placex, int linesize, + const void* data, int begy, int begx, int leny, int lenx, unsigned blendcolors){ - (void)tcache; const int bpp = 32; int dimy, dimx, x, y; int total = 0; // number of cells written @@ -927,7 +922,7 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v return -1; } const bool blend = (vopts->flags & NCVISUAL_OPTION_BLEND); - return bset->blit(NULL, nc, vopts->y, vopts->x, linesize, data, begy, begx, + return bset->blit(nc, vopts->y, vopts->x, linesize, data, begy, begx, leny, lenx, blend); } @@ -944,7 +939,7 @@ const struct blitset* lookup_blitset(const tinfo* tcache, ncblitter_e setid, boo } } // without pixel support, NCBLIT_PIXEL decays to NCBLIT_3x2 - if(!tcache->pixelon && setid == NCBLIT_PIXEL){ + if(!tcache->sixel_supported && setid == NCBLIT_PIXEL){ if(may_degrade){ setid = NCBLIT_3x2; }else{ diff --git a/src/lib/direct.cpp b/src/lib/direct.cpp index 79eca220e..7cfc85583 100644 --- a/src/lib/direct.cpp +++ b/src/lib/direct.cpp @@ -513,7 +513,7 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file, ncvisual_destroy(ncv); return nullptr; } - if(ncvisual_blit(&n->tcache, ncv, disprows, dispcols, ncdv, bset, + if(ncvisual_blit(ncv, disprows, dispcols, ncdv, bset, 0, 0, 0, 0, leny, lenx, n->tcache.cellpixx)){ ncvisual_destroy(ncv); free_plane(ncdv); @@ -1080,7 +1080,7 @@ int ncdirect_check_pixel_support(ncdirect* n){ if(query_term(&n->tcache, n->ctermfd)){ return -1; } - if(n->tcache.pixelon){ + if(n->tcache.sixel_supported){ return 1; } return 0; diff --git a/src/lib/internal.h b/src/lib/internal.h index 6169ff8ff..46e90e184 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -290,8 +290,7 @@ typedef struct tinfo { // bg_collides_default is either 0x0000000 or 0x1RRGGBB. uint32_t bg_collides_default; pthread_mutex_t pixel_query; // only query for pixel support once - char* pixelon; // enter pixel graphics mode - char* pixeloff; // leave pixel graphics mode + bool sixel_supported; // do we support sixel (post pixel_query_done)? bool pixel_query_done; // have we yet performed pixel query? bool sextants; // do we have (good, vetted) Unicode 13 sextant support? bool braille; // do we have Braille support? (linux console does not) @@ -391,7 +390,7 @@ struct blitset { // quickly, i.e. it can be indexed as height arrays of 1 + height glyphs. i.e. // the first five braille EGCs are all 0 on the left, [0..4] on the right. const wchar_t* egcs; - int (*blit)(const tinfo* tcache, struct ncplane* n, int placey, int placex, + int (*blit)(struct ncplane* n, int placey, int placex, int linesize, const void* data, int begy, int begx, int leny, int lenx, unsigned blendcolors); const char* name; @@ -741,10 +740,10 @@ rgba_blitter(const struct notcurses* nc, const struct ncvisual_options* opts) { } static inline int -rgba_blit_dispatch(const tinfo* tcache, ncplane* nc, const struct blitset* bset, - int placey, int placex, int linesize, const void* data, - int begy, int begx, int leny, int lenx, bool blendcolors){ - return bset->blit(tcache, nc, placey, placex, linesize, data, begy, begx, +rgba_blit_dispatch(ncplane* nc, const struct blitset* bset, int placey, + int placex, int linesize, const void* data, int begy, + int begx, int leny, int lenx, bool blendcolors){ + return bset->blit(nc, placey, placex, linesize, data, begy, begx, leny, lenx, blendcolors); } @@ -878,8 +877,8 @@ ALLOC char* ncplane_vprintf_prep(const char* format, va_list ap); // Resize the provided ncviusal to the specified 'rows' x 'cols', but do not // change the internals of the ncvisual. Uses oframe. -int ncvisual_blit(const tinfo* tcache, struct ncvisual* ncv, - int rows, int cols, ncplane* n, const struct blitset* bset, +int ncvisual_blit(struct ncvisual* ncv, int rows, int cols, + ncplane* n, const struct blitset* bset, int placey, int placex, int begy, int begx, int leny, int lenx, bool blendcolors); @@ -1219,8 +1218,8 @@ ncdirect_bg_default_p(const struct ncdirect* nc){ return channels_bg_default_p(ncdirect_channels(nc)); } -int sixel_blit(const tinfo* tcache, ncplane* nc, int placey, int placex, - int linesize, const void* data, int begy, int begx, +int sixel_blit(ncplane* nc, int placey, int placex, int linesize, + const void* data, int begy, int begx, int leny, int lenx, unsigned cellpixx); int term_fg_rgb8(bool RGBflag, const char* setaf, int colors, FILE* out, @@ -1229,8 +1228,7 @@ int term_fg_rgb8(bool RGBflag, const char* setaf, int colors, FILE* out, typedef struct ncvisual_implementation { int (*visual_init)(int loglevel); void (*visual_printbanner)(const struct notcurses* nc); - int (*visual_blit)(const tinfo* tcache, struct ncvisual* ncv, - int rows, int cols, ncplane* n, + int (*visual_blit)(struct ncvisual* ncv, int rows, int cols, ncplane* n, const struct blitset* bset, int placey, int placex, int begy, int begx, int leny, int lenx, bool blendcolors); diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 8efafd5c5..62eb09838 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -976,7 +976,7 @@ int notcurses_check_pixel_support(notcurses* nc){ if(query_term(&nc->tcache, nc->ttyfd)){ return -1; } - if(nc->tcache.pixelon){ + if(nc->tcache.sixel_supported){ return 1; } return 0; @@ -2146,7 +2146,7 @@ bool notcurses_canchangecolor(const notcurses* nc){ } bool notcurses_canpixel(const notcurses* nc){ - return nc->tcache.pixelon; + return nc->tcache.sixel_supported; } palette256* palette256_new(notcurses* nc){ diff --git a/src/lib/sixel.c b/src/lib/sixel.c index 5f0764c31..7cdb86b31 100644 --- a/src/lib/sixel.c +++ b/src/lib/sixel.c @@ -161,10 +161,12 @@ write_rle(FILE* fp, int seenrle, unsigned char crle){ // Emit the sprixel in its entirety, plus enable and disable pixel mode. static int -write_sixel_data(const tinfo* tcache, FILE* fp, int lenx, sixeltable* stab){ - // DECSDM (sixel scrolling enable) plus enter sixel mode +write_sixel_data(FILE* fp, int lenx, sixeltable* stab){ + // \e[?80: DECSDM "sixel scrolling" mode (put output at cursor location) + // \x90: 8-bit "device control sequence", lowercase q (start sixel) + // doesn't seem to work with at least xterm; we instead use '\ePq' // FIXME i think we can print DESDM on the first one, and never again - fprintf(fp, tcache->pixelon); + fprintf(fp, "\e[?80h\ePq"); // Set Raster Attributes - pan/pad=1 (pixel aspect ratio), Ph=lenx, Pv=leny // using Ph/Pv causes a background to be drawn using color register 0 for all @@ -209,7 +211,9 @@ write_sixel_data(const tinfo* tcache, FILE* fp, int lenx, sixeltable* stab){ } p += lenx; } - fprintf(fp, tcache->pixeloff); + // \x9c: 8-bit "string terminator" (end sixel) doesn't work on at + // least xterm; we instead use '\e\\' + fprintf(fp, "\e\\"); if(fclose(fp) == EOF){ return -1; } @@ -220,15 +224,15 @@ write_sixel_data(const tinfo* tcache, FILE* fp, int lenx, sixeltable* stab){ // are programmed as a set of registers, which are then referenced by the // stacks. There is also a RLE component, handled in rasterization. // A pixel block is indicated by setting cell_pixels_p(). -int sixel_blit_inner(const tinfo* tcache, ncplane* nc, int placey, int placex, - int lenx, sixeltable* stab, unsigned cellpixx){ +int sixel_blit_inner(ncplane* nc, int placey, int placex, int lenx, + sixeltable* stab, unsigned cellpixx){ char* buf = NULL; size_t size = 0; FILE* fp = open_memstream(&buf, &size); if(fp == NULL){ return -1; } - if(write_sixel_data(tcache, fp, lenx, stab)){ + if(write_sixel_data(fp, lenx, stab)){ fclose(fp); free(buf); return -1; @@ -243,8 +247,8 @@ int sixel_blit_inner(const tinfo* tcache, ncplane* nc, int placey, int placex, return 1; } -int sixel_blit(const tinfo* tcache, ncplane* nc, int placey, int placex, - int linesize, const void* data, int begy, int begx, +int sixel_blit(ncplane* nc, int placey, int placex, int linesize, + const void* data, int begy, int begx, int leny, int lenx, unsigned cellpixx){ colortable* ctab = malloc(sizeof(*ctab)); if(ctab == NULL){ @@ -265,7 +269,7 @@ int sixel_blit(const tinfo* tcache, ncplane* nc, int placey, int placex, free(stable.data); return -1; } - int r = sixel_blit_inner(tcache, nc, placey, placex, lenx, &stable, cellpixx); + int r = sixel_blit_inner(nc, placey, placex, lenx, &stable, cellpixx); free(stable.data); free(ctab); return r; diff --git a/src/lib/terminfo.c b/src/lib/terminfo.c index 5683fa07b..cabc9f08d 100644 --- a/src/lib/terminfo.c +++ b/src/lib/terminfo.c @@ -235,14 +235,8 @@ query_sixel(tinfo* ti, int fd){ if(in == 'c'){ state = DONE; }else if(in == '4'){ - if(!ti->pixelon){ - // \e[?80: "sixel scrolling" mode (put output at cursor location) - // \x90: 8-bit "device control sequence", lowercase q (start sixel) - // doesn't seem to work with at least xterm; we instead use '\ePq' - ti->pixelon = "\e[?80h\ePq"; - // \x9c: 8-bit "string terminator" (end sixel) doesn't work on at - // least xterm; we instead use '\e\\' - ti->pixeloff = "\e\\"; + if(!ti->sixel_supported){ + ti->sixel_supported = true; } // FIXME else warning? } break; diff --git a/src/lib/visual.cpp b/src/lib/visual.cpp index e49bb7d5f..50ba6bec1 100644 --- a/src/lib/visual.cpp +++ b/src/lib/visual.cpp @@ -13,20 +13,19 @@ auto ncvisual_decode(ncvisual* nc) -> int { return visual_implementation->visual_decode(nc); } -auto ncvisual_blit(const tinfo* tcache, ncvisual* ncv, int rows, int cols, - ncplane* n, const struct blitset* bset, - int placey, int placex, int begy, int begx, - int leny, int lenx, bool blendcolors) -> int { +auto ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n, + const struct blitset* bset, int placey, int placex, + int begy, int begx, int leny, int lenx, + bool blendcolors) -> int { int ret = -1; if(visual_implementation){ - if(visual_implementation->visual_blit(tcache, ncv, rows, cols, n, bset, - placey, placex, begy, begx, - leny, lenx, blendcolors) >= 0){ + if(visual_implementation->visual_blit(ncv, rows, cols, n, bset, placey, placex, + begy, begx, leny, lenx, blendcolors) >= 0){ ret = 0; } }else{ - if(rgba_blit_dispatch(tcache, n, bset, placey, placex, ncv->rowstride, - ncv->data, begy, begx, leny, lenx, blendcolors) >= 0){ + if(rgba_blit_dispatch(n, bset, placey, placex, ncv->rowstride, ncv->data, + begy, begx, leny, lenx, blendcolors) >= 0){ ret = 0; } } @@ -472,7 +471,7 @@ auto ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const blitset* bset, leny = (leny / (double)ncv->rows) * ((double)disprows); lenx = (lenx / (double)ncv->cols) * ((double)dispcols); //fprintf(stderr, "blit: %dx%d:%d+%d of %d/%d stride %u %p\n", begy, begx, leny, lenx, ncv->rows, ncv->cols, ncv->rowstride, ncv->data); - if(ncvisual_blit(&nc->tcache, ncv, disprows, dispcols, n, bset, + if(ncvisual_blit(ncv, disprows, dispcols, n, bset, placey, placex, begy, begx, leny, lenx, blendcolors)){ ncplane_destroy(n); return nullptr; @@ -525,7 +524,7 @@ auto ncvisual_render_pixels(tinfo* tcache, ncvisual* ncv, const blitset* bset, scale_visual(ncv, &disprows, &dispcols); } //fprintf(stderr, "blit: %dx%d <- %dx%d:%d+%d of %d/%d stride %u @%dx%d %p\n", disprows, dispcols, begy, begx, leny, lenx, ncv->rows, ncv->cols, ncv->rowstride, placey, placex, ncv->data); - if(ncvisual_blit(tcache, ncv, disprows, dispcols, n, bset, + if(ncvisual_blit(ncv, disprows, dispcols, n, bset, placey, placex, begy, begx, disprows, dispcols, ncplane_notcurses(stdn)->tcache.cellpixx)){ ncplane_destroy(n); diff --git a/src/media/ffmpeg.cpp b/src/media/ffmpeg.cpp index 221a5484f..4b7f62a45 100644 --- a/src/media/ffmpeg.cpp +++ b/src/media/ffmpeg.cpp @@ -467,8 +467,8 @@ int ffmpeg_decode_loop(ncvisual* ncv){ return r; } -int ffmpeg_blit(const tinfo* tcache, ncvisual* ncv, int rows, int cols, - ncplane* n, const struct blitset* bset, int placey, int placex, +int ffmpeg_blit(ncvisual* ncv, int rows, int cols, ncplane* n, + const struct blitset* bset, int placey, int placex, int begy, int begx, int leny, int lenx, bool blendcolors) { const AVFrame* inframe = ncv->details->oframe ? ncv->details->oframe : ncv->details->frame; //fprintf(stderr, "inframe: %p oframe: %p frame: %p\n", inframe, ncv->details->oframe, ncv->details->frame); @@ -522,8 +522,8 @@ int ffmpeg_blit(const tinfo* tcache, ncvisual* ncv, int rows, int cols, data = ncv->data; } //fprintf(stderr, "place: %d/%d rows/cols: %d/%d %d/%d+%d/%d\n", placey, placex, rows, cols, begy, begx, leny, lenx); - if(rgba_blit_dispatch(tcache, n, bset, placey, placex, stride, data, - begy, begx, leny, lenx, blendcolors) < 0){ + if(rgba_blit_dispatch(n, bset, placey, placex, stride, data, begy, begx, + leny, lenx, blendcolors) < 0){ //fprintf(stderr, "rgba dispatch failed!\n"); if(sframe){ av_freep(sframe->data); diff --git a/src/media/oiio.cpp b/src/media/oiio.cpp index 41e06f1de..0182cc0e4 100644 --- a/src/media/oiio.cpp +++ b/src/media/oiio.cpp @@ -149,10 +149,10 @@ int oiio_resize(ncvisual* nc, int rows, int cols) { return 0; } -int oiio_blit(const tinfo* tcache, struct ncvisual* ncv, int rows, int cols, - ncplane* n, const struct blitset* bset, - int placey, int placex, int begy, int begx, - int leny, int lenx, bool blendcolors) { +int oiio_blit(struct ncvisual* ncv, int rows, int cols, + ncplane* n, const struct blitset* bset, + int placey, int placex, int begy, int begx, + int leny, int lenx, bool blendcolors) { //fprintf(stderr, "%d/%d -> %d/%d on the resize\n", ncv->rows, ncv->cols, rows, cols); void* data = nullptr; int stride = 0; @@ -173,8 +173,8 @@ int oiio_blit(const tinfo* tcache, struct ncvisual* ncv, int rows, int cols, data = ncv->data; stride = ncv->rowstride; } - if(rgba_blit_dispatch(tcache, n, bset, placey, placex, stride, data, - begy, begx, leny, lenx, blendcolors) < 0){ + if(rgba_blit_dispatch(n, bset, placey, placex, stride, data, begy, begx, + leny, lenx, blendcolors) < 0){ return -1; } return 0;