Use NCBLIT_2x2 by default with NCSCALE_STRETCH

We're not using NCBLIT_2x2 by default because it warps the
aspect ratio. If we're using NCSCALE_STRETCH, though, we've
(1) already indicated that aspect ratio isn't terribly
important to us and (2) are trying to maximize the space.
Since NCBLIT_2x2 is best for large images anyway, make it
the default when NCSCALE_STRECTH is being used.

Remove all explicit uses of NCBLIT_2x2 when NCSCALE_STRETCH
is being used in notcurses-demo.
This commit is contained in:
nick black 2020-06-25 14:09:15 -04:00
parent ee690c12df
commit 78c2cef7e9
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
8 changed files with 22 additions and 17 deletions

View File

@ -1,6 +1,11 @@
This document attempts to list user-visible changes and any major internal
rearrangements of Notcurses.
* 1.5.3 (not yet released)
* The default blitter when `NCSCALE_STRETCH` is used is now `NCBLIT_2x2`,
replacing `NCBLIT_2x1`. It is not the default for `NCSCALE_NONE` and
`NCSCALE_SCALE` because it does not preserve aspect ratio.
* 1.5.2 (2020-06-19)
* The `ncneofetch` program has been added, of no great consequence.
* A `NULL` value can now be passed as `sbytes` to `ncplane_puttext()`.

View File

@ -157,7 +157,6 @@ int luigi_demo(struct notcurses* nc){
struct ncvisual_options vopts = {
.n = notcurses_stddim_yx(nc, &rows, &cols),
.scaling = NCSCALE_STRETCH,
.blitter = NCBLIT_2x2,
};
if(ncvisual_render(nc, nv, &vopts) == NULL){
return -1;

View File

@ -86,7 +86,6 @@ rotate_visual(struct notcurses* nc, struct ncplane* n, int dy, int dx){
if(nncv){
struct ncvisual_options nvopts = {
.n = notcurses_stdplane(nc),
.blitter = NCBLIT_2x2,
.y = 1,
.scaling = NCSCALE_STRETCH,
};

View File

@ -59,7 +59,6 @@ videothread(void* vnc){
.scaling = NCSCALE_STRETCH,
.n = ncp,
.y = 1,
.blitter = NCBLIT_2x2,
};
int three = 3;
if(ncvisual_render(nc, ncv, &ovopts) == NULL){

View File

@ -15,7 +15,6 @@ view_video_demo(struct notcurses* nc){
struct ncvisual_options vopts = {
.scaling = NCSCALE_STRETCH,
.n = ncp,
.blitter = NCBLIT_2x2,
.y = 1,
};
int ret = ncvisual_stream(nc, ncv, &err, 0.5 * delaymultiplier,
@ -81,7 +80,6 @@ view_images(struct notcurses* nc, struct ncplane* nstd, int dimy, int dimx){
struct ncvisual_options vopts = {
.n = dsplane,
.scaling = NCSCALE_STRETCH,
.blitter = NCBLIT_2x2,
.y = 1,
};
if(ncvisual_render(nc, ncv2, &vopts) == NULL){
@ -107,7 +105,6 @@ view_images(struct notcurses* nc, struct ncplane* nstd, int dimy, int dimx){
}
free(pic);
vopts.n = notcurses_stdplane(nc);
vopts.blitter = NCBLIT_2x2;
if(ncvisual_render(nc, ncv, &vopts) == NULL){
ncvisual_destroy(ncv);
ncplane_destroy(dsplane);

View File

@ -94,6 +94,7 @@ int xray_demo(struct notcurses* nc){
struct ncvisual_options vopts = {
.n = n,
.scaling = NCSCALE_STRETCH,
.blitter = NCBLIT_2x1,
};
int ret = ncvisual_stream(nc, ncv, &err, 0.5 * delaymultiplier, perframecb, &vopts, newpanel);
ncvisual_destroy(ncv);

View File

@ -29,8 +29,14 @@ encoding_x_scale(const struct blitset* bset) -> int {
}
static inline auto
ncvisual_default_blitter(const notcurses* nc) -> ncblitter_e {
ncvisual_default_blitter(const notcurses* nc, ncscale_e scale) -> ncblitter_e {
if(notcurses_canutf8(nc)){
// NCBLIT_2x2 is better image quality, especially for large images, but
// it's not the general default because it doesn't preserve aspect ratio.
// NCSCALE_STRETCH throws away aspect ratio, and can safely use NCBLIT_2x2.
if(scale == NCSCALE_STRETCH){
return NCBLIT_2x2;
}
return NCBLIT_2x1;
}
return NCBLIT_1x1;
@ -48,9 +54,10 @@ void scale_visual(const ncvisual* ncv, int* disprows, int* dispcols) {
auto ncvisual_geom(const notcurses* nc, const ncvisual* n,
const struct ncvisual_options* vopts,
int* y, int* x, int* toy, int* tox) -> int {
const ncscale_e scale = vopts ? vopts->scaling : NCSCALE_NONE;
ncblitter_e blitter;
if(!vopts || vopts->blitter == NCBLIT_DEFAULT){
blitter = ncvisual_default_blitter(nc);
blitter = ncvisual_default_blitter(nc, scale);
}else{
blitter = vopts->blitter;
}
@ -67,19 +74,16 @@ auto ncvisual_geom(const notcurses* nc, const ncvisual* n,
x = &fauxx;
}
if(n){
if(!vopts || vopts->scaling == NCSCALE_NONE){
if(scale == NCSCALE_NONE){
*y = n->rows;
}else{
int rows = vopts->n ? ncplane_dim_y(vopts->n) : ncplane_dim_y(nc->stdscr);
*y = rows * encoding_y_scale(bset);
}
if(!vopts || vopts->scaling == NCSCALE_NONE){
*x = n->cols;
}else{
int rows = vopts->n ? ncplane_dim_y(vopts->n) : ncplane_dim_y(nc->stdscr);
int cols = vopts->n ? ncplane_dim_x(vopts->n) : ncplane_dim_x(nc->stdscr);
*y = rows * encoding_y_scale(bset);
*x = cols * encoding_x_scale(bset);
}
if(vopts && vopts->scaling == NCSCALE_SCALE){
if(scale == NCSCALE_SCALE){
scale_visual(n, y, x);
}
}
@ -98,10 +102,11 @@ static const struct blitset*
rgba_blitter(const notcurses* nc, const struct ncvisual_options* opts){
const struct blitset* bset;
const bool maydegrade = !(opts && (opts->flags & NCVISUAL_OPTION_NODEGRADE));
const ncscale_e scale = opts ? opts->scaling : NCSCALE_NONE;
if(opts && opts->blitter != NCBLIT_DEFAULT){
bset = lookup_blitset(nc, opts->blitter, maydegrade);
}else{
bset = lookup_blitset(nc, ncvisual_default_blitter(nc), maydegrade);
bset = lookup_blitset(nc, ncvisual_default_blitter(nc, scale), maydegrade);
}
if(bset && !bset->blit){ // FIXME remove this once all blitters are enabled
bset = nullptr;

View File

@ -20,7 +20,7 @@ int main(int argc, char** argv){
file = argv[1];
}
notcurses_options opts{};
opts.loglevel = NCLOGLEVEL_TRACE;
//opts.loglevel = NCLOGLEVEL_TRACE;
opts.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN;
struct notcurses* nc;
if((nc = notcurses_init(&opts, nullptr)) == nullptr){