From 81f689b6a24f304646887926d4f3617bb0e06238 Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 20 Jan 2021 23:41:21 -0500 Subject: [PATCH] don't violate ODR with visual_implementation --- src/media/ffmpeg.cpp | 2 +- src/media/oiio.cpp | 44 ++++++++++++++++++++++---------------------- src/media/shim.c | 4 ++++ 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/media/ffmpeg.cpp b/src/media/ffmpeg.cpp index e8acb275e..4c62bd055 100644 --- a/src/media/ffmpeg.cpp +++ b/src/media/ffmpeg.cpp @@ -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 diff --git a/src/media/oiio.cpp b/src/media/oiio.cpp index ac3f9f3a6..9cd96d92b 100644 --- a/src/media/oiio.cpp +++ b/src/media/oiio.cpp @@ -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 diff --git a/src/media/shim.c b/src/media/shim.c index 72655eede..68fa77d0c 100644 --- a/src/media/shim.c +++ b/src/media/shim.c @@ -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); }