notcurses_canopen: split into images/videos #598

This commit is contained in:
nick black 2020-05-12 20:10:53 -04:00
parent 999c6c0742
commit 9a80750316
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
15 changed files with 93 additions and 58 deletions

View File

@ -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).

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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");

View File

@ -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;

View File

@ -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,6 +150,7 @@ int outro(struct notcurses* nc){
y = ystart - 1;
DEMO_RENDER(nc);
ncplane_move_top(on);
if(notcurses_canopen_videos(nc)){
pthread_t tid;
// will fade across 2 * demodelay
targy = 3;
@ -159,6 +160,7 @@ int outro(struct notcurses* nc){
if(ret == PTHREAD_CANCELED){
return 1;
}
}
ncplane_fadeout(on, &demodelay, demo_fader, NULL);
ncplane_destroy(on);
return on ? 0 : -1;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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){

View File

@ -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){

View File

@ -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;

View File

@ -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,6 +88,7 @@ TEST_CASE("Visual") {
}
SUBCASE("LoadVideo") {
if(notcurses_canopen_videos(nc_)){
nc_err_e ncerr = NCERR_SUCCESS;
int dimy, dimx;
ncplane_dim_yx(ncp_, &dimy, &dimx);
@ -106,8 +108,10 @@ TEST_CASE("Visual") {
}
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);
@ -122,6 +126,7 @@ TEST_CASE("Visual") {
CHECK(0 == notcurses_render(nc_));
ncvisual_destroy(ncv);
}
}
#endif
SUBCASE("LoadRGBAFromMemory") {