From dc87bd7c793237b2c2899cd1dbc32157298934c9 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 24 Apr 2021 05:16:18 -0400 Subject: [PATCH] ncvisual_blitset_geom: no pixel size checks for scale/stretch #1572 --- src/lib/visual.c | 22 +++++++++++++--------- src/tests/bitmap.cpp | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/lib/visual.c b/src/lib/visual.c index cd63b5c16..9814d7b38 100644 --- a/src/lib/visual.c +++ b/src/lib/visual.c @@ -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; + } } } } diff --git a/src/tests/bitmap.cpp b/src/tests/bitmap.cpp index 4244694b5..d6c4e36f3 100644 --- a/src/tests/bitmap.cpp +++ b/src/tests/bitmap.cpp @@ -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 v(x * y, htole(0xe61c28ff)); auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);