ncvisual_blitset_geom: no pixel size checks for scale/stretch #1572

This commit is contained in:
nick black 2021-04-24 05:16:18 -04:00
parent 311fbfa8e8
commit dc87bd7c79
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 14 additions and 10 deletions

View File

@ -158,15 +158,19 @@ ncvisual_blitset_geom(const notcurses* nc, const ncvisual* n,
logerror(nc, "Non-origin x placement %d for sprixel\n", vopts->x);
return -1;
}
int rows = (*leny + nc->tcache.cellpixy - 1) / nc->tcache.cellpixy;
if(rows > ncplane_dim_y(vopts->n) * nc->tcache.cellpixy){
logerror(nc, "Sprixel too tall %d for plane %d\n", *leny, ncplane_dim_y(vopts->n) * nc->tcache.cellpixy);
return -1;
}
int cols = (*lenx + nc->tcache.cellpixx - 1) / nc->tcache.cellpixx;
if(cols > ncplane_dim_x(vopts->n) * nc->tcache.cellpixx){
logerror(nc, "Sprixel too wide %d for plane %d\n", *lenx, ncplane_dim_x(vopts->n) * nc->tcache.cellpixx);
return -1;
// FIXME clamp to sprixel limits
if(vopts->scaling == NCSCALE_NONE || vopts->scaling == NCSCALE_NONE_HIRES){
int rows = (*leny + nc->tcache.cellpixy - 1) / nc->tcache.cellpixy;
fprintf(stderr, "rows: %d dim: %d\n", rows, ncplane_dim_y(vopts->n));
if(rows > ncplane_dim_y(vopts->n)){
logerror(nc, "Sprixel too tall %d for plane %d\n", *leny, ncplane_dim_y(vopts->n) * nc->tcache.cellpixy);
return -1;
}
int cols = (*lenx + nc->tcache.cellpixx - 1) / nc->tcache.cellpixx;
if(cols > ncplane_dim_x(vopts->n)){
logerror(nc, "Sprixel too wide %d for plane %d\n", *lenx, ncplane_dim_x(vopts->n) * nc->tcache.cellpixx);
return -1;
}
}
}
}

View File

@ -48,7 +48,7 @@ TEST_CASE("Bitmaps") {
// a sprixel requires a plane large enough to hold it
SUBCASE("SprixelTooTall") {
auto y = nc_->tcache.cellpixy + 1;
auto y = nc_->tcache.cellpixy + 6;
auto x = nc_->tcache.cellpixx;
std::vector<uint32_t> v(x * y, htole(0xe61c28ff));
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);