From 53a85871fe2f5357b2ac4c46a960be9f2f99aa4c Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 20 Mar 2021 02:02:20 -0400 Subject: [PATCH] [pixel] detach old sprite when blitting onto existing plane --- src/demo/keller.c | 1 + src/demo/yield.c | 1 + src/lib/internal.h | 3 +++ src/lib/visual.c | 30 +++++++++++++++--------------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/demo/keller.c b/src/demo/keller.c index bd138882f..55469fcd9 100644 --- a/src/demo/keller.c +++ b/src/demo/keller.c @@ -42,6 +42,7 @@ visualize(struct notcurses* nc, struct ncvisual* ncv){ if((n = ncvisual_render(nc, ncv, &vopts)) == NULL){ ncplane_printf_aligned(stdn, ncplane_dim_y(stdn) / 2 - 1, NCALIGN_CENTER, "not available"); }else{ + // FIXME shouldn't need this once z-axis is united with bitmap graphics ncplane_move_below(n, stdn); if(vopts.blitter == NCBLIT_PIXEL){ DEMO_RENDER(nc); diff --git a/src/demo/yield.c b/src/demo/yield.c index 9884feae3..cea7693b2 100644 --- a/src/demo/yield.c +++ b/src/demo/yield.c @@ -107,6 +107,7 @@ int yield_demo(struct notcurses* nc){ tfilled += pfilled; if(ncvisual_render(nc, wmv, &vopts) == NULL){ ncvisual_destroy(wmv); + ncplane_destroy(vopts.n); return -1; } if(tfilled > threshold_painted){ diff --git a/src/lib/internal.h b/src/lib/internal.h index 5c9d628da..2f146710a 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -1105,6 +1105,9 @@ plane_blit_sixel(ncplane* n, const char* s, int bytes, int leny, int lenx, c->width = lenx; } } + if(n->sprite){ + sprixel_hide(n->sprite); + } n->sprite = spx; return 0; } diff --git a/src/lib/visual.c b/src/lib/visual.c index 7b9897c22..a9b5c3d7f 100644 --- a/src/lib/visual.c +++ b/src/lib/visual.c @@ -481,7 +481,7 @@ ncplane* ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const struct blitse return n; } -ncplane* ncvisual_render_pixels(tinfo* tcache, ncvisual* ncv, const struct blitset* bset, +ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blitset* bset, int placey, int placex, int begy, int begx, ncplane* n, ncscale_e scaling, ncplane* stdn){ int disprows, dispcols; @@ -493,15 +493,15 @@ ncplane* ncvisual_render_pixels(tinfo* tcache, ncvisual* ncv, const struct blits if(n == NULL){ // create plane if(scaling != NCSCALE_NONE && scaling != NCSCALE_NONE_HIRES){ ncplane_dim_yx(stdn, &disprows, &dispcols); - dispcols *= tcache->cellpixx; - disprows *= tcache->cellpixy; + dispcols *= nc->tcache.cellpixx; + disprows *= nc->tcache.cellpixy; } //fprintf(stderr, "PLACING NEW PLANE: %d/%d @ %d/%d\n", disprows, dispcols, placey, placex); struct ncplane_options nopts = { .y = placey, .x = placex, - .rows = disprows / tcache->cellpixy + !!(disprows % tcache->cellpixy), - .cols = dispcols / tcache->cellpixx + !!(dispcols % tcache->cellpixx), + .rows = disprows / nc->tcache.cellpixy + !!(disprows % nc->tcache.cellpixy), + .cols = dispcols / nc->tcache.cellpixx + !!(dispcols % nc->tcache.cellpixx), .userptr = NULL, .name = "rgba", .resizecb = NULL, @@ -515,21 +515,21 @@ ncplane* ncvisual_render_pixels(tinfo* tcache, ncvisual* ncv, const struct blits }else{ if(scaling != NCSCALE_NONE && scaling != NCSCALE_NONE_HIRES){ ncplane_dim_yx(n, &disprows, &dispcols); - dispcols *= tcache->cellpixx; - disprows *= tcache->cellpixy; - dispcols -= (placex * tcache->cellpixx + 1); - disprows -= (placey * tcache->cellpixy + 1); + dispcols *= nc->tcache.cellpixx; + disprows *= nc->tcache.cellpixy; + dispcols -= (placex * nc->tcache.cellpixx + 1); + disprows -= (placey * nc->tcache.cellpixy + 1); } } if(scaling == NCSCALE_SCALE || scaling == NCSCALE_SCALE_HIRES){ scale_visual(ncv, &disprows, &dispcols); } -//fprintf(stderr, "pblit: %dx%d <- %dx%d of %d/%d stride %u @%dx%d %p %u\n", disprows, dispcols, begy, begx, ncv->rows, ncv->cols, ncv->rowstride, placey, placex, ncv->data, ncplane_notcurses(stdn)->tcache.cellpixx); +//fprintf(stderr, "pblit: %dx%d <- %dx%d of %d/%d stride %u @%dx%d %p %u\n", disprows, dispcols, begy, begx, ncv->rows, ncv->cols, ncv->rowstride, placey, placex, ncv->data, ncplane_notcurses(stdn)->nc->tcache.cellpixx); blitterargs bargs; - bargs.pixel.celldimx = ncplane_notcurses(stdn)->tcache.cellpixx; - bargs.pixel.celldimy = ncplane_notcurses(stdn)->tcache.cellpixy; - bargs.pixel.colorregs = ncplane_notcurses(stdn)->tcache.color_registers; - bargs.pixel.sprixelid = tcache->sprixelnonce++; + bargs.pixel.celldimx = nc->tcache.cellpixx; + bargs.pixel.celldimy = nc->tcache.cellpixy; + bargs.pixel.colorregs = nc->tcache.color_registers; + bargs.pixel.sprixelid = nc->tcache.sprixelnonce++; if(ncvisual_blit(ncv, disprows, dispcols, n, bset, begy, begx, disprows, dispcols, &bargs)){ ncplane_destroy(n); @@ -585,7 +585,7 @@ ncplane* ncvisual_render(notcurses* nc, ncvisual* ncv, const struct ncvisual_opt n, scaling, vopts && (vopts->flags & NCVISUAL_OPTION_BLEND)); }else{ - n = ncvisual_render_pixels(&nc->tcache, ncv, bset, placey, placex, begy, begx, + n = ncvisual_render_pixels(nc, ncv, bset, placey, placex, begy, begx, n, scaling, notcurses_stdplane(nc)); } return n;