add NCSCALE_NONE_HIRES, NCSCALE_SCALE_HIRES #1250

This commit is contained in:
nick black 2020-12-25 18:25:44 -05:00 committed by Nick Black
parent fbe4352233
commit dd1cdc40d5
10 changed files with 38 additions and 22 deletions

View File

@ -28,7 +28,7 @@ be any non-negative number.
**-l** ***loglevel***: Log everything (high log level) or nothing (log level 0) to stderr. **-l** ***loglevel***: Log everything (high log level) or nothing (log level 0) to stderr.
**-s** ***scalemode***: Scaling mode, one of **none**, **scale**, or **stretch**. **-s** ***scalemode***: Scaling mode, one of **none**, **hires**, **scale**, **scalehi**, or **stretch**.
**-b** ***blitter***: Blitter, one of **ascii**, **halfblocks**, **quadblitter**, **-b** ***blitter***: Blitter, one of **ascii**, **halfblocks**, **quadblitter**,
**sexblitter**, or **braille**. **sexblitter**, or **braille**.

View File

@ -14,6 +14,8 @@ typedef enum {
NCSCALE_NONE, NCSCALE_NONE,
NCSCALE_SCALE, NCSCALE_SCALE,
NCSCALE_STRETCH, NCSCALE_STRETCH,
NCSCALE_NONE_HIRES,
NCSCALE_SCALE_HIRES,
} ncscale_e; } ncscale_e;
typedef enum { typedef enum {

View File

@ -78,11 +78,15 @@ typedef enum {
// How to scale an ncvisual during rendering. NCSCALE_NONE will apply no // How to scale an ncvisual during rendering. NCSCALE_NONE will apply no
// scaling. NCSCALE_SCALE scales a visual to the plane's size, maintaining // scaling. NCSCALE_SCALE scales a visual to the plane's size, maintaining
// aspect ratio. NCSCALE_STRETCH stretches and scales the image in an // aspect ratio. NCSCALE_STRETCH stretches and scales the image in an
// attempt to fill the entirety of the plane. // attempt to fill the entirety of the plane. NCSCALE_NONE_HIRES and
// NCSCALE_SCALE_HIRES behave like their counterparts, but admit blitters
// which don't preserve aspect ratio.
typedef enum { typedef enum {
NCSCALE_NONE, NCSCALE_NONE,
NCSCALE_SCALE, NCSCALE_SCALE,
NCSCALE_STRETCH, NCSCALE_STRETCH,
NCSCALE_NONE_HIRES,
NCSCALE_SCALE_HIRES,
} ncscale_e; } ncscale_e;
// Returns the number of columns occupied by a multibyte (UTF-8) string, or // Returns the number of columns occupied by a multibyte (UTF-8) string, or
@ -1193,6 +1197,9 @@ API bool notcurses_canopen_videos(const struct notcurses* nc);
// Is our encoding UTF-8? Requires LANG being set to a UTF8 locale. // Is our encoding UTF-8? Requires LANG being set to a UTF8 locale.
API bool notcurses_canutf8(const struct notcurses* nc); API bool notcurses_canutf8(const struct notcurses* nc);
// Can we reliably use Unicode 13 sextants?
API bool notcurses_cansextant(const struct notcurses* nc);
// Can we blit to Sixel? // Can we blit to Sixel?
API bool notcurses_cansixel(const struct notcurses* nc); API bool notcurses_cansixel(const struct notcurses* nc);

View File

@ -42,7 +42,7 @@ zoom_map(struct notcurses* nc, const char* map, int* ret){
// but *do* explicitly supply NCBLIT_2x2 since we're not scaling. // but *do* explicitly supply NCBLIT_2x2 since we're not scaling.
struct ncvisual_options vopts = { struct ncvisual_options vopts = {
.y = 1, .y = 1,
.blitter = ncvisual_media_defblitter(nc, NCSCALE_NONE), .blitter = ncvisual_media_defblitter(nc, NCSCALE_NONE_HIRES),
}; };
if(ncvisual_geom(nc, ncv, &vopts, &vheight, &vwidth, &yscale, &xscale)){ if(ncvisual_geom(nc, ncv, &vopts, &vheight, &vwidth, &yscale, &xscale)){
ncvisual_destroy(ncv); ncvisual_destroy(ncv);

View File

@ -44,7 +44,7 @@ rgba_blitter_default(bool utf8, ncscale_e scale, bool sextants){
if(!utf8){ if(!utf8){
return NCBLIT_1x1; return NCBLIT_1x1;
} }
if(scale != NCSCALE_STRETCH){ if(scale == NCSCALE_NONE || scale == NCSCALE_SCALE){
return NCBLIT_2x1; return NCBLIT_2x1;
} }
if(!sextants){ if(!sextants){

View File

@ -366,11 +366,6 @@ typedef struct notcurses {
bool libsixel; // do we have Sixel support? bool libsixel; // do we have Sixel support?
} notcurses; } notcurses;
static inline bool
notcurses_cansextant(const notcurses* nc){
return nc->tcache.sextants;
}
#include "blitset.h" #include "blitset.h"
void sigwinch_handler(int signo); void sigwinch_handler(int signo);

View File

@ -2111,6 +2111,10 @@ bool notcurses_canutf8(const notcurses* nc){
return nc->utf8; return nc->utf8;
} }
bool notcurses_cansextant(const notcurses* nc){
return nc->tcache.sextants && nc->utf8;
}
bool notcurses_canfade(const notcurses* nc){ bool notcurses_canfade(const notcurses* nc){
return nc->tcache.CCCflag || nc->tcache.RGBflag; return nc->tcache.CCCflag || nc->tcache.RGBflag;
} }
@ -2403,6 +2407,10 @@ lex_long(const char* op, int* i, char** endptr){
int notcurses_lex_scalemode(const char* op, ncscale_e* scalemode){ int notcurses_lex_scalemode(const char* op, ncscale_e* scalemode){
if(strcasecmp(op, "stretch") == 0){ if(strcasecmp(op, "stretch") == 0){
*scalemode = NCSCALE_STRETCH; *scalemode = NCSCALE_STRETCH;
}else if(strcasecmp(op, "scalehi") == 0){
*scalemode = NCSCALE_SCALE_HIRES;
}else if(strcasecmp(op, "hires") == 0){
*scalemode = NCSCALE_NONE_HIRES;
}else if(strcasecmp(op, "scale") == 0){ }else if(strcasecmp(op, "scale") == 0){
*scalemode = NCSCALE_SCALE; *scalemode = NCSCALE_SCALE;
}else if(strcasecmp(op, "none") == 0){ }else if(strcasecmp(op, "none") == 0){
@ -2420,6 +2428,10 @@ const char* notcurses_str_scalemode(ncscale_e scalemode){
return "scale"; return "scale";
}else if(scalemode == NCSCALE_NONE){ }else if(scalemode == NCSCALE_NONE){
return "none"; return "none";
}else if(scalemode == NCSCALE_NONE_HIRES){
return "hires";
}else if(scalemode == NCSCALE_SCALE_HIRES){
return "scalehi";
} }
return NULL; return NULL;
} }

View File

@ -33,16 +33,16 @@ auto ncvisual_geom(const notcurses* nc, const ncvisual* n,
x = &fauxx; x = &fauxx;
} }
if(n){ if(n){
if(scale == NCSCALE_NONE){ if(scale == NCSCALE_NONE || scale == NCSCALE_NONE_HIRES){
*y = n->rows; *y = n->rows * encoding_y_scale(bset);
*x = n->cols; *x = n->cols * encoding_x_scale(bset);
}else{ }else{
int rows = vopts->n ? ncplane_dim_y(vopts->n) : ncplane_dim_y(nc->stdplane); int rows = vopts->n ? ncplane_dim_y(vopts->n) : ncplane_dim_y(nc->stdplane);
int cols = vopts->n ? ncplane_dim_x(vopts->n) : ncplane_dim_x(nc->stdplane); int cols = vopts->n ? ncplane_dim_x(vopts->n) : ncplane_dim_x(nc->stdplane);
*y = rows * encoding_y_scale(bset); *y = rows * encoding_y_scale(bset);
*x = cols * encoding_x_scale(bset); *x = cols * encoding_x_scale(bset);
} }
if(scale == NCSCALE_SCALE){ if(scale == NCSCALE_SCALE || scale == NCSCALE_SCALE_HIRES){
scale_visual(n, y, x); scale_visual(n, y, x);
} }
} }
@ -413,7 +413,7 @@ auto ncvisual_render(notcurses* nc, ncvisual* ncv,
notcurses_term_dim_yx(nc, &disprows, &dispcols); notcurses_term_dim_yx(nc, &disprows, &dispcols);
dispcols *= encoding_x_scale(bset); dispcols *= encoding_x_scale(bset);
disprows *= encoding_y_scale(bset); disprows *= encoding_y_scale(bset);
if(vopts->scaling == NCSCALE_SCALE){ if(vopts->scaling == NCSCALE_SCALE || vopts->scaling == NCSCALE_SCALE_HIRES){
scale_visual(ncv, &disprows, &dispcols); scale_visual(ncv, &disprows, &dispcols);
} }
} }
@ -434,16 +434,16 @@ auto ncvisual_render(notcurses* nc, ncvisual* ncv,
placey = 0; placey = 0;
placex = 0; placex = 0;
}else{ }else{
if(!vopts || vopts->scaling == NCSCALE_NONE){ if(!vopts || vopts->scaling == NCSCALE_NONE || vopts->scaling == NCSCALE_NONE_HIRES){
dispcols = ncv->cols; dispcols = ncv->cols * encoding_x_scale(bset);
disprows = ncv->rows; disprows = ncv->rows * encoding_y_scale(bset);
}else{ }else{
ncplane_dim_yx(n, &disprows, &dispcols); ncplane_dim_yx(n, &disprows, &dispcols);
dispcols *= encoding_x_scale(bset); dispcols *= encoding_x_scale(bset);
disprows *= encoding_y_scale(bset); disprows *= encoding_y_scale(bset);
disprows -= placey; disprows -= placey;
dispcols -= placex; dispcols -= placex;
if(vopts->scaling == NCSCALE_SCALE){ if(vopts->scaling == NCSCALE_SCALE || vopts->scaling == NCSCALE_SCALE_HIRES){
scale_visual(ncv, &disprows, &dispcols); scale_visual(ncv, &disprows, &dispcols);
} }
} }

View File

@ -142,11 +142,11 @@ void ncls_thread(const lsContext* ctx) {
work.pop(); work.pop();
pthread_mutex_unlock(&mtx); pthread_mutex_unlock(&mtx);
auto s = j.dir / j.p; auto s = j.dir / j.p;
auto faken = ctx->nc.prep_image(s.c_str(), NCBLIT_DEFAULT, NCSCALE_SCALE); auto faken = ctx->nc.prep_image(s.c_str(), NCBLIT_DEFAULT, NCSCALE_SCALE_HIRES);
pthread_mutex_lock(&outmtx); pthread_mutex_lock(&outmtx);
std::cout << j.p << '\n'; std::cout << j.p << '\n';
if(faken){ if(faken){
ctx->nc.raster_image(faken, ctx->alignment, NCBLIT_DEFAULT, NCSCALE_SCALE); ctx->nc.raster_image(faken, ctx->alignment, NCBLIT_DEFAULT, NCSCALE_SCALE_HIRES);
} }
pthread_mutex_unlock(&outmtx); pthread_mutex_unlock(&outmtx);
}else if(!keep_working){ }else if(!keep_working){

View File

@ -24,7 +24,7 @@ void usage(std::ostream& o, const char* name, int exitcode){
o << " -L: loop frames\n"; o << " -L: loop frames\n";
o << " -t seconds: delay t seconds after each file\n"; o << " -t seconds: delay t seconds after each file\n";
o << " -l loglevel: integer between 0 and 9, goes to stderr'\n"; o << " -l loglevel: integer between 0 and 9, goes to stderr'\n";
o << " -s scaletype: one of 'none', 'scale', or 'stretch'\n"; o << " -s scaletype: one of 'none', 'hires', 'scale', 'scalehi', or 'stretch'\n";
o << " -b blitter: 'ascii', 'halfblock', 'quadblitter', 'sexblitter', or 'braille'\n"; o << " -b blitter: 'ascii', 'halfblock', 'quadblitter', 'sexblitter', or 'braille'\n";
o << " -m margins: margin, or 4 comma-separated margins\n"; o << " -m margins: margin, or 4 comma-separated margins\n";
o << " -d mult: non-negative floating point scale for frame time" << std::endl; o << " -d mult: non-negative floating point scale for frame time" << std::endl;
@ -189,7 +189,7 @@ auto handle_opts(int argc, char** argv, notcurses_options& opts, bool* quiet,
break; break;
case 's': case 's':
if(notcurses_lex_scalemode(optarg, scalemode)){ if(notcurses_lex_scalemode(optarg, scalemode)){
std::cerr << "Scaling type should be one of stretch, scale, none (got " std::cerr << "Scaling type should be one of stretch, scale, scalehi, hires, none (got "
<< optarg << ")" << std::endl; << optarg << ")" << std::endl;
usage(std::cerr, argv[0], EXIT_FAILURE); usage(std::cerr, argv[0], EXIT_FAILURE);
} }