mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
oiio: open and close image #453
This commit is contained in:
parent
78da4e67ad
commit
5f42e06383
@ -116,6 +116,7 @@ that fine library.
|
||||
* (build+runtime) From NCURSES: terminfo 6.1+
|
||||
* (OPTIONAL) (build+runtime) From QR-Code-generator: [libqrcodegen](https://github.com/nayuki/QR-Code-generator) 1.5.0+
|
||||
* (OPTIONAL) (build+runtime) From [FFMpeg](https://www.ffmpeg.org/): libswscale 5.0+, libavformat 57.0+, libavutil 56.0+
|
||||
* (OPTIONAL) (build+runtime) [OpenImageIO](https://github.com/OpenImageIO/oiio) 2.0.7+
|
||||
* (OPTIONAL) (testing) [Doctest](https://github.com/onqtam/doctest) 2.3.5+
|
||||
* (OPTIONAL) (documentation) [pandoc](https://pandoc.org/index.html) 1.19.2+
|
||||
* (OPTIONAL) (python bindings): Python 3.7+, [CFFI](https://pypi.org/project/cffi/) 1.13.2+
|
||||
@ -129,6 +130,10 @@ that fine library.
|
||||
* `make`
|
||||
* `make test`
|
||||
|
||||
The default multimedia engine is FFmpeg. You can select a different engine
|
||||
using `USE_MULTIMEDIA`. Valid values are `ffmpeg`, `oiio` (for OpenImageIO),
|
||||
or `none`.
|
||||
|
||||
If you have unit test failures, *please* file a bug including the output of
|
||||
`./notcurses-tester > log 2>&1` (`make test` also runs `notcurses-tester`, but
|
||||
hides important output).
|
||||
|
@ -21,7 +21,7 @@ static char *datadir = NOTCURSES_SHARE;
|
||||
|
||||
// yes, these are in different orders in different configurations on purpose
|
||||
// (since some transition into the next). FIXME handle case sans libqrcodegen.
|
||||
#ifndef USE_FFMPEG
|
||||
#ifndef USE_MULTIMEDIA
|
||||
static const char DEFAULT_DEMO[] = "itfhbrgnswjqu";
|
||||
#else
|
||||
#ifdef DFSG_BUILD
|
||||
@ -68,9 +68,9 @@ struct timespec demodelay = {
|
||||
};
|
||||
|
||||
// anything that's dfsg non-free requires ncvisual (i.e. it's all multimedia),
|
||||
// so also check for USE_FFMPEG here in DFSG_BUILD
|
||||
// so also check for USE_MULTIMEDIA here in DFSG_BUILD
|
||||
#ifndef DFSG_BUILD
|
||||
#ifdef USE_FFMPEG
|
||||
#ifdef USE_MULTIMEDIA
|
||||
#define NONFREE(name, fxn) { name, fxn, }
|
||||
#else
|
||||
#endif
|
||||
@ -85,14 +85,14 @@ struct timespec demodelay = {
|
||||
#define NONFREE(name, fxn) { NULL, NULL, }
|
||||
#endif
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
#ifdef USE_MULTIMEDIA
|
||||
#define FREEFFMPEG(name, fxn) { name, fxn, }
|
||||
#else
|
||||
#define FREEFFMPEG(name, fxn) { NULL, NULL, }
|
||||
#endif
|
||||
|
||||
// define with NONFREE() to exempt from any DFSG or non-FFmpeg build. define
|
||||
// with FREEFFMPEG() to exempt from any non-FFmpeg build.
|
||||
// define with NONFREE() to exempt from any DFSG or non-multimedia build.
|
||||
// define with FREEFFMPEG() to exempt from any non-multimedia build.
|
||||
static struct {
|
||||
const char* name;
|
||||
int (*fxn)(struct notcurses*);
|
||||
|
@ -108,6 +108,7 @@ int xray_demo(struct notcurses* nc){
|
||||
char* path = find_data("notcursesI.avi");
|
||||
nc_err_e err;
|
||||
struct ncvisual* ncv = ncplane_visual_open(n, path, &err);
|
||||
fprintf(stderr, "NCV: %p %s\n", ncv, path);
|
||||
free(path);
|
||||
if(ncv == NULL){
|
||||
return -1;
|
||||
|
@ -41,9 +41,9 @@ ncplane* ncvisual_plane(ncvisual* ncv){
|
||||
return ncv->ncp;
|
||||
}
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
void ncvisual_destroy(ncvisual* ncv){
|
||||
if(ncv){
|
||||
#ifdef USE_FFMPEG
|
||||
avcodec_close(ncv->codecctx);
|
||||
avcodec_free_context(&ncv->codecctx);
|
||||
av_frame_free(&ncv->frame);
|
||||
@ -53,7 +53,6 @@ void ncvisual_destroy(ncvisual* ncv){
|
||||
av_packet_free(&ncv->packet);
|
||||
avformat_close_input(&ncv->fmtctx);
|
||||
avsubtitle_free(&ncv->subtitle);
|
||||
#endif
|
||||
if(ncv->ncobj && ncv->ncp){
|
||||
ncplane_destroy(ncv->ncp);
|
||||
}
|
||||
@ -61,7 +60,6 @@ void ncvisual_destroy(ncvisual* ncv){
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
bool notcurses_canopen(const notcurses* nc __attribute__ ((unused))){
|
||||
return true;
|
||||
}
|
||||
@ -569,5 +567,11 @@ int ncvisual_init(int loglevel){
|
||||
(void)loglevel;
|
||||
return 0; // allow success here
|
||||
}
|
||||
|
||||
void ncvisual_destroy(ncvisual* ncv){
|
||||
assert(!ncv);
|
||||
(void)ncv;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -937,9 +937,13 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
|
||||
LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO,
|
||||
LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO);
|
||||
fflush(stdout);
|
||||
#else
|
||||
#ifdef USE_OIIO
|
||||
// FIXME
|
||||
#else
|
||||
term_fg_palindex(ret, ret->ttyfp, ret->colors <= 88 ? 1 % ret->colors : 0xcb);
|
||||
fprintf(stderr, "\n Warning! Notcurses was built without ffmpeg support\n");
|
||||
fprintf(stderr, "\n Warning! Notcurses was built without multimedia support\n");
|
||||
#endif
|
||||
#endif
|
||||
term_fg_palindex(ret, ret->ttyfp, ret->colors <= 88 ? 1 % ret->colors : 0xcb);
|
||||
if(!ret->RGBflag){ // FIXME
|
||||
|
@ -9,6 +9,7 @@ typedef struct ncvisual {
|
||||
int packet_outstanding;
|
||||
int dstwidth, dstheight;
|
||||
float timescale; // scale frame duration by this value
|
||||
std::unique_ptr<OIIO::ImageInput> image; // must be close()d
|
||||
ncplane* ncp;
|
||||
// if we're creating the plane based off the first frame's dimensions, these
|
||||
// describe where the plane ought be placed, and how it ought be sized. this
|
||||
@ -28,30 +29,37 @@ ncvisual_create(float timescale){
|
||||
if(ret == nullptr){
|
||||
return nullptr;
|
||||
}
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
ret->packet_outstanding = 0;
|
||||
ret->dstwidth = ret->dstheight = 0;
|
||||
ret->timescale = timescale;
|
||||
ret->image = nullptr;
|
||||
ret->ncp = nullptr;
|
||||
ret->placex = ret->placey = 0;
|
||||
ret->style = NCSCALE_NONE;
|
||||
ret->ncobj = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ncvisual*
|
||||
ncvisual_open(const char* filename, nc_err_e* err){
|
||||
auto in = OIIO::ImageInput::open(filename);
|
||||
if(!in){
|
||||
return nullptr;
|
||||
}
|
||||
ncvisual* ncv = ncvisual_create(1);
|
||||
if(ncv == nullptr){
|
||||
// fprintf(stderr, "Couldn't create %s (%s)\n", filename, strerror(errno));
|
||||
*err = NCERR_NOMEM;
|
||||
return nullptr;
|
||||
}
|
||||
memset(ncv, 0, sizeof(*ncv));
|
||||
ncv->image = OIIO::ImageInput::open(filename);
|
||||
if(!ncv->image){
|
||||
// fprintf(stderr, "Couldn't create %s (%s)\n", filename, strerror(errno));
|
||||
*err = NCERR_DECODE;
|
||||
return nullptr;
|
||||
}
|
||||
return ncv;
|
||||
}
|
||||
|
||||
ncvisual* ncplane_visual_open(ncplane* nc, const char* filename, nc_err_e* ncerr){
|
||||
ncvisual* ncv = ncvisual_open(filename, ncerr);
|
||||
if(ncv == nullptr){
|
||||
*ncerr = NCERR_NOMEM;
|
||||
return nullptr;
|
||||
}
|
||||
ncplane_dim_yx(nc, &ncv->dstheight, &ncv->dstwidth);
|
||||
@ -110,6 +118,13 @@ int ncvisual_init(int loglevel){
|
||||
return 0; // allow success here
|
||||
}
|
||||
|
||||
void ncvisual_destroy(ncvisual* ncv){
|
||||
if(ncv){
|
||||
ncv->image->close();
|
||||
free(ncv);
|
||||
}
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user