Skip to content

Commit 667e22e

Browse files
committed
avfilter/vsdc_testsrc: simplify yuvtest_fill_picture
Copy what's done for rgbtest_fill_picture. It will be useful for the following commit. Signed-off-by: James Almer <[email protected]>
1 parent e347b4f commit 667e22e

File tree

3 files changed

+75
-119
lines changed

3 files changed

+75
-119
lines changed

libavfilter/drawutils.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,17 @@
3232

3333
enum { RED = 0, GREEN, BLUE, ALPHA };
3434

35-
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
35+
static int fill_map(const AVPixFmtDescriptor *desc, uint8_t *map)
3636
{
37-
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
38-
if (!(desc->flags & AV_PIX_FMT_FLAG_RGB))
39-
return AVERROR(EINVAL);
40-
if (desc->flags & AV_PIX_FMT_FLAG_BITSTREAM)
37+
if (desc->flags & (AV_PIX_FMT_FLAG_BITSTREAM | AV_PIX_FMT_FLAG_HWACCEL |
38+
AV_PIX_FMT_FLAG_BAYER | AV_PIX_FMT_FLAG_XYZ | AV_PIX_FMT_FLAG_PAL))
4139
return AVERROR(EINVAL);
4240
av_assert0(desc->nb_components == 3 + !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA));
4341
if (desc->flags & AV_PIX_FMT_FLAG_PLANAR) {
44-
rgba_map[RED] = desc->comp[0].plane;
45-
rgba_map[GREEN] = desc->comp[1].plane;
46-
rgba_map[BLUE] = desc->comp[2].plane;
47-
rgba_map[ALPHA] = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) ? desc->comp[3].plane : 3;
42+
map[RED] = desc->comp[0].plane;
43+
map[GREEN] = desc->comp[1].plane;
44+
map[BLUE] = desc->comp[2].plane;
45+
map[ALPHA] = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) ? desc->comp[3].plane : 3;
4846
} else {
4947
int had0 = 0;
5048
unsigned depthb = 0;
@@ -60,24 +58,40 @@ int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
6058
return AVERROR(ENOSYS);
6159

6260
had0 |= pos == 0;
63-
rgba_map[i] = pos;
61+
map[i] = pos;
6462
depthb = db;
6563
}
6664

6765
if (desc->nb_components == 3)
68-
rgba_map[ALPHA] = had0 ? 3 : 0;
66+
map[ALPHA] = had0 ? 3 : 0;
6967
}
7068

71-
av_assert0(rgba_map[RED] != rgba_map[GREEN]);
72-
av_assert0(rgba_map[GREEN] != rgba_map[BLUE]);
73-
av_assert0(rgba_map[BLUE] != rgba_map[RED]);
74-
av_assert0(rgba_map[RED] != rgba_map[ALPHA]);
75-
av_assert0(rgba_map[GREEN] != rgba_map[ALPHA]);
76-
av_assert0(rgba_map[BLUE] != rgba_map[ALPHA]);
69+
av_assert0(map[RED] != map[GREEN]);
70+
av_assert0(map[GREEN] != map[BLUE]);
71+
av_assert0(map[BLUE] != map[RED]);
72+
av_assert0(map[RED] != map[ALPHA]);
73+
av_assert0(map[GREEN] != map[ALPHA]);
74+
av_assert0(map[BLUE] != map[ALPHA]);
7775

7876
return 0;
7977
}
8078

79+
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
80+
{
81+
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
82+
if (!(desc->flags & AV_PIX_FMT_FLAG_RGB))
83+
return AVERROR(EINVAL);
84+
return fill_map(desc, rgba_map);
85+
}
86+
87+
int ff_fill_ayuv_map(uint8_t *ayuv_map, enum AVPixelFormat pix_fmt)
88+
{
89+
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
90+
if (desc->flags & AV_PIX_FMT_FLAG_RGB)
91+
return AVERROR(EINVAL);
92+
return fill_map(desc, ayuv_map);
93+
}
94+
8195
int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp,
8296
enum AVColorRange range, unsigned flags)
8397
{

libavfilter/drawutils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "libavutil/pixfmt.h"
3030

3131
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt);
32+
int ff_fill_ayuv_map(uint8_t *ayuv_map, enum AVPixelFormat pix_fmt);
3233

