diff --git a/USAGE.md b/USAGE.md index d1a89648b..76475e6ce 100644 --- a/USAGE.md +++ b/USAGE.md @@ -3068,8 +3068,8 @@ int ncvisual_blitter_geom(const struct notcurses* nc, const struct ncvisual* n, const struct ncvisual_options* vopts, int* y, int* x, int* scaley, int* scalex, ncblitter_e* blitter); -// Rotate the visual 'rads' radians. Only M_PI/2 and -M_PI/2 are -// supported at the moment, but this will change FIXME. +// Scale the visual to 'rows' X 'columns' pixels, using the best scheme +// available. This is a lossy transformation, unless the size is unchanged. int ncvisual_rotate(struct ncvisual* n, double rads); // Resize the visual so that it is 'rows' X 'columns'. This is a lossy diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 24902e941..2bd9e18c1 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -2735,7 +2735,7 @@ API int ncvisual_decode_loop(struct ncvisual* nc) API int ncvisual_rotate(struct ncvisual* n, double rads) __attribute__ ((nonnull (1))); -// Resize the visual so that it is 'rows' X 'columns', using the best scheme +// Scale the visual to 'rows' X 'columns' pixels, using the best scheme // available. This is a lossy transformation, unless the size is unchanged. API int ncvisual_resize(struct ncvisual* n, int rows, int cols) __attribute__ ((nonnull (1))); diff --git a/src/lib/visual.c b/src/lib/visual.c index 0b7e602d4..8bd3594af 100644 --- a/src/lib/visual.c +++ b/src/lib/visual.c @@ -106,7 +106,7 @@ ncvisual_blitset_geom(const notcurses* nc, const ncvisual* n, return -1; } if(n){ -//fprintf(stderr, "OUR DATA: %p rows/cols: %d/%d\n", ncv->data, ncv->rows, ncv->cols); +//fprintf(stderr, "OUR DATA: %p rows/cols: %d/%d\n", n->data, n->rows, n->cols); if(n->data == NULL){ logerror(nc, "No data in visual\n"); return -1; @@ -906,7 +906,10 @@ int ncvisual_resize(ncvisual* nc, int rows, int cols){ if(!visual_implementation){ return -1; } - return visual_implementation->visual_resize(nc, rows, cols); + if(visual_implementation->visual_resize(nc, rows, cols)){ + return -1; + } + return 0; } // Inflate each pixel of 'bmap' to 'scale'x'scale' pixels square, using the diff --git a/src/pocpp/visual.cpp b/src/pocpp/visual.cpp index 14b63abd3..5cb46be16 100644 --- a/src/pocpp/visual.cpp +++ b/src/pocpp/visual.cpp @@ -51,7 +51,9 @@ int main(int argc, char** argv){ ncplane_erase(n); ncvisual_blitter_geom(nc, ncv, &vopts, nullptr, nullptr, &scaley, &scalex, nullptr); - ncvisual_resize(ncv, dimy * scaley, dimx * scalex); + if(ncvisual_resize(ncv, dimy * scaley, dimx * scalex)){ + goto err; + } vopts.n = n; if(ncvisual_render(nc, ncv, &vopts) == nullptr){ goto err; diff --git a/src/tests/bitmap.cpp b/src/tests/bitmap.cpp index 5125aba4a..f0d1b6fde 100644 --- a/src/tests/bitmap.cpp +++ b/src/tests/bitmap.cpp @@ -50,7 +50,7 @@ TEST_CASE("Bitmaps") { .scaling = NCSCALE_NONE, .y = 0, .x = 0, .begy = 0, .begx = 0, - .leny = y, .lenx = x, + .leny = 0, .lenx = 0, .blitter = NCBLIT_PIXEL, .flags = NCVISUAL_OPTION_NODEGRADE, .transcolor = 0, @@ -71,10 +71,11 @@ TEST_CASE("Bitmaps") { .flags = 0, .margin_b = 0, .margin_r = 0, }; vopts.scaling = NCSCALE_SCALE; - vopts.n = ncplane_create(n_, &nopts); - REQUIRE(vopts.n); + auto bigp = ncplane_create(n_, &nopts); + REQUIRE(bigp); + vopts.n = bigp; uint64_t white = CHANNELS_RGB_INITIALIZER(0xff, 0xff, 0xff, 0xff, 0xff, 0xff); - ncplane_set_base(vopts.n, "x", 0, white); + ncplane_set_base(bigp, "x", 0, white); CHECK(vopts.n == ncvisual_render(nc_, ncv, &vopts)); CHECK(0 == notcurses_render(nc_)); CHECK(0 == ncvisual_inflate(ncv, 4)); @@ -89,7 +90,18 @@ TEST_CASE("Bitmaps") { CHECK(4 == ncplane_dim_y(infn)); CHECK(4 == ncplane_dim_x(infn)); CHECK(0 == notcurses_render(nc_)); - CHECK(0 == ncplane_destroy(vopts.n)); + CHECK(0 == ncvisual_resize(ncv, 8, 8)); + CHECK(ncv->rows == 8); + CHECK(ncv->cols == 8); + vopts.x = 11; + auto resizen = ncvisual_render(nc_, ncv, &vopts); + REQUIRE(resizen); + CHECK((8 + nc_->tcache.cellpixy - 1) / nc_->tcache.cellpixy == ncplane_dim_y(resizen)); + CHECK((8 + nc_->tcache.cellpixx - 1) / nc_->tcache.cellpixx == ncplane_dim_x(resizen)); + CHECK(0 == notcurses_render(nc_)); + CHECK(0 == ncplane_destroy(bigp)); + CHECK(0 == ncplane_destroy(resizen)); + CHECK(0 == ncplane_destroy(infn)); CHECK(0 == ncplane_destroy(n)); ncvisual_destroy(ncv); }