[visual] back to basics

This commit is contained in:
nick black 2021-03-20 10:37:12 -04:00
parent 7bcc68136d
commit 760bdd2c35
8 changed files with 40 additions and 38 deletions

View File

@ -1302,13 +1302,13 @@ typedef struct ncvisual_implementation {
// AVFrame* 'frame' according to their own data, which is assumed to
// have been prepared already in 'ncv'.
void (*visual_details_seed)(struct ncvisual* ncv);
void (*visual_details_destroy)(struct ncvisual_details* deets);
int (*visual_decode)(struct ncvisual* nc);
int (*visual_decode_loop)(struct ncvisual* nc);
int (*visual_stream)(notcurses* nc, struct ncvisual* ncv, float timescale,
streamcb streamer, const struct ncvisual_options* vopts, void* curry);
char* (*visual_subtitle)(const struct ncvisual* ncv);
int (*visual_resize)(struct ncvisual* ncv, int rows, int cols);
void (*visual_destroy)(struct ncvisual* ncv);
bool canopen_images;
bool canopen_videos;
} ncvisual_implementation;

View File

@ -42,8 +42,6 @@ scale_visual(const ncvisual* ncv, int* disprows, int* dispcols){
*dispcols = xratio * (ncv->cols);
}
void ncvisual_destroy(struct ncvisual* ncv);
#ifdef __cplusplus
}
#endif

View File

@ -613,19 +613,9 @@ ncvisual* ncvisual_from_plane(const ncplane* n, ncblitter_e blit, int begy, int
return ncv;
}
void ncvisual_details_destroy(struct ncvisual_details* deets){
if(visual_implementation){
visual_implementation->visual_details_destroy(deets);
}
}
void ncvisual_destroy(ncvisual* ncv){
if(ncv){
ncvisual_details_destroy(ncv->details);
if(ncv->owndata){
free(ncv->data);
}
free(ncv);
if(visual_implementation){
visual_implementation->visual_destroy(ncv);
}
}

View File

@ -598,6 +598,16 @@ auto ffmpeg_details_destroy(ncvisual_details* deets) -> void {
free(deets);
}
auto ffmpeg_destroy(ncvisual* ncv) -> void {
if(ncv){
ffmpeg_details_destroy(ncv->details);
if(ncv->owndata){
delete ncv->data;
}
delete ncv;
}
}
static const ncvisual_implementation ffmpeg_impl = {
.visual_init = ffmpeg_init,
.visual_printbanner = ffmpeg_printbanner,
@ -605,12 +615,12 @@ static const ncvisual_implementation ffmpeg_impl = {
.visual_create = ffmpeg_create,
.visual_from_file = ffmpeg_from_file,
.visual_details_seed = ffmpeg_details_seed,
.visual_details_destroy = ffmpeg_details_destroy,
.visual_decode = ffmpeg_decode,
.visual_decode_loop = ffmpeg_decode_loop,
.visual_stream = ffmpeg_stream,
.visual_subtitle = ffmpeg_subtitle,
.visual_resize = ffmpeg_resize,
.visual_destroy = ffmpeg_destroy,
.canopen_images = true,
.canopen_videos = true,
};

View File

@ -5,7 +5,11 @@
#include "visual-details.h"
ncvisual* none_create(){
return malloc(sizeof(ncvisual));
return new ncvisual{};
}
void none_destroy(ncvisual* ncv){
delete ncv;
}
int none_decode(ncvisual* nc){
@ -86,12 +90,12 @@ static const ncvisual_implementation none_impl = {
.visual_create = none_create,
.visual_from_file = none_from_file,
.visual_details_seed = none_details_seed,
.visual_details_destroy = none_details_destroy,
.visual_decode = none_decode,
.visual_decode_loop = none_decode_loop,
.visual_stream = none_stream,
.visual_subtitle = none_subtitle,
.visual_resize = none_resize,
.visual_destroy = none_destroy,
.canopen_images = false,
.canopen_videos = false,
};

View File

@ -91,12 +91,12 @@ static const ncvisual_implementation oiio_impl = {
.visual_create = oiio_create,
.visual_from_file = oiio_from_file,
.visual_details_seed = oiio_details_seed,
.visual_details_destroy = oiio_details_destroy,
.visual_decode = oiio_decode,
.visual_decode_loop = oiio_decode_loop,
.visual_stream = oiio_stream,
.visual_subtitle = oiio_subtitle,
.visual_resize = oiio_resize,
.visual_destroy = oiio_destroy,
.canopen_images = true,
.canopen_videos = false,
};

View File

@ -16,14 +16,7 @@ typedef struct ncvisual_details {
} ncvisual_details;
auto oiio_details_init(void) -> ncvisual_details* {
auto deets = static_cast<ncvisual_details*>(malloc(sizeof(ncvisual_details)));
if(deets){
deets->image = nullptr;
deets->frame = nullptr;
deets->ibuf = nullptr;
deets->framenum = 0;
}
return deets;
return new ncvisual_details{};
}
auto oiio_details_destroy(ncvisual_details* deets) -> void {
@ -34,13 +27,10 @@ auto oiio_details_destroy(ncvisual_details* deets) -> void {
}
auto oiio_create() -> ncvisual* {
auto nc = static_cast<ncvisual*>(malloc(sizeof(ncvisual)));
if(nc){
memset(nc, 0, sizeof(*nc));
if((nc->details = oiio_details_init()) == nullptr){
free(nc);
return nullptr;
}
auto nc = new ncvisual{};
if((nc->details = oiio_details_init()) == nullptr){
delete nc;
return nullptr;
}
return nc;
}
@ -197,6 +187,16 @@ auto ncvisual_rotate(ncvisual* ncv, double rads) -> int {
}
*/
auto oiio_destroy(ncvisual* ncv) -> void {
if(ncv){
oiio_details_destroy(ncv->details);
if(ncv->owndata){
delete ncv->data;
}
delete ncv;
}
}
// FIXME would be nice to have OIIO::attributes("libraries") in here
void oiio_printbanner(const struct notcurses* nc __attribute__ ((unused))){
printf(" openimageio %s\n", OIIO_VERSION_STRING);

View File

@ -7,17 +7,17 @@ extern "C" {
#include "internal.h"
int oiio_decode(struct ncvisual* nc);
int oiio_decode(ncvisual* nc);
struct ncvisual_details* oiio_details_init(void);
void oiio_printbanner(const struct notcurses* nc);
int oiio_blit(struct ncvisual* ncv, int rows, int cols,
int oiio_blit(ncvisual* ncv, int rows, int cols,
struct ncplane* n, const struct blitset* bset,
int begy, int begx, int leny, int lenx, const blitterargs* bargs);
ncvisual* oiio_from_file(const char* filename);
void oiio_details_destroy(struct ncvisual_details* deets);
int oiio_decode_loop(ncvisual* ncv);
int oiio_resize(ncvisual* nc, int rows, int cols);
struct ncvisual* oiio_create(void);
ncvisual* oiio_create(void);
void oiio_destroy(ncvisual* ncv);
int oiio_blit_dispatch(struct ncplane* nc, const struct blitset* bset,
int linesize, const void* data, int begy, int begx,
int leny, int lenx, const blitterargs* bargs);