notcurses_canopen: split into images/videos #598

pull/600/head^2
nick black 4 years ago
parent 999c6c0742
commit 9a80750316
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -10,6 +10,8 @@ rearrangements of Notcurses.
* `ncvisual_from_plane()`, `ncplane_move_below_unsafe()`, `ncplane_dup()`,
and `ncplane_move_above_unsafe()` now accept `const` arguments where they
did not before.
* `notcurses_canopen()` has been split into `notcurses_canopen_images()` and
`notcurses_canopen_videos()`.
* 1.4.1 (2020-05-11)
* No user-visible changes (fixed two unit tests).

@ -225,8 +225,11 @@ int notcurses_palette_size(const struct notcurses* nc);
// Can we fade? Fading requires either the "rgb" or "ccc" terminfo capability.
bool notcurses_canfade(const struct notcurses* nc);
// Can we load images/videos? This requires being built against FFmpeg.
bool notcurses_canopen(const struct notcurses* nc);
// Can we load images? This requires being built against FFmpeg/OIIO.
bool notcurses_canopen_images(const struct notcurses* nc);
// Can we load videos? This requires being built against FFmpeg.
bool notcurses_canopen_videos(const struct notcurses* nc);
// Can we change colors in the hardware palette? Requires "ccc" and "initc".
bool notcurses_canchangecolors(const struct notcurses* nc);

@ -101,9 +101,14 @@ namespace ncpp
return notcurses_canfade (nc);
}
bool can_open () const noexcept
bool can_open_images () const noexcept
{
return notcurses_canopen (nc);
return notcurses_canopen_images (nc);
}
bool can_open_videos () const noexcept
{
return notcurses_canopen_videos (nc);
}
bool can_change_color () const noexcept

@ -1028,8 +1028,11 @@ API bool notcurses_canfade(const struct notcurses* nc);
// Can we set the "hardware" palette? Requires the "ccc" terminfo capability.
API bool notcurses_canchangecolor(const struct notcurses* nc);
// Can we load images/videos? This requires being built against FFmpeg.
API bool notcurses_canopen(const struct notcurses* nc);
// Can we load images? This requires being built against FFmpeg/OIIO.
API bool notcurses_canopen_images(const struct notcurses* nc);
// Can we load videos? This requires being built against FFmpeg.
API bool notcurses_canopen_videos(const struct notcurses* nc);
// Is our encoding UTF-8?
API bool notcurses_canutf8(const struct notcurses* nc);

