diff --git a/CMakeLists.txt b/CMakeLists.txt index 09e0c295c..bbe41238d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ include(GNUInstallDirs) find_package(PkgConfig REQUIRED) pkg_check_modules(TERMINFO REQUIRED tinfo>=6.1) +pkg_check_modules(AVFORMAT REQUIRED libavformat) find_library(LIBRT rt) file(GLOB LIBSRCS CONFIGURE_DEPENDS src/lib/*.c) @@ -21,10 +22,12 @@ target_include_directories(notcurses include "${PROJECT_BINARY_DIR}/include" "${TERMINFO_INCLUDE_DIR}" + "${AVFORMAT_INCLUDE_DIR}" ) target_link_libraries(notcurses PRIVATE "${TERMINFO_LIBRARIES}" + "${AVFORMAT_LIBRARIES}" "${LIBRT}" ) set_target_properties(notcurses PROPERTIES diff --git a/include/notcurses.h b/include/notcurses.h index 5a19e4cca..7f641db11 100644 --- a/include/notcurses.h +++ b/include/notcurses.h @@ -356,6 +356,9 @@ cell_wide_p(const cell* c){ return (c->channels & CELL_WIDEASIAN_MASK); } +// multimedia functionality +int notcurses_image_open(struct notcurses* nc, const char* filename); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/lib/libav.c b/src/lib/libav.c new file mode 100644 index 000000000..6f651b5b8 --- /dev/null +++ b/src/lib/libav.c @@ -0,0 +1,14 @@ +#include +#include +#include "notcurses.h" + +int notcurses_image_open(struct notcurses* nc, const char* filename){ + AVFormatContext* ps = NULL; + int ret = avformat_open_input(&ps, filename, NULL, NULL); + if(ret < 0){ + fprintf(stderr, "Couldn't open %s (%s)\n", filename, av_err2str(ret)); + return ret; + } + avformat_free_context(ps); + return 0; +} diff --git a/tests/libav.cpp b/tests/libav.cpp new file mode 100644 index 000000000..3a34dfb4f --- /dev/null +++ b/tests/libav.cpp @@ -0,0 +1,28 @@ +#include +#include "main.h" + +class LibavTest : public :: testing::Test { + protected: + void SetUp() override { + notcurses_options nopts{}; + nopts.outfd = STDIN_FILENO; + nc_ = notcurses_init(&nopts); + ASSERT_NE(nullptr, nc_); + n_ = notcurses_stdplane(nc_); + ASSERT_NE(nullptr, n_); + } + + void TearDown() override { + if(nc_){ + EXPECT_EQ(0, notcurses_stop(nc_)); + } + } + + struct notcurses* nc_{}; + struct ncplane* n_{}; +}; + +TEST_F(LibavTest, LoadImage) { + int ret = notcurses_image_open(nc_, "../tools/dsscaw-purp.png"); + ASSERT_EQ(0, ret); +} diff --git a/tools/dsscaw-purp.png b/tools/dsscaw-purp.png new file mode 100644 index 000000000..96f0047db Binary files /dev/null and b/tools/dsscaw-purp.png differ