avfilter/vsrc_testsrc: add planar support to rgbtestsrc

This commit is contained in:
Paul B Mahol 2021-01-16 15:36:25 +01:00
parent 1ed6b80c28
commit 79f2bca59c

View File

@ -77,6 +77,7 @@ typedef struct TestSourceContext {
/* only used by rgbtest */
uint8_t rgba_map[4];
int depth;
/* only used by haldclut */
int level;
@ -970,12 +971,15 @@ AVFILTER_DEFINE_CLASS(rgbtestsrc);
#define B 2
#define A 3
static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
static void rgbtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
int x, int y, unsigned r, unsigned g, unsigned b, enum AVPixelFormat fmt,
uint8_t rgba_map[4])
{
uint8_t *dst = dstp[0];
int dst_linesize = dst_linesizep[0];
uint32_t v;
uint8_t *p;
uint16_t *p16;
switch (fmt) {
case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
@ -998,6 +1002,25 @@ static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
p = dst + 4*x + y*dst_linesize;
AV_WL32(p, v);
break;
case AV_PIX_FMT_GBRP:
p = dstp[0] + x + y * dst_linesizep[0];
p[0] = g;
p = dstp[1] + x + y * dst_linesizep[1];
p[0] = b;
p = dstp[2] + x + y * dst_linesizep[2];
p[0] = r;
case AV_PIX_FMT_GBRP9:
case AV_PIX_FMT_GBRP10:
case AV_PIX_FMT_GBRP12:
case AV_PIX_FMT_GBRP14:
case AV_PIX_FMT_GBRP16:
p16 = (uint16_t *)(dstp[0] + x*2 + y * dst_linesizep[0]);
p16[0] = g;
p16 = (uint16_t *)(dstp[1] + x*2 + y * dst_linesizep[1]);
p16[0] = b;
p16 = (uint16_t *)(dstp[2] + x*2 + y * dst_linesizep[2]);
p16[0] = r;
break;
}
}
@ -1008,14 +1031,14 @@ static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
int c = 256*x/w;
int c = (1 << FFMAX(test->depth, 8))*x/w;
int r = 0, g = 0, b = 0;
if (3*y < h ) r = c;
else if (3*y < 2*h) g = c;
else b = c;
rgbtest_put_pixel(frame->data[0], frame->linesize[0], x, y, r, g, b,
rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
ctx->outputs[0]->format, test->rgba_map);
}
}
@ -1038,6 +1061,8 @@ static int rgbtest_query_formats(AVFilterContext *ctx)
AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
AV_PIX_FMT_NONE
};
@ -1050,7 +1075,9 @@ static int rgbtest_query_formats(AVFilterContext *ctx)
static int rgbtest_config_props(AVFilterLink *outlink)
{
TestSourceContext *test = outlink->src->priv;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
test->depth = desc->comp[0].depth;
ff_fill_rgba_map(test->rgba_map, outlink->format);
return config_props(outlink);
}