@ -48,7 +48,7 @@ chunli_draw(struct notcurses* nc, const char* ext, int count, const cell* b){
// test of sprites from files
int chunli_demo(struct notcurses* nc){
if(!notcurses_canopen(nc)){
if(!notcurses_canopen_images(nc)){
return 0;
}
struct timespec iterdelay;

@ -199,7 +199,7 @@ eagles(struct notcurses* nc){
// motherfucking eagles!
int eagle_demo(struct notcurses* nc){
if(!notcurses_canopen(nc)){
if(!notcurses_canopen_images(nc)){
return 0;
}
char* map = find_data("eagles.png");

@ -143,7 +143,7 @@ draw_luigi(struct ncplane* n, const char* sprite){
}
int luigi_demo(struct notcurses* nc){
if(!notcurses_canopen(nc)){
if(!notcurses_canopen_images(nc)){
return 0;
}
int rows, cols;

@ -120,7 +120,7 @@ outro_message(struct notcurses* nc, int* rows, int* cols){
}
int outro(struct notcurses* nc){
if(!notcurses_canopen(nc)){
if(!notcurses_canopen_images(nc)){
return 0;
}
int rows, cols;
@ -150,14 +150,16 @@ int outro(struct notcurses* nc){
y = ystart - 1;
DEMO_RENDER(nc);
ncplane_move_top(on);
pthread_t tid;
// will fade across 2 * demodelay
targy = 3;
pthread_create(&tid, NULL, fadethread, nc);
void* ret;
pthread_join(tid, &ret);
if(ret == PTHREAD_CANCELED){
return 1;
if(notcurses_canopen_videos(nc)){
pthread_t tid;
// will fade across 2 * demodelay
targy = 3;
pthread_create(&tid, NULL, fadethread, nc);
void* ret;
pthread_join(tid, &ret);
if(ret == PTHREAD_CANCELED){
return 1;
}
}
ncplane_fadeout(on, &demodelay, demo_fader, NULL);
ncplane_destroy(on);

@ -65,7 +65,7 @@ legend(struct notcurses* nc, int dimy, int dimx){
}
int view_demo(struct notcurses* nc){
if(!notcurses_canopen(nc)){
if(!notcurses_canopen_images(nc)){
return 0;
}
int dimy, dimx;
@ -135,7 +135,10 @@ int view_demo(struct notcurses* nc){
if(ncpl == NULL){
return -1;
}
int ret = view_video_demo(nc);
int ret = 0;
if(notcurses_canopen_videos(nc)){
ret |= view_video_demo(nc);
}
ncplane_destroy(ncpl);
return ret;
}

@ -96,7 +96,7 @@ perframecb(struct notcurses* nc, struct ncvisual* ncv __attribute__ ((unused)),
}
int xray_demo(struct notcurses* nc){
if(!notcurses_canopen(nc)){
if(!notcurses_canopen_videos(nc)){
return 0;
}
int dimx, dimy;

@ -363,7 +363,11 @@ void ncvisual_destroy(ncvisual* ncv){
}
}
bool notcurses_canopen(const notcurses* nc __attribute__ ((unused))){
bool notcurses_canopen_images(const notcurses* nc __attribute__ ((unused))){
return true;
}
bool notcurses_canopen_videos(const notcurses* nc __attribute__ ((unused))){
return true;
}
@ -785,7 +789,11 @@ int ncvisual_init(int loglevel){
} // extern "C"
#else // built without ffmpeg
#ifndef USE_OIIO // built without ffmpeg or oiio
bool notcurses_canopen(const notcurses* nc __attribute__ ((unused))){
bool notcurses_canopen_images(const notcurses* nc __attribute__ ((unused))){
return false;
}
bool notcurses_canopen_videos(const notcurses* nc __attribute__ ((unused))){
return false;
}
@ -840,10 +848,14 @@ void ncvisual_destroy(ncvisual* ncv){
}
#else
#ifdef USE_OIIO
bool notcurses_canopen(const notcurses* nc __attribute__ ((unused))){
bool notcurses_canopen_images(const notcurses* nc __attribute__ ((unused))){
return true;
}
bool notcurses_canopen_videos(const notcurses* nc __attribute__ ((unused))){
return false; // too slow for reliable use at the moment
}
static ncvisual*
ncvisual_open(const char* filename, nc_err_e* err){
*ncerr = NCERR_SUCCESS;

@ -82,7 +82,7 @@ int main(void){
channels_set_bg_alpha(&sopts.bgchannels, CELL_ALPHA_BLEND);
struct ncplane* n = notcurses_stdplane(nc);
if(notcurses_canopen(nc)){
if(notcurses_canopen_images(nc)){
nc_err_e err;
struct ncvisual* ncv = ncplane_visual_open(n, "../data/covid19.jpg", &err);
if(!ncv){

@ -83,7 +83,7 @@ int main(void){
channels_set_bg_alpha(&sopts.bgchannels, CELL_ALPHA_BLEND);
struct ncplane* n = notcurses_stdplane(nc);
if(notcurses_canopen(nc)){
if(notcurses_canopen_images(nc)){
nc_err_e err;
struct ncvisual* ncv = ncplane_visual_open(n, "../data/changes.jpg", &err);
if(!ncv){

@ -178,7 +178,7 @@ auto main(int argc, char** argv) -> int {
NCScale stretchmode;
auto nonopt = handle_opts(argc, argv, NotCurses::default_notcurses_options, &timescale, &stretchmode);
NotCurses nc;
if(!nc.can_open()){
if(!nc.can_open_images()){
nc.stop();
std::cerr << "Notcurses was compiled without multimedia support\n";
return EXIT_FAILURE;

@ -16,12 +16,13 @@ TEST_CASE("Visual") {
REQUIRE(ncp_);
#ifndef USE_MULTIMEDIA
SUBCASE("LibavDisabled"){
REQUIRE(!notcurses_canopen(nc_));
SUBCASE("VisualDisabled"){
REQUIRE(!notcurses_canopen_images(nc_));
REQUIRE(!notcurses_canopen_videos(nc_));
}
#else
SUBCASE("LibavEnabled"){
REQUIRE(notcurses_canopen(nc_));
SUBCASE("ImagesEnabled"){
REQUIRE(notcurses_canopen_images(nc_));
}
SUBCASE("LoadImageCreatePlane") {
@ -87,40 +88,44 @@ TEST_CASE("Visual") {
}
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;
if(notcurses_canopen_videos(nc_)){
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") {
if(notcurses_canopen_videos(nc_)){
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);
}
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

Loading…
Cancel
Save