don't violate ODR with visual_implementation

This commit is contained in:
nick black 2021-01-20 23:41:21 -05:00
parent 822d41eb8f
commit 81f689b6a2
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 27 additions and 23 deletions

View File

@ -598,6 +598,6 @@ static const ncvisual_implementation ffmpeg_impl = {
.canopen_videos = true,
};
const ncvisual_implementation* visual_implementation = &ffmpeg_impl;
const ncvisual_implementation* local_visual_implementation = &ffmpeg_impl;
#endif

View File

@ -44,27 +44,6 @@ auto oiio_create() -> ncvisual* {
return nc;
}
ncvisual* oiio_from_file(const char* filename) {
ncvisual* ncv = oiio_create();
if(ncv == nullptr){
return nullptr;
}
ncv->details->image = OIIO::ImageInput::open(filename);
if(!ncv->details->image){
// fprintf(stderr, "Couldn't create %s (%s)\n", filename, strerror(errno));
ncvisual_destroy(ncv);
return nullptr;
}
/*const auto &spec = ncv->details->image->spec_dimensions(0);
std::cout << "Opened " << filename << ": " << spec.height << "x" <<
spec.width << "@" << spec.nchannels << " (" << spec.format << ")" << std::endl;*/
if(oiio_decode(ncv)){
ncvisual_destroy(ncv);
return nullptr;
}
return ncv;
}
int oiio_decode(ncvisual* nc) {
//fprintf(stderr, "current subimage: %d frame: %p\n", nc->details->image->current_subimage(), nc->details->frame.get());
const auto &spec = nc->details->image->spec_dimensions(nc->details->framenum);
@ -111,6 +90,27 @@ int oiio_decode(ncvisual* nc) {
return 0;
}
ncvisual* oiio_from_file(const char* filename) {
ncvisual* ncv = oiio_create();
if(ncv == nullptr){
return nullptr;
}
ncv->details->image = OIIO::ImageInput::open(filename);
if(!ncv->details->image){
// fprintf(stderr, "Couldn't create %s (%s)\n", filename, strerror(errno));
ncvisual_destroy(ncv);
return nullptr;
}
/*const auto &spec = ncv->details->image->spec_dimensions(0);
std::cout << "Opened " << filename << ": " << spec.height << "x" <<
spec.width << "@" << spec.nchannels << " (" << spec.format << ")" << std::endl;*/
if(oiio_decode(ncv)){
ncvisual_destroy(ncv);
return nullptr;
}
return ncv;
}
int ncvisual_decode_loop(ncvisual* ncv){
int r = oiio_decode(ncv);
if(r == 1){
@ -282,6 +282,6 @@ const static ncvisual_implementation oiio_impl = {
.canopen_videos = false,
};
const ncvisual_implementation* visual_implementation = &oiio_impl;
const ncvisual_implementation* local_visual_implementation = &oiio_impl;
#endif

View File

@ -1,10 +1,14 @@
#include "notcurses/direct.h"
#include "internal.h"
extern const ncvisual_implementation* local_visual_implementation;
ncdirect* ncdirect_init(const char* termtype, FILE* outfp, uint64_t flags){
visual_implementation = local_visual_implementation;
return ncdirect_core_init(termtype, outfp, flags);
}
notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
visual_implementation = local_visual_implementation;
return notcurses_core_init(opts, outfp);
}