pass tcache down through visual blit stack #1095

pull/1394/head
nick black 3 years ago
parent 014e2ea8f8
commit 6693e5f386
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -3399,23 +3399,6 @@ API void ncreader_destroy(struct ncreader* n, char** contents);
API void notcurses_debug(struct notcurses* nc, FILE* debugfp)
__attribute__ ((nonnull (1, 2)));
// a system for rendering RGBA pixels as text glyphs
struct blitset {
ncblitter_e geom;
int width;
int height;
// the EGCs which form the various levels of a given plotset. if the geometry
// is wide, things are arranged with the rightmost side increasing most
// 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)(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;
bool fill;
};
// replaced by ncvisual_media_defblitter(). this original version never returns
// NCBLIT_3x2.
static inline ncblitter_e

@ -33,10 +33,11 @@ trilerp(uint32_t c0, uint32_t c1, uint32_t c2){
// Retarded RGBA blitter (ASCII only).
static inline int
tria_blit_ascii(ncplane* nc, int placey, int placex, int linesize,
const void* data, int begy, int begx,
tria_blit_ascii(const tinfo* tcache, 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
@ -82,9 +83,10 @@ tria_blit_ascii(ncplane* nc, int placey, int placex, int linesize,
// RGBA half-block blitter. Best for most images/videos. Full fidelity
// combined with 1:1 pixel aspect ratio.
static inline int
tria_blit(ncplane* nc, int placey, int placex, int linesize,
const void* data, int begy, int begx,
tria_blit(const tinfo* tcache, 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;
@ -416,9 +418,10 @@ 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(ncplane* nc, int placey, int placex, int linesize,
const void* data, int begy, int begx,
quadrant_blit(const tinfo* tcache, 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
@ -639,9 +642,10 @@ 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(ncplane* nc, int placey, int placex, int linesize,
const void* data, int begy, int begx,
sextant_blit(const tinfo* tcache, 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
@ -708,9 +712,10 @@ 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(ncplane* nc, int placey, int placex, int linesize,
const void* data, int begy, int begx,
braille_blit(const tinfo* tcache, 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
@ -922,7 +927,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(nc, vopts->y, vopts->x, linesize, data, begy, begx,
return bset->blit(NULL, nc, vopts->y, vopts->x, linesize, data, begy, begx,
leny, lenx, blend);
}

@ -513,7 +513,7 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
ncvisual_destroy(ncv);
return nullptr;
}
if(ncvisual_blit(ncv, disprows, dispcols, ncdv, bset,
if(ncvisual_blit(&n->tcache, ncv, disprows, dispcols, ncdv, bset,
0, 0, 0, 0, leny, lenx, n->tcache.cellpixx)){
ncvisual_destroy(ncv);
free_plane(ncdv);

@ -381,6 +381,23 @@ typedef struct notcurses {
unsigned stdio_blocking_save; // was stdio blocking at entry? restore on stop.
} notcurses;
// a system for rendering RGBA pixels as text glyphs
struct blitset {
ncblitter_e geom;
int width;
int height;
// the EGCs which form the various levels of a given plotset. if the geometry
// is wide, things are arranged with the rightmost side increasing most
// 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 linesize, const void* data, int begy, int begx,
int leny, int lenx, unsigned blendcolors);
const char* name;
bool fill;
};
#include "blitset.h"
void sigwinch_handler(int signo);
@ -724,10 +741,10 @@ rgba_blitter(const struct notcurses* nc, const struct ncvisual_options* opts) {
}
static inline int
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,
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,
leny, lenx, blendcolors);
}
@ -861,8 +878,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(struct ncvisual* ncv, int rows, int cols,
ncplane* n, const struct blitset* bset,
int ncvisual_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);
@ -1202,8 +1219,8 @@ ncdirect_bg_default_p(const struct ncdirect* nc){
return channels_bg_default_p(ncdirect_channels(nc));
}
int sixel_blit(ncplane* nc, int placey, int placex, int linesize,
const void* data, int begy, int begx,
int sixel_blit(const tinfo* tcache, 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,
@ -1212,7 +1229,8 @@ 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)(struct ncvisual* ncv, int rows, int cols, ncplane* n,
int (*visual_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);

@ -161,10 +161,10 @@ 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(FILE* fp, int lenx, sixeltable* stab){
write_sixel_data(const tinfo* tcache, FILE* fp, int lenx, sixeltable* stab){
// DECSDM (sixel scrolling enable) plus enter sixel mode
// FIXME i think we can print DESDM on the first one, and never again
fprintf(fp, "\e[?80h\ePq"); // FIXME pixelon
fprintf(fp, tcache->pixelon);
// 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 +209,7 @@ write_sixel_data(FILE* fp, int lenx, sixeltable* stab){
}
p += lenx;
}
fprintf(fp, "\e\\"); // FIXME pixeloff
fprintf(fp, tcache->pixeloff);
if(fclose(fp) == EOF){
return -1;
}
@ -220,15 +220,15 @@ write_sixel_data(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(ncplane* nc, int placey, int placex, int lenx,
sixeltable* stab, unsigned cellpixx){
int sixel_blit_inner(const tinfo* tcache, 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(fp, lenx, stab)){
if(write_sixel_data(tcache, fp, lenx, stab)){
fclose(fp);
free(buf);
return -1;
@ -243,8 +243,8 @@ int sixel_blit_inner(ncplane* nc, int placey, int placex, int lenx,
return 1;
}
int sixel_blit(ncplane* nc, int placey, int placex, int linesize,
const void* data, int begy, int begx,
int sixel_blit(const tinfo* tcache, 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 +265,7 @@ int sixel_blit(ncplane* nc, int placey, int placex, int linesize,
free(stable.data);
return -1;
}
int r = sixel_blit_inner(nc, placey, placex, lenx, &stable, cellpixx);
int r = sixel_blit_inner(tcache, nc, placey, placex, lenx, &stable, cellpixx);
free(stable.data);
free(ctab);
return r;

@ -13,19 +13,20 @@ auto ncvisual_decode(ncvisual* nc) -> int {
return visual_implementation->visual_decode(nc);
}
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 {
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 {
int ret = -1;
if(visual_implementation){
if(visual_implementation->visual_blit(ncv, rows, cols, n, bset, placey, placex,
begy, begx, leny, lenx, blendcolors) >= 0){
if(visual_implementation->visual_blit(tcache, ncv, rows, cols, n, bset,
placey, placex, begy, begx,
leny, lenx, blendcolors) >= 0){
ret = 0;
}
}else{
if(rgba_blit_dispatch(n, bset, placey, placex, ncv->rowstride, ncv->data,
begy, begx, leny, lenx, blendcolors) >= 0){
if(rgba_blit_dispatch(tcache, n, bset, placey, placex, ncv->rowstride,
ncv->data, begy, begx, leny, lenx, blendcolors) >= 0){
ret = 0;
}
}
@ -471,7 +472,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(ncv, disprows, dispcols, n, bset,
if(ncvisual_blit(&nc->tcache, ncv, disprows, dispcols, n, bset,
placey, placex, begy, begx, leny, lenx, blendcolors)){
ncplane_destroy(n);
return nullptr;
@ -524,7 +525,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(ncv, disprows, dispcols, n, bset,
if(ncvisual_blit(tcache, ncv, disprows, dispcols, n, bset,
placey, placex, begy, begx, disprows, dispcols,
ncplane_notcurses(stdn)->tcache.cellpixx)){
ncplane_destroy(n);

@ -467,8 +467,8 @@ int ffmpeg_decode_loop(ncvisual* ncv){
return r;
}
int ffmpeg_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
const struct blitset* bset, int placey, int placex,
int ffmpeg_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) {
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(ncvisual* ncv, int rows, int cols, ncplane* n,
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(n, bset, placey, placex, stride, data, begy, begx,
leny, lenx, blendcolors) < 0){
if(rgba_blit_dispatch(tcache, n, bset, placey, placex, stride, data,
begy, begx, leny, lenx, blendcolors) < 0){
//fprintf(stderr, "rgba dispatch failed!\n");
if(sframe){
av_freep(sframe->data);

@ -149,10 +149,10 @@ int oiio_resize(ncvisual* nc, int rows, int cols) {
return 0;
}
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) {
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) {
//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(struct ncvisual* ncv, int rows, int cols,
data = ncv->data;
stride = ncv->rowstride;
}
if(rgba_blit_dispatch(n, bset, placey, placex, stride, data, begy, begx,
leny, lenx, blendcolors) < 0){
if(rgba_blit_dispatch(tcache, n, bset, placey, placex, stride, data,
begy, begx, leny, lenx, blendcolors) < 0){
return -1;
}
return 0;

Loading…
Cancel
Save