ncdirect: proper scaling for NCBLIT_PIXEL #1380

dankamongmen/sixel-speedup
nick black 3 years ago committed by Nick Black
parent 7592d0c4a3
commit 3ad8057965

@ -841,7 +841,7 @@ static const struct blitset notcurses_blitters[] = {
.blit = tria_blit, .name = "fourstep", .fill = false, },
{ .geom = NCBLIT_BRAILLE, .width = 2, .height = 4, .egcs = L"⠀⢀⢠⢰⢸⡀⣀⣠⣰⣸⡄⣄⣤⣴⣼⡆⣆⣦⣶⣾⡇⣇⣧⣷⣿",
.blit = braille_blit, .name = "braille", .fill = true, },
{ .geom = NCBLIT_PIXEL, .width = 1, .height = 6, .egcs = L"",
{ .geom = NCBLIT_PIXEL, .width = 1, .height = 1, .egcs = L"",
.blit = sixel_blit, .name = "pixel", .fill = true, },
{ .geom = 0, .width = 0, .height = 0, .egcs = NULL,
.blit = NULL, .name = NULL, .fill = false, },

@ -477,8 +477,13 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
}
int disprows, dispcols;
if(scale != NCSCALE_NONE && scale != NCSCALE_NONE_HIRES){
dispcols = ncdirect_dim_x(n) * encoding_x_scale(bset);
disprows = ncdirect_dim_y(n) * encoding_y_scale(bset);
if(bset->geom != NCBLIT_PIXEL){
dispcols = ncdirect_dim_x(n) * encoding_x_scale(bset);
disprows = ncdirect_dim_y(n) * encoding_y_scale(bset);
}else{
dispcols = ncdirect_dim_x(n) * n->tcache.cellpixx;
disprows = ncdirect_dim_y(n) * n->tcache.cellpixy;
}
if(scale == NCSCALE_SCALE || scale == NCSCALE_SCALE_HIRES){
scale_visual(ncv, &disprows, &dispcols);
}
@ -501,6 +506,7 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
};
if(bset->geom == NCBLIT_PIXEL){
nopts.rows = 1;
nopts.cols = dispcols / n->tcache.cellpixx;
}
auto ncdv = ncplane_new_internal(nullptr, nullptr, &nopts);
if(!ncdv){
@ -664,6 +670,7 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
if(interrogate_terminfo(&ret->tcache, shortname_term, utf8)){
goto err;
}
update_term_dimensions(ret->ctermfd, NULL, NULL, &ret->tcache);
ncdirect_set_styles(ret, 0);
return ret;

@ -183,8 +183,16 @@ void ncplane_dim_yx(const ncplane* n, int* rows, int* cols){
int update_term_dimensions(int fd, int* rows, int* cols, tinfo* tcache){
// if we're not a real tty, we presumably haven't changed geometry, return
if(fd < 0){
*rows = DEFAULT_ROWS;
*cols = DEFAULT_COLS;
if(rows){
*rows = DEFAULT_ROWS;
}
if(cols){
*cols = DEFAULT_COLS;
}
if(tcache){
tcache->cellpixy = 0;
tcache->cellpixx = 0;
}
return 0;
}
struct winsize ws;

@ -479,21 +479,20 @@ auto ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const blitset* bset,
return n;
}
auto ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const blitset* bset,
auto ncvisual_render_pixels(tinfo* tcache, ncvisual* ncv, const blitset* bset,
int placey, int placex, int begy, int begx,
int leny, int lenx, ncplane* n, ncscale_e scaling) -> ncplane* {
int leny, int lenx, ncplane* n, ncscale_e scaling,
ncplane* stdn) -> ncplane* {
int disprows, dispcols;
//fprintf(stderr, "INPUT N: %p\n", vopts ? vopts->n : nullptr);
if(n == nullptr){ // create plane
if(scaling == NCSCALE_NONE || scaling == NCSCALE_NONE_HIRES){
dispcols = ncv->cols;
disprows = ncv->rows;
/*dispcols = dispcols / nc->tcache.cellpixx + dispcols % nc->tcache.cellpixx;
disprows = disprows / nc->tcache.cellpixy + disprows % nc->tcache.cellpixy;*/
}else{
notcurses_term_dim_yx(nc, &disprows, &dispcols);
dispcols *= nc->tcache.cellpixx;
disprows *= nc->tcache.cellpixy;
ncplane_dim_yx(stdn, &disprows, &dispcols);
dispcols *= tcache->cellpixx;
disprows *= tcache->cellpixy;
if(scaling == NCSCALE_SCALE || scaling == NCSCALE_SCALE_HIRES){
scale_visual(ncv, &disprows, &dispcols);
}
@ -503,13 +502,13 @@ auto ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const blitset* bset,
.y = placey,
.x = placex,
.rows = 1,
.cols = dispcols / nc->tcache.cellpixx,
.cols = dispcols / tcache->cellpixx,
.userptr = nullptr,
.name = "rgba",
.resizecb = nullptr,
.flags = 0,
};
if((n = ncplane_create(notcurses_stdplane(nc), &nopts)) == nullptr){
if((n = ncplane_create(stdn, &nopts)) == nullptr){
return nullptr;
}
placey = 0;
@ -518,14 +517,14 @@ auto ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const blitset* bset,
if(scaling == NCSCALE_NONE || scaling == NCSCALE_NONE_HIRES){
dispcols = ncv->cols;
disprows = ncv->rows;
/*dispcols = dispcols / nc->tcache.cellpixx + dispcols % nc->tcache.cellpixx;
disprows = disprows / nc->tcache.cellpixy + disprows % nc->tcache.cellpixy;*/
/*dispcols = dispcols / tcache->cellpixx + dispcols % tcache->cellpixx;
disprows = disprows / tcache->cellpixy + disprows % tcache->cellpixy;*/
}else{
ncplane_dim_yx(n, &disprows, &dispcols);
dispcols *= nc->tcache.cellpixx;
disprows *= nc->tcache.cellpixy;
dispcols -= (placex * nc->tcache.cellpixx + 1);
disprows -= (placey * nc->tcache.cellpixy + 1);
dispcols *= tcache->cellpixx;
disprows *= tcache->cellpixy;
dispcols -= (placex * tcache->cellpixx + 1);
disprows -= (placey * tcache->cellpixy + 1);
if(scaling == NCSCALE_SCALE || scaling == NCSCALE_SCALE_HIRES){
scale_visual(ncv, &disprows, &dispcols);
} // else stretch
@ -533,7 +532,7 @@ auto ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const blitset* bset,
}
leny = disprows;
lenx = 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);
//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,
placey, placex, begy, begx, leny, lenx, false)){
ncplane_destroy(n);
@ -590,8 +589,8 @@ auto ncvisual_render(notcurses* nc, ncvisual* ncv,
n, scaling,
vopts && (vopts->flags & NCVISUAL_OPTION_BLEND));
}else{
n = ncvisual_render_pixels(nc, ncv, bset, placey, placex, begy, begx, leny, lenx,
n, scaling);
n = ncvisual_render_pixels(&nc->tcache, ncv, bset, placey, placex, begy, begx,
leny, lenx, n, scaling, notcurses_stdplane(nc));
}
return n;
}

Loading…
Cancel
Save