remove placey/placex from pixel chain #1560

pull/1621/head
nick black 3 years ago
parent 1242e06d23
commit 3c574b5866
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -40,7 +40,7 @@ rgba_trans_q(const unsigned char* p, uint32_t transcolor){
static inline int
tria_blit_ascii(ncplane* nc, int linesize, const void* data,
int leny, int lenx, const blitterargs* bargs){
//fprintf(stderr, "ASCII %d X %d @ %d X %d (%p) place: %d X %d\n", leny, lenx, bargs->begy, bargs->begx, data, bargs->placey, bargs->placex);
//fprintf(stderr, "ASCII %d X %d @ %d X %d (%p) place: %d X %d\n", leny, lenx, bargs->begy, bargs->begx, data, bargs->u.cell.placey, bargs->u.cell.placex);
const int bpp = 32;
int dimy, dimx, x, y;
int total = 0; // number of cells written
@ -48,15 +48,15 @@ tria_blit_ascii(ncplane* nc, int linesize, const void* data,
// FIXME not going to necessarily be safe on all architectures hrmmm
const unsigned char* dat = data;
int visy = bargs->begy;
for(y = bargs->placey ; visy < (bargs->begy + leny) && y < dimy ; ++y, ++visy){
for(y = bargs->u.cell.placey ; visy < (bargs->begy + leny) && y < dimy ; ++y, ++visy){
if(y < 0){
continue;
}
if(ncplane_cursor_move_yx(nc, y, bargs->placex < 0 ? 0 : bargs->placex)){
if(ncplane_cursor_move_yx(nc, y, bargs->u.cell.placex < 0 ? 0 : bargs->u.cell.placex)){
return -1;
}
int visx = bargs->begx;
for(x = bargs->placex ; visx < (bargs->begx + lenx) && x < dimx ; ++x, ++visx){
for(x = bargs->u.cell.placex ; visx < (bargs->begx + lenx) && x < dimx ; ++x, ++visx){
if(x < 0){
continue;
}
@ -94,7 +94,7 @@ tria_blit_ascii(ncplane* nc, int linesize, const void* data,
static inline int
tria_blit(ncplane* nc, int linesize, const void* data,
int leny, int lenx, const blitterargs* bargs){
//fprintf(stderr, "HALF %d X %d @ %d X %d (%p) place: %d X %d\n", leny, lenx, bargs->begy, bargs->begx, data, bargs->placey, bargs->placex);
//fprintf(stderr, "HALF %d X %d @ %d X %d (%p) place: %d X %d\n", leny, lenx, bargs->begy, bargs->begx, data, bargs->u.cell.placey, bargs->u.cell.placex);
uint32_t transcolor = bargs->transcolor;
const int bpp = 32;
int dimy, dimx, x, y;
@ -103,15 +103,15 @@ tria_blit(ncplane* nc, int linesize, const void* data,
// FIXME not going to necessarily be safe on all architectures hrmmm
const unsigned char* dat = data;
int visy = bargs->begy;
for(y = bargs->placey ; visy < (bargs->begy + leny) && y < dimy ; ++y, visy += 2){
for(y = bargs->u.cell.placey ; visy < (bargs->begy + leny) && y < dimy ; ++y, visy += 2){
if(y < 0){
continue;
}
if(ncplane_cursor_move_yx(nc, y, bargs->placex < 0 ? 0 : bargs->placex)){
if(ncplane_cursor_move_yx(nc, y, bargs->u.cell.placex < 0 ? 0 : bargs->u.cell.placex)){
return -1;
}
int visx = bargs->begx;
for(x = bargs->placex ; visx < (bargs->begx + lenx) && x < dimx ; ++x, ++visx){
for(x = bargs->u.cell.placex ; visx < (bargs->begx + lenx) && x < dimx ; ++x, ++visx){
if(x < 0){
continue;
}
@ -428,19 +428,19 @@ quadrant_blit(ncplane* nc, int linesize, const void* data,
int dimy, dimx, x, y;
int total = 0; // number of cells written
ncplane_dim_yx(nc, &dimy, &dimx);
//fprintf(stderr, "quadblitter %dx%d -> %d/%d+%d/%d\n", leny, lenx, dimy, dimx, bargs->placey, bargs->placex);
//fprintf(stderr, "quadblitter %dx%d -> %d/%d+%d/%d\n", leny, lenx, dimy, dimx, bargs->u.cell.placey, bargs->u.cell.placex);
// FIXME not going to necessarily be safe on all architectures hrmmm
const unsigned char* dat = data;
int visy = bargs->begy;
for(y = bargs->placey ; visy < (bargs->begy + leny) && y < dimy ; ++y, visy += 2){
for(y = bargs->u.cell.placey ; visy < (bargs->begy + leny) && y < dimy ; ++y, visy += 2){
if(y < 0){
continue;
}
if(ncplane_cursor_move_yx(nc, y, bargs->placex < 0 ? 0 : bargs->placex)){
if(ncplane_cursor_move_yx(nc, y, bargs->u.cell.placex < 0 ? 0 : bargs->u.cell.placex)){
return -1;
}
int visx = bargs->begx;
for(x = bargs->placex ; visx < (bargs->begx + lenx) && x < dimx ; ++x, visx += 2){
for(x = bargs->u.cell.placex ; visx < (bargs->begx + lenx) && x < dimx ; ++x, visx += 2){
if(x < 0){
continue;
}
@ -657,18 +657,18 @@ sextant_blit(ncplane* nc, int linesize, const void* data,
int dimy, dimx, x, y;
int total = 0; // number of cells written
ncplane_dim_yx(nc, &dimy, &dimx);
//fprintf(stderr, "sexblitter %dx%d -> %d/%d+%d/%d\n", leny, lenx, dimy, dimx, bargs->placey, bargs->placex);
//fprintf(stderr, "sexblitter %dx%d -> %d/%d+%d/%d\n", leny, lenx, dimy, dimx, bargs->u.cell.placey, bargs->u.cell.placex);
const unsigned char* dat = data;
int visy = bargs->begy;
for(y = bargs->placey ; visy < (bargs->begy + leny) && y < dimy ; ++y, visy += 3){
for(y = bargs->u.cell.placey ; visy < (bargs->begy + leny) && y < dimy ; ++y, visy += 3){
if(y < 0){
continue;
}
if(ncplane_cursor_move_yx(nc, y, bargs->placex < 0 ? 0 : bargs->placex)){
if(ncplane_cursor_move_yx(nc, y, bargs->u.cell.placex < 0 ? 0 : bargs->u.cell.placex)){
return -1;
}
int visx = bargs->begx;
for(x = bargs->placex ; visx < (bargs->begx + lenx) && x < dimx ; ++x, visx += 2){
for(x = bargs->u.cell.placex ; visx < (bargs->begx + lenx) && x < dimx ; ++x, visx += 2){
if(x < 0){
continue;
}
@ -734,15 +734,15 @@ braille_blit(ncplane* nc, int linesize, const void* data,
// FIXME not going to necessarily be safe on all architectures hrmmm
const unsigned char* dat = data;
int visy = bargs->begy;
for(y = bargs->placey ; visy < (bargs->begy + leny) && y < dimy ; ++y, visy += 4){
for(y = bargs->u.cell.placey ; visy < (bargs->begy + leny) && y < dimy ; ++y, visy += 4){
if(y < 0){
continue;
}
if(ncplane_cursor_move_yx(nc, y, bargs->placex < 0 ? 0 : bargs->placex)){
if(ncplane_cursor_move_yx(nc, y, bargs->u.cell.placex < 0 ? 0 : bargs->u.cell.placex)){
return -1;
}
int visx = bargs->begx;
for(x = bargs->placex ; visx < (bargs->begx + lenx) && x < dimx ; ++x, visx += 2){
for(x = bargs->u.cell.placex ; visx < (bargs->begx + lenx) && x < dimx ; ++x, visx += 2){
if(x < 0){
continue;
}
@ -1006,10 +1006,10 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v
return -1;
}
blitterargs bargs = {
.placey = vopts->y,
.placex = vopts->x,
.u = {
.cell = {
.placey = vopts->y,
.placex = vopts->x,
.blendcolors = (vopts->flags & NCVISUAL_OPTION_BLEND),
},
},

@ -619,11 +619,11 @@ typedef struct notcurses {
typedef struct blitterargs {
int begy; // upper left start within visual
int begx;
int placey; // placement within ncplane
int placex;
uint32_t transcolor; // if non-zero, treat the lower 24 bits as a transparent color
union { // cell vs pixel-specific arguments
struct {
int placey; // placement within ncplane
int placex;
int blendcolors; // use CELL_ALPHA_BLEND
} cell; // for cells
struct {
@ -1251,7 +1251,7 @@ void free_plane(ncplane* p);
// heap-allocated formatted output
ALLOC char* ncplane_vprintf_prep(const char* format, va_list ap);
// Resize the provided ncviusal to the specified 'rows' x 'cols', but do not
// Resize the provided ncvisual to the specified 'rows' x 'cols', but do not
// change the internals of the ncvisual. Uses oframe.
int ncvisual_blit(struct ncvisual* ncv, int rows, int cols,
ncplane* n, const struct blitset* bset,
@ -1464,17 +1464,15 @@ egc_rtl(const char* egc, int* bytes){
// new, purpose-specific plane.
static inline int
plane_blit_sixel(sprixel* spx, char* s, int bytes, int rows, int cols,
int placey, int placex, int leny, int lenx,
int parse_start, tament* tam){
int leny, int lenx, int parse_start, tament* tam){
if(sprixel_load(spx, s, bytes, leny, lenx, parse_start)){
return -1;
}
ncplane* n = spx->n;
uint32_t gcluster = htole(0x02000000ul) + htole(spx->id);
// FIXME rows/cols ought never exceed the size, just as placey/placex
// ought never be negative. why need we check the former?
for(int y = placey ; y < placey + rows && y < ncplane_dim_y(n) ; ++y){
for(int x = placex ; x < placex + cols && x < ncplane_dim_x(n) ; ++x){
// FIXME rows/cols ought never exceed the size, right?. why need we check?
for(int y = 0 ; y < rows && y < ncplane_dim_y(n) ; ++y){
for(int x = 0 ; x < cols && x < ncplane_dim_x(n) ; ++x){
nccell* c = ncplane_cell_ref_yx(n, y, x);
memcpy(&c->gcluster, &gcluster, sizeof(gcluster));
c->width = cols;

@ -549,7 +549,6 @@ int kitty_blit(ncplane* n, int linesize, const void* data,
}
// take ownership of |buf| and |tam| on success
if(plane_blit_sixel(bargs->u.pixel.spx, buf, size, rows, cols,
bargs->placey, bargs->placex,
leny, lenx, parse_start, tam) < 0){
if(!reuse){
free(tam);

@ -603,15 +603,13 @@ int ncplane_resize_internal(ncplane* n, int keepy, int keepx, int keepleny,
logerror(ncplane_notcurses_const(n), "Can't retain null dimension %dx%d\n", keepleny, keeplenx);
return -1;
}
// can't be smaller than keep length + abs(offset from keep area)
const int yprescribed = keepleny + (yoff < 0 ? -yoff : yoff);
if(ylen < yprescribed){
logerror(ncplane_notcurses_const(n), "Can't map in y dimension: %d < %d\n", ylen, yprescribed);
// can't be smaller than keep length
if(ylen < keepleny){
logerror(ncplane_notcurses_const(n), "Can't map in y dimension: %d < %d\n", ylen, keepleny);
return -1;
}
const int xprescribed = keeplenx + (xoff < 0 ? -xoff : xoff);
if(xlen < xprescribed){
logerror(ncplane_notcurses_const(n), "Can't map in x dimension: %d < %d\n", xlen, xprescribed);
if(xlen < keeplenx){
logerror(ncplane_notcurses_const(n), "Can't map in x dimension: %d < %d\n", xlen, keeplenx);
return -1;
}
if(ylen <= 0 || xlen <= 0){ // can't resize to trivial or negative size
@ -2422,6 +2420,9 @@ ncplane* ncplane_reparent_family(ncplane* n, ncplane* newparent){
n->bnext->bprev = n->bprev;
}
}
// ncplane_notcurses() goes through ncplane_pile(). since we're possibly
// destroying piles below, get the notcurses reference early on.
notcurses* nc = ncplane_notcurses(n);
// if leaving a pile, extract n from the old zaxis, and also any sprixel
sprixel* s = NULL;
if(n == newparent || ncplane_pile(n) != ncplane_pile(newparent)){
@ -2433,12 +2434,12 @@ ncplane* ncplane_reparent_family(ncplane* n, ncplane* newparent){
n->bnext = NULL;
n->bprev = NULL;
splice_zaxis_recursive(n);
pthread_mutex_lock(&ncplane_notcurses(n)->pilelock);
pthread_mutex_lock(&nc->pilelock);
if(ncplane_pile(n)->top == NULL){ // did we just empty our pile?
ncpile_destroy(ncplane_pile(n));
}
make_ncpile(ncplane_notcurses(n), n);
pthread_mutex_unlock(&ncplane_notcurses(n)->pilelock);
pthread_mutex_unlock(&nc->pilelock);
}else{ // establish ourselves as a sibling of new parent's children
if( (n->bnext = newparent->blist) ){
n->bnext->bprev = &n->bnext;
@ -2448,12 +2449,12 @@ ncplane* ncplane_reparent_family(ncplane* n, ncplane* newparent){
// place it immediately above the new binding plane if crossing piles
if(n->pile != ncplane_pile(n->boundto)){
splice_zaxis_recursive(n);
pthread_mutex_lock(&ncplane_notcurses(n)->pilelock);
pthread_mutex_lock(&nc->pilelock);
if(ncplane_pile(n)->top == NULL){ // did we just empty our pile?
ncpile_destroy(ncplane_pile(n));
}
pthread_mutex_unlock(&ncplane_notcurses(n)->pilelock);
n->pile = ncplane_pile(n->boundto);
pthread_mutex_unlock(&nc->pilelock);
}
}
if(s){ // must be on new plane, with sprixels to donate

@ -596,7 +596,6 @@ sixel_blit_inner(int leny, int lenx, const sixeltable* stab, int rows, int cols,
bargs->u.pixel.celldimx);
// take ownership of buf on success
if(plane_blit_sixel(bargs->u.pixel.spx, buf, size, rows, cols,
bargs->placey, bargs->placex,
leny, lenx, parse_start, tam) < 0){
free(buf);
return -1;

@ -600,8 +600,8 @@ ncplane* ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const struct blitse
}
bargs.begy = begy;
bargs.begx = begx;
bargs.placey = placey;
bargs.placex = placex;
bargs.u.cell.placey = placey;
bargs.u.cell.placex = placex;
bargs.u.cell.blendcolors = flags & NCVISUAL_OPTION_BLEND;
if(ncvisual_blit(ncv, disprows, dispcols, n, bset, leny, lenx, &bargs)){
ncplane_destroy(createdn);
@ -692,28 +692,6 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
clamp_to_sixelmax(&nc->tcache, &disprows, &dispcols);
}
}
// FIXME why are we allowing arbitrary location within a plane?
if(flags & NCVISUAL_OPTION_HORALIGNED){
if(placex == NCALIGN_CENTER){
placex = (ncplane_dim_x(n) - dispcols / nc->tcache.cellpixx) / 2;
}else if(placex == NCALIGN_RIGHT){
placex = ncplane_dim_x(n) - dispcols / nc->tcache.cellpixx;
}
if(placex < 0){
return NULL;
}
}
if(flags & NCVISUAL_OPTION_VERALIGNED){
if(placey == NCALIGN_CENTER){
// FIXME why are these calculations structurally different from HORALIGNED above?
placey = ((ncplane_dim_y(n) * nc->tcache.cellpixy - disprows) / 2) / nc->tcache.cellpixy;
}else if(placey == NCALIGN_BOTTOM){
placey = ncplane_dim_y(n) * nc->tcache.cellpixy - disprows / nc->tcache.cellpixy;
}
if(placey < 0){
return NULL;
}
}
//fprintf(stderr, "pblit: %dx%d <- %dx%d of %d/%d stride %u @%dx%d %p %u\n", disprows, dispcols, begy, begx, ncv->pixy, ncv->pixx, ncv->rowstride, placey, placex, ncv->data, nc->tcache.cellpixx);
blitterargs bargs;
if(flags & NCVISUAL_OPTION_ADDALPHA){
@ -748,11 +726,36 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
ncplane_destroy(createdn);
return NULL;
}
// if we created the plane earlier, placex/placey were taken into account, and
// zeroed out, thus neither of these will have any effect.
if(flags & NCVISUAL_OPTION_HORALIGNED){
if(placex == NCALIGN_CENTER){
placex = (ncplane_dim_x(ncplane_parent_const(n)) * nc->tcache.cellpixx - dispcols) / 2 / nc->tcache.cellpixx;
}else if(placex == NCALIGN_RIGHT){
placex = (ncplane_dim_x(ncplane_parent_const(n)) * nc->tcache.cellpixy - dispcols) / nc->tcache.cellpixx;
}
if(placex < 0){
return NULL;
}
}
if(flags & NCVISUAL_OPTION_VERALIGNED){
if(placey == NCALIGN_CENTER){
placey = (ncplane_dim_y(ncplane_parent_const(n)) * nc->tcache.cellpixy - disprows) / 2 / nc->tcache.cellpixy;
}else if(placey == NCALIGN_BOTTOM){
placey = (ncplane_dim_y(ncplane_parent_const(n)) * nc->tcache.cellpixy - disprows) / nc->tcache.cellpixy;
}
if(placey < 0){
return NULL;
}
}
// ncplane_resize() hides any attached sprixel, so lift it (the sprixel) out
// for a moment as we shrink the plane to fit.
// for a moment as we shrink the plane to fit. we keep the origin and move to
// the intended location.
sprixel* s = n->sprite;
n->sprite = NULL;
if(ncplane_resize(n, placey, placex, s->dimy, s->dimx, 0, 0, s->dimy, s->dimx)){
// FIXME might need shrink down the TAM and kill unnecessary auxvecs
if(ncplane_resize(n, 0, 0, s->dimy, s->dimx, placey - ncplane_y(n),
placex - ncplane_x(n), s->dimy, s->dimx)){
sprixel_hide(bargs.u.pixel.spx);
ncplane_destroy(createdn);
return NULL;

Loading…
Cancel
Save