add notcurses_image_open() #23

pull/55/head
nick black 5 years ago committed by Nick Black
parent f1e7b4a8e5
commit f20e8fde4b

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

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

@ -0,0 +1,14 @@
#include <libavutil/error.h>
#include <libavformat/avformat.h>
#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;
}

@ -0,0 +1,28 @@
#include <notcurses.h>
#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);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 980 KiB

Loading…
Cancel
Save