You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1815 lines
56KB

  1. /*
  2. * Copyright (c) 2007 Nicolas George <nicolas.george@normalesup.org>
  3. * Copyright (c) 2011 Stefano Sabatini
  4. * Copyright (c) 2012 Paul B Mahol
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * Misc test sources.
  25. *
  26. * testsrc is based on the test pattern generator demuxer by Nicolas George:
  27. * http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2007-October/037845.html
  28. *
  29. * rgbtestsrc is ported from MPlayer libmpcodecs/vf_rgbtest.c by
  30. * Michael Niedermayer.
  31. *
  32. * allyuv, smptebars and smptehdbars are by Paul B Mahol.
  33. */
  34. #include <float.h>
  35. #include "libavutil/avassert.h"
  36. #include "libavutil/common.h"
  37. #include "libavutil/ffmath.h"
  38. #include "libavutil/opt.h"
  39. #include "libavutil/imgutils.h"
  40. #include "libavutil/intreadwrite.h"
  41. #include "libavutil/parseutils.h"
  42. #include "libavutil/xga_font_data.h"
  43. #include "avfilter.h"
  44. #include "drawutils.h"
  45. #include "filters.h"
  46. #include "formats.h"
  47. #include "internal.h"
  48. #include "video.h"
  49. typedef struct TestSourceContext {
  50. const AVClass *class;
  51. int w, h;
  52. unsigned int nb_frame;
  53. AVRational time_base, frame_rate;
  54. int64_t pts;
  55. int64_t duration; ///< duration expressed in microseconds
  56. AVRational sar; ///< sample aspect ratio
  57. int draw_once; ///< draw only the first frame, always put out the same picture
  58. int draw_once_reset; ///< draw only the first frame or in case of reset
  59. AVFrame *picref; ///< cached reference containing the painted picture
  60. void (* fill_picture_fn)(AVFilterContext *ctx, AVFrame *frame);
  61. /* only used by testsrc */
  62. int nb_decimals;
  63. /* only used by testsrc2 */
  64. int alpha;
  65. /* only used by color */
  66. FFDrawContext draw;
  67. FFDrawColor color;
  68. uint8_t color_rgba[4];
  69. /* only used by rgbtest */
  70. uint8_t rgba_map[4];
  71. /* only used by haldclut */
  72. int level;
  73. } TestSourceContext;
  74. #define OFFSET(x) offsetof(TestSourceContext, x)
  75. #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  76. #define FLAGSR AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
  77. #define SIZE_OPTIONS \
  78. { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
  79. { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
  80. #define COMMON_OPTIONS_NOSIZE \
  81. { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
  82. { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
  83. { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
  84. { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
  85. { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
  86. #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
  87. static const AVOption options[] = {
  88. COMMON_OPTIONS
  89. { NULL }
  90. };
  91. static av_cold int init(AVFilterContext *ctx)
  92. {
  93. TestSourceContext *test = ctx->priv;
  94. test->time_base = av_inv_q(test->frame_rate);
  95. test->nb_frame = 0;
  96. test->pts = 0;
  97. av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
  98. test->w, test->h, test->frame_rate.num, test->frame_rate.den,
  99. test->duration < 0 ? -1 : (double)test->duration/1000000,
  100. test->sar.num, test->sar.den);
  101. return 0;
  102. }
  103. static av_cold void uninit(AVFilterContext *ctx)
  104. {
  105. TestSourceContext *test = ctx->priv;
  106. av_frame_free(&test->picref);
  107. }
  108. static int config_props(AVFilterLink *outlink)
  109. {
  110. TestSourceContext *test = outlink->src->priv;
  111. outlink->w = test->w;
  112. outlink->h = test->h;
  113. outlink->sample_aspect_ratio = test->sar;
  114. outlink->frame_rate = test->frame_rate;
  115. outlink->time_base = test->time_base;
  116. return 0;
  117. }
  118. static int activate(AVFilterContext *ctx)
  119. {
  120. AVFilterLink *outlink = ctx->outputs[0];
  121. TestSourceContext *test = ctx->priv;
  122. AVFrame *frame;
  123. if (!ff_outlink_frame_wanted(outlink))
  124. return FFERROR_NOT_READY;
  125. if (test->duration >= 0 &&
  126. av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration) {
  127. ff_outlink_set_status(outlink, AVERROR_EOF, test->pts);
  128. return 0;
  129. }
  130. if (test->draw_once) {
  131. if (test->draw_once_reset) {
  132. av_frame_free(&test->picref);
  133. test->draw_once_reset = 0;
  134. }
  135. if (!test->picref) {
  136. test->picref =
  137. ff_get_video_buffer(outlink, test->w, test->h);
  138. if (!test->picref)
  139. return AVERROR(ENOMEM);
  140. test->fill_picture_fn(outlink->src, test->picref);
  141. }
  142. frame = av_frame_clone(test->picref);
  143. } else
  144. frame = ff_get_video_buffer(outlink, test->w, test->h);
  145. if (!frame)
  146. return AVERROR(ENOMEM);
  147. frame->pts = test->pts;
  148. frame->key_frame = 1;
  149. frame->interlaced_frame = 0;
  150. frame->pict_type = AV_PICTURE_TYPE_I;
  151. frame->sample_aspect_ratio = test->sar;
  152. if (!test->draw_once)
  153. test->fill_picture_fn(outlink->src, frame);
  154. test->pts++;
  155. test->nb_frame++;
  156. return ff_filter_frame(outlink, frame);
  157. }
  158. #if CONFIG_COLOR_FILTER
  159. static const AVOption color_options[] = {
  160. { "color", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGSR },
  161. { "c", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGSR },
  162. COMMON_OPTIONS
  163. { NULL }
  164. };
  165. AVFILTER_DEFINE_CLASS(color);
  166. static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
  167. {
  168. TestSourceContext *test = ctx->priv;
  169. ff_fill_rectangle(&test->draw, &test->color,
  170. picref->data, picref->linesize,
  171. 0, 0, test->w, test->h);
  172. }
  173. static av_cold int color_init(AVFilterContext *ctx)
  174. {
  175. TestSourceContext *test = ctx->priv;
  176. test->fill_picture_fn = color_fill_picture;
  177. test->draw_once = 1;
  178. return init(ctx);
  179. }
  180. static int color_query_formats(AVFilterContext *ctx)
  181. {
  182. return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
  183. }
  184. static int color_config_props(AVFilterLink *inlink)
  185. {
  186. AVFilterContext *ctx = inlink->src;
  187. TestSourceContext *test = ctx->priv;
  188. int ret;
  189. ff_draw_init(&test->draw, inlink->format, 0);
  190. ff_draw_color(&test->draw, &test->color, test->color_rgba);
  191. test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
  192. test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
  193. if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
  194. return AVERROR(EINVAL);
  195. if ((ret = config_props(inlink)) < 0)
  196. return ret;
  197. return 0;
  198. }
  199. static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
  200. char *res, int res_len, int flags)
  201. {
  202. TestSourceContext *test = ctx->priv;
  203. int ret;
  204. ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
  205. if (ret < 0)
  206. return ret;
  207. ff_draw_color(&test->draw, &test->color, test->color_rgba);
  208. test->draw_once_reset = 1;
  209. return 0;
  210. }
  211. static const AVFilterPad color_outputs[] = {
  212. {
  213. .name = "default",
  214. .type = AVMEDIA_TYPE_VIDEO,
  215. .config_props = color_config_props,
  216. },
  217. { NULL }
  218. };
  219. AVFilter ff_vsrc_color = {
  220. .name = "color",
  221. .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
  222. .priv_class = &color_class,
  223. .priv_size = sizeof(TestSourceContext),
  224. .init = color_init,
  225. .uninit = uninit,
  226. .activate = activate,
  227. .query_formats = color_query_formats,
  228. .inputs = NULL,
  229. .outputs = color_outputs,
  230. .process_command = color_process_command,
  231. };
  232. #endif /* CONFIG_COLOR_FILTER */
  233. #if CONFIG_HALDCLUTSRC_FILTER
  234. static const AVOption haldclutsrc_options[] = {
  235. { "level", "set level", OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 6}, 2, 16, FLAGS },
  236. COMMON_OPTIONS_NOSIZE
  237. { NULL }
  238. };
  239. AVFILTER_DEFINE_CLASS(haldclutsrc);
  240. static void haldclutsrc_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  241. {
  242. int i, j, k, x = 0, y = 0, is16bit = 0, step;
  243. uint32_t alpha = 0;
  244. const TestSourceContext *hc = ctx->priv;
  245. int level = hc->level;
  246. float scale;
  247. const int w = frame->width;
  248. const int h = frame->height;
  249. const uint8_t *data = frame->data[0];
  250. const int linesize = frame->linesize[0];
  251. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
  252. uint8_t rgba_map[4];
  253. av_assert0(w == h && w == level*level*level);
  254. ff_fill_rgba_map(rgba_map, frame->format);
  255. switch (frame->format) {
  256. case AV_PIX_FMT_RGB48:
  257. case AV_PIX_FMT_BGR48:
  258. case AV_PIX_FMT_RGBA64:
  259. case AV_PIX_FMT_BGRA64:
  260. is16bit = 1;
  261. alpha = 0xffff;
  262. break;
  263. case AV_PIX_FMT_RGBA:
  264. case AV_PIX_FMT_BGRA:
  265. case AV_PIX_FMT_ARGB:
  266. case AV_PIX_FMT_ABGR:
  267. alpha = 0xff;
  268. break;
  269. }
  270. step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
  271. scale = ((float)(1 << (8*(is16bit+1))) - 1) / (level*level - 1);
  272. #define LOAD_CLUT(nbits) do { \
  273. uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step; \
  274. dst[rgba_map[0]] = av_clip_uint##nbits(i * scale); \
  275. dst[rgba_map[1]] = av_clip_uint##nbits(j * scale); \
  276. dst[rgba_map[2]] = av_clip_uint##nbits(k * scale); \
  277. if (step == 4) \
  278. dst[rgba_map[3]] = alpha; \
  279. } while (0)
  280. level *= level;
  281. for (k = 0; k < level; k++) {
  282. for (j = 0; j < level; j++) {
  283. for (i = 0; i < level; i++) {
  284. if (!is16bit)
  285. LOAD_CLUT(8);
  286. else
  287. LOAD_CLUT(16);
  288. if (++x == w) {
  289. x = 0;
  290. y++;
  291. }
  292. }
  293. }
  294. }
  295. }
  296. static av_cold int haldclutsrc_init(AVFilterContext *ctx)
  297. {
  298. TestSourceContext *hc = ctx->priv;
  299. hc->fill_picture_fn = haldclutsrc_fill_picture;
  300. hc->draw_once = 1;
  301. return init(ctx);
  302. }
  303. static int haldclutsrc_query_formats(AVFilterContext *ctx)
  304. {
  305. static const enum AVPixelFormat pix_fmts[] = {
  306. AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
  307. AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA,
  308. AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR,
  309. AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR,
  310. AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0,
  311. AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48,
  312. AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
  313. AV_PIX_FMT_NONE,
  314. };
  315. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  316. if (!fmts_list)
  317. return AVERROR(ENOMEM);
  318. return ff_set_common_formats(ctx, fmts_list);
  319. }
  320. static int haldclutsrc_config_props(AVFilterLink *outlink)
  321. {
  322. AVFilterContext *ctx = outlink->src;
  323. TestSourceContext *hc = ctx->priv;
  324. hc->w = hc->h = hc->level * hc->level * hc->level;
  325. return config_props(outlink);
  326. }
  327. static const AVFilterPad haldclutsrc_outputs[] = {
  328. {
  329. .name = "default",
  330. .type = AVMEDIA_TYPE_VIDEO,
  331. .config_props = haldclutsrc_config_props,
  332. },
  333. { NULL }
  334. };
  335. AVFilter ff_vsrc_haldclutsrc = {
  336. .name = "haldclutsrc",
  337. .description = NULL_IF_CONFIG_SMALL("Provide an identity Hald CLUT."),
  338. .priv_class = &haldclutsrc_class,
  339. .priv_size = sizeof(TestSourceContext),
  340. .init = haldclutsrc_init,
  341. .uninit = uninit,
  342. .query_formats = haldclutsrc_query_formats,
  343. .activate = activate,
  344. .inputs = NULL,
  345. .outputs = haldclutsrc_outputs,
  346. };
  347. #endif /* CONFIG_HALDCLUTSRC_FILTER */
  348. #if CONFIG_NULLSRC_FILTER
  349. #define nullsrc_options options
  350. AVFILTER_DEFINE_CLASS(nullsrc);
  351. static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
  352. static av_cold int nullsrc_init(AVFilterContext *ctx)
  353. {
  354. TestSourceContext *test = ctx->priv;
  355. test->fill_picture_fn = nullsrc_fill_picture;
  356. return init(ctx);
  357. }
  358. static const AVFilterPad nullsrc_outputs[] = {
  359. {
  360. .name = "default",
  361. .type = AVMEDIA_TYPE_VIDEO,
  362. .config_props = config_props,
  363. },
  364. { NULL },
  365. };
  366. AVFilter ff_vsrc_nullsrc = {
  367. .name = "nullsrc",
  368. .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
  369. .init = nullsrc_init,
  370. .uninit = uninit,
  371. .activate = activate,
  372. .priv_size = sizeof(TestSourceContext),
  373. .priv_class = &nullsrc_class,
  374. .inputs = NULL,
  375. .outputs = nullsrc_outputs,
  376. };
  377. #endif /* CONFIG_NULLSRC_FILTER */
  378. #if CONFIG_TESTSRC_FILTER
  379. static const AVOption testsrc_options[] = {
  380. COMMON_OPTIONS
  381. { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
  382. { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
  383. { NULL }
  384. };
  385. AVFILTER_DEFINE_CLASS(testsrc);
  386. /**
  387. * Fill a rectangle with value val.
  388. *
  389. * @param val the RGB value to set
  390. * @param dst pointer to the destination buffer to fill
  391. * @param dst_linesize linesize of destination
  392. * @param segment_width width of the segment
  393. * @param x horizontal coordinate where to draw the rectangle in the destination buffer
  394. * @param y horizontal coordinate where to draw the rectangle in the destination buffer
  395. * @param w width of the rectangle to draw, expressed as a number of segment_width units
  396. * @param h height of the rectangle to draw, expressed as a number of segment_width units
  397. */
  398. static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, int segment_width,
  399. int x, int y, int w, int h)
  400. {
  401. int i;
  402. int step = 3;
  403. dst += segment_width * (step * x + y * dst_linesize);
  404. w *= segment_width * step;
  405. h *= segment_width;
  406. for (i = 0; i < h; i++) {
  407. memset(dst, val, w);
  408. dst += dst_linesize;
  409. }
  410. }
  411. static void draw_digit(int digit, uint8_t *dst, int dst_linesize,
  412. int segment_width)
  413. {
  414. #define TOP_HBAR 1
  415. #define MID_HBAR 2
  416. #define BOT_HBAR 4
  417. #define LEFT_TOP_VBAR 8
  418. #define LEFT_BOT_VBAR 16
  419. #define RIGHT_TOP_VBAR 32
  420. #define RIGHT_BOT_VBAR 64
  421. struct segments {
  422. int x, y, w, h;
  423. } segments[] = {
  424. { 1, 0, 5, 1 }, /* TOP_HBAR */
  425. { 1, 6, 5, 1 }, /* MID_HBAR */
  426. { 1, 12, 5, 1 }, /* BOT_HBAR */
  427. { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
  428. { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
  429. { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
  430. { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
  431. };
  432. static const unsigned char masks[10] = {
  433. /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  434. /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  435. /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
  436. /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  437. /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  438. /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
  439. /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
  440. /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  441. /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  442. /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  443. };
  444. unsigned mask = masks[digit];
  445. int i;
  446. draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
  447. for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
  448. if (mask & (1<<i))
  449. draw_rectangle(255, dst, dst_linesize, segment_width,
  450. segments[i].x, segments[i].y, segments[i].w, segments[i].h);
  451. }
  452. #define GRADIENT_SIZE (6 * 256)
  453. static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  454. {
  455. TestSourceContext *test = ctx->priv;
  456. uint8_t *p, *p0;
  457. int x, y;
  458. int color, color_rest;
  459. int icolor;
  460. int radius;
  461. int quad0, quad;
  462. int dquad_x, dquad_y;
  463. int grad, dgrad, rgrad, drgrad;
  464. int seg_size;
  465. int second;
  466. int i;
  467. uint8_t *data = frame->data[0];
  468. int width = frame->width;
  469. int height = frame->height;
  470. /* draw colored bars and circle */
  471. radius = (width + height) / 4;
  472. quad0 = width * width / 4 + height * height / 4 - radius * radius;
  473. dquad_y = 1 - height;
  474. p0 = data;
  475. for (y = 0; y < height; y++) {
  476. p = p0;
  477. color = 0;
  478. color_rest = 0;
  479. quad = quad0;
  480. dquad_x = 1 - width;
  481. for (x = 0; x < width; x++) {
  482. icolor = color;
  483. if (quad < 0)
  484. icolor ^= 7;
  485. quad += dquad_x;
  486. dquad_x += 2;
  487. *(p++) = icolor & 1 ? 255 : 0;
  488. *(p++) = icolor & 2 ? 255 : 0;
  489. *(p++) = icolor & 4 ? 255 : 0;
  490. color_rest += 8;
  491. if (color_rest >= width) {
  492. color_rest -= width;
  493. color++;
  494. }
  495. }
  496. quad0 += dquad_y;
  497. dquad_y += 2;
  498. p0 += frame->linesize[0];
  499. }
  500. /* draw sliding color line */
  501. p0 = p = data + frame->linesize[0] * (height * 3/4);
  502. grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
  503. GRADIENT_SIZE;
  504. rgrad = 0;
  505. dgrad = GRADIENT_SIZE / width;
  506. drgrad = GRADIENT_SIZE % width;
  507. for (x = 0; x < width; x++) {
  508. *(p++) =
  509. grad < 256 || grad >= 5 * 256 ? 255 :
  510. grad >= 2 * 256 && grad < 4 * 256 ? 0 :
  511. grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
  512. *(p++) =
  513. grad >= 4 * 256 ? 0 :
  514. grad >= 1 * 256 && grad < 3 * 256 ? 255 :
  515. grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
  516. *(p++) =
  517. grad < 2 * 256 ? 0 :
  518. grad >= 3 * 256 && grad < 5 * 256 ? 255 :
  519. grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
  520. grad += dgrad;
  521. rgrad += drgrad;
  522. if (rgrad >= GRADIENT_SIZE) {
  523. grad++;
  524. rgrad -= GRADIENT_SIZE;
  525. }
  526. if (grad >= GRADIENT_SIZE)
  527. grad -= GRADIENT_SIZE;
  528. }
  529. p = p0;
  530. for (y = height / 8; y > 0; y--) {
  531. memcpy(p+frame->linesize[0], p, 3 * width);
  532. p += frame->linesize[0];
  533. }
  534. /* draw digits */
  535. seg_size = width / 80;
  536. if (seg_size >= 1 && height >= 13 * seg_size) {
  537. int64_t p10decimals = 1;
  538. double time = av_q2d(test->time_base) * test->nb_frame *
  539. ff_exp10(test->nb_decimals);
  540. if (time >= INT_MAX)
  541. return;
  542. for (x = 0; x < test->nb_decimals; x++)
  543. p10decimals *= 10;
  544. second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
  545. x = width - (width - seg_size * 64) / 2;
  546. y = (height - seg_size * 13) / 2;
  547. p = data + (x*3 + y * frame->linesize[0]);
  548. for (i = 0; i < 8; i++) {
  549. p -= 3 * 8 * seg_size;
  550. draw_digit(second % 10, p, frame->linesize[0], seg_size);
  551. second /= 10;
  552. if (second == 0)
  553. break;
  554. }
  555. }
  556. }
  557. static av_cold int test_init(AVFilterContext *ctx)
  558. {
  559. TestSourceContext *test = ctx->priv;
  560. test->fill_picture_fn = test_fill_picture;
  561. return init(ctx);
  562. }
  563. static int test_query_formats(AVFilterContext *ctx)
  564. {
  565. static const enum AVPixelFormat pix_fmts[] = {
  566. AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
  567. };
  568. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  569. if (!fmts_list)
  570. return AVERROR(ENOMEM);
  571. return ff_set_common_formats(ctx, fmts_list);
  572. }
  573. static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
  574. {
  575. .name = "default",
  576. .type = AVMEDIA_TYPE_VIDEO,
  577. .config_props = config_props,
  578. },
  579. { NULL }
  580. };
  581. AVFilter ff_vsrc_testsrc = {
  582. .name = "testsrc",
  583. .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
  584. .priv_size = sizeof(TestSourceContext),
  585. .priv_class = &testsrc_class,
  586. .init = test_init,
  587. .uninit = uninit,
  588. .query_formats = test_query_formats,
  589. .activate = activate,
  590. .inputs = NULL,
  591. .outputs = avfilter_vsrc_testsrc_outputs,
  592. };
  593. #endif /* CONFIG_TESTSRC_FILTER */
  594. #if CONFIG_TESTSRC2_FILTER
  595. static const AVOption testsrc2_options[] = {
  596. COMMON_OPTIONS
  597. { "alpha", "set global alpha (opacity)", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 255}, 0, 255, FLAGS },
  598. { NULL }
  599. };
  600. AVFILTER_DEFINE_CLASS(testsrc2);
  601. static void set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
  602. {
  603. uint8_t rgba[4] = { (argb >> 16) & 0xFF,
  604. (argb >> 8) & 0xFF,
  605. (argb >> 0) & 0xFF,
  606. (argb >> 24) & 0xFF, };
  607. ff_draw_color(&s->draw, color, rgba);
  608. }
  609. static uint32_t color_gradient(unsigned index)
  610. {
  611. unsigned si = index & 0xFF, sd = 0xFF - si;
  612. switch (index >> 8) {
  613. case 0: return 0xFF0000 + (si << 8);
  614. case 1: return 0x00FF00 + (sd << 16);
  615. case 2: return 0x00FF00 + (si << 0);
  616. case 3: return 0x0000FF + (sd << 8);
  617. case 4: return 0x0000FF + (si << 16);
  618. case 5: return 0xFF0000 + (sd << 0);
  619. }
  620. av_assert0(0);
  621. }
  622. static void draw_text(TestSourceContext *s, AVFrame *frame, FFDrawColor *color,
  623. int x0, int y0, const uint8_t *text)
  624. {
  625. int x = x0;
  626. for (; *text; text++) {
  627. if (*text == '\n') {
  628. x = x0;
  629. y0 += 16;
  630. continue;
  631. }
  632. ff_blend_mask(&s->draw, color, frame->data, frame->linesize,
  633. frame->width, frame->height,
  634. avpriv_vga16_font + *text * 16, 1, 8, 16, 0, 0, x, y0);
  635. x += 8;
  636. }
  637. }
  638. static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  639. {
  640. TestSourceContext *s = ctx->priv;
  641. FFDrawColor color;
  642. unsigned alpha = (uint32_t)s->alpha << 24;
  643. /* colored background */
  644. {
  645. unsigned i, x = 0, x2;
  646. x = 0;
  647. for (i = 1; i < 7; i++) {
  648. x2 = av_rescale(i, s->w, 6);
  649. x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2);
  650. set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) |
  651. ((i & 2) ? 0x00FF00 : 0) |
  652. ((i & 4) ? 0x0000FF : 0) |
  653. alpha);
  654. ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
  655. x, 0, x2 - x, frame->height);
  656. x = x2;
  657. }
  658. }
  659. /* oblique gradient */
  660. /* note: too slow if using blending */
  661. if (s->h >= 64) {
  662. unsigned x, dx, y0, y, g0, g;
  663. dx = ff_draw_round_to_sub(&s->draw, 0, +1, 1);
  664. y0 = av_rescale_q(s->pts, s->time_base, av_make_q(2, s->h - 16));
  665. g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128));
  666. for (x = 0; x < s->w; x += dx) {
  667. g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256);
  668. set_color(s, &color, color_gradient(g) | alpha);
  669. y = y0 + av_rescale(x, s->h / 2, s->w);
  670. y %= 2 * (s->h - 16);
  671. if (y > s->h - 16)
  672. y = 2 * (s->h - 16) - y;
  673. y = ff_draw_round_to_sub(&s->draw, 1, 0, y);
  674. ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
  675. x, y, dx, 16);
  676. }
  677. }
  678. /* top right: draw clock hands */
  679. if (s->w >= 64 && s->h >= 64) {
  680. int l = (FFMIN(s->w, s->h) - 32) >> 1;
  681. int steps = FFMAX(4, l >> 5);
  682. int xc = (s->w >> 2) + (s->w >> 1);
  683. int yc = (s->h >> 2);
  684. int cycle = l << 2;
  685. int pos, xh, yh;
  686. int c, i;
  687. for (c = 0; c < 3; c++) {
  688. set_color(s, &color, (0xBBBBBB ^ (0xFF << (c << 3))) | alpha);
  689. pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle;
  690. xh = pos < 1 * l ? pos :
  691. pos < 2 * l ? l :
  692. pos < 3 * l ? 3 * l - pos : 0;
  693. yh = pos < 1 * l ? 0 :
  694. pos < 2 * l ? pos - l :
  695. pos < 3 * l ? l :
  696. cycle - pos;
  697. xh -= l >> 1;
  698. yh -= l >> 1;
  699. for (i = 1; i <= steps; i++) {
  700. int x = av_rescale(xh, i, steps) + xc;
  701. int y = av_rescale(yh, i, steps) + yc;
  702. x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
  703. y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
  704. ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
  705. x, y, 8, 8);
  706. }
  707. }
  708. }
  709. /* bottom left: beating rectangles */
  710. if (s->w >= 64 && s->h >= 64) {
  711. int l = (FFMIN(s->w, s->h) - 16) >> 2;
  712. int cycle = l << 3;
  713. int xc = (s->w >> 2);
  714. int yc = (s->h >> 2) + (s->h >> 1);
  715. int xm1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 8);
  716. int xm2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 8);
  717. int ym1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 8);
  718. int ym2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 8);
  719. int size, step, x1, x2, y1, y2;
  720. size = av_rescale_q(s->pts, s->time_base, av_make_q(4, cycle));
  721. step = size / l;
  722. size %= l;
  723. if (step & 1)
  724. size = l - size;
  725. step = (step >> 1) & 3;
  726. set_color(s, &color, 0xFF808080);
  727. x1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 4 - size);
  728. x2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 4 + size);
  729. y1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 4 - size);
  730. y2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 4 + size);
  731. if (step == 0 || step == 2)
  732. ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
  733. x1, ym1, x2 - x1, ym2 - ym1);
  734. if (step == 1 || step == 2)
  735. ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
  736. xm1, y1, xm2 - xm1, y2 - y1);
  737. if (step == 3)
  738. ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
  739. x1, y1, x2 - x1, y2 - y1);
  740. }
  741. /* bottom right: checker with random noise */
  742. {
  743. unsigned xmin = av_rescale(5, s->w, 8);
  744. unsigned xmax = av_rescale(7, s->w, 8);
  745. unsigned ymin = av_rescale(5, s->h, 8);
  746. unsigned ymax = av_rescale(7, s->h, 8);
  747. unsigned x, y, i, r;
  748. uint8_t alpha[256];
  749. r = s->pts;
  750. for (y = ymin; y + 15 < ymax; y += 16) {
  751. for (x = xmin; x + 15 < xmax; x += 16) {
  752. if ((x ^ y) & 16)
  753. continue;
  754. for (i = 0; i < 256; i++) {
  755. r = r * 1664525 + 1013904223;
  756. alpha[i] = r >> 24;
  757. }
  758. set_color(s, &color, 0xFF00FF80);
  759. ff_blend_mask(&s->draw, &color, frame->data, frame->linesize,
  760. frame->width, frame->height,
  761. alpha, 16, 16, 16, 3, 0, x, y);
  762. }
  763. }
  764. }
  765. /* bouncing square */
  766. if (s->w >= 16 && s->h >= 16) {
  767. unsigned w = s->w - 8;
  768. unsigned h = s->h - 8;
  769. unsigned x = av_rescale_q(s->pts, s->time_base, av_make_q(233, 55 * w)) % (w << 1);
  770. unsigned y = av_rescale_q(s->pts, s->time_base, av_make_q(233, 89 * h)) % (h << 1);
  771. if (x > w)
  772. x = (w << 1) - x;
  773. if (y > h)
  774. y = (h << 1) - y;
  775. x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
  776. y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
  777. set_color(s, &color, 0xFF8000FF);
  778. ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
  779. x, y, 8, 8);
  780. }
  781. /* top right: draw frame time and frame number */
  782. {
  783. char buf[256];
  784. unsigned time;
  785. time = av_rescale_q(s->pts, s->time_base, av_make_q(1, 1000)) % 86400000;
  786. set_color(s, &color, 0xC0000000);
  787. ff_blend_rectangle(&s->draw, &color, frame->data, frame->linesize,
  788. frame->width, frame->height,
  789. 2, 2, 100, 36);
  790. set_color(s, &color, 0xFFFF8000);
  791. snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%03d\n%12"PRIi64,
  792. time / 3600000, (time / 60000) % 60, (time / 1000) % 60,
  793. time % 1000, s->pts);
  794. draw_text(s, frame, &color, 4, 4, buf);
  795. }
  796. }
  797. static av_cold int test2_init(AVFilterContext *ctx)
  798. {
  799. TestSourceContext *s = ctx->priv;
  800. s->fill_picture_fn = test2_fill_picture;
  801. return init(ctx);
  802. }
  803. static int test2_query_formats(AVFilterContext *ctx)
  804. {
  805. return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
  806. }
  807. static int test2_config_props(AVFilterLink *inlink)
  808. {
  809. AVFilterContext *ctx = inlink->src;
  810. TestSourceContext *s = ctx->priv;
  811. av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0);
  812. s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
  813. s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
  814. if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
  815. return AVERROR(EINVAL);
  816. return config_props(inlink);
  817. }
  818. static const AVFilterPad avfilter_vsrc_testsrc2_outputs[] = {
  819. {
  820. .name = "default",
  821. .type = AVMEDIA_TYPE_VIDEO,
  822. .config_props = test2_config_props,
  823. },
  824. { NULL }
  825. };
  826. AVFilter ff_vsrc_testsrc2 = {
  827. .name = "testsrc2",
  828. .description = NULL_IF_CONFIG_SMALL("Generate another test pattern."),
  829. .priv_size = sizeof(TestSourceContext),
  830. .priv_class = &testsrc2_class,
  831. .init = test2_init,
  832. .uninit = uninit,
  833. .query_formats = test2_query_formats,
  834. .activate = activate,
  835. .inputs = NULL,
  836. .outputs = avfilter_vsrc_testsrc2_outputs,
  837. };
  838. #endif /* CONFIG_TESTSRC2_FILTER */
  839. #if CONFIG_RGBTESTSRC_FILTER
  840. #define rgbtestsrc_options options
  841. AVFILTER_DEFINE_CLASS(rgbtestsrc);
  842. #define R 0
  843. #define G 1
  844. #define B 2
  845. #define A 3
  846. static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
  847. int x, int y, unsigned r, unsigned g, unsigned b, enum AVPixelFormat fmt,
  848. uint8_t rgba_map[4])
  849. {
  850. uint32_t v;
  851. uint8_t *p;
  852. switch (fmt) {
  853. case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
  854. case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
  855. case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
  856. case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
  857. case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
  858. case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
  859. case AV_PIX_FMT_RGB24:
  860. case AV_PIX_FMT_BGR24:
  861. v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
  862. p = dst + 3*x + y*dst_linesize;
  863. AV_WL24(p, v);
  864. break;
  865. case AV_PIX_FMT_RGBA:
  866. case AV_PIX_FMT_BGRA:
  867. case AV_PIX_FMT_ARGB:
  868. case AV_PIX_FMT_ABGR:
  869. v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255U << (rgba_map[A]*8));
  870. p = dst + 4*x + y*dst_linesize;
  871. AV_WL32(p, v);
  872. break;
  873. }
  874. }
  875. static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  876. {
  877. TestSourceContext *test = ctx->priv;
  878. int x, y, w = frame->width, h = frame->height;
  879. for (y = 0; y < h; y++) {
  880. for (x = 0; x < w; x++) {
  881. int c = 256*x/w;
  882. int r = 0, g = 0, b = 0;
  883. if (3*y < h ) r = c;
  884. else if (3*y < 2*h) g = c;
  885. else b = c;
  886. rgbtest_put_pixel(frame->data[0], frame->linesize[0], x, y, r, g, b,
  887. ctx->outputs[0]->format, test->rgba_map);
  888. }
  889. }
  890. }
  891. static av_cold int rgbtest_init(AVFilterContext *ctx)
  892. {
  893. TestSourceContext *test = ctx->priv;
  894. test->draw_once = 1;
  895. test->fill_picture_fn = rgbtest_fill_picture;
  896. return init(ctx);
  897. }
  898. static int rgbtest_query_formats(AVFilterContext *ctx)
  899. {
  900. static const enum AVPixelFormat pix_fmts[] = {
  901. AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
  902. AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
  903. AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
  904. AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
  905. AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
  906. AV_PIX_FMT_NONE
  907. };
  908. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  909. if (!fmts_list)
  910. return AVERROR(ENOMEM);
  911. return ff_set_common_formats(ctx, fmts_list);
  912. }
  913. static int rgbtest_config_props(AVFilterLink *outlink)
  914. {
  915. TestSourceContext *test = outlink->src->priv;
  916. ff_fill_rgba_map(test->rgba_map, outlink->format);
  917. return config_props(outlink);
  918. }
  919. static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
  920. {
  921. .name = "default",
  922. .type = AVMEDIA_TYPE_VIDEO,
  923. .config_props = rgbtest_config_props,
  924. },
  925. { NULL }
  926. };
  927. AVFilter ff_vsrc_rgbtestsrc = {
  928. .name = "rgbtestsrc",
  929. .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
  930. .priv_size = sizeof(TestSourceContext),
  931. .priv_class = &rgbtestsrc_class,
  932. .init = rgbtest_init,
  933. .uninit = uninit,
  934. .query_formats = rgbtest_query_formats,
  935. .activate = activate,
  936. .inputs = NULL,
  937. .outputs = avfilter_vsrc_rgbtestsrc_outputs,
  938. };
  939. #endif /* CONFIG_RGBTESTSRC_FILTER */
  940. #if CONFIG_YUVTESTSRC_FILTER
  941. #define yuvtestsrc_options options
  942. AVFILTER_DEFINE_CLASS(yuvtestsrc);
  943. static void yuvtest_fill_picture8(AVFilterContext *ctx, AVFrame *frame)
  944. {
  945. int x, y, w = frame->width, h = frame->height / 3;
  946. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
  947. const int factor = 1 << desc->comp[0].depth;
  948. const int mid = 1 << (desc->comp[0].depth - 1);
  949. uint8_t *ydst = frame->data[0];
  950. uint8_t *udst = frame->data[1];
  951. uint8_t *vdst = frame->data[2];
  952. int ylinesize = frame->linesize[0];
  953. int ulinesize = frame->linesize[1];
  954. int vlinesize = frame->linesize[2];
  955. for (y = 0; y < h; y++) {
  956. for (x = 0; x < w; x++) {
  957. int c = factor * x / w;
  958. ydst[x] = c;
  959. udst[x] = mid;
  960. vdst[x] = mid;
  961. }
  962. ydst += ylinesize;
  963. udst += ulinesize;
  964. vdst += vlinesize;
  965. }
  966. h += h;
  967. for (; y < h; y++) {
  968. for (x = 0; x < w; x++) {
  969. int c = factor * x / w;
  970. ydst[x] = mid;
  971. udst[x] = c;
  972. vdst[x] = mid;
  973. }
  974. ydst += ylinesize;
  975. udst += ulinesize;
  976. vdst += vlinesize;
  977. }
  978. for (; y < frame->height; y++) {
  979. for (x = 0; x < w; x++) {
  980. int c = factor * x / w;
  981. ydst[x] = mid;
  982. udst[x] = mid;
  983. vdst[x] = c;
  984. }
  985. ydst += ylinesize;
  986. udst += ulinesize;
  987. vdst += vlinesize;
  988. }
  989. }
  990. static void yuvtest_fill_picture16(AVFilterContext *ctx, AVFrame *frame)
  991. {
  992. int x, y, w = frame->width, h = frame->height / 3;
  993. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
  994. const int factor = 1 << desc->comp[0].depth;
  995. const int mid = 1 << (desc->comp[0].depth - 1);
  996. uint16_t *ydst = (uint16_t *)frame->data[0];
  997. uint16_t *udst = (uint16_t *)frame->data[1];
  998. uint16_t *vdst = (uint16_t *)frame->data[2];
  999. int ylinesize = frame->linesize[0] / 2;
  1000. int ulinesize = frame->linesize[1] / 2;
  1001. int vlinesize = frame->linesize[2] / 2;
  1002. for (y = 0; y < h; y++) {
  1003. for (x = 0; x < w; x++) {
  1004. int c = factor * x / w;
  1005. ydst[x] = c;
  1006. udst[x] = mid;
  1007. vdst[x] = mid;
  1008. }
  1009. ydst += ylinesize;
  1010. udst += ulinesize;
  1011. vdst += vlinesize;
  1012. }
  1013. h += h;
  1014. for (; y < h; y++) {
  1015. for (x = 0; x < w; x++) {
  1016. int c = factor * x / w;
  1017. ydst[x] = mid;
  1018. udst[x] = c;
  1019. vdst[x] = mid;
  1020. }
  1021. ydst += ylinesize;
  1022. udst += ulinesize;
  1023. vdst += vlinesize;
  1024. }
  1025. for (; y < frame->height; y++) {
  1026. for (x = 0; x < w; x++) {
  1027. int c = factor * x / w;
  1028. ydst[x] = mid;
  1029. udst[x] = mid;
  1030. vdst[x] = c;
  1031. }
  1032. ydst += ylinesize;
  1033. udst += ulinesize;
  1034. vdst += vlinesize;
  1035. }
  1036. }
  1037. static av_cold int yuvtest_init(AVFilterContext *ctx)
  1038. {
  1039. TestSourceContext *test = ctx->priv;
  1040. test->draw_once = 1;
  1041. return init(ctx);
  1042. }
  1043. static int yuvtest_query_formats(AVFilterContext *ctx)
  1044. {
  1045. static const enum AVPixelFormat pix_fmts[] = {
  1046. AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
  1047. AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
  1048. AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14,
  1049. AV_PIX_FMT_YUV444P16,
  1050. AV_PIX_FMT_NONE
  1051. };
  1052. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  1053. if (!fmts_list)
  1054. return AVERROR(ENOMEM);
  1055. return ff_set_common_formats(ctx, fmts_list);
  1056. }
  1057. static int yuvtest_config_props(AVFilterLink *outlink)
  1058. {
  1059. TestSourceContext *test = outlink->src->priv;
  1060. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
  1061. test->fill_picture_fn = desc->comp[0].depth > 8 ? yuvtest_fill_picture16 : yuvtest_fill_picture8;
  1062. return config_props(outlink);
  1063. }
  1064. static const AVFilterPad avfilter_vsrc_yuvtestsrc_outputs[] = {
  1065. {
  1066. .name = "default",
  1067. .type = AVMEDIA_TYPE_VIDEO,
  1068. .config_props = yuvtest_config_props,
  1069. },
  1070. { NULL }
  1071. };
  1072. AVFilter ff_vsrc_yuvtestsrc = {
  1073. .name = "yuvtestsrc",
  1074. .description = NULL_IF_CONFIG_SMALL("Generate YUV test pattern."),
  1075. .priv_size = sizeof(TestSourceContext),
  1076. .priv_class = &yuvtestsrc_class,
  1077. .init = yuvtest_init,
  1078. .uninit = uninit,
  1079. .query_formats = yuvtest_query_formats,
  1080. .activate = activate,
  1081. .inputs = NULL,
  1082. .outputs = avfilter_vsrc_yuvtestsrc_outputs,
  1083. };
  1084. #endif /* CONFIG_YUVTESTSRC_FILTER */
  1085. #if CONFIG_PAL75BARS_FILTER || CONFIG_PAL100BARS_FILTER || CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
  1086. static const uint8_t rainbow[7][4] = {
  1087. { 180, 128, 128, 255 }, /* 75% white */
  1088. { 162, 44, 142, 255 }, /* 75% yellow */
  1089. { 131, 156, 44, 255 }, /* 75% cyan */
  1090. { 112, 72, 58, 255 }, /* 75% green */
  1091. { 84, 184, 198, 255 }, /* 75% magenta */
  1092. { 65, 100, 212, 255 }, /* 75% red */
  1093. { 35, 212, 114, 255 }, /* 75% blue */
  1094. };
  1095. static const uint8_t rainbow100[7][4] = {
  1096. { 235, 128, 128, 255 }, /* 100% white */
  1097. { 210, 16, 146, 255 }, /* 100% yellow */
  1098. { 170, 166, 16, 255 }, /* 100% cyan */
  1099. { 145, 54, 34, 255 }, /* 100% green */
  1100. { 106, 202, 222, 255 }, /* 100% magenta */
  1101. { 81, 90, 240, 255 }, /* 100% red */
  1102. { 41, 240, 110, 255 }, /* 100% blue */
  1103. };
  1104. static const uint8_t rainbowhd[7][4] = {
  1105. { 180, 128, 128, 255 }, /* 75% white */
  1106. { 168, 44, 136, 255 }, /* 75% yellow */
  1107. { 145, 147, 44, 255 }, /* 75% cyan */
  1108. { 133, 63, 52, 255 }, /* 75% green */
  1109. { 63, 193, 204, 255 }, /* 75% magenta */
  1110. { 51, 109, 212, 255 }, /* 75% red */
  1111. { 28, 212, 120, 255 }, /* 75% blue */
  1112. };
  1113. static const uint8_t wobnair[7][4] = {
  1114. { 35, 212, 114, 255 }, /* 75% blue */
  1115. { 19, 128, 128, 255 }, /* 7.5% intensity black */
  1116. { 84, 184, 198, 255 }, /* 75% magenta */
  1117. { 19, 128, 128, 255 }, /* 7.5% intensity black */
  1118. { 131, 156, 44, 255 }, /* 75% cyan */
  1119. { 19, 128, 128, 255 }, /* 7.5% intensity black */
  1120. { 180, 128, 128, 255 }, /* 75% white */
  1121. };
  1122. static const uint8_t white[4] = { 235, 128, 128, 255 };
  1123. /* pluge pulses */
  1124. static const uint8_t neg4ire[4] = { 7, 128, 128, 255 };
  1125. static const uint8_t pos4ire[4] = { 24, 128, 128, 255 };
  1126. /* fudged Q/-I */
  1127. static const uint8_t i_pixel[4] = { 57, 156, 97, 255 };
  1128. static const uint8_t q_pixel[4] = { 44, 171, 147, 255 };
  1129. static const uint8_t gray40[4] = { 104, 128, 128, 255 };
  1130. static const uint8_t gray15[4] = { 49, 128, 128, 255 };
  1131. static const uint8_t cyan[4] = { 188, 154, 16, 255 };
  1132. static const uint8_t yellow[4] = { 219, 16, 138, 255 };
  1133. static const uint8_t blue[4] = { 32, 240, 118, 255 };
  1134. static const uint8_t red[4] = { 63, 102, 240, 255 };
  1135. static const uint8_t black0[4] = { 16, 128, 128, 255 };
  1136. static const uint8_t black2[4] = { 20, 128, 128, 255 };
  1137. static const uint8_t black4[4] = { 25, 128, 128, 255 };
  1138. static const uint8_t neg2[4] = { 12, 128, 128, 255 };
  1139. static void draw_bar(TestSourceContext *test, const uint8_t color[4],
  1140. int x, int y, int w, int h,
  1141. AVFrame *frame)
  1142. {
  1143. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
  1144. uint8_t *p, *p0;
  1145. int plane;
  1146. x = FFMIN(x, test->w - 1);
  1147. y = FFMIN(y, test->h - 1);
  1148. w = FFMAX(FFMIN(w, test->w - x), 0);
  1149. h = FFMAX(FFMIN(h, test->h - y), 0);
  1150. av_assert0(x + w <= test->w);
  1151. av_assert0(y + h <= test->h);
  1152. for (plane = 0; frame->data[plane]; plane++) {
  1153. const int c = color[plane];
  1154. const int linesize = frame->linesize[plane];
  1155. int i, px, py, pw, ph;
  1156. if (plane == 1 || plane == 2) {
  1157. px = x >> desc->log2_chroma_w;
  1158. pw = AV_CEIL_RSHIFT(w, desc->log2_chroma_w);
  1159. py = y >> desc->log2_chroma_h;
  1160. ph = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
  1161. } else {
  1162. px = x;
  1163. pw = w;
  1164. py = y;
  1165. ph = h;
  1166. }
  1167. p0 = p = frame->data[plane] + py * linesize + px;
  1168. memset(p, c, pw);
  1169. p += linesize;
  1170. for (i = 1; i < ph; i++, p += linesize)
  1171. memcpy(p, p0, pw);
  1172. }
  1173. }
  1174. static int smptebars_query_formats(AVFilterContext *ctx)
  1175. {
  1176. static const enum AVPixelFormat pix_fmts[] = {
  1177. AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
  1178. AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
  1179. AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
  1180. AV_PIX_FMT_NONE,
  1181. };
  1182. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  1183. if (!fmts_list)
  1184. return AVERROR(ENOMEM);
  1185. return ff_set_common_formats(ctx, fmts_list);
  1186. }
  1187. static const AVFilterPad smptebars_outputs[] = {
  1188. {
  1189. .name = "default",
  1190. .type = AVMEDIA_TYPE_VIDEO,
  1191. .config_props = config_props,
  1192. },
  1193. { NULL }
  1194. };
  1195. #if CONFIG_PAL75BARS_FILTER
  1196. #define pal75bars_options options
  1197. AVFILTER_DEFINE_CLASS(pal75bars);
  1198. static void pal75bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
  1199. {
  1200. TestSourceContext *test = ctx->priv;
  1201. int r_w, i, x = 0;
  1202. const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
  1203. picref->color_range = AVCOL_RANGE_MPEG;
  1204. picref->colorspace = AVCOL_SPC_BT470BG;
  1205. r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
  1206. draw_bar(test, white, x, 0, r_w, test->h, picref);
  1207. x += r_w;
  1208. for (i = 1; i < 7; i++) {
  1209. draw_bar(test, rainbow[i], x, 0, r_w, test->h, picref);
  1210. x += r_w;
  1211. }
  1212. draw_bar(test, black0, x, 0, r_w, test->h, picref);
  1213. }
  1214. static av_cold int pal75bars_init(AVFilterContext *ctx)
  1215. {
  1216. TestSourceContext *test = ctx->priv;
  1217. test->fill_picture_fn = pal75bars_fill_picture;
  1218. test->draw_once = 1;
  1219. return init(ctx);
  1220. }
  1221. AVFilter ff_vsrc_pal75bars = {
  1222. .name = "pal75bars",
  1223. .description = NULL_IF_CONFIG_SMALL("Generate PAL 75% color bars."),
  1224. .priv_size = sizeof(TestSourceContext),
  1225. .priv_class = &pal75bars_class,
  1226. .init = pal75bars_init,
  1227. .uninit = uninit,
  1228. .query_formats = smptebars_query_formats,
  1229. .activate = activate,
  1230. .inputs = NULL,
  1231. .outputs = smptebars_outputs,
  1232. };
  1233. #endif /* CONFIG_PAL75BARS_FILTER */
  1234. #if CONFIG_PAL100BARS_FILTER
  1235. #define pal100bars_options options
  1236. AVFILTER_DEFINE_CLASS(pal100bars);
  1237. static void pal100bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
  1238. {
  1239. TestSourceContext *test = ctx->priv;
  1240. int r_w, i, x = 0;
  1241. const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
  1242. picref->color_range = AVCOL_RANGE_MPEG;
  1243. picref->colorspace = AVCOL_SPC_BT470BG;
  1244. r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
  1245. for (i = 0; i < 7; i++) {
  1246. draw_bar(test, rainbow100[i], x, 0, r_w, test->h, picref);
  1247. x += r_w;
  1248. }
  1249. draw_bar(test, black0, x, 0, r_w, test->h, picref);
  1250. }
  1251. static av_cold int pal100bars_init(AVFilterContext *ctx)
  1252. {
  1253. TestSourceContext *test = ctx->priv;
  1254. test->fill_picture_fn = pal100bars_fill_picture;
  1255. test->draw_once = 1;
  1256. return init(ctx);
  1257. }
  1258. AVFilter ff_vsrc_pal100bars = {
  1259. .name = "pal100bars",
  1260. .description = NULL_IF_CONFIG_SMALL("Generate PAL 100% color bars."),
  1261. .priv_size = sizeof(TestSourceContext),
  1262. .priv_class = &pal100bars_class,
  1263. .init = pal100bars_init,
  1264. .uninit = uninit,
  1265. .query_formats = smptebars_query_formats,
  1266. .activate = activate,
  1267. .inputs = NULL,
  1268. .outputs = smptebars_outputs,
  1269. };
  1270. #endif /* CONFIG_PAL100BARS_FILTER */
  1271. #if CONFIG_SMPTEBARS_FILTER
  1272. #define smptebars_options options
  1273. AVFILTER_DEFINE_CLASS(smptebars);
  1274. static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
  1275. {
  1276. TestSourceContext *test = ctx->priv;
  1277. int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
  1278. const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
  1279. picref->colorspace = AVCOL_SPC_BT470BG;
  1280. r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
  1281. r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
  1282. w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
  1283. p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
  1284. p_h = test->h - w_h - r_h;
  1285. for (i = 0; i < 7; i++) {
  1286. draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
  1287. draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
  1288. x += r_w;
  1289. }
  1290. x = 0;
  1291. draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
  1292. x += p_w;
  1293. draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
  1294. x += p_w;
  1295. draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
  1296. x += p_w;
  1297. tmp = FFALIGN(5 * r_w - x, 1 << pixdesc->log2_chroma_w);
  1298. draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
  1299. x += tmp;
  1300. tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
  1301. draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
  1302. x += tmp;
  1303. draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
  1304. x += tmp;
  1305. draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
  1306. x += tmp;
  1307. draw_bar(test, black0, x, r_h + w_h, test->w - x, p_h, picref);
  1308. }
  1309. static av_cold int smptebars_init(AVFilterContext *ctx)
  1310. {
  1311. TestSourceContext *test = ctx->priv;
  1312. test->fill_picture_fn = smptebars_fill_picture;
  1313. test->draw_once = 1;
  1314. return init(ctx);
  1315. }
  1316. AVFilter ff_vsrc_smptebars = {
  1317. .name = "smptebars",
  1318. .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
  1319. .priv_size = sizeof(TestSourceContext),
  1320. .priv_class = &smptebars_class,
  1321. .init = smptebars_init,
  1322. .uninit = uninit,
  1323. .query_formats = smptebars_query_formats,
  1324. .activate = activate,
  1325. .inputs = NULL,
  1326. .outputs = smptebars_outputs,
  1327. };
  1328. #endif /* CONFIG_SMPTEBARS_FILTER */
  1329. #if CONFIG_SMPTEHDBARS_FILTER
  1330. #define smptehdbars_options options
  1331. AVFILTER_DEFINE_CLASS(smptehdbars);
  1332. static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
  1333. {
  1334. TestSourceContext *test = ctx->priv;
  1335. int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
  1336. const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
  1337. picref->colorspace = AVCOL_SPC_BT709;
  1338. d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
  1339. r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
  1340. draw_bar(test, gray40, x, 0, d_w, r_h, picref);
  1341. x += d_w;
  1342. r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
  1343. for (i = 0; i < 7; i++) {
  1344. draw_bar(test, rainbowhd[i], x, 0, r_w, r_h, picref);
  1345. x += r_w;
  1346. }
  1347. draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
  1348. y = r_h;
  1349. r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
  1350. draw_bar(test, cyan, 0, y, d_w, r_h, picref);
  1351. x = d_w;
  1352. draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
  1353. x += r_w;
  1354. tmp = r_w * 6;
  1355. draw_bar(test, rainbowhd[0], x, y, tmp, r_h, picref);
  1356. x += tmp;
  1357. l_w = x;
  1358. draw_bar(test, blue, x, y, test->w - x, r_h, picref);
  1359. y += r_h;
  1360. draw_bar(test, yellow, 0, y, d_w, r_h, picref);
  1361. x = d_w;
  1362. draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
  1363. x += r_w;
  1364. for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
  1365. uint8_t yramp[4] = {0};
  1366. yramp[0] = i * 255 / tmp;
  1367. yramp[1] = 128;
  1368. yramp[2] = 128;
  1369. yramp[3] = 255;
  1370. draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
  1371. x += 1 << pixdesc->log2_chroma_w;
  1372. }
  1373. draw_bar(test, red, x, y, test->w - x, r_h, picref);
  1374. y += r_h;
  1375. draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
  1376. x = d_w;
  1377. tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
  1378. draw_bar(test, black0, x, y, tmp, test->h - y, picref);
  1379. x += tmp;
  1380. tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
  1381. draw_bar(test, white, x, y, tmp, test->h - y, picref);
  1382. x += tmp;
  1383. tmp = FFALIGN(r_w * 5 / 6, 1 << pixdesc->log2_chroma_w);
  1384. draw_bar(test, black0, x, y, tmp, test->h - y, picref);
  1385. x += tmp;
  1386. tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
  1387. draw_bar(test, neg2, x, y, tmp, test->h - y, picref);
  1388. x += tmp;
  1389. draw_bar(test, black0, x, y, tmp, test->h - y, picref);
  1390. x += tmp;
  1391. draw_bar(test, black2, x, y, tmp, test->h - y, picref);
  1392. x += tmp;
  1393. draw_bar(test, black0, x, y, tmp, test->h - y, picref);
  1394. x += tmp;
  1395. draw_bar(test, black4, x, y, tmp, test->h - y, picref);
  1396. x += tmp;
  1397. r_w = l_w - x;
  1398. draw_bar(test, black0, x, y, r_w, test->h - y, picref);
  1399. x += r_w;
  1400. draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
  1401. }
  1402. static av_cold int smptehdbars_init(AVFilterContext *ctx)
  1403. {
  1404. TestSourceContext *test = ctx->priv;
  1405. test->fill_picture_fn = smptehdbars_fill_picture;
  1406. test->draw_once = 1;
  1407. return init(ctx);
  1408. }
  1409. AVFilter ff_vsrc_smptehdbars = {
  1410. .name = "smptehdbars",
  1411. .description = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
  1412. .priv_size = sizeof(TestSourceContext),
  1413. .priv_class = &smptehdbars_class,
  1414. .init = smptehdbars_init,
  1415. .uninit = uninit,
  1416. .query_formats = smptebars_query_formats,
  1417. .activate = activate,
  1418. .inputs = NULL,
  1419. .outputs = smptebars_outputs,
  1420. };
  1421. #endif /* CONFIG_SMPTEHDBARS_FILTER */
  1422. #endif /* CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */
  1423. #if CONFIG_ALLYUV_FILTER
  1424. static const AVOption allyuv_options[] = {
  1425. COMMON_OPTIONS_NOSIZE
  1426. { NULL }
  1427. };
  1428. AVFILTER_DEFINE_CLASS(allyuv);
  1429. static void allyuv_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  1430. {
  1431. const int ys = frame->linesize[0];
  1432. const int us = frame->linesize[1];
  1433. const int vs = frame->linesize[2];
  1434. int x, y, j;
  1435. for (y = 0; y < 4096; y++) {
  1436. for (x = 0; x < 2048; x++) {
  1437. frame->data[0][y * ys + x] = ((x / 8) % 256);
  1438. frame->data[0][y * ys + 4095 - x] = ((x / 8) % 256);
  1439. }
  1440. for (x = 0; x < 2048; x+=8) {
  1441. for (j = 0; j < 8; j++) {
  1442. frame->data[1][vs * y + x + j] = (y%16 + (j % 8) * 16);
  1443. frame->data[1][vs * y + 4095 - x - j] = (128 + y%16 + (j % 8) * 16);
  1444. }
  1445. }
  1446. for (x = 0; x < 4096; x++)
  1447. frame->data[2][y * us + x] = 256 * y / 4096;
  1448. }
  1449. }
  1450. static av_cold int allyuv_init(AVFilterContext *ctx)
  1451. {
  1452. TestSourceContext *test = ctx->priv;
  1453. test->w = test->h = 4096;
  1454. test->draw_once = 1;
  1455. test->fill_picture_fn = allyuv_fill_picture;
  1456. return init(ctx);
  1457. }
  1458. static int allyuv_query_formats(AVFilterContext *ctx)
  1459. {
  1460. static const enum AVPixelFormat pix_fmts[] = {
  1461. AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP,
  1462. AV_PIX_FMT_NONE
  1463. };
  1464. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  1465. if (!fmts_list)
  1466. return AVERROR(ENOMEM);
  1467. return ff_set_common_formats(ctx, fmts_list);
  1468. }
  1469. static const AVFilterPad avfilter_vsrc_allyuv_outputs[] = {
  1470. {
  1471. .name = "default",
  1472. .type = AVMEDIA_TYPE_VIDEO,
  1473. .config_props = config_props,
  1474. },
  1475. { NULL }
  1476. };
  1477. AVFilter ff_vsrc_allyuv = {
  1478. .name = "allyuv",
  1479. .description = NULL_IF_CONFIG_SMALL("Generate all yuv colors."),
  1480. .priv_size = sizeof(TestSourceContext),
  1481. .priv_class = &allyuv_class,
  1482. .init = allyuv_init,
  1483. .uninit = uninit,
  1484. .query_formats = allyuv_query_formats,
  1485. .activate = activate,
  1486. .inputs = NULL,
  1487. .outputs = avfilter_vsrc_allyuv_outputs,
  1488. };
  1489. #endif /* CONFIG_ALLYUV_FILTER */
  1490. #if CONFIG_ALLRGB_FILTER
  1491. static const AVOption allrgb_options[] = {
  1492. COMMON_OPTIONS_NOSIZE
  1493. { NULL }
  1494. };
  1495. AVFILTER_DEFINE_CLASS(allrgb);
  1496. static void allrgb_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  1497. {
  1498. unsigned x, y;
  1499. const int linesize = frame->linesize[0];
  1500. uint8_t *line = frame->data[0];
  1501. for (y = 0; y < 4096; y++) {
  1502. uint8_t *dst = line;
  1503. for (x = 0; x < 4096; x++) {
  1504. *dst++ = x;
  1505. *dst++ = y;
  1506. *dst++ = (x >> 8) | ((y >> 8) << 4);
  1507. }
  1508. line += linesize;
  1509. }
  1510. }
  1511. static av_cold int allrgb_init(AVFilterContext *ctx)
  1512. {
  1513. TestSourceContext *test = ctx->priv;
  1514. test->w = test->h = 4096;
  1515. test->draw_once = 1;
  1516. test->fill_picture_fn = allrgb_fill_picture;
  1517. return init(ctx);
  1518. }
  1519. static int allrgb_config_props(AVFilterLink *outlink)
  1520. {
  1521. TestSourceContext *test = outlink->src->priv;
  1522. ff_fill_rgba_map(test->rgba_map, outlink->format);
  1523. return config_props(outlink);
  1524. }
  1525. static int allrgb_query_formats(AVFilterContext *ctx)
  1526. {
  1527. static const enum AVPixelFormat pix_fmts[] = {
  1528. AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
  1529. };
  1530. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  1531. if (!fmts_list)
  1532. return AVERROR(ENOMEM);
  1533. return ff_set_common_formats(ctx, fmts_list);
  1534. }
  1535. static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
  1536. {
  1537. .name = "default",
  1538. .type = AVMEDIA_TYPE_VIDEO,
  1539. .config_props = allrgb_config_props,
  1540. },
  1541. { NULL }
  1542. };
  1543. AVFilter ff_vsrc_allrgb = {
  1544. .name = "allrgb",
  1545. .description = NULL_IF_CONFIG_SMALL("Generate all RGB colors."),
  1546. .priv_size = sizeof(TestSourceContext),
  1547. .priv_class = &allrgb_class,
  1548. .init = allrgb_init,
  1549. .uninit = uninit,
  1550. .query_formats = allrgb_query_formats,
  1551. .activate = activate,
  1552. .inputs = NULL,
  1553. .outputs = avfilter_vsrc_allrgb_outputs,
  1554. };
  1555. #endif /* CONFIG_ALLRGB_FILTER */