From b1029fc19192a5b156d65b5899d9f592fb9fa351 Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 27 Nov 2019 18:22:32 -0500 Subject: [PATCH] av: pass down through libswscale #61 --- src/lib/libav.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/lib/libav.c b/src/lib/libav.c index 7bb9a1b5d..0270b2320 100644 --- a/src/lib/libav.c +++ b/src/lib/libav.c @@ -1,4 +1,5 @@ #include +#include #include #include #include "notcurses.h" @@ -53,7 +54,14 @@ AVFrame* ncvisual_decode(struct ncvisual* nc){ fprintf(stderr, "Error decoding AVPacket (%s)\n", av_err2str(ret)); return NULL; } +#define IMGALLOCALIGN 32 fprintf(stderr, "Got frame %05d\n", nc->codecctx->frame_number); + ret = av_image_alloc(nc->frame->data, nc->frame->linesize, nc->frame->width, + nc->frame->height, nc->frame->format, IMGALLOCALIGN); + if(ret < 0){ + fprintf(stderr, "Error allocating input data (%s)\n", av_err2str(ret)); + return NULL; + } nc->swsctx = sws_getCachedContext(nc->swsctx, nc->frame->width, nc->frame->height, @@ -67,7 +75,29 @@ AVFrame* ncvisual_decode(struct ncvisual* nc){ fprintf(stderr, "Error retrieving swsctx (%s)\n", av_err2str(ret)); return NULL; } - return nc->frame; + AVFrame* oframe = av_frame_alloc(); + if(oframe == NULL){ + fprintf(stderr, "Couldn't allocate output frame\n"); + return NULL; + } + oframe->format = AV_PIX_FMT_RGB24; + oframe->width = nc->dstwidth; + oframe->height = nc->dstheight; + if((ret = av_image_alloc(oframe->data, oframe->linesize, oframe->width, oframe->height, + oframe->format, IMGALLOCALIGN)) < 0){ + fprintf(stderr, "Error allocating visual data (%s)\n", av_err2str(ret)); + av_frame_free(&oframe); + return NULL; + } + ret = sws_scale(nc->swsctx, (const uint8_t* const*)nc->frame->data, nc->frame->linesize, 0, + nc->frame->height, oframe->data, oframe->linesize); + if(ret < 0){ + fprintf(stderr, "Error applying scaling (%s)\n", av_err2str(ret)); + av_frame_free(&oframe); + return NULL; + } +#undef IMGALLOCALIGN + return oframe; } ncvisual* ncplane_visual_open(struct ncplane* nc, const char* filename){