[ncvgeom] perform further checks

pull/2320/head
nick black 3 years ago committed by nick black
parent 2aabc30148
commit 95f4ea32aa

@ -161,21 +161,26 @@ int ncvisual_geom_inner(const tinfo* ti, const ncvisual* n,
logerror("got NULL for both sources\n"); logerror("got NULL for both sources\n");
return -1; return -1;
} }
struct ncvisual_options fakevopts;
if(vopts == NULL){
memset(&fakevopts, 0, sizeof(fakevopts));
vopts = &fakevopts;
}
// check basic vopts preconditions // check basic vopts preconditions
if(vopts && vopts->flags >= (NCVISUAL_OPTION_NOINTERPOLATE << 1u)){ if(vopts->flags >= (NCVISUAL_OPTION_NOINTERPOLATE << 1u)){
logwarn("Warning: unknown ncvisual options %016" PRIx64 "\n", vopts->flags); logwarn("Warning: unknown ncvisual options %016" PRIx64 "\n", vopts->flags);
} }
if(vopts && (vopts->flags & NCVISUAL_OPTION_CHILDPLANE) && !vopts->n){ if((vopts->flags & NCVISUAL_OPTION_CHILDPLANE) && !vopts->n){
logerror("Requested child plane with NULL n\n"); logerror("Requested child plane with NULL n\n");
return -1; return -1;
} }
if(vopts && vopts->flags & NCVISUAL_OPTION_HORALIGNED){ if(vopts->flags & NCVISUAL_OPTION_HORALIGNED){
if(vopts->x < NCALIGN_UNALIGNED || vopts->x > NCALIGN_RIGHT){ if(vopts->x < NCALIGN_UNALIGNED || vopts->x > NCALIGN_RIGHT){
logerror("Bad x %d for horizontal alignment\n", vopts->x); logerror("Bad x %d for horizontal alignment\n", vopts->x);
return -1; return -1;
} }
} }
if(vopts && vopts->flags & NCVISUAL_OPTION_VERALIGNED){ if(vopts->flags & NCVISUAL_OPTION_VERALIGNED){
if(vopts->y < NCALIGN_UNALIGNED || vopts->y > NCALIGN_RIGHT){ if(vopts->y < NCALIGN_UNALIGNED || vopts->y > NCALIGN_RIGHT){
logerror("Bad y %d for vertical alignment\n", vopts->y); logerror("Bad y %d for vertical alignment\n", vopts->y);
return -1; return -1;
@ -209,8 +214,8 @@ int ncvisual_geom_inner(const tinfo* ti, const ncvisual* n,
} }
// determine how much of the original image we're using (leny/lenx) // determine how much of the original image we're using (leny/lenx)
ncvisual_origin(vopts, &geom->begy, &geom->begx); ncvisual_origin(vopts, &geom->begy, &geom->begx);
geom->lenx = vopts ? vopts->lenx : 0; geom->lenx = vopts->lenx;
geom->leny = vopts ? vopts->leny : 0; geom->leny = vopts->leny;
logdebug("blit %dx%d+%dx%d %p\n", geom->begy, geom->begx, geom->leny, geom->lenx, n->data); logdebug("blit %dx%d+%dx%d %p\n", geom->begy, geom->begx, geom->leny, geom->lenx, n->data);
if(geom->begy < 0 || geom->begx < 0){ if(geom->begy < 0 || geom->begx < 0){
logerror("invalid geometry for visual %d %d %d %d\n", geom->begy, geom->begx, geom->leny, geom->lenx); logerror("invalid geometry for visual %d %d %d %d\n", geom->begy, geom->begx, geom->leny, geom->lenx);
@ -238,12 +243,10 @@ int ncvisual_geom_inner(const tinfo* ti, const ncvisual* n,
logerror("geometry too large %d > %d or %d > %d\n", geom->begy + geom->leny, n->pixy, geom->begx + geom->lenx, n->pixx); logerror("geometry too large %d > %d or %d > %d\n", geom->begy + geom->leny, n->pixy, geom->begx + geom->lenx, n->pixx);
return -1; return -1;
} }
/* if((*bset)->geom == NCBLIT_PIXEL){
// FIXME several unsafe uses of NULL nc within here!
if(vopts){
if(bset->geom == NCBLIT_PIXEL){
if(vopts->n){ if(vopts->n){
if(vopts->n == notcurses_stdplane_const(nc)){ // FIXME does this work from direct mode?
if(vopts->n == notcurses_stdplane_const(ncplane_notcurses_const(vopts->n))){
if(!(vopts->flags & NCVISUAL_OPTION_CHILDPLANE)){ if(!(vopts->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 -1; return -1;
@ -259,26 +262,24 @@ int ncvisual_geom_inner(const tinfo* ti, const ncvisual* n,
} }
// FIXME clamp to sprixel limits // FIXME clamp to sprixel limits
if(vopts->scaling == NCSCALE_NONE || vopts->scaling == NCSCALE_NONE_HIRES){ if(vopts->scaling == NCSCALE_NONE || vopts->scaling == NCSCALE_NONE_HIRES){
if(vopts->pxoffy >= nc->tcache.cellpixy){ if(vopts->pxoffy >= ti->cellpixy){
logerror("pixel y-offset %d too tall for cell %d\n", vopts->pxoffy, nc->tcache.cellpixy); logerror("pixel y-offset %d too tall for cell %d\n", vopts->pxoffy, ti->cellpixy);
return -1; return -1;
} }
int rows = ((*leny + nc->tcache.cellpixy - 1) / nc->tcache.cellpixy) int rows = ((geom->leny + ti->cellpixy - 1) / ti->cellpixy) + !!vopts->pxoffy;
+ !!vopts->pxoffy;
if(rows > ncplane_dim_y(vopts->n)){ if(rows > ncplane_dim_y(vopts->n)){
logerror("sprixel too tall %d for plane %d\n", logerror("sprixel too tall %d for plane %d\n", geom->leny + vopts->pxoffy,
*leny + vopts->pxoffy, ncplane_dim_y(vopts->n) * nc->tcache.cellpixy); ncplane_dim_y(vopts->n) * ti->cellpixy);
return -1; return -1;
} }
if(vopts->pxoffx >= nc->tcache.cellpixx){ if(vopts->pxoffx >= ti->cellpixx){
logerror("pixel x-offset %d too wide for cell %d\n", vopts->pxoffx, nc->tcache.cellpixx); logerror("pixel x-offset %d too wide for cell %d\n", vopts->pxoffx, ti->cellpixx);
return -1; return -1;
} }
int cols = ((*lenx + nc->tcache.cellpixx - 1) / nc->tcache.cellpixx) int cols = ((geom->lenx + ti->cellpixx - 1) / ti->cellpixx) + !!vopts->pxoffx;
+ !!vopts->pxoffx;
if(cols > ncplane_dim_x(vopts->n)){ if(cols > ncplane_dim_x(vopts->n)){
logerror("sprixel too wide %d for plane %d\n", logerror("sprixel too wide %d for plane %d\n", geom->lenx + vopts->pxoffx,
*lenx + vopts->pxoffx, ncplane_dim_x(vopts->n) * nc->tcache.cellpixx); ncplane_dim_x(vopts->n) * ti->cellpixx);
return -1; return -1;
} }
} }
@ -289,8 +290,6 @@ int ncvisual_geom_inner(const tinfo* ti, const ncvisual* n,
return -1; return -1;
} }
} }
}
*/
return 0; return 0;
} }

Loading…
Cancel
Save