From a288d2b6836d398098098cf69e4f88db7799f49e Mon Sep 17 00:00:00 2001 From: Hunter Kvalevog Date: Thu, 26 Feb 2026 21:46:32 -0600 Subject: yuvbench: libswscale --- yuvbench/yuvbench_swscale.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 yuvbench/yuvbench_swscale.c (limited to 'yuvbench/yuvbench_swscale.c') diff --git a/yuvbench/yuvbench_swscale.c b/yuvbench/yuvbench_swscale.c new file mode 100644 index 0000000..556e5e3 --- /dev/null +++ b/yuvbench/yuvbench_swscale.c @@ -0,0 +1,41 @@ +#include "yuvbench.h" + +#include + +static bool yuvbench_swscale_init(Ctx* ctx) +{ + struct SwsContext* sws = sws_getContext(ctx->inp_w, ctx->inp_h, AV_PIX_FMT_YUV420P, + ctx->inp_w, ctx->inp_h, AV_PIX_FMT_RGB24, + 0, 0, 0, 0); + ctx->user = sws; + return !!sws; +} + +static void yuvbench_swscale_deinit(Ctx* ctx) +{ + sws_freeContext(ctx->user); +} + +static bool yuvbench_swscale_convert(Ctx* ctx) +{ + struct SwsContext* sws = ctx->user; + const uint32_t w = ctx->inp_w; + const uint32_t h = ctx->inp_h; + const uint8_t* Y = (const uint8_t*)ctx->inp_buf; + const uint8_t* Cb = Y + (w * h); + const uint8_t* Cr = Cb + (w / 2 * h / 2); + const uint8_t* const src_slices[] = { Y, Cb, Cr }; + const int src_strides[] = { w, w / 2, w / 2 }; + uint8_t* const dst_slices[] = { ctx->out_buf }; + const int dst_strides[] = { w * 3 }; + return sws_scale(sws, src_slices, src_strides, 0, h, dst_slices, dst_strides) == (int)h; +} + +Backend yuvbench_swscale(void) +{ + Backend b = { 0 }; + b.init_fn = yuvbench_swscale_init; + b.deinit_fn = yuvbench_swscale_deinit; + b.convert_fn = yuvbench_swscale_convert; + return b; +} -- cgit v1.2.3