[kitty] pass pixel offsets through to sprixel_load() #1682

pull/2274/head
nick black 3 years ago committed by nick black
parent 9b0bf6af23
commit 56fffba757

@ -730,9 +730,8 @@ static int
write_kitty_data(fbuf* f, int linesize, int leny, int lenx, int cols,
const uint32_t* data, const blitterargs* bargs,
tament* tam, int* parse_start, ncpixelimpl_e level){
//fprintf(stderr, "drawing kitty %p\n", tam);
if(linesize % sizeof(*data)){
logerror("Stride (%d) badly aligned\n", linesize);
logerror("stride (%d) badly aligned\n", linesize);
return -1;
}
// we only deflate if we're using animation, since otherwise we need be able
@ -805,7 +804,6 @@ write_kitty_data(fbuf* f, int linesize, int leny, int lenx, int cols,
if(translucent){
ncpixel_set_a(&source[e], ncpixel_a(source[e]) / 2);
}
//fprintf(stderr, "%u/%u/%u -> %c%c%c%c %u %u %u %u\n", r, g, b, b64[0], b64[1], b64[2], b64[3], b64[0], b64[1], b64[2], b64[3]);
int xcell = x / cdimx;
int ycell = y / cdimy;
int tyx = xcell + ycell * cols;
@ -820,6 +818,7 @@ write_kitty_data(fbuf* f, int linesize, int leny, int lenx, int cols,
data, linesize, tam[tyx].auxvector,
transcolor);
if(tmp == NULL){
logerror("got a NULL auxvec at %d/%d\n", y, x);
goto err;
}
tam[tyx].auxvector = tmp;
@ -827,6 +826,7 @@ write_kitty_data(fbuf* f, int linesize, int leny, int lenx, int cols,
if(tam[tyx].auxvector == NULL){
tam[tyx].auxvector = malloc(sizeof(tam[tyx].state));
if(tam[tyx].auxvector == NULL){
logerror("got a NULL auxvec at %d\n", tyx);
goto err;
}
}
@ -1052,7 +1052,6 @@ int kitty_rebuild_animation(sprixel* s, int ycell, int xcell, uint8_t* auxvec){
static inline int
kitty_blit_core(ncplane* n, int linesize, const void* data, int leny, int lenx,
const blitterargs* bargs, ncpixelimpl_e level){
//fprintf(stderr, "IMAGE: start %p end %p\n", data, (const char*)data + leny * linesize);
int cols = bargs->u.pixel.spx->dimx;
sprixel* s = bargs->u.pixel.spx;
if(init_sprixel_animation(s)){
@ -1060,15 +1059,19 @@ kitty_blit_core(ncplane* n, int linesize, const void* data, int leny, int lenx,
}
int parse_start = 0;
fbuf* f = &s->glyph;
int pxoffx = bargs->u.pixel.pxoffx;
int pxoffy = bargs->u.pixel.pxoffy;
if(write_kitty_data(f, linesize, leny, lenx, cols, data,
bargs, n->tam, &parse_start, level)){
goto error;
}
// FIXME need set pxoffx and pxoffy in sprixel
if(level == NCPIXEL_KITTY_STATIC){
s->animating = false;
}
// take ownership of |buf| and |tam| on success.
if(plane_blit_sixel(s, &s->glyph, leny, lenx, parse_start, n->tam, SPRIXEL_UNSEEN) < 0){
if(plane_blit_sixel(s, &s->glyph, leny + pxoffy, lenx + pxoffx, parse_start,
n->tam, SPRIXEL_UNSEEN) < 0){
goto error;
}
return 1;

@ -896,12 +896,18 @@ ncplane* ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const struct blitse
// create a plane in which to blit the sprixel. |disppixx| and |disppixy| are
// scaled pixel geometry on output, and unused on input. |placey| and |placex|
// are used to position the new plane, and reset to 0 on output. |outy| is
// output height on output, and unused on input.
// are used to position the new plane, and reset to 0 on output. |outy| and
// |outx| are true output geometry on output, and unused on input (actual input
// pixel geometry come from ncv->pixy and ncv->pixx).
// |pxoffy| and |pxoffx| are pixel offset within the origin cell. they are not
// included within |disppixx| nor |disppixy|, but count towards |outx| and
// |outy|. these last two are furthermore clamped to sixel maxima, and |outy|
// accounts for sixels being a multiple of six pixels tall.
static ncplane*
make_sprixel_plane(notcurses* nc, ncplane* parent, ncvisual* ncv,
ncscale_e scaling, int* disppixy, int* disppixx,
uint64_t flags, int* outy, int* placey, int* placex){
uint64_t flags, int* outy, int* outx,
int* placey, int* placex, int pxoffy, int pxoffx){
if(scaling != NCSCALE_NONE && scaling != NCSCALE_NONE_HIRES){
ncplane_dim_yx(parent, disppixy, disppixx);
// FIXME why do we clamp only vertical, not horizontal, here?
@ -916,14 +922,18 @@ make_sprixel_plane(notcurses* nc, ncplane* parent, ncvisual* ncv,
}
*disppixx *= nc->tcache.cellpixx;
*disppixy *= nc->tcache.cellpixy;
*disppixx += pxoffx;
*disppixy += pxoffy;
*outx = *disppixx;
clamp_to_sixelmax(&nc->tcache, disppixy, disppixx, outy, scaling);
if(scaling == NCSCALE_SCALE || scaling == NCSCALE_SCALE_HIRES){
scale_visual(ncv, disppixy, disppixx); // can only shrink
clamp_to_sixelmax(&nc->tcache, disppixy, disppixx, outy, scaling);
}
}else{
*disppixx = ncv->pixx;
*disppixy = ncv->pixy;
*disppixx = ncv->pixx + pxoffx;
*disppixy = ncv->pixy + pxoffy;
*outx = *disppixx;
clamp_to_sixelmax(&nc->tcache, disppixy, disppixx, outy, scaling);
}
struct ncplane_options nopts = {
@ -943,6 +953,10 @@ make_sprixel_plane(notcurses* nc, ncplane* parent, ncvisual* ncv,
if(n == NULL){
return NULL;
}
// pixel offsets ought be counted for clamping purposes, but not returned
// as part of the scaled geometry (they are included in outx/outy).
*disppixy -= pxoffy;
*disppixx -= pxoffx;
// we always actually blit to the origin of the plane
*placey = 0;
*placex = 0;
@ -973,17 +987,18 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
int pxoffy, int pxoffx){
ncplane* stdn = notcurses_stdplane(nc);
if(n == stdn && !(flags & NCVISUAL_OPTION_CHILDPLANE)){
logerror("Won't blit bitmaps to the standard plane\n");
logerror("won't blit bitmaps to the standard plane\n");
return NULL;
}
int disppixy = 0, disppixx = 0, outy = 0;
int disppixy = 0, disppixx = 0, outy = 0, outx = 0;
ncplane* createdn = NULL;
if(n == NULL || (flags & NCVISUAL_OPTION_CHILDPLANE)){ // create plane
if(n == NULL){
n = notcurses_stdplane(nc);
}
if((createdn = make_sprixel_plane(nc, n, ncv, scaling, &disppixy, &disppixx,
flags, &outy, &placey, &placex)) == NULL){
flags, &outy, &outx, &placey, &placex,
pxoffy, pxoffx)) == NULL){
return NULL;
}
n = createdn;
@ -991,7 +1006,9 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
if(scaling != NCSCALE_NONE && scaling != NCSCALE_NONE_HIRES){
ncplane_dim_yx(n, &disppixy, &disppixx);
disppixx *= nc->tcache.cellpixx;
disppixx += pxoffx;
disppixy *= nc->tcache.cellpixy;
disppixy += pxoffy;
clamp_to_sixelmax(&nc->tcache, &disppixy, &disppixx, &outy, scaling);
int absplacex = 0, absplacey = 0;
if(!(flags & NCVISUAL_OPTION_HORALIGNED)){
@ -1003,8 +1020,8 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
disppixx -= absplacex * nc->tcache.cellpixx;
disppixy -= absplacey * nc->tcache.cellpixy;
}else{
disppixx = lenx;
disppixy = leny;
disppixx = lenx + pxoffx;
disppixy = leny + pxoffy;
}
if(scaling == NCSCALE_SCALE || scaling == NCSCALE_SCALE_HIRES){
clamp_to_sixelmax(&nc->tcache, &disppixy, &disppixx, &outy, scaling);
@ -1016,8 +1033,11 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
outy -= nc->tcache.sprixel_scale_height;
disppixy = outy;
}
outx = disppixx;
disppixx -= pxoffx;
disppixy -= pxoffy;
}
//fprintf(stderr, "pblit: %dx%d <- %dx%d of %d/%d stride %u @%dx%d %p %u\n", disppixy, disppixx, begy, begx, ncv->pixy, ncv->pixx, ncv->rowstride, placey, placex, ncv->data, nc->tcache.cellpixx);
logdebug("pblit: %dx%d <- %dx%d of %d/%d stride %u @%dx%d %p %u\n", disppixy, disppixx, begy, begx, ncv->pixy, ncv->pixx, ncv->rowstride, placey, placex, ncv->data, nc->tcache.cellpixx);
blitterargs bargs;
if(flags & NCVISUAL_OPTION_ADDALPHA){
bargs.transcolor = transcolor | 0x1000000ul;
@ -1032,7 +1052,7 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
bargs.u.pixel.colorregs = nc->tcache.color_registers;
bargs.u.pixel.pxoffy = pxoffy;
bargs.u.pixel.pxoffx = pxoffx;
int cols = disppixx / nc->tcache.cellpixx + !!(disppixx % nc->tcache.cellpixx);
int cols = outx / nc->tcache.cellpixx + !!(outx % nc->tcache.cellpixx);
int rows = outy / nc->tcache.cellpixy + !!(outy % nc->tcache.cellpixy);
if(n->sprite == NULL){
if((n->sprite = sprixel_alloc(&nc->tcache, n, rows, cols)) == NULL){

@ -690,6 +690,7 @@ TEST_CASE("Bitmaps") {
vopts.pxoffy = yat % nc_->tcache.cellpixy;
CHECK(0 == ncplane_destroy(n));
n = ncvisual_render(nc_, ncv, &vopts);
REQUIRE(nullptr != n);
CHECK(0 == notcurses_render(nc_));
}
ncvisual_destroy(ncv);

Loading…
Cancel
Save