ncdirectf_render: accept an ncvisual_options #1738

This commit is contained in:
nick black 2021-06-08 23:37:15 -04:00 committed by Nick Black
parent 6fcaad3c5d
commit 59f4edd777
7 changed files with 58 additions and 33 deletions

View File

@ -11,6 +11,11 @@ rearrangements of Notcurses.
* `ncvisual_inflate()` has been rewritten as a wrapper around the new
function `ncvisual_resize_noninterpolative()`, and deprecated. It will be
removed for ABI3. Godspeed, `ncvisual_inflate()`; we hardly knew ye.
* `ncdirect_renderf()` has been changed to accept a `ncvisual_options`,
replacing and extending its four final arguments. Sorry about the breakage
here, but `ncdirect_renderf()` was introduced pretty recently (2.3.1).
As a result, `ncdirect_renderf()` and `ncdirect_stream()` now honor
`NCVISUAL_OPTION_BLEND` and `NCVISUAL_OPTION_NOINTERPOLATE`.
* 2.3.2 (2021-06-03)
* Fixed a bug affecting certain scalings of `ncvisual` objects created from

View File

@ -116,7 +116,7 @@ typedef struct ncvgeom {
**void ncdirectf_free(struct ncdirectf* ***frame***);**
**ncdirectv* ncdirectf_render(struct ncdirect* ***n***, struct ncdirectf* ***frame***, ncblitter_e ***blitter***, ncscale_e ***scale***, int ***maxy***, int ***maxx***);**
**ncdirectv* ncdirectf_render(struct ncdirect* ***n***, struct ncdirectf* ***frame***, struct ncvisual_options ***vopts***);**
**int ncdirectf_geom(struct ncdirect* ***n***, struct ncdirectf* ***frame***, ncblitter_e* ***blitter***, ncscale_e ***scale***, int ***maxy***, int ***maxx***, ncvgeom* ***geom***);**

View File

@ -389,8 +389,7 @@ API void ncdirectf_free(ncdirectf* frame);
// loaded. A loaded frame may be rendered in different ways before it is
// destroyed.
API ALLOC ncdirectv* ncdirectf_render(struct ncdirect* n, ncdirectf* frame,
ncblitter_e blitter, ncscale_e scale,
int maxy, int maxx)
struct ncvisual_options* vopts)
__attribute__ ((nonnull (1, 2)));
// Having loaded the frame 'frame', get the geometry of a potential render.

View File

