diff --git a/src/lib/sprite.c b/src/lib/sprite.c index 57ecd7c11..53bfccd03 100644 --- a/src/lib/sprite.c +++ b/src/lib/sprite.c @@ -157,11 +157,11 @@ int sprixel_load(sprixel* spx, fbuf* f, int pixy, int pixx, int parse_start, sprixel_e state){ assert(spx->n); if(spx->cellpxy > 0){ // don't explode on ncdirect case - if((pixy + spx->cellpxy - 1) / spx->cellpxy != spx->dimy){ + if((pixy + spx->cellpxy - 1) / spx->cellpxy > spx->dimy){ logerror("bad pixy %d (cellpxy %d dimy %d)\n", pixy, spx->cellpxy, spx->dimy); return -1; } - if((pixx + spx->cellpxx - 1) / spx->cellpxx != spx->dimx){ + if((pixx + spx->cellpxx - 1) / spx->cellpxx > spx->dimx){ logerror("bad pixx %d (cellpxx %d dimx %d)\n", pixx, spx->cellpxx, spx->dimx); return -1; } diff --git a/src/tests/bitmap.cpp b/src/tests/bitmap.cpp index c222fa7f1..95ba13644 100644 --- a/src/tests/bitmap.cpp +++ b/src/tests/bitmap.cpp @@ -270,7 +270,7 @@ TEST_CASE("Bitmaps") { } // create an image of exactly 1 cell, inflate it, scale it, and compare the - // resulting geometries for equality + // resulting geometries for (rough) equality SUBCASE("InflateVsScale") { // first, assemble a visual equivalent to 1 cell auto y = nc_->tcache.cellpixy; @@ -287,32 +287,44 @@ TEST_CASE("Bitmaps") { struct ncplane_options nopts = { .y = 2, .x = 0, - .rows = 4, + .rows = 5, .cols = 4, .userptr = nullptr, .name = "scale", .resizecb = nullptr, .flags = 0, .margin_b = 0, .margin_r = 0, }; - auto nres = ncplane_create(n_, &nopts); - REQUIRE(nullptr != nres); - vopts.n = nres; + auto scal = ncplane_create(n_, &nopts); + REQUIRE(nullptr != scal); + vopts.n = scal; vopts.scaling = NCSCALE_SCALE; - ncvisual_blit(nc_, ncv, &vopts); + auto bmap = ncvisual_blit(nc_, ncv, &vopts); + REQUIRE(nullptr != bmap); CHECK(4 == ncplane_dim_x(vopts.n)); - CHECK(0 == ncvisual_resize_noninterpolative(ncv, ncv->pixy * 4, ncv->pixx * 4)); - vopts.n = nres; + CHECK(0 == ncvisual_resize_noninterpolative(ncv, ncv->pixy * 5, ncv->pixx * 4)); + vopts.n = scal; vopts.y = 2; vopts.x = 5; vopts.scaling = NCSCALE_NONE; auto ninf = ncvisual_blit(nc_, ncv, &vopts); + ncplane_set_name(ninf, "ninf"); notcurses_debug(nc_, stderr); REQUIRE(nullptr != ninf); - CHECK(ncplane_dim_y(nres) == ncplane_dim_y(ninf)); - CHECK(ncplane_dim_x(nres) == ncplane_dim_x(ninf)); + // y of scaled might not be exactly equal to y of inflated since one + // is based around what can be fit into a specific space, whereas the + // other is based on a multiple of the original image size, which might + // not be a multiple of the sixel quantum. + CHECK(5 == ncplane_dim_y(scal)); + if(5 >= ncplane_dim_y(ninf)){ + CHECK(5 == ncplane_dim_y(ninf)); + }else{ + CHECK(6 == ncplane_dim_y(ninf)); + } + CHECK(ncplane_dim_x(scal) == ncplane_dim_x(ninf)); CHECK(0 == notcurses_render(nc_)); ncvisual_destroy(ncv); CHECK(0 == ncplane_destroy(n)); CHECK(0 == ncplane_destroy(ninf)); - CHECK(0 == ncplane_destroy(nres)); + CHECK(0 == ncplane_destroy(scal)); + CHECK(0 == ncplane_destroy(bmap)); } // test NCVISUAL_OPTIONS_CHILDPLANE + stretch + (null) alignment