1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include "yuvbench.h"
#include <libswscale/swscale.h>
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;
}
|