@ -545,23 +545,27 @@ int ncdirect_raster_frame(ncdirect* n, ncdirectv* ncdv, ncalign_e align){
}
static ncdirectv*
ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn,
ncscale_e scale, int ymax, int xmax,
uint32_t transcolor){
if(ymax < 0 || xmax < 0){
fprintf(stderr, "Invalid render geometry %d/%d\n", ymax, xmax);
ncdirect_render_visual(ncdirect* n, ncvisual* ncv, struct ncvisual_options* vopts){
struct ncvisual_options defvopts = {};
if(!vopts){
vopts = &defvopts;
}
if(vopts->leny < 0 || vopts->lenx < 0){
fprintf(stderr, "Invalid render geometry %d/%d\n", vopts->leny, vopts->lenx);
return NULL;
}
int dimy = ymax > 0 ? ymax : (ncdirect_dim_y(n) - 1);
int dimx = xmax > 0 ? xmax : ncdirect_dim_x(n);
//fprintf(stderr, "OUR DATA: %p rows/cols: %d/%d outsize: %d/%d %d/%d\n", ncv->data, ncv->pixy, ncv->pixx, dimy, dimx, ymax, xmax);
//fprintf(stderr, "render %d/%d to scaling: %d\n", ncv->pixy, ncv->pixx, scale);
const struct blitset* bset = rgba_blitter_low(&n->tcache, scale, true, blitfxn);
//fprintf(stderr, "render %d/%d to scaling: %d\n", ncv->pixy, ncv->pixx, vopts->scaling);
const struct blitset* bset = rgba_blitter_low(&n->tcache, vopts->scaling, true, vopts->blitter);
if(!bset){
return NULL;
}
int ymax = vopts->leny / bset->height;
int xmax = vopts->lenx / bset->width;
int dimy = vopts->leny > 0 ? ymax : ncdirect_dim_y(n);
int dimx = vopts->lenx > 0 ? xmax : ncdirect_dim_x(n);
int disprows, dispcols, outy;
if(scale != NCSCALE_NONE && scale != NCSCALE_NONE_HIRES){
if(vopts->scaling != NCSCALE_NONE && vopts->scaling != NCSCALE_NONE_HIRES){
if(bset->geom != NCBLIT_PIXEL){
dispcols = dimx * encoding_x_scale(&n->tcache, bset);
disprows = dimy * encoding_y_scale(&n->tcache, bset);
@ -569,20 +573,20 @@ ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn,
}else{
dispcols = dimx * n->tcache.cellpixx;
disprows = dimy * n->tcache.cellpixy;
clamp_to_sixelmax(&n->tcache, &disprows, &dispcols, &outy, scale);
clamp_to_sixelmax(&n->tcache, &disprows, &dispcols, &outy, vopts->scaling);
}
if(scale == NCSCALE_SCALE || scale == NCSCALE_SCALE_HIRES){
if(vopts->scaling == NCSCALE_SCALE || vopts->scaling == NCSCALE_SCALE_HIRES){
scale_visual(ncv, &disprows, &dispcols);
outy = disprows;
if(bset->geom == NCBLIT_PIXEL){
clamp_to_sixelmax(&n->tcache, &disprows, &dispcols, &outy, scale);
clamp_to_sixelmax(&n->tcache, &disprows, &dispcols, &outy, vopts->scaling);
}
}
}else{
disprows = ncv->pixy;
dispcols = ncv->pixx;
if(bset->geom == NCBLIT_PIXEL){
clamp_to_sixelmax(&n->tcache, &disprows, &dispcols, &outy, scale);
clamp_to_sixelmax(&n->tcache, &disprows, &dispcols, &outy, vopts->scaling);
}else{
outy = disprows;
}
@ -620,7 +624,9 @@ ncdirect_render_visual(ncdirect* n, ncvisual* ncv, ncblitter_e blitfxn,
return NULL;
}
blitterargs bargs = {};
bargs.transcolor = transcolor;
if(vopts->flags & NCVISUAL_OPTION_ADDALPHA){
bargs.transcolor = vopts->transcolor | 0x1000000ull;
}
if(bset->geom == NCBLIT_PIXEL){
bargs.u.pixel.celldimx = n->tcache.cellpixx;
bargs.u.pixel.celldimy = n->tcache.cellpixy;
@ -645,7 +651,11 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
if(ncv == NULL){
return NULL;
}
ncdirectv* v = ncdirectf_render(n, ncv, blitfxn, scale, ymax, xmax);
struct ncvisual_options vopts = {};
vopts.blitter = blitfxn;
vopts.scaling = scale;
// FIXME convery ymax, xmax into leny/lenx, or something
ncdirectv* v = ncdirectf_render(n, ncv, &vopts);
ncvisual_destroy(ncv);
return v;
}
@ -1249,10 +1259,7 @@ int ncdirect_stream(ncdirect* n, const char* filename, ncstreamcb streamer,
if(x > 0){
ncdirect_cursor_left(n, x);
}
// FIXME what about vopts->beg{yx} and vopts->len{yx}?
ncdirectv* v = ncdirect_render_visual(n, ncv, vopts->blitter, vopts->scaling,
0, 0, (vopts->flags & NCVISUAL_OPTION_ADDALPHA) ?
vopts->transcolor | 0x1000000ul : 0);
ncdirectv* v = ncdirect_render_visual(n, ncv, vopts);
if(v == NULL){
ncvisual_destroy(ncv);
return -1;
@ -1286,10 +1293,8 @@ void ncdirectf_free(ncdirectf* frame){
ncvisual_destroy(frame);
}
ncdirectv* ncdirectf_render(ncdirect* n, ncdirectf* frame,
ncblitter_e blitter, ncscale_e scale,
int maxy, int maxx){
return ncdirect_render_visual(n, frame, blitter, scale, maxy, maxx, 0);
ncdirectv* ncdirectf_render(ncdirect* n, ncdirectf* frame, struct ncvisual_options* vopts){
return ncdirect_render_visual(n, frame, vopts);
}
int ncdirectf_geom(ncdirect* n, ncdirectf* frame,

View File

@ -372,7 +372,9 @@ int rendered_mode_player_inner(NotCurses& nc, int argc, char** argv,
struct ncplane_options nopts{};
// leave a line at the bottom. perhaps one day we'll put information there.
// for now, this keeps us from scrolling when we use bitmaps.
nopts.margin_b = 1;
if(nopts.margin_b == 0){
nopts.margin_b = 1;
}
nopts.name = "play";
nopts.resizecb = ncplane_resize_marginalized;
nopts.flags = NCPLANE_OPTION_MARGINALIZED;

View File

@ -24,7 +24,12 @@ partial_image(struct ncdirect* n, const char* file){
int cols = x;
ncdirectv* v;
printf("Size: %dx%d\n", cols, rows);
if((v = ncdirectf_render(n, nf, blit, NCSCALE_NONE, rows, cols)) == NULL){
struct ncvisual_options vopts = {
.blitter = blit,
.leny = rows * geom.scaley,
.lenx = cols * geom.scalex,
};
if((v = ncdirectf_render(n, nf, &vopts)) == NULL){
ncdirectf_free(nf);
return -1;
}

View File

@ -83,7 +83,9 @@ TEST_CASE("DirectMode") {
CHECK(475 == geom.pixy);
CHECK(860 == geom.pixx);
CHECK(NCBLIT_DEFAULT != blitter);
auto ncdv = ncdirectf_render(nc_, dirf, blitter, NCSCALE_NONE, 0, 0);
struct ncvisual_options vopts{};
vopts.blitter = blitter;
auto ncdv = ncdirectf_render(nc_, dirf, &vopts);
CHECK(nullptr != ncdv);
CHECK(0 == ncdirect_raster_frame(nc_, ncdv, NCALIGN_LEFT));
ncdirectf_free(dirf);
@ -101,7 +103,9 @@ TEST_CASE("DirectMode") {
CHECK(NCBLIT_PIXEL == blitter);
CHECK(geom.cdimy == geom.scaley);
CHECK(geom.cdimx == geom.scalex);
auto ncdv = ncdirectf_render(nc_, dirf, blitter, NCSCALE_NONE, 0, 0);
struct ncvisual_options vopts{};
vopts.blitter = blitter;
auto ncdv = ncdirectf_render(nc_, dirf, &vopts);
CHECK(nullptr != ncdv);
CHECK(0 == ncdirect_raster_frame(nc_, ncdv, NCALIGN_LEFT));
ncdirectf_free(dirf);
@ -112,7 +116,9 @@ TEST_CASE("DirectMode") {
if(is_test_tty()){
auto dirf = ncdirectf_from_file(nc_, find_data("worldmap.png").get());
REQUIRE(nullptr != dirf);
auto ncdv = ncdirectf_render(nc_, dirf, NCBLIT_1x1, NCSCALE_NONE, 0, 0);
struct ncvisual_options vopts{};
vopts.blitter = NCBLIT_1x1;
auto ncdv = ncdirectf_render(nc_, dirf, &vopts);
CHECK(nullptr != ncdv);
CHECK(0 == ncdirect_raster_frame(nc_, ncdv, NCALIGN_LEFT));
ncdirectf_free(dirf);
@ -132,7 +138,10 @@ TEST_CASE("DirectMode") {
if(ncdirect_check_pixel_support(nc_) > 0){
auto dirf = ncdirectf_from_file(nc_, find_data("worldmap.png").get());
REQUIRE(nullptr != dirf);
auto ncdv = ncdirectf_render(nc_, dirf, NCBLIT_PIXEL, NCSCALE_NONE, 0, 0);
struct ncvisual_options vopts{};
vopts.blitter = NCBLIT_PIXEL;
vopts.flags = NCVISUAL_OPTION_NODEGRADE;
auto ncdv = ncdirectf_render(nc_, dirf, &vopts);
CHECK(nullptr != ncdv);
CHECK(0 == ncdirect_raster_frame(nc_, ncdv, NCALIGN_LEFT));
ncdirectf_free(dirf);