3334
#define MAX_PLANES 4
3435

libavfilter/vsrc_testsrc.c

Lines changed: 43 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ typedef struct TestSourceContext {
7171
/* only used by testsrc2 */
7272
int alpha;
7373

74+
/* only used by yuvtest */
75+
uint8_t ayuv_map[4];
76+
7477
/* only used by colorspectrum */
7578
int type;
7679

@@ -1141,125 +1144,64 @@ const AVFilter ff_vsrc_rgbtestsrc = {
11411144

11421145
#if CONFIG_YUVTESTSRC_FILTER
11431146

1144-
static void yuvtest_fill_picture8(AVFilterContext *ctx, AVFrame *frame)
1145-
{
1146-
int x, y, w = frame->width, h = frame->height / 3;
1147-
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1148-
const int factor = 1 << desc->comp[0].depth;
1149-
const int mid = 1 << (desc->comp[0].depth - 1);
1150-
uint8_t *ydst = frame->data[0];
1151-
uint8_t *udst = frame->data[1];
1152-
uint8_t *vdst = frame->data[2];
1153-
ptrdiff_t ylinesize = frame->linesize[0];
1154-
ptrdiff_t ulinesize = frame->linesize[1];
1155-
ptrdiff_t vlinesize = frame->linesize[2];
1156-
1157-
for (y = 0; y < h; y++) {
1158-
for (x = 0; x < w; x++) {
1159-
int c = factor * x / w;
1160-
1161-
ydst[x] = c;
1162-
udst[x] = mid;
1163-
vdst[x] = mid;
1164-
}
1165-
1166-
ydst += ylinesize;
1167-
udst += ulinesize;
1168-
vdst += vlinesize;
1169-
}
1170-
1171-
h += h;
1172-
for (; y < h; y++) {
1173-
for (x = 0; x < w; x++) {
1174-
int c = factor * x / w;
1175-
1176-
ydst[x] = mid;
1177-
udst[x] = c;
1178-
vdst[x] = mid;
1179-
}
1180-
1181-
ydst += ylinesize;
1182-
udst += ulinesize;
1183-
vdst += vlinesize;
1184-
}
1185-
1186-
for (; y < frame->height; y++) {
1187-
for (x = 0; x < w; x++) {
1188-
int c = factor * x / w;
1147+
#define Y 0
1148+
#define U 1
1149+
#define V 2
11891150

1190-
ydst[x] = mid;
1191-
udst[x] = mid;
1192-
vdst[x] = c;
1193-
}
1151+
static void yuvtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
1152+
int i, int j, unsigned y, unsigned u, unsigned v, enum AVPixelFormat fmt,
1153+
uint8_t ayuv_map[4])
1154+
{
1155+
uint32_t n;
11941156

1195-
ydst += ylinesize;
1196-
udst += ulinesize;
1197-
vdst += vlinesize;
1157+
switch (fmt) {
1158+
case AV_PIX_FMT_YUV444P:
1159+
case AV_PIX_FMT_YUVJ444P:
1160+
dstp[0][i + j*dst_linesizep[0]] = y;
1161+
dstp[1][i + j*dst_linesizep[1]] = u;
1162+
dstp[2][i + j*dst_linesizep[2]] = v;
1163+
break;
1164+
case AV_PIX_FMT_YUV444P9:
1165+
case AV_PIX_FMT_YUV444P10:
1166+
case AV_PIX_FMT_YUV444P12:
1167+
case AV_PIX_FMT_YUV444P14:
1168+
case AV_PIX_FMT_YUV444P16:
1169+
AV_WN16(&dstp[0][i*2 + j*dst_linesizep[0]], y);
1170+
AV_WN16(&dstp[1][i*2 + j*dst_linesizep[1]], u);
1171+
AV_WN16(&dstp[2][i*2 + j*dst_linesizep[2]], v);
1172+
break;
11981173
}
11991174
}
12001175

1201-
static void yuvtest_fill_picture16(AVFilterContext *ctx, AVFrame *frame)
1176+
static void yuvtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
12021177
{
1203-
int x, y, w = frame->width, h = frame->height / 3;
1178+
TestSourceContext *test = ctx->priv;
1179+
int i, j, w = frame->width, h = frame->height;
12041180
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
12051181
const int factor = 1 << desc->comp[0].depth;
12061182
const int mid = 1 << (desc->comp[0].depth - 1);
1207-
uint16_t *ydst = (uint16_t *)frame->data[0];
1208-
uint16_t *udst = (uint16_t *)frame->data[1];
1209-
uint16_t *vdst = (uint16_t *)frame->data[2];
1210-
ptrdiff_t ylinesize = frame->linesize[0] / 2;
1211-
ptrdiff_t ulinesize = frame->linesize[1] / 2;
1212-
ptrdiff_t vlinesize = frame->linesize[2] / 2;
1213-
1214-
for (y = 0; y < h; y++) {
1215-
for (x = 0; x < w; x++) {
1216-
int c = factor * x / w;
12171183

1218-
ydst[x] = c;
1219-
udst[x] = mid;
1220-
vdst[x] = mid;
1221-
}
1222-
1223-
ydst += ylinesize;
1224-
udst += ulinesize;
1225-
vdst += vlinesize;
1226-
}
1184+
for (j = 0; j < h; j++) {
1185+
for (i = 0; i < w; i++) {
1186+
int c = factor * i / w;
1187+
int y = mid, u = mid, v = mid;
12271188

1228-
h += h;
1229-
for (; y < h; y++) {
1230-
for (x = 0; x < w; x++) {
1231-
int c = factor * x / w;
1232-
1233-
ydst[x] = mid;
1234-
udst[x] = c;
1235-
vdst[x] = mid;
1236-
}
1189+
if (3*j < h ) y = c;
1190+
else if (3*j < 2*h) u = c;
1191+
else v = c;
12371192

1238-
ydst += ylinesize;
1239-
udst += ulinesize;
1240-
vdst += vlinesize;
1241-
}
1242-
1243-
for (; y < frame->height; y++) {
1244-
for (x = 0; x < w; x++) {
1245-
int c = factor * x / w;
1246-
1247-
ydst[x] = mid;
1248-
udst[x] = mid;
1249-
vdst[x] = c;
1250-
}
1251-
1252-
ydst += ylinesize;
1253-
udst += ulinesize;
1254-
vdst += vlinesize;
1255-
}
1193+
yuvtest_put_pixel(frame->data, frame->linesize, i, j, y, u, v,
1194+
ctx->outputs[0]->format, test->ayuv_map);
1195+
}
1196+
}
12561197
}
12571198

12581199
static av_cold int yuvtest_init(AVFilterContext *ctx)
12591200
{
12601201
TestSourceContext *test = ctx->priv;
12611202

12621203
test->draw_once = 1;
1204+
test->fill_picture_fn = yuvtest_fill_picture;
12631205
return init(ctx);
12641206
}
12651207

@@ -1274,9 +1216,8 @@ static const enum AVPixelFormat yuvtest_pix_fmts[] = {
12741216
static int yuvtest_config_props(AVFilterLink *outlink)
12751217
{
12761218
TestSourceContext *test = outlink->src->priv;
1277-
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
12781219

1279-
test->fill_picture_fn = desc->comp[0].depth > 8 ? yuvtest_fill_picture16 : yuvtest_fill_picture8;
1220+
ff_fill_ayuv_map(test->ayuv_map, outlink->format);
12801221
return config_props(outlink);
12811222
}
12821223

0 commit comments

Comments
 (0)