From 8482c1157f4ae098832b26d3eb1b4522d41aea3e Mon Sep 17 00:00:00 2001 From: nick black Date: Mon, 15 Mar 2021 17:32:01 -0400 Subject: [PATCH] [pixel] honor configured margins when rasterizing --- src/lib/render.c | 49 ++++++++++++++++++++++++++++++---------------- src/lib/visual.cpp | 4 ++-- src/poc/pixel.c | 8 +++++++- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/lib/render.c b/src/lib/render.c index abd8ed219..0c426ad02 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -928,7 +928,7 @@ rasterize_sprixels(notcurses* nc, FILE* out){ if(s->invalidated == SPRIXEL_INVALIDATED){ int y, x; ncplane_yx(s->n, &y, &x); - if(goto_location(nc, out, y, x)){ + if(goto_location(nc, out, y + nc->stdplane->absy, x + nc->stdplane->absx)){ return -1; } if(ncfputs(s->glyph, out) < 0){ @@ -938,7 +938,12 @@ rasterize_sprixels(notcurses* nc, FILE* out){ nc->rstate.hardcursorpos = true; }else if(s->invalidated == SPRIXEL_HIDE){ fprintf(stderr, "OUGHT HIDE [%dx%d @ %d/%d] %p\n", s->dimy, s->dimx, s->y, s->x, s); - // FIXME delete it + // FIXME only do this for sixel + for(int y = s->y ; y < s->y + s->dimy - 1 ; ++y){ + for(int x = s->x ; x < s->x + s->dimx - 1 ; ++x){ + } + } + // FIXME delete it in kitty *parent = s->next; sprixel_free(s); } @@ -958,20 +963,11 @@ fprintf(stderr, "OUGHT HIDE [%dx%d @ %d/%d] %p\n", s->dimy, s->dimx, s->y, s->x, // lastframe has *not yet been written to the screen*, i.e. it's only about to // *become* the last frame rasterized. static int -notcurses_rasterize_inner(notcurses* nc, const ncpile* p, FILE* out){ - const struct crender* rvec = p->crender; - int y, x; - fseeko(out, 0, SEEK_SET); - // we only need to emit a coordinate if it was damaged. the damagemap is a - // bit per coordinate, one per struct crender. - // don't write a clearscreen. we only update things that have been changed. - // we explicitly move the cursor at the beginning of each output line, so no - // need to home it expliticly. - update_palette(nc, out); -//fprintf(stderr, "pile %p ymax: %d xmax: %d\n", p, p->dimy + nc->stdplane->absy, p->dimx + nc->stdplane->absx); - for(y = nc->stdplane->absy ; y < p->dimy + nc->stdplane->absy ; ++y){ +rasterize_core(notcurses* nc, const ncpile* p, FILE* out){ + struct crender* rvec = p->crender; + for(int y = nc->stdplane->absy ; y < p->dimy + nc->stdplane->absy ; ++y){ const int innery = y - nc->stdplane->absy; - for(x = nc->stdplane->absx ; x < p->dimx + nc->stdplane->absx ; ++x){ + for(int x = nc->stdplane->absx ; x < p->dimx + nc->stdplane->absx ; ++x){ const int innerx = x - nc->stdplane->absx; const size_t damageidx = innery * nc->lfdimx + innerx; unsigned r, g, b, br, bg, bb; @@ -1059,7 +1055,7 @@ notcurses_rasterize_inner(notcurses* nc, const ncpile* p, FILE* out){ if(term_putc(out, &nc->pool, srccell)){ return -1; } - // if we just emitted a sixel, always force a hard cursor relocation + rvec[damageidx].s.damaged = 0; ++nc->rstate.x; if(srccell->width >= 2){ x += srccell->width - 1; @@ -1069,10 +1065,29 @@ notcurses_rasterize_inner(notcurses* nc, const ncpile* p, FILE* out){ //fprintf(stderr, "damageidx: %ld\n", damageidx); } } + return 0; +} + +static int +notcurses_rasterize_inner(notcurses* nc, const ncpile* p, FILE* out){ + fseeko(out, 0, SEEK_SET); + // we only need to emit a coordinate if it was damaged. the damagemap is a + // bit per coordinate, one per struct crender. + // don't write a clearscreen. we only update things that have been changed. + // we explicitly move the cursor at the beginning of each output line, so no + // need to home it expliticly. + update_palette(nc, out); +//fprintf(stderr, "pile %p ymax: %d xmax: %d\n", p, p->dimy + nc->stdplane->absy, p->dimx + nc->stdplane->absx); + if(rasterize_core(nc, p, out)){ + return -1; + } if(rasterize_sprixels(nc, out)){ return -1; } - // FIXME now emit damaged cells sitting atop sprixels + // FIXME only do this refresh loop if necessary + if(rasterize_core(nc, p, out)){ + return -1; + } if(fflush(out)){ return -1; } diff --git a/src/lib/visual.cpp b/src/lib/visual.cpp index 67f931f05..3c52c20e4 100644 --- a/src/lib/visual.cpp +++ b/src/lib/visual.cpp @@ -500,8 +500,8 @@ auto ncvisual_render_pixels(tinfo* tcache, ncvisual* ncv, const blitset* bset, struct ncplane_options nopts = { .y = placey, .x = placex, - .rows = disprows / tcache->cellpixy, - .cols = dispcols / tcache->cellpixx, + .rows = disprows / tcache->cellpixy + !!(disprows % tcache->cellpixy), + .cols = dispcols / tcache->cellpixx + !!(dispcols % tcache->cellpixx), .userptr = nullptr, .name = "rgba", .resizecb = nullptr, diff --git a/src/poc/pixel.c b/src/poc/pixel.c index 632d87326..786790129 100644 --- a/src/poc/pixel.c +++ b/src/poc/pixel.c @@ -37,7 +37,13 @@ int main(int argc, char** argv){ return EXIT_FAILURE; } char** a = argv + 1; - struct notcurses* nc = notcurses_init(NULL, NULL); + struct notcurses_options opts = { + .margin_t = 2, + .margin_l = 2, + .margin_b = 2, + .margin_r = 2, + }; + struct notcurses* nc = notcurses_init(&opts, NULL); if(!notcurses_check_pixel_support(nc)){ notcurses_stop(nc); fprintf(stderr, "this program requires pixel graphics support\n");