vsrc_testsrc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /*
  2. * Copyright (c) 2007 Nicolas George <nicolas.george@normalesup.org>
  3. * Copyright (c) 2011 Stefano Sabatini
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Misc test sources.
  24. *
  25. * testsrc is based on the test pattern generator demuxer by Nicolas George:
  26. * http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2007-October/037845.html
  27. *
  28. * rgbtestsrc is ported from MPlayer libmpcodecs/vf_rgbtest.c by
  29. * Michael Niedermayer.
  30. */
  31. #include <float.h>
  32. #include "libavutil/opt.h"
  33. #include "libavutil/intreadwrite.h"
  34. #include "libavutil/parseutils.h"
  35. #include "avfilter.h"
  36. typedef struct {
  37. const AVClass *class;
  38. int w, h;
  39. unsigned int nb_frame;
  40. AVRational time_base;
  41. int64_t pts, max_pts;
  42. char *rate; ///< video frame rate
  43. char *duration; ///< total duration of the generated video
  44. AVRational sar; ///< sample aspect ratio
  45. int nb_decimals;
  46. void (* fill_picture_fn)(AVFilterContext *ctx, AVFilterBufferRef *picref);
  47. /* only used by rgbtest */
  48. int rgba_map[4];
  49. } TestSourceContext;
  50. #define OFFSET(x) offsetof(TestSourceContext, x)
  51. static const AVOption testsrc_options[]= {
  52. { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
  53. { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
  54. { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
  55. { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
  56. { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
  57. { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
  58. { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX },
  59. { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
  60. { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
  61. { NULL },
  62. };
  63. static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
  64. {
  65. TestSourceContext *test = ctx->priv;
  66. AVRational frame_rate_q;
  67. int64_t duration = -1;
  68. int ret = 0;
  69. av_opt_set_defaults(test);
  70. if ((ret = (av_set_options_string(test, args, "=", ":"))) < 0) {
  71. av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
  72. return ret;
  73. }
  74. if ((ret = av_parse_video_rate(&frame_rate_q, test->rate)) < 0 ||
  75. frame_rate_q.den <= 0 || frame_rate_q.num <= 0) {
  76. av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", test->rate);
  77. return ret;
  78. }
  79. av_freep(&test->rate);
  80. if ((test->duration) && (ret = av_parse_time(&duration, test->duration, 1)) < 0) {
  81. av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration);
  82. return ret;
  83. }
  84. av_freep(&test->duration);
  85. if (test->nb_decimals && strcmp(ctx->filter->name, "testsrc")) {
  86. av_log(ctx, AV_LOG_WARNING,
  87. "Option 'decimals' is ignored with source '%s'\n",
  88. ctx->filter->name);
  89. }
  90. test->time_base.num = frame_rate_q.den;
  91. test->time_base.den = frame_rate_q.num;
  92. test->max_pts = duration >= 0 ?
  93. av_rescale_q(duration, AV_TIME_BASE_Q, test->time_base) : -1;
  94. test->nb_frame = 0;
  95. test->pts = 0;
  96. av_log(ctx, AV_LOG_INFO, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
  97. test->w, test->h, frame_rate_q.num, frame_rate_q.den,
  98. duration < 0 ? -1 : test->max_pts * av_q2d(test->time_base),
  99. test->sar.num, test->sar.den);
  100. return 0;
  101. }
  102. static int config_props(AVFilterLink *outlink)
  103. {
  104. TestSourceContext *test = outlink->src->priv;
  105. outlink->w = test->w;
  106. outlink->h = test->h;
  107. outlink->sample_aspect_ratio = test->sar;
  108. outlink->time_base = test->time_base;
  109. return 0;
  110. }
  111. static int request_frame(AVFilterLink *outlink)
  112. {
  113. TestSourceContext *test = outlink->src->priv;
  114. AVFilterBufferRef *picref;
  115. if (test->max_pts >= 0 && test->pts >= test->max_pts)
  116. return AVERROR_EOF;
  117. picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
  118. test->w, test->h);
  119. picref->pts = test->pts++;
  120. picref->pos = -1;
  121. picref->video->key_frame = 1;
  122. picref->video->interlaced = 0;
  123. picref->video->pict_type = AV_PICTURE_TYPE_I;
  124. picref->video->sample_aspect_ratio = test->sar;
  125. test->fill_picture_fn(outlink->src, picref);
  126. test->nb_frame++;
  127. avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
  128. avfilter_draw_slice(outlink, 0, picref->video->h, 1);
  129. avfilter_end_frame(outlink);
  130. avfilter_unref_buffer(picref);
  131. return 0;
  132. }
  133. #if CONFIG_NULLSRC_FILTER
  134. static const char *nullsrc_get_name(void *ctx)
  135. {
  136. return "nullsrc";
  137. }
  138. static const AVClass nullsrc_class = {
  139. .class_name = "NullSourceContext",
  140. .item_name = nullsrc_get_name,
  141. .option = testsrc_options,
  142. };
  143. static void nullsrc_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) { }
  144. static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args, void *opaque)
  145. {
  146. TestSourceContext *test = ctx->priv;
  147. test->class = &nullsrc_class;
  148. test->fill_picture_fn = nullsrc_fill_picture;
  149. return init(ctx, args, opaque);
  150. }
  151. AVFilter avfilter_vsrc_nullsrc = {
  152. .name = "nullsrc",
  153. .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
  154. .init = nullsrc_init,
  155. .priv_size = sizeof(TestSourceContext),
  156. .inputs = (const AVFilterPad[]) {{ .name = NULL}},
  157. .outputs = (const AVFilterPad[]) {{ .name = "default",
  158. .type = AVMEDIA_TYPE_VIDEO,
  159. .request_frame = request_frame,
  160. .config_props = config_props, },
  161. { .name = NULL}},
  162. };
  163. #endif /* CONFIG_NULLSRC_FILTER */
  164. #if CONFIG_TESTSRC_FILTER
  165. static const char *testsrc_get_name(void *ctx)
  166. {
  167. return "testsrc";
  168. }
  169. static const AVClass testsrc_class = {
  170. .class_name = "TestSourceContext",
  171. .item_name = testsrc_get_name,
  172. .option = testsrc_options,
  173. };
  174. /**
  175. * Fill a rectangle with value val.
  176. *
  177. * @param val the RGB value to set
  178. * @param dst pointer to the destination buffer to fill
  179. * @param dst_linesize linesize of destination
  180. * @param segment_width width of the segment
  181. * @param x horizontal coordinate where to draw the rectangle in the destination buffer
  182. * @param y horizontal coordinate where to draw the rectangle in the destination buffer
  183. * @param w width of the rectangle to draw, expressed as a number of segment_width units
  184. * @param h height of the rectangle to draw, expressed as a number of segment_width units
  185. */
  186. static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, unsigned segment_width,
  187. unsigned x, unsigned y, unsigned w, unsigned h)
  188. {
  189. int i;
  190. int step = 3;
  191. dst += segment_width * (step * x + y * dst_linesize);
  192. w *= segment_width * step;
  193. h *= segment_width;
  194. for (i = 0; i < h; i++) {
  195. memset(dst, val, w);
  196. dst += dst_linesize;
  197. }
  198. }
  199. static void draw_digit(int digit, uint8_t *dst, unsigned dst_linesize,
  200. unsigned segment_width)
  201. {
  202. #define TOP_HBAR 1
  203. #define MID_HBAR 2
  204. #define BOT_HBAR 4
  205. #define LEFT_TOP_VBAR 8
  206. #define LEFT_BOT_VBAR 16
  207. #define RIGHT_TOP_VBAR 32
  208. #define RIGHT_BOT_VBAR 64
  209. struct {
  210. int x, y, w, h;
  211. } segments[] = {
  212. { 1, 0, 5, 1 }, /* TOP_HBAR */
  213. { 1, 6, 5, 1 }, /* MID_HBAR */
  214. { 1, 12, 5, 1 }, /* BOT_HBAR */
  215. { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
  216. { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
  217. { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
  218. { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
  219. };
  220. static const unsigned char masks[10] = {
  221. /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  222. /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  223. /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
  224. /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  225. /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  226. /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
  227. /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
  228. /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  229. /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  230. /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  231. };
  232. unsigned mask = masks[digit];
  233. int i;
  234. draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
  235. for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
  236. if (mask & (1<<i))
  237. draw_rectangle(255, dst, dst_linesize, segment_width,
  238. segments[i].x, segments[i].y, segments[i].w, segments[i].h);
  239. }
  240. #define GRADIENT_SIZE (6 * 256)
  241. static void test_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
  242. {
  243. TestSourceContext *test = ctx->priv;
  244. uint8_t *p, *p0;
  245. int x, y;
  246. int color, color_rest;
  247. int icolor;
  248. int radius;
  249. int quad0, quad;
  250. int dquad_x, dquad_y;
  251. int grad, dgrad, rgrad, drgrad;
  252. int seg_size;
  253. int second;
  254. int i;
  255. uint8_t *data = picref->data[0];
  256. int width = picref->video->w;
  257. int height = picref->video->h;
  258. /* draw colored bars and circle */
  259. radius = (width + height) / 4;
  260. quad0 = width * width / 4 + height * height / 4 - radius * radius;
  261. dquad_y = 1 - height;
  262. p0 = data;
  263. for (y = 0; y < height; y++) {
  264. p = p0;
  265. color = 0;
  266. color_rest = 0;
  267. quad = quad0;
  268. dquad_x = 1 - width;
  269. for (x = 0; x < width; x++) {
  270. icolor = color;
  271. if (quad < 0)
  272. icolor ^= 7;
  273. quad += dquad_x;
  274. dquad_x += 2;
  275. *(p++) = icolor & 1 ? 255 : 0;
  276. *(p++) = icolor & 2 ? 255 : 0;
  277. *(p++) = icolor & 4 ? 255 : 0;
  278. color_rest += 8;
  279. if (color_rest >= width) {
  280. color_rest -= width;
  281. color++;
  282. }
  283. }
  284. quad0 += dquad_y;
  285. dquad_y += 2;
  286. p0 += picref->linesize[0];
  287. }
  288. /* draw sliding color line */
  289. p0 = p = data + picref->linesize[0] * height * 3/4;
  290. grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
  291. GRADIENT_SIZE;
  292. rgrad = 0;
  293. dgrad = GRADIENT_SIZE / width;
  294. drgrad = GRADIENT_SIZE % width;
  295. for (x = 0; x < width; x++) {
  296. *(p++) =
  297. grad < 256 || grad >= 5 * 256 ? 255 :
  298. grad >= 2 * 256 && grad < 4 * 256 ? 0 :
  299. grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
  300. *(p++) =
  301. grad >= 4 * 256 ? 0 :
  302. grad >= 1 * 256 && grad < 3 * 256 ? 255 :
  303. grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
  304. *(p++) =
  305. grad < 2 * 256 ? 0 :
  306. grad >= 3 * 256 && grad < 5 * 256 ? 255 :
  307. grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
  308. grad += dgrad;
  309. rgrad += drgrad;
  310. if (rgrad >= GRADIENT_SIZE) {
  311. grad++;
  312. rgrad -= GRADIENT_SIZE;
  313. }
  314. if (grad >= GRADIENT_SIZE)
  315. grad -= GRADIENT_SIZE;
  316. }
  317. p = p0;
  318. for (y = height / 8; y > 0; y--) {
  319. memcpy(p+picref->linesize[0], p, 3 * width);
  320. p += picref->linesize[0];
  321. }
  322. /* draw digits */
  323. seg_size = width / 80;
  324. if (seg_size >= 1 && height >= 13 * seg_size) {
  325. double time = av_q2d(test->time_base) * test->nb_frame *
  326. pow(10, test->nb_decimals);
  327. if (time > INT_MAX)
  328. return;
  329. second = (int)time;
  330. x = width - (width - seg_size * 64) / 2;
  331. y = (height - seg_size * 13) / 2;
  332. p = data + (x*3 + y * picref->linesize[0]);
  333. for (i = 0; i < 8; i++) {
  334. p -= 3 * 8 * seg_size;
  335. draw_digit(second % 10, p, picref->linesize[0], seg_size);
  336. second /= 10;
  337. if (second == 0)
  338. break;
  339. }
  340. }
  341. }
  342. static av_cold int test_init(AVFilterContext *ctx, const char *args, void *opaque)
  343. {
  344. TestSourceContext *test = ctx->priv;
  345. test->class = &testsrc_class;
  346. test->fill_picture_fn = test_fill_picture;
  347. return init(ctx, args, opaque);
  348. }
  349. static int test_query_formats(AVFilterContext *ctx)
  350. {
  351. static const enum PixelFormat pix_fmts[] = {
  352. PIX_FMT_RGB24, PIX_FMT_NONE
  353. };
  354. avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
  355. return 0;
  356. }
  357. AVFilter avfilter_vsrc_testsrc = {
  358. .name = "testsrc",
  359. .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
  360. .priv_size = sizeof(TestSourceContext),
  361. .init = test_init,
  362. .query_formats = test_query_formats,
  363. .inputs = (const AVFilterPad[]) {{ .name = NULL}},
  364. .outputs = (const AVFilterPad[]) {{ .name = "default",
  365. .type = AVMEDIA_TYPE_VIDEO,
  366. .request_frame = request_frame,
  367. .config_props = config_props, },
  368. { .name = NULL }},
  369. };
  370. #endif /* CONFIG_TESTSRC_FILTER */
  371. #if CONFIG_RGBTESTSRC_FILTER
  372. static const char *rgbtestsrc_get_name(void *ctx)
  373. {
  374. return "rgbtestsrc";
  375. }
  376. static const AVClass rgbtestsrc_class = {
  377. .class_name = "RGBTestSourceContext",
  378. .item_name = rgbtestsrc_get_name,
  379. .option = testsrc_options,
  380. };
  381. #define R 0
  382. #define G 1
  383. #define B 2
  384. #define A 3
  385. static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
  386. int x, int y, int r, int g, int b, enum PixelFormat fmt,
  387. int rgba_map[4])
  388. {
  389. int32_t v;
  390. uint8_t *p;
  391. switch (fmt) {
  392. case PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
  393. case PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
  394. case PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
  395. case PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
  396. case PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
  397. case PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
  398. case PIX_FMT_RGB24:
  399. case PIX_FMT_BGR24:
  400. v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
  401. p = dst + 3*x + y*dst_linesize;
  402. AV_WL24(p, v);
  403. break;
  404. case PIX_FMT_RGBA:
  405. case PIX_FMT_BGRA:
  406. case PIX_FMT_ARGB:
  407. case PIX_FMT_ABGR:
  408. v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
  409. p = dst + 4*x + y*dst_linesize;
  410. AV_WL32(p, v);
  411. break;
  412. }
  413. }
  414. static void rgbtest_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
  415. {
  416. TestSourceContext *test = ctx->priv;
  417. int x, y, w = picref->video->w, h = picref->video->h;
  418. for (y = 0; y < h; y++) {
  419. for (x = 0; x < picref->video->w; x++) {
  420. int c = 256*x/w;
  421. int r = 0, g = 0, b = 0;
  422. if (3*y < h ) r = c;
  423. else if (3*y < 2*h) g = c;
  424. else b = c;
  425. rgbtest_put_pixel(picref->data[0], picref->linesize[0], x, y, r, g, b,
  426. ctx->outputs[0]->format, test->rgba_map);
  427. }
  428. }
  429. }
  430. static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args, void *opaque)
  431. {
  432. TestSourceContext *test = ctx->priv;
  433. test->class = &rgbtestsrc_class;
  434. test->fill_picture_fn = rgbtest_fill_picture;
  435. return init(ctx, args, opaque);
  436. }
  437. static int rgbtest_query_formats(AVFilterContext *ctx)
  438. {
  439. static const enum PixelFormat pix_fmts[] = {
  440. PIX_FMT_RGBA, PIX_FMT_ARGB, PIX_FMT_BGRA, PIX_FMT_ABGR,
  441. PIX_FMT_BGR24, PIX_FMT_RGB24,
  442. PIX_FMT_RGB444, PIX_FMT_BGR444,
  443. PIX_FMT_RGB565, PIX_FMT_BGR565,
  444. PIX_FMT_RGB555, PIX_FMT_BGR555,
  445. PIX_FMT_NONE
  446. };
  447. avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
  448. return 0;
  449. }
  450. static int rgbtest_config_props(AVFilterLink *outlink)
  451. {
  452. TestSourceContext *test = outlink->src->priv;
  453. switch (outlink->format) {
  454. case PIX_FMT_ARGB: test->rgba_map[A] = 0; test->rgba_map[R] = 1; test->rgba_map[G] = 2; test->rgba_map[B] = 3; break;
  455. case PIX_FMT_ABGR: test->rgba_map[A] = 0; test->rgba_map[B] = 1; test->rgba_map[G] = 2; test->rgba_map[R] = 3; break;
  456. case PIX_FMT_RGBA:
  457. case PIX_FMT_RGB24: test->rgba_map[R] = 0; test->rgba_map[G] = 1; test->rgba_map[B] = 2; test->rgba_map[A] = 3; break;
  458. case PIX_FMT_BGRA:
  459. case PIX_FMT_BGR24: test->rgba_map[B] = 0; test->rgba_map[G] = 1; test->rgba_map[R] = 2; test->rgba_map[A] = 3; break;
  460. }
  461. return config_props(outlink);
  462. }
  463. AVFilter avfilter_vsrc_rgbtestsrc = {
  464. .name = "rgbtestsrc",
  465. .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
  466. .priv_size = sizeof(TestSourceContext),
  467. .init = rgbtest_init,
  468. .query_formats = rgbtest_query_formats,
  469. .inputs = (const AVFilterPad[]) {{ .name = NULL}},
  470. .outputs = (const AVFilterPad[]) {{ .name = "default",
  471. .type = AVMEDIA_TYPE_VIDEO,
  472. .request_frame = request_frame,
  473. .config_props = rgbtest_config_props, },
  474. { .name = NULL }},
  475. };
  476. #endif /* CONFIG_RGBTESTSRC_FILTER */