[ncplayer] direct mode support for chromakey #1515

pull/1544/head
nick black 3 years ago committed by Nick Black
parent feab25bd7d
commit d4e2598c9e

@ -487,7 +487,8 @@ int ncdirect_raster_frame(ncdirect* n, ncdirectv* ncdv, ncalign_e align){
static ncdirectv* static ncdirectv*
ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn, ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn,
ncscale_e scale, int ymax, int xmax){ ncscale_e scale, int ymax, int xmax,
uint32_t transcolor){
int dimy = ymax > 0 ? ymax : ncdirect_dim_y(n); int dimy = ymax > 0 ? ymax : ncdirect_dim_y(n);
int dimx = xmax > 0 ? xmax : ncdirect_dim_x(n); int dimx = xmax > 0 ? xmax : ncdirect_dim_x(n);
//fprintf(stderr, "OUR DATA: %p rows/cols: %d/%d\n", ncv->data, ncv->rows, ncv->cols); //fprintf(stderr, "OUR DATA: %p rows/cols: %d/%d\n", ncv->data, ncv->rows, ncv->cols);
@ -539,6 +540,7 @@ ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn,
return NULL; return NULL;
} }
blitterargs bargs = {}; blitterargs bargs = {};
bargs.transcolor = transcolor;
if(bset->geom == NCBLIT_PIXEL){ if(bset->geom == NCBLIT_PIXEL){
bargs.u.pixel.celldimx = n->tcache.cellpixx; bargs.u.pixel.celldimx = n->tcache.cellpixx;
bargs.u.pixel.celldimy = n->tcache.cellpixy; bargs.u.pixel.celldimy = n->tcache.cellpixy;
@ -564,7 +566,7 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
if(ncv == NULL){ if(ncv == NULL){
return NULL; return NULL;
} }
ncdirectv* v = ncdirect_render_visual(n, ncv, blitfxn, scale, ymax, xmax); ncdirectv* v = ncdirect_render_visual(n, ncv, blitfxn, scale, ymax, xmax, 0);
ncvisual_destroy(ncv); ncvisual_destroy(ncv);
return v; return v;
} }
@ -1137,7 +1139,9 @@ int ncdirect_stream(ncdirect* n, const char* filename, ncstreamcb streamer,
if(x > 0){ if(x > 0){
ncdirect_cursor_left(n, x); ncdirect_cursor_left(n, x);
} }
ncdirectv* v = ncdirect_render_visual(n, ncv, vopts->blitter, vopts->scaling, 0, 0); ncdirectv* v = ncdirect_render_visual(n, ncv, vopts->blitter, vopts->scaling,
0, 0, (vopts->flags & NCVISUAL_OPTION_ADDALPHA) ?
vopts->transcolor | 0x1000000ul : 0);
if(v == NULL){ if(v == NULL){
ncvisual_destroy(ncv); ncvisual_destroy(ncv);
return -1; return -1;

@ -592,25 +592,25 @@ typedef struct notcurses {
} notcurses; } notcurses;
typedef struct { typedef struct {
int begy; // upper left start within visual int begy; // upper left start within visual
int begx; int begx;
int placey; // placement within ncplane int placey; // placement within ncplane
int placex; int placex;
uint32_t transcolor; // if non-zero, treat the lower 24 bits as a transparent color uint32_t transcolor; // if non-zero, treat the lower 24 bits as a transparent color
union { // cell vs pixel-specific arguments union { // cell vs pixel-specific arguments
struct { struct {
int blendcolors; // use CELL_ALPHA_BLEND int blendcolors; // use CELL_ALPHA_BLEND
} cell; // for cells } cell; // for cells
struct { struct {
int celldimx; // horizontal pixels per cell int celldimx; // horizontal pixels per cell
int celldimy; // vertical pixels per cell int celldimy; // vertical pixels per cell
int colorregs; // number of color registers int colorregs; // number of color registers
sprixel* spx; // sprixel object sprixel* spx; // sprixel object
// in at least mlterm, emitting a sixel makes the cursor visible. // in at least mlterm, emitting a sixel makes the cursor visible.
// if the cursor is hidden, and sprixel_cursor_hack is set, this // if the cursor is hidden, and sprixel_cursor_hack is set, this
// is set to the civis capability. // is set to the civis capability.
const char* cursor_hack; const char* cursor_hack;
} pixel; // for pixels } pixel; // for pixels
} u; } u;
} blitterargs; } blitterargs;

@ -310,7 +310,8 @@ int perframe_direct(struct ncvisual* ncv, struct ncvisual_options* vopts,
// argc/argv ought already be reduced to only the media arguments // argc/argv ought already be reduced to only the media arguments
int direct_mode_player(int argc, char** argv, ncscale_e scalemode, int direct_mode_player(int argc, char** argv, ncscale_e scalemode,
ncblitter_e blitter, int lmargin){ ncblitter_e blitter, int lmargin,
unsigned transcolor){
Direct dm{}; Direct dm{};
if(!dm.canopen_images()){ if(!dm.canopen_images()){
std::cerr << "Notcurses was compiled without multimedia support\n"; std::cerr << "Notcurses was compiled without multimedia support\n";
@ -340,6 +341,10 @@ int direct_mode_player(int argc, char** argv, ncscale_e scalemode,
vopts.scaling = scalemode; vopts.scaling = scalemode;
vopts.x = static_cast<int>(a); vopts.x = static_cast<int>(a);
vopts.flags = NCVISUAL_OPTION_HORALIGNED; vopts.flags = NCVISUAL_OPTION_HORALIGNED;
if(transcolor){
vopts.flags |= NCVISUAL_OPTION_ADDALPHA;
}
vopts.transcolor = transcolor & 0xffffffull;
if(dm.streamfile(argv[i], perframe_direct, &vopts, NULL)){ if(dm.streamfile(argv[i], perframe_direct, &vopts, NULL)){
failed = true; failed = true;
} }
@ -504,7 +509,8 @@ auto main(int argc, char** argv) -> int {
// if -k was provided, we now use direct mode rather than simply not using the // if -k was provided, we now use direct mode rather than simply not using the
// alternate screen, so that output is inline with the shell. // alternate screen, so that output is inline with the shell.
if(ncopts.flags & NCOPTION_NO_ALTERNATE_SCREEN){ if(ncopts.flags & NCOPTION_NO_ALTERNATE_SCREEN){
r = direct_mode_player(argc - nonopt, argv + nonopt, scalemode, blitter, ncopts.margin_l); r = direct_mode_player(argc - nonopt, argv + nonopt, scalemode, blitter,
ncopts.margin_l, transcolor);
}else{ }else{
r = rendered_mode_player(argc - nonopt, argv + nonopt, scalemode, blitter, ncopts, r = rendered_mode_player(argc - nonopt, argv + nonopt, scalemode, blitter, ncopts,
quiet, loop, timescale, displaytime, transcolor); quiet, loop, timescale, displaytime, transcolor);

Loading…
Cancel
Save