History

avfilter/vsdc_testsrc: simplify yuvtest_fill_picture

Copy what's done for rgbtest_fill_picture. It will be useful for the following commit.

James Almer committed 2 years ago

Commit 667e22e1 parent e347b4f3 files · +75 −119Browse files

Showing the changes to libavfilter (3 of 3 files). Show all

Unified · Split

3 files
  1. libavfilter/drawutils.c +31 −17
  2. libavfilter/drawutils.h +1 −0
  3. libavfilter/vsrc_testsrc.c +43 −102
libavfilter/drawutils.c+31−17
@@ -32,19 +32,17 @@ · 31 unmodified lines
32 32
33enum { RED = 0, GREEN, BLUE, ALPHA };33enum { RED = 0, GREEN, BLUE, ALPHA };
34 34
35int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)35static int fill_map(const AVPixFmtDescriptor *desc, uint8_t *map)
36{36{
37 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);37 if (desc->flags & (AV_PIX_FMT_FLAG_BITSTREAM | AV_PIX_FMT_FLAG_HWACCEL |
38 if (!(desc->flags & AV_PIX_FMT_FLAG_RGB))38 AV_PIX_FMT_FLAG_BAYER | AV_PIX_FMT_FLAG_XYZ | AV_PIX_FMT_FLAG_PAL))
39 return AVERROR(EINVAL);
40 if (desc->flags & AV_PIX_FMT_FLAG_BITSTREAM)
41 return AVERROR(EINVAL);39 return AVERROR(EINVAL);
42 av_assert0(desc->nb_components == 3 + !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA));40 av_assert0(desc->nb_components == 3 + !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA));
43 if (desc->flags & AV_PIX_FMT_FLAG_PLANAR) {41 if (desc->flags & AV_PIX_FMT_FLAG_PLANAR) {
44 rgba_map[RED] = desc->comp[0].plane;42 map[RED] = desc->comp[0].plane;
45 rgba_map[GREEN] = desc->comp[1].plane;43 map[GREEN] = desc->comp[1].plane;
46 rgba_map[BLUE] = desc->comp[2].plane;44 map[BLUE] = desc->comp[2].plane;
47 rgba_map[ALPHA] = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) ? desc->comp[3].plane : 3;45 map[ALPHA] = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) ? desc->comp[3].plane : 3;
48 } else {46 } else {
49 int had0 = 0;47 int had0 = 0;
50 unsigned depthb = 0;48 unsigned depthb = 0;
@@ -60,24 +58,40 @@ int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt) · 9 unmodified lines
60 return AVERROR(ENOSYS);58 return AVERROR(ENOSYS);
61 59
62 had0 |= pos == 0;60 had0 |= pos == 0;
63 rgba_map[i] = pos;61 map[i] = pos;
64 depthb = db;62 depthb = db;
65 }63 }
66 64
67 if (desc->nb_components == 3)65 if (desc->nb_components == 3)
68 rgba_map[ALPHA] = had0 ? 3 : 0;66 map[ALPHA] = had0 ? 3 : 0;
69 }67 }
70 68
71 av_assert0(rgba_map[RED] != rgba_map[GREEN]);69 av_assert0(map[RED] != map[GREEN]);
72 av_assert0(rgba_map[GREEN] != rgba_map[BLUE]);70 av_assert0(map[GREEN] != map[BLUE]);
73 av_assert0(rgba_map[BLUE] != rgba_map[RED]);71 av_assert0(map[BLUE] != map[RED]);
74 av_assert0(rgba_map[RED] != rgba_map[ALPHA]);72 av_assert0(map[RED] != map[ALPHA]);
75 av_assert0(rgba_map[GREEN] != rgba_map[ALPHA]);73 av_assert0(map[GREEN] != map[ALPHA]);
76 av_assert0(rgba_map[BLUE] != rgba_map[ALPHA]);74 av_assert0(map[BLUE] != map[ALPHA]);
77 75
78 return 0;76 return 0;
79}77}
80 78
79int 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
87int 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
81int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp,95int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp,
82 enum AVColorRange range, unsigned flags)96 enum AVColorRange range, unsigned flags)
83{97{
libavfilter/drawutils.h+1−0
@@ -29,6 +29,7 @@ · 28 unmodified lines
29#include "libavutil/pixfmt.h"29#include "libavutil/pixfmt.h"
30 30
31int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt);31int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt);
32int ff_fill_ayuv_map(uint8_t *ayuv_map, enum AVPixelFormat pix_fmt);
32 33
33#define MAX_PLANES 434#define MAX_PLANES 4
34 35
libavfilter/vsrc_testsrc.c+43−102
@@ -71,6 +71,9 @@ typedef struct TestSourceContext { · 70 unmodified lines
71 /* only used by testsrc2 */71 /* only used by testsrc2 */
72 int alpha;72 int alpha;
73 73
74 /* only used by yuvtest */
75 uint8_t ayuv_map[4];
76
74 /* only used by colorspectrum */77 /* only used by colorspectrum */
75 int type;78 int type;
76 79
@@ -1141,118 +1144,56 @@ const AVFilter ff_vsrc_rgbtestsrc = { · 1064 unmodified lines
1141 1144
1142#if CONFIG_YUVTESTSRC_FILTER1145#if CONFIG_YUVTESTSRC_FILTER
1143 1146
1144static void yuvtest_fill_picture8(AVFilterContext *ctx, AVFrame *frame)1147#define Y 0
1145{1148#define U 1
1146 int x, y, w = frame->width, h = frame->height / 3;1149#define V 2
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;
1189 1150
1190 ydst[x] = mid;1151static void yuvtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
1191 udst[x] = mid;1152 int i, int j, unsigned y, unsigned u, unsigned v, enum AVPixelFormat fmt,
1192 vdst[x] = c;1153 uint8_t ayuv_map[4])
1193 }1154{
1155 uint32_t n;
1194 1156
1195 ydst += ylinesize;1157 switch (fmt) {
1196 udst += ulinesize;1158 case AV_PIX_FMT_YUV444P:
1197 vdst += vlinesize;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;
1198 }1173 }
1199}1174}
1200 1175
1201static void yuvtest_fill_picture16(AVFilterContext *ctx, AVFrame *frame)1176static void yuvtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1202{1177{
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;
1204 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);1180 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1205 const int factor = 1 << desc->comp[0].depth;1181 const int factor = 1 << desc->comp[0].depth;
1206 const int mid = 1 << (desc->comp[0].depth - 1);1182 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;
1217 1183
1218 ydst[x] = c;1184 for (j = 0; j < h; j++) {
1219 udst[x] = mid;1185 for (i = 0; i < w; i++) {
1220 vdst[x] = mid;1186 int c = factor * i / w;
1221 }1187 int y = mid, u = mid, v = mid;
1222
1223 ydst += ylinesize;
1224 udst += ulinesize;
1225 vdst += vlinesize;
1226 }
1227 1188
1228 h += h;1189 if (3*j < h ) y = c;
1229 for (; y < h; y++) {1190 else if (3*j < 2*h) u = c;
1230 for (x = 0; x < w; x++) {1191 else v = c;
1231 int c = factor * x / w;
1232
1233 ydst[x] = mid;
1234 udst[x] = c;
1235 vdst[x] = mid;
1236 }
1237 1192
1238 ydst += ylinesize;1193 yuvtest_put_pixel(frame->data, frame->linesize, i, j, y, u, v,
1239 udst += ulinesize;1194 ctx->outputs[0]->format, test->ayuv_map);
1240 vdst += vlinesize;1195 }
1241 }1196 }
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 }
1256}1197}
1257 1198
1258static av_cold int yuvtest_init(AVFilterContext *ctx)1199static av_cold int yuvtest_init(AVFilterContext *ctx)
@@ -1260,6 +1201,7 @@ static av_cold int yuvtest_init(AVFilterContext *ctx) · 1 unmodified line
1260 TestSourceContext *test = ctx->priv;1201 TestSourceContext *test = ctx->priv;
1261 1202
1262 test->draw_once = 1;1203 test->draw_once = 1;
1204 test->fill_picture_fn = yuvtest_fill_picture;
1263 return init(ctx);1205 return init(ctx);
1264}1206}
1265 1207
@@ -1274,9 +1216,8 @@ static const enum AVPixelFormat yuvtest_pix_fmts[] = { · 8 unmodified lines
1274static int yuvtest_config_props(AVFilterLink *outlink)1216static int yuvtest_config_props(AVFilterLink *outlink)
1275{1217{
1276 TestSourceContext *test = outlink->src->priv;1218 TestSourceContext *test = outlink->src->priv;
1277 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
1278 1219
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);
1280 return config_props(outlink);1221 return config_props(outlink);
1281}1222}
1282 1223

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t