vsrc_testsrc.c 19 KB

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