2021-03-14 21:54:36 +00:00
|
|
|
#include "main.h"
|
2021-04-18 14:34:37 +00:00
|
|
|
#include "visual-details.h"
|
2021-03-20 07:00:29 +00:00
|
|
|
#include <vector>
|
2021-03-14 21:54:36 +00:00
|
|
|
|
2021-04-16 11:05:14 +00:00
|
|
|
TEST_CASE("Bitmaps") {
|
2021-03-14 21:54:36 +00:00
|
|
|
auto nc_ = testing_notcurses();
|
|
|
|
REQUIRE(nullptr != nc_);
|
|
|
|
auto n_ = notcurses_stdplane(nc_);
|
|
|
|
REQUIRE(n_);
|
|
|
|
|
2021-06-22 02:20:58 +00:00
|
|
|
if(!notcurses_check_pixel_support(nc_)){
|
2021-03-14 21:54:36 +00:00
|
|
|
CHECK(!notcurses_stop(nc_));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-20 07:00:29 +00:00
|
|
|
SUBCASE("SprixelTermValues") {
|
|
|
|
CHECK(0 < nc_->tcache.cellpixy);
|
|
|
|
CHECK(0 < nc_->tcache.cellpixx);
|
2021-06-22 19:55:53 +00:00
|
|
|
CHECK(nc_->tcache.pixel_draw);
|
2021-03-20 07:00:29 +00:00
|
|
|
}
|
|
|
|
|
2021-05-16 10:57:48 +00:00
|
|
|
SUBCASE("SprixelMinimize") {
|
2021-04-24 05:51:26 +00:00
|
|
|
auto y = 10;
|
|
|
|
auto x = 10;
|
|
|
|
std::vector<uint32_t> v(x * y, htole(0xe61c28ff));
|
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = nullptr,
|
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = 0, .lenx = 0,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
|
|
|
.transcolor = 0,
|
|
|
|
};
|
2021-05-02 21:41:55 +00:00
|
|
|
CHECK(0 == ncvisual_resize(ncv, 1, 1));
|
2021-04-24 05:51:26 +00:00
|
|
|
auto n = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(nullptr != n);
|
|
|
|
auto s = n->sprite;
|
|
|
|
REQUIRE(nullptr != s);
|
|
|
|
ncvisual_destroy(ncv);
|
2021-05-18 03:25:28 +00:00
|
|
|
CHECK(0 == ncplane_destroy(n));
|
2021-04-24 05:51:26 +00:00
|
|
|
}
|
|
|
|
|
2021-05-16 10:57:48 +00:00
|
|
|
SUBCASE("SprixelMaximize") {
|
|
|
|
auto y = 10;
|
|
|
|
auto x = 10;
|
|
|
|
std::vector<uint32_t> v(x * y, htole(0xe61c28ff));
|
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
2021-05-16 11:40:05 +00:00
|
|
|
auto nn = ncplane_dup(n_, nullptr);
|
|
|
|
REQUIRE(nullptr != nn);
|
2021-05-16 10:57:48 +00:00
|
|
|
struct ncvisual_options vopts = {
|
2021-05-16 11:40:05 +00:00
|
|
|
.n = nn,
|
2021-05-16 10:57:48 +00:00
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = 0, .lenx = 0,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
|
|
|
.transcolor = 0,
|
|
|
|
};
|
|
|
|
int maxy, maxx;
|
|
|
|
ncplane_pixelgeom(n_, nullptr, nullptr, nullptr, nullptr, &maxy, &maxx);
|
|
|
|
CHECK(0 == ncvisual_resize(ncv, maxy, maxx));
|
|
|
|
auto n = ncvisual_render(nc_, ncv, &vopts);
|
2021-05-16 11:40:05 +00:00
|
|
|
REQUIRE(nn == n);
|
2021-05-16 10:57:48 +00:00
|
|
|
auto s = n->sprite;
|
|
|
|
REQUIRE(nullptr != s);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncvisual_destroy(ncv);
|
2021-05-16 11:40:05 +00:00
|
|
|
CHECK(0 == ncplane_destroy(nn));
|
2021-05-16 10:57:48 +00:00
|
|
|
}
|
|
|
|
|
2021-04-24 08:41:23 +00:00
|
|
|
// a sprixel requires a plane large enough to hold it
|
2021-04-24 08:47:05 +00:00
|
|
|
SUBCASE("SprixelTooTall") {
|
2021-04-24 09:16:18 +00:00
|
|
|
auto y = nc_->tcache.cellpixy + 6;
|
2021-04-24 08:47:05 +00:00
|
|
|
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);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.rows = 1, .cols = 1,
|
|
|
|
.userptr = nullptr, .name = "small", .resizecb = nullptr,
|
|
|
|
.flags = 0, .margin_b = 0, .margin_r = 0,
|
|
|
|
};
|
|
|
|
auto n = ncplane_create(n_, &nopts);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = n,
|
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = 0,
|
|
|
|
.x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = 0, .lenx = 0,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
|
|
|
.transcolor = 0,
|
|
|
|
};
|
|
|
|
CHECK(nullptr == ncvisual_render(nc_, ncv, &vopts));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == ncplane_destroy(n));
|
|
|
|
}
|
|
|
|
|
|
|
|
SUBCASE("SprixelTooWide") {
|
|
|
|
auto y = nc_->tcache.cellpixy;
|
2021-04-24 08:41:23 +00:00
|
|
|
auto x = nc_->tcache.cellpixx + 1;
|
|
|
|
std::vector<uint32_t> v(x * y, htole(0xe61c28ff));
|
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.rows = 1, .cols = 1,
|
|
|
|
.userptr = nullptr, .name = "small", .resizecb = nullptr,
|
|
|
|
.flags = 0, .margin_b = 0, .margin_r = 0,
|
|
|
|
};
|
|
|
|
auto n = ncplane_create(n_, &nopts);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = n,
|
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = 0,
|
|
|
|
.x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = 0, .lenx = 0,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
|
|
|
.transcolor = 0,
|
|
|
|
};
|
|
|
|
CHECK(nullptr == ncvisual_render(nc_, ncv, &vopts));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-24 08:47:05 +00:00
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == ncplane_destroy(n));
|
2021-04-24 17:08:09 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-24 08:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// should not be able to emit glyphs to a sprixelated plane
|
|
|
|
SUBCASE("SprixelNoGlyphs") {
|
|
|
|
auto y = nc_->tcache.cellpixy;
|
|
|
|
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);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.rows = 1, .cols = 1,
|
|
|
|
.userptr = nullptr, .name = "small", .resizecb = nullptr,
|
|
|
|
.flags = 0, .margin_b = 0, .margin_r = 0,
|
|
|
|
};
|
|
|
|
auto n = ncplane_create(n_, &nopts);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = n,
|
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = 0,
|
|
|
|
.x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = 0, .lenx = 0,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
|
|
|
.transcolor = 0,
|
|
|
|
};
|
|
|
|
CHECK(nullptr != ncvisual_render(nc_, ncv, &vopts));
|
|
|
|
CHECK(0 > ncplane_putchar_yx(n, ' ', 0, 0));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-24 08:41:23 +00:00
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == ncplane_destroy(n));
|
2021-04-24 17:08:09 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-24 08:41:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-24 14:10:20 +00:00
|
|
|
SUBCASE("BitmapStack") {
|
|
|
|
auto y = nc_->tcache.cellpixy * 10;
|
|
|
|
auto x = nc_->tcache.cellpixx * 10;
|
|
|
|
std::vector<uint32_t> v(x * y, htole(0xe61c28ff));
|
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = nullptr, .scaling = NCSCALE_NONE,
|
|
|
|
.y = 0,
|
|
|
|
.x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = 0, .lenx = 0,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
|
|
|
.transcolor = 0,
|
|
|
|
};
|
|
|
|
auto botn = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(nullptr != botn);
|
|
|
|
// should just have a red plane
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
y = nc_->tcache.cellpixy * 5;
|
|
|
|
x = nc_->tcache.cellpixx * 5;
|
|
|
|
std::vector<uint32_t> v2(x * y, htole(0x8142f1ff));
|
|
|
|
auto ncv2 = ncvisual_from_rgba(v2.data(), y, sizeof(decltype(v2)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv2);
|
|
|
|
auto topn = ncvisual_render(nc_, ncv2, &vopts);
|
|
|
|
REQUIRE(nullptr != topn);
|
|
|
|
// should have a yellow plane partially obscuring a red one
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncplane_move_yx(topn, 5, 5);
|
|
|
|
// yellow bitmap ought move to lower right, but remain visible
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncplane_move_top(botn);
|
|
|
|
// should see only the red one now
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
CHECK(0 == ncplane_destroy(botn));
|
|
|
|
ncvisual_destroy(ncv);
|
2021-04-24 17:08:09 +00:00
|
|
|
// now we see only yellow
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
CHECK(0 == ncplane_destroy(topn));
|
2021-04-24 14:10:20 +00:00
|
|
|
ncvisual_destroy(ncv2);
|
2021-04-24 17:08:09 +00:00
|
|
|
// and now we see none
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-24 14:10:20 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 04:13:26 +00:00
|
|
|
#ifdef NOTCURSES_USE_MULTIMEDIA
|
|
|
|
SUBCASE("PixelRender") {
|
2021-06-06 02:45:17 +00:00
|
|
|
auto ncv = ncvisual_from_file(find_data("worldmap.png").get());
|
2021-03-15 04:13:26 +00:00
|
|
|
REQUIRE(ncv);
|
|
|
|
struct ncvisual_options vopts{};
|
|
|
|
vopts.blitter = NCBLIT_PIXEL;
|
2021-03-27 07:47:12 +00:00
|
|
|
vopts.flags = NCVISUAL_OPTION_NODEGRADE;
|
2021-03-15 04:13:26 +00:00
|
|
|
auto newn = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
CHECK(newn);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-18 14:34:37 +00:00
|
|
|
CHECK(0 == ncplane_destroy(newn));
|
2021-03-15 04:13:26 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncvisual_destroy(ncv);
|
2021-04-24 17:08:09 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-15 04:13:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-04-18 14:34:37 +00:00
|
|
|
SUBCASE("BitmapStretch") {
|
|
|
|
// first, assemble a visual equivalent to 1 cell
|
|
|
|
auto y = nc_->tcache.cellpixy;
|
|
|
|
auto x = nc_->tcache.cellpixx;
|
2021-05-06 14:09:20 +00:00
|
|
|
std::vector<uint32_t> v(x * y, htole(0xffffffff));
|
2021-04-18 14:34:37 +00:00
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = nullptr,
|
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
2021-04-18 16:12:13 +00:00
|
|
|
.leny = 0, .lenx = 0,
|
2021-04-18 14:34:37 +00:00
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
|
|
|
.transcolor = 0,
|
|
|
|
};
|
|
|
|
auto n = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(nullptr != n);
|
|
|
|
auto s = n->sprite;
|
|
|
|
REQUIRE(nullptr != s);
|
2021-04-28 03:56:56 +00:00
|
|
|
CHECK(nc_->tcache.cellpixy == ncv->pixy);
|
|
|
|
CHECK(nc_->tcache.cellpixx == ncv->pixx);
|
2021-04-18 14:34:37 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 1,
|
|
|
|
.x = 1,
|
|
|
|
.rows = 4,
|
|
|
|
.cols = 4,
|
|
|
|
.userptr = nullptr, .name = "bigp", .resizecb = nullptr,
|
|
|
|
.flags = 0, .margin_b = 0, .margin_r = 0,
|
|
|
|
};
|
2021-04-18 14:37:22 +00:00
|
|
|
vopts.scaling = NCSCALE_SCALE;
|
2021-04-18 16:12:13 +00:00
|
|
|
auto bigp = ncplane_create(n_, &nopts);
|
|
|
|
REQUIRE(bigp);
|
|
|
|
vopts.n = bigp;
|
2021-07-10 21:54:06 +00:00
|
|
|
uint64_t white = NCCHANNELS_INITIALIZER(0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
|
2021-04-18 16:12:13 +00:00
|
|
|
ncplane_set_base(bigp, "x", 0, white);
|
2021-04-18 14:34:37 +00:00
|
|
|
CHECK(vopts.n == ncvisual_render(nc_, ncv, &vopts));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-06-08 20:32:03 +00:00
|
|
|
CHECK(0 == ncvisual_resize_noninterpolative(ncv, ncv->pixy * 4, ncv->pixx * 4));
|
2021-04-28 03:56:56 +00:00
|
|
|
CHECK(4 * nc_->tcache.cellpixy == ncv->pixy);
|
|
|
|
CHECK(4 * nc_->tcache.cellpixx == ncv->pixx);
|
2021-04-18 14:34:37 +00:00
|
|
|
vopts.y = 1;
|
|
|
|
vopts.x = 6;
|
|
|
|
vopts.n = nullptr;
|
|
|
|
vopts.scaling = NCSCALE_NONE;
|
|
|
|
auto infn = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(infn);
|
2021-05-02 22:04:19 +00:00
|
|
|
if(nc_->tcache.sprixel_scale_height == 6){
|
|
|
|
if(4 * nc_->tcache.cellpixy % 6){
|
|
|
|
CHECK(5 == ncplane_dim_y(infn));
|
|
|
|
}else{
|
|
|
|
CHECK(4 == ncplane_dim_y(infn));
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
CHECK(nc_->tcache.sprixel_scale_height == 1);
|
|
|
|
CHECK(4 == ncplane_dim_y(infn));
|
|
|
|
}
|
2021-04-18 14:34:37 +00:00
|
|
|
CHECK(4 == ncplane_dim_x(infn));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-18 16:12:13 +00:00
|
|
|
CHECK(0 == ncvisual_resize(ncv, 8, 8));
|
2021-04-28 03:56:56 +00:00
|
|
|
CHECK(ncv->pixy == 8);
|
|
|
|
CHECK(ncv->pixx == 8);
|
2021-04-18 16:12:13 +00:00
|
|
|
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));
|
2021-04-18 14:34:37 +00:00
|
|
|
CHECK(0 == ncplane_destroy(n));
|
|
|
|
ncvisual_destroy(ncv);
|
2021-04-24 17:08:09 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-18 14:34:37 +00:00
|
|
|
}
|
|
|
|
|
2021-06-06 18:02:15 +00:00
|
|
|
// create an image of exactly 1 cell, inflate it, scale it, and compare the
|
|
|
|
// resulting geometries for equality
|
|
|
|
SUBCASE("InflateVsScale") {
|
|
|
|
// first, assemble a visual equivalent to 1 cell
|
|
|
|
auto y = nc_->tcache.cellpixy;
|
|
|
|
auto x = nc_->tcache.cellpixx;
|
|
|
|
std::vector<uint32_t> v(x * y, htole(0xff7799dd));
|
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = nullptr,
|
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = 0, .lenx = 0,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
|
|
|
.transcolor = 0,
|
|
|
|
};
|
|
|
|
auto n = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(nullptr != n);
|
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 2,
|
|
|
|
.x = 0,
|
|
|
|
.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;
|
|
|
|
vopts.scaling = NCSCALE_SCALE;
|
|
|
|
ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
CHECK(4 == ncplane_dim_x(vopts.n));
|
2021-06-08 20:32:03 +00:00
|
|
|
CHECK(0 == ncvisual_resize_noninterpolative(ncv, ncv->pixy * 4, ncv->pixx * 4));
|
2021-06-06 18:02:15 +00:00
|
|
|
vopts.n = nullptr;
|
|
|
|
vopts.y = 2;
|
|
|
|
vopts.x = 5;
|
|
|
|
vopts.scaling = NCSCALE_NONE;
|
|
|
|
auto ninf = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(nullptr != ninf);
|
2021-06-06 20:18:25 +00:00
|
|
|
CHECK(ncplane_dim_y(nres) == ncplane_dim_y(ninf));
|
|
|
|
CHECK(ncplane_dim_x(nres) == ncplane_dim_x(ninf));
|
2021-06-06 18:02:15 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == ncplane_destroy(n));
|
|
|
|
CHECK(0 == ncplane_destroy(ninf));
|
|
|
|
CHECK(0 == ncplane_destroy(nres));
|
|
|
|
}
|
|
|
|
|
2021-05-04 22:50:09 +00:00
|
|
|
// test NCVISUAL_OPTIONS_CHILDPLANE + stretch + (null) alignment
|
|
|
|
SUBCASE("ImageChildScaling") {
|
|
|
|
struct ncplane_options opts = {
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.rows = 18, .cols = 5,
|
|
|
|
.userptr = nullptr,
|
|
|
|
.name = "parent",
|
|
|
|
.resizecb = nullptr,
|
|
|
|
.flags = 0,
|
|
|
|
.margin_b = 0,
|
|
|
|
.margin_r = 0,
|
|
|
|
};
|
|
|
|
auto parent = ncplane_create(n_, &opts);
|
|
|
|
REQUIRE(parent);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = parent,
|
|
|
|
.scaling = NCSCALE_STRETCH,
|
|
|
|
.y = NCALIGN_CENTER,
|
|
|
|
.x = NCALIGN_CENTER,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = 0, .lenx = 0,
|
2021-05-04 23:01:20 +00:00
|
|
|
.blitter = NCBLIT_PIXEL,
|
2021-05-04 22:50:09 +00:00
|
|
|
.flags = NCVISUAL_OPTION_CHILDPLANE |
|
|
|
|
NCVISUAL_OPTION_HORALIGNED |
|
|
|
|
NCVISUAL_OPTION_VERALIGNED,
|
|
|
|
.transcolor = 0,
|
|
|
|
};
|
|
|
|
auto y = nc_->tcache.cellpixy * 6;
|
|
|
|
auto x = nc_->tcache.cellpixx;
|
2021-05-06 14:09:20 +00:00
|
|
|
std::vector<uint32_t> v(x * y, htole(0xffffffff));
|
2021-05-04 22:50:09 +00:00
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
auto child = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(child);
|
|
|
|
CHECK(18 == ncplane_dim_y(child));
|
|
|
|
CHECK(5 == ncplane_dim_x(child));
|
|
|
|
CHECK(0 == ncplane_y(child));
|
|
|
|
CHECK(0 == ncplane_x(child));
|
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == ncplane_destroy(parent));
|
|
|
|
CHECK(0 == ncplane_destroy(child));
|
|
|
|
}
|
|
|
|
|
|
|
|
SUBCASE("ImageChildAlignment") {
|
|
|
|
struct ncplane_options opts = {
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.rows = 18, .cols = 5,
|
|
|
|
.userptr = nullptr,
|
|
|
|
.name = "parent",
|
|
|
|
.resizecb = nullptr,
|
|
|
|
.flags = 0,
|
|
|
|
.margin_b = 0,
|
|
|
|
.margin_r = 0,
|
|
|
|
};
|
|
|
|
auto parent = ncplane_create(n_, &opts);
|
|
|
|
REQUIRE(parent);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = parent,
|
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = NCALIGN_CENTER,
|
|
|
|
.x = NCALIGN_CENTER,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = 0, .lenx = 0,
|
2021-05-04 23:01:20 +00:00
|
|
|
.blitter = NCBLIT_PIXEL,
|
2021-05-04 22:50:09 +00:00
|
|
|
.flags = NCVISUAL_OPTION_CHILDPLANE |
|
|
|
|
NCVISUAL_OPTION_HORALIGNED |
|
|
|
|
NCVISUAL_OPTION_VERALIGNED,
|
|
|
|
.transcolor = 0,
|
|
|
|
};
|
|
|
|
auto y = nc_->tcache.cellpixy * 6;
|
|
|
|
auto x = nc_->tcache.cellpixx;
|
2021-05-06 14:09:20 +00:00
|
|
|
std::vector<uint32_t> v(x * y, htole(0xffffffff));
|
2021-05-04 22:50:09 +00:00
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
auto child = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(child);
|
|
|
|
CHECK(6 == ncplane_dim_y(child));
|
|
|
|
CHECK(1 == ncplane_dim_x(child));
|
|
|
|
CHECK(6 == ncplane_y(child));
|
|
|
|
CHECK(2 == ncplane_x(child));
|
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == ncplane_destroy(parent));
|
|
|
|
CHECK(0 == ncplane_destroy(child));
|
|
|
|
}
|
|
|
|
|
2021-03-20 07:00:29 +00:00
|
|
|
SUBCASE("PixelCellWipe") {
|
|
|
|
// first, assemble a visual equivalent to 4 cells
|
2021-03-20 08:44:40 +00:00
|
|
|
auto y = 2 * nc_->tcache.cellpixy;
|
|
|
|
auto x = 2 * nc_->tcache.cellpixx;
|
2021-04-18 14:34:37 +00:00
|
|
|
std::vector<uint32_t> v(x * y, htole(0xffffffff));
|
2021-03-20 07:00:29 +00:00
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = nullptr,
|
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = y, .lenx = x,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
2021-04-10 14:17:41 +00:00
|
|
|
.transcolor = 0,
|
2021-03-20 07:00:29 +00:00
|
|
|
};
|
|
|
|
auto n = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(nullptr != n);
|
|
|
|
auto s = n->sprite;
|
|
|
|
REQUIRE(nullptr != s);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 0, 0, 'x'));
|
2021-03-20 07:00:29 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 1, 1, 'x'));
|
2021-03-20 07:00:29 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 1, 0, 'x'));
|
2021-03-20 07:00:29 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 0, 1, 'x'));
|
2021-03-20 07:00:29 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-18 14:34:37 +00:00
|
|
|
CHECK(0 == ncplane_destroy(n));
|
2021-03-20 07:00:29 +00:00
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
|
|
|
|
2021-03-20 16:00:13 +00:00
|
|
|
SUBCASE("PixelCellWipePolychromatic") {
|
|
|
|
// first, assemble a visual equivalent to 4 cells
|
|
|
|
auto y = 2 * nc_->tcache.cellpixy;
|
|
|
|
auto x = 2 * nc_->tcache.cellpixx;
|
2021-04-18 14:34:37 +00:00
|
|
|
std::vector<uint32_t> v(x * y, htole(0xffffffff));
|
2021-03-20 16:00:13 +00:00
|
|
|
for(auto& e : v){
|
2021-05-06 14:09:20 +00:00
|
|
|
e -= htole(random() % 0x1000000);
|
2021-03-20 16:00:13 +00:00
|
|
|
}
|
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = nullptr,
|
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = y, .lenx = x,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
2021-04-10 14:17:41 +00:00
|
|
|
.transcolor = 0,
|
2021-03-20 16:00:13 +00:00
|
|
|
};
|
|
|
|
auto n = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(nullptr != n);
|
|
|
|
auto s = n->sprite;
|
|
|
|
REQUIRE(nullptr != s);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 0, 0, 'x'));
|
2021-03-20 16:00:13 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 1, 1, 'x'));
|
2021-03-20 16:00:13 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 1, 0, 'x'));
|
2021-03-20 16:00:13 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 0, 1, 'x'));
|
2021-03-20 16:00:13 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-18 14:34:37 +00:00
|
|
|
CHECK(0 == ncplane_destroy(n));
|
2021-03-20 16:00:13 +00:00
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
2021-03-20 21:55:37 +00:00
|
|
|
|
|
|
|
SUBCASE("PixelBigCellWipePolychromatic") {
|
2021-03-31 06:01:39 +00:00
|
|
|
// first, assemble a visual equivalent to 100 cells
|
2021-03-20 21:55:37 +00:00
|
|
|
auto y = 10 * nc_->tcache.cellpixy;
|
|
|
|
auto x = 10 * nc_->tcache.cellpixx;
|
2021-04-18 14:34:37 +00:00
|
|
|
std::vector<uint32_t> v(x * y, htole(0xffffffff));
|
2021-03-20 21:55:37 +00:00
|
|
|
for(auto& e : v){
|
2021-05-06 14:09:20 +00:00
|
|
|
e -= htole(random() % 0x1000000);
|
2021-03-20 21:55:37 +00:00
|
|
|
}
|
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = nullptr,
|
|
|
|
.scaling = NCSCALE_NONE,
|
|
|
|
.y = 0, .x = 0,
|
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = y, .lenx = x,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
2021-04-10 14:17:41 +00:00
|
|
|
.transcolor = 0,
|
2021-03-20 21:55:37 +00:00
|
|
|
};
|
|
|
|
auto n = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(nullptr != n);
|
|
|
|
auto s = n->sprite;
|
|
|
|
REQUIRE(nullptr != s);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 5, 5, 'x'));
|
2021-03-20 21:55:37 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 3, 3, 'x'));
|
2021-03-20 21:55:37 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 8, 8, 'x'));
|
2021-03-20 21:55:37 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, 8, 3, 'x'));
|
2021-03-20 21:55:37 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-04-18 14:34:37 +00:00
|
|
|
CHECK(0 == ncplane_destroy(n));
|
2021-03-20 21:55:37 +00:00
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-31 06:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// verify that the sprixel's TAM is properly initialized
|
|
|
|
SUBCASE("PixelTAMSetup") {
|
2021-04-20 01:47:38 +00:00
|
|
|
// first, assemble a visual equivalent to 54 cells
|
|
|
|
auto dimy = 6;
|
2021-03-31 06:08:04 +00:00
|
|
|
auto dimx = 9;
|
|
|
|
auto y = dimy * nc_->tcache.cellpixy;
|
|
|
|
auto x = dimx * nc_->tcache.cellpixx;
|
2021-04-18 14:34:37 +00:00
|
|
|
std::vector<uint32_t> v(x * y, htole(0xffffffff));
|
2021-03-31 06:08:04 +00:00
|
|
|
// every other cell, set some pixels transparent
|
|
|
|
for(int i = 0 ; i < dimy * dimx ; ++i){
|
|
|
|
if(i % 2){
|
|
|
|
int py = (i / dimx) * nc_->tcache.cellpixy;
|
|
|
|
int px = (i % dimx) * nc_->tcache.cellpixx;
|
|
|
|
ncpixel_set_a(&v[py * x + px], 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto ncv = ncvisual_from_rgba(v.data(), y, sizeof(decltype(v)::value_type) * x, x);
|
|
|
|
REQUIRE(nullptr != ncv);
|
|
|
|
struct ncvisual_options vopts = {
|
|
|
|
.n = nullptr,
|
|
|
|
.scaling = NCSCALE_NONE,
|
2021-04-16 11:05:14 +00:00
|
|
|
.y = 2, .x = 2,
|
2021-03-31 06:08:04 +00:00
|
|
|
.begy = 0, .begx = 0,
|
|
|
|
.leny = y, .lenx = x,
|
|
|
|
.blitter = NCBLIT_PIXEL,
|
|
|
|
.flags = NCVISUAL_OPTION_NODEGRADE,
|
2021-04-10 14:17:41 +00:00
|
|
|
.transcolor = 0,
|
2021-03-31 06:08:04 +00:00
|
|
|
};
|
|
|
|
auto n = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
REQUIRE(nullptr != n);
|
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
const auto s = n->sprite;
|
|
|
|
REQUIRE(s);
|
|
|
|
CHECK(s->dimy == dimy);
|
|
|
|
CHECK(s->dimx == dimx);
|
2021-04-25 04:27:47 +00:00
|
|
|
const auto tam = n->tam;
|
2021-03-31 06:08:04 +00:00
|
|
|
for(int i = 0 ; i < s->dimy * s->dimx ; ++i){
|
|
|
|
int py = (i / dimx) * nc_->tcache.cellpixy;
|
|
|
|
int px = (i % dimx) * nc_->tcache.cellpixx;
|
2021-04-25 08:56:59 +00:00
|
|
|
// cells with a transparent pixel ought be SPRIXCELL_MIXED;
|
2021-03-31 06:08:04 +00:00
|
|
|
// cells without one ought be SPRIXCELL_OPAQUE.
|
2021-04-25 04:27:47 +00:00
|
|
|
sprixcell_e state = tam[(i / dimx) + (i % dimx)].state;
|
2021-04-25 08:56:59 +00:00
|
|
|
if(i % 2){
|
|
|
|
if(state == SPRIXCELL_MIXED_SIXEL){
|
|
|
|
state = SPRIXCELL_MIXED_KITTY;
|
|
|
|
}
|
|
|
|
CHECK(SPRIXCELL_MIXED_KITTY == state);
|
|
|
|
}else{
|
|
|
|
if(state == SPRIXCELL_OPAQUE_SIXEL){
|
|
|
|
state = SPRIXCELL_OPAQUE_KITTY;
|
|
|
|
}
|
|
|
|
CHECK(SPRIXCELL_OPAQUE_KITTY == state);
|
|
|
|
}
|
2021-03-31 06:08:04 +00:00
|
|
|
ncpixel_set_a(&v[py * x + px], 0);
|
|
|
|
}
|
2021-04-16 11:05:14 +00:00
|
|
|
for(int yy = vopts.y ; yy < vopts.y + dimy ; ++yy){
|
|
|
|
for(int xx = vopts.x ; xx < vopts.x + dimx ; ++xx){
|
2021-04-25 08:56:59 +00:00
|
|
|
sprixcell_e state = sprixel_state(s, yy, xx);
|
|
|
|
if((yy * dimx + xx) % 2){
|
|
|
|
if(state == SPRIXCELL_MIXED_SIXEL){
|
|
|
|
state = SPRIXCELL_MIXED_KITTY;
|
|
|
|
}
|
|
|
|
CHECK(SPRIXCELL_MIXED_KITTY == state);
|
|
|
|
}else{
|
|
|
|
if(state == SPRIXCELL_OPAQUE_SIXEL){
|
|
|
|
state = SPRIXCELL_OPAQUE_KITTY;
|
|
|
|
}
|
|
|
|
CHECK(SPRIXCELL_OPAQUE_KITTY == state);
|
|
|
|
}
|
2021-04-16 11:05:14 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-18 14:34:37 +00:00
|
|
|
CHECK(0 == ncplane_destroy(n));
|
2021-04-24 17:08:09 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-20 21:55:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-27 07:47:12 +00:00
|
|
|
#ifdef NOTCURSES_USE_MULTIMEDIA
|
2021-03-27 21:28:22 +00:00
|
|
|
SUBCASE("PixelWipeImage") {
|
2021-03-28 23:47:27 +00:00
|
|
|
uint64_t channels = 0;
|
2021-06-10 07:02:30 +00:00
|
|
|
ncchannels_set_fg_alpha(&channels, NCALPHA_TRANSPARENT);
|
|
|
|
ncchannels_set_bg_alpha(&channels, NCALPHA_TRANSPARENT);
|
2021-03-28 23:47:27 +00:00
|
|
|
CHECK(0 == ncplane_set_base(n_, "", 0, channels));
|
2021-06-06 02:45:17 +00:00
|
|
|
auto ncv = ncvisual_from_file(find_data("worldmap.png").get());
|
2021-03-27 07:47:12 +00:00
|
|
|
REQUIRE(ncv);
|
|
|
|
struct ncvisual_options vopts{};
|
|
|
|
vopts.blitter = NCBLIT_PIXEL;
|
|
|
|
vopts.flags = NCVISUAL_OPTION_NODEGRADE;
|
2021-04-25 20:08:35 +00:00
|
|
|
vopts.scaling = NCSCALE_STRETCH;
|
2021-03-27 07:47:12 +00:00
|
|
|
auto newn = ncvisual_render(nc_, ncv, &vopts);
|
|
|
|
CHECK(newn);
|
2021-03-28 23:47:27 +00:00
|
|
|
ncplane_move_bottom(newn);
|
2021-03-27 07:47:12 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
const auto s = newn->sprite;
|
|
|
|
for(int y = 0 ; y < s->dimy ; ++y){
|
|
|
|
for(int x = 0 ; x < s->dimx ; ++x){
|
2021-03-28 23:42:47 +00:00
|
|
|
CHECK(1 == ncplane_putchar_yx(n_, y, x, 'x'));
|
2021-04-24 08:41:23 +00:00
|
|
|
// FIXME generates too much output, OOMing ctest
|
|
|
|
// CHECK(0 == notcurses_render(nc_));
|
2021-03-27 07:47:12 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-18 14:34:37 +00:00
|
|
|
CHECK(0 == ncplane_destroy(newn));
|
2021-03-27 07:47:12 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncvisual_destroy(ncv);
|
2021-04-24 17:08:09 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2021-03-27 07:47:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-03-14 21:54:36 +00:00
|
|
|
CHECK(!notcurses_stop(nc_));
|
|
|
|
}
|