mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-08 01:10:23 +00:00
f63325db60
Unify ffmpeg/oiio/null implementations, where possible. This effectively required placing all three in the same file, which meant they're all now C++. Update FFmpeg implemenation to be C++-usable. Implement ncvisual_rotate_cw() and ncvisual_rotate_ccw() #515. Move most of tetris over to Visual from Plane #558. Add bgra_to_rgba(), necessary for creating ncvisual from BGRA memory. Implement ncvisual_from_rgba() and ncvisual_from_bgra() #557. Add unit tests on ncvisual rotation.
155 lines
4.7 KiB
C++
155 lines
4.7 KiB
C++
#include "main.h"
|
|
#include <vector>
|
|
|
|
TEST_CASE("Multimedia") {
|
|
if(getenv("TERM") == nullptr){
|
|
return;
|
|
}
|
|
notcurses_options nopts{};
|
|
nopts.inhibit_alternate_screen = true;
|
|
nopts.suppress_banner = true;
|
|
FILE* outfp_ = fopen("/dev/tty", "wb");
|
|
REQUIRE(outfp_);
|
|
notcurses* nc_ = notcurses_init(&nopts, outfp_);
|
|
REQUIRE(nc_);
|
|
ncplane* ncp_ = notcurses_stdplane(nc_);
|
|
REQUIRE(ncp_);
|
|
|
|
#ifndef USE_MULTIMEDIA
|
|
SUBCASE("LibavDisabled"){
|
|
REQUIRE(!notcurses_canopen(nc_));
|
|
}
|
|
#else
|
|
SUBCASE("LibavEnabled"){
|
|
REQUIRE(notcurses_canopen(nc_));
|
|
}
|
|
|
|
SUBCASE("LoadImageCreatePlane") {
|
|
nc_err_e ncerr = NCERR_SUCCESS;
|
|
int dimy, dimx;
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
|
auto ncv = ncvisual_from_file(nc_, find_data("changes.jpg"), &ncerr, 0, 0, NCSCALE_STRETCH);
|
|
REQUIRE(ncv);
|
|
REQUIRE(NCERR_SUCCESS == ncerr);
|
|
ncerr = ncvisual_decode(ncv);
|
|
REQUIRE(NCERR_SUCCESS == ncerr);
|
|
/*CHECK(dimy * 2 == frame->height);
|
|
CHECK(dimx == frame->width); FIXME */
|
|
CHECK(0 < ncvisual_render(ncv, 0, 0, -1, -1));
|
|
CHECK(0 == notcurses_render(nc_));
|
|
ncerr = ncvisual_decode(ncv);
|
|
CHECK(NCERR_EOF == ncerr);
|
|
ncvisual_destroy(ncv);
|
|
}
|
|
|
|
SUBCASE("LoadImage") {
|
|
nc_err_e ncerr = NCERR_SUCCESS;
|
|
int dimy, dimx;
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
|
auto ncv = ncplane_visual_open(ncp_, find_data("changes.jpg"), &ncerr);
|
|
REQUIRE(ncv);
|
|
REQUIRE(0 == ncerr);
|
|
ncerr = ncvisual_decode(ncv);
|
|
REQUIRE(NCERR_SUCCESS == ncerr);
|
|
/*CHECK(dimy * 2 == frame->height);
|
|
CHECK(dimx == frame->width); FIXME */
|
|
CHECK(0 < ncvisual_render(ncv, 0, 0, -1, -1));
|
|
CHECK(0 == notcurses_render(nc_));
|
|
ncerr = ncvisual_decode(ncv);
|
|
CHECK(NCERR_EOF == ncerr);
|
|
ncvisual_destroy(ncv);
|
|
}
|
|
|
|
SUBCASE("PlaneDuplicate") {
|
|
nc_err_e ncerr = NCERR_SUCCESS;
|
|
int dimy, dimx;
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
|
auto ncv = ncplane_visual_open(ncp_, find_data("changes.jpg"), &ncerr);
|
|
REQUIRE(ncv);
|
|
REQUIRE(NCERR_SUCCESS == ncerr);
|
|
ncerr = ncvisual_decode(ncv);
|
|
REQUIRE(NCERR_SUCCESS == ncerr);
|
|
/*CHECK(dimy * 2 == frame->height);
|
|
CHECK(dimx == frame->width); FIXME */
|
|
CHECK(0 < ncvisual_render(ncv, 0, 0, -1, -1));
|
|
void* needle = malloc(1);
|
|
REQUIRE(nullptr != needle);
|
|
struct ncplane* newn = ncplane_dup(ncvisual_plane(ncv), needle);
|
|
int ndimx, ndimy;
|
|
REQUIRE(nullptr != newn);
|
|
ncvisual_destroy(ncv);
|
|
ncplane_erase(ncp_);
|
|
// should still have the image
|
|
CHECK(0 == notcurses_render(nc_));
|
|
ncplane_dim_yx(newn, &ndimy, &ndimx);
|
|
CHECK(ndimy == dimy);
|
|
CHECK(ndimx == dimx);
|
|
}
|
|
|
|
SUBCASE("LoadVideo") {
|
|
nc_err_e ncerr = NCERR_SUCCESS;
|
|
int dimy, dimx;
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
|
auto ncv = ncplane_visual_open(ncp_, find_data("notcursesI.avi"), &ncerr);
|
|
REQUIRE(ncv);
|
|
CHECK(NCERR_SUCCESS == ncerr);
|
|
for(;;){ // run at the highest speed we can
|
|
ncerr = ncvisual_decode(ncv);
|
|
if(NCERR_EOF == ncerr){
|
|
break;
|
|
}
|
|
CHECK(NCERR_SUCCESS == ncerr);
|
|
/*CHECK(dimy * 2 == frame->height);
|
|
CHECK(dimx == frame->width); FIXME */
|
|
CHECK(0 < ncvisual_render(ncv, 0, 0, -1, -1));
|
|
CHECK(0 == notcurses_render(nc_));
|
|
}
|
|
ncvisual_destroy(ncv);
|
|
}
|
|
|
|
SUBCASE("LoadVideoCreatePlane") {
|
|
nc_err_e ncerr = NCERR_SUCCESS;
|
|
int dimy, dimx;
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
|
auto ncv = ncvisual_from_file(nc_, find_data("notcursesI.avi"), &ncerr, 0, 0, NCSCALE_STRETCH);
|
|
REQUIRE(ncv);
|
|
CHECK(NCERR_SUCCESS == ncerr);
|
|
ncerr = ncvisual_decode(ncv);
|
|
CHECK(NCERR_SUCCESS == ncerr);
|
|
/*CHECK(dimy * 2 == frame->height);
|
|
CHECK(dimx == frame->width); FIXME */
|
|
CHECK(0 < ncvisual_render(ncv, 0, 0, -1, -1));
|
|
CHECK(0 == notcurses_render(nc_));
|
|
ncvisual_destroy(ncv);
|
|
}
|
|
#endif
|
|
|
|
SUBCASE("LoadRGBAFromMemory") {
|
|
int dimy, dimx;
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
|
std::vector<uint32_t> rgba(dimx * dimy * 2, 0x88bbccff);
|
|
auto ncv = ncvisual_from_rgba(nc_, rgba.data(), dimy * 2, dimx * 4, dimx);
|
|
REQUIRE(ncv);
|
|
CHECK(dimx * dimy == ncvisual_render(ncv, 0, 0, -1, -1));
|
|
CHECK(0 == notcurses_render(nc_));
|
|
ncvisual_destroy(ncv);
|
|
CHECK(0 == notcurses_render(nc_));
|
|
}
|
|
|
|
SUBCASE("LoadBGRAFromMemory") {
|
|
int dimy, dimx;
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
|
std::vector<uint32_t> rgba(dimx * dimy * 2, 0x88bbccff);
|
|
auto ncv = ncvisual_from_bgra(nc_, rgba.data(), dimy * 2, dimx * 4, dimx);
|
|
REQUIRE(ncv);
|
|
CHECK(dimx * dimy == ncvisual_render(ncv, 0, 0, -1, -1));
|
|
CHECK(0 == notcurses_render(nc_));
|
|
ncvisual_destroy(ncv);
|
|
CHECK(0 == notcurses_render(nc_));
|
|
}
|
|
|
|
CHECK(!notcurses_stop(nc_));
|
|
CHECK(!fclose(outfp_));
|
|
}
|
|
|