Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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. /**
  24.  * @file
  25.  * Misc test sources.
  26.  *
  27.  * testsrc is based on the test pattern generator demuxer by Nicolas George:
  28.  * http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2007-October/037845.html
  29.  *
  30.  * rgbtestsrc is ported from MPlayer libmpcodecs/vf_rgbtest.c by
  31.  * Michael Niedermayer.
  32.  *
  33.  * allyuv, smptebars and smptehdbars are by Paul B Mahol.
  34.  */
  35.  
  36. #include <float.h>
  37.  
  38. #include "libavutil/avassert.h"
  39. #include "libavutil/common.h"
  40. #include "libavutil/opt.h"
  41. #include "libavutil/imgutils.h"
  42. #include "libavutil/intreadwrite.h"
  43. #include "libavutil/parseutils.h"
  44. #include "avfilter.h"
  45. #include "drawutils.h"
  46. #include "formats.h"
  47. #include "internal.h"
  48. #include "video.h"
  49.  
  50. typedef struct TestSourceContext {
  51.     const AVClass *class;
  52.     int w, h;
  53.     unsigned int nb_frame;
  54.     AVRational time_base, frame_rate;
  55.     int64_t pts;
  56.     int64_t duration;           ///< duration expressed in microseconds
  57.     AVRational sar;             ///< sample aspect ratio
  58.     int draw_once;              ///< draw only the first frame, always put out the same picture
  59.     int draw_once_reset;        ///< draw only the first frame or in case of reset
  60.     AVFrame *picref;            ///< cached reference containing the painted picture
  61.  
  62.     void (* fill_picture_fn)(AVFilterContext *ctx, AVFrame *frame);
  63.  
  64.     /* only used by testsrc */
  65.     int nb_decimals;
  66.  
  67.     /* only used by color */
  68.     FFDrawContext draw;
  69.     FFDrawColor color;
  70.     uint8_t color_rgba[4];
  71.  
  72.     /* only used by rgbtest */
  73.     uint8_t rgba_map[4];
  74.  
  75.     /* only used by haldclut */
  76.     int level;
  77. } TestSourceContext;
  78.  
  79. #define OFFSET(x) offsetof(TestSourceContext, x)
  80. #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  81.  
  82. #define SIZE_OPTIONS \
  83.     { "size",     "set video size",     OFFSET(w),        AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
  84.     { "s",        "set video size",     OFFSET(w),        AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
  85.  
  86. #define COMMON_OPTIONS_NOSIZE \
  87.     { "rate",     "set video rate",     OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },\
  88.     { "r",        "set video rate",     OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },\
  89.     { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
  90.     { "d",        "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
  91.     { "sar",      "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1},  0, INT_MAX, FLAGS },
  92.  
  93. #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
  94.  
  95. static const AVOption options[] = {
  96.     COMMON_OPTIONS
  97.     { NULL }
  98. };
  99.  
  100. static av_cold int init(AVFilterContext *ctx)
  101. {
  102.     TestSourceContext *test = ctx->priv;
  103.  
  104.     test->time_base = av_inv_q(test->frame_rate);
  105.     test->nb_frame = 0;
  106.     test->pts = 0;
  107.  
  108.     av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
  109.            test->w, test->h, test->frame_rate.num, test->frame_rate.den,
  110.            test->duration < 0 ? -1 : (double)test->duration/1000000,
  111.            test->sar.num, test->sar.den);
  112.     return 0;
  113. }
  114.  
  115. static av_cold void uninit(AVFilterContext *ctx)
  116. {
  117.     TestSourceContext *test = ctx->priv;
  118.  
  119.     av_frame_free(&test->picref);
  120. }
  121.  
  122. static int config_props(AVFilterLink *outlink)
  123. {
  124.     TestSourceContext *test = outlink->src->priv;
  125.  
  126.     outlink->w = test->w;
  127.     outlink->h = test->h;
  128.     outlink->sample_aspect_ratio = test->sar;
  129.     outlink->frame_rate = test->frame_rate;
  130.     outlink->time_base  = test->time_base;
  131.  
  132.     return 0;
  133. }
  134.  
  135. static int request_frame(AVFilterLink *outlink)
  136. {
  137.     TestSourceContext *test = outlink->src->priv;
  138.     AVFrame *frame;
  139.  
  140.     if (test->duration >= 0 &&
  141.         av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration)
  142.         return AVERROR_EOF;
  143.  
  144.     if (test->draw_once) {
  145.         if (test->draw_once_reset) {
  146.             av_frame_free(&test->picref);
  147.             test->draw_once_reset = 0;
  148.         }
  149.         if (!test->picref) {
  150.             test->picref =
  151.                 ff_get_video_buffer(outlink, test->w, test->h);
  152.             if (!test->picref)
  153.                 return AVERROR(ENOMEM);
  154.             test->fill_picture_fn(outlink->src, test->picref);
  155.         }
  156.         frame = av_frame_clone(test->picref);
  157.     } else
  158.         frame = ff_get_video_buffer(outlink, test->w, test->h);
  159.  
  160.     if (!frame)
  161.         return AVERROR(ENOMEM);
  162.     frame->pts                 = test->pts;
  163.     frame->key_frame           = 1;
  164.     frame->interlaced_frame    = 0;
  165.     frame->pict_type           = AV_PICTURE_TYPE_I;
  166.     frame->sample_aspect_ratio = test->sar;
  167.     if (!test->draw_once)
  168.         test->fill_picture_fn(outlink->src, frame);
  169.  
  170.     test->pts++;
  171.     test->nb_frame++;
  172.  
  173.     return ff_filter_frame(outlink, frame);
  174. }
  175.  
  176. #if CONFIG_COLOR_FILTER
  177.  
  178. static const AVOption color_options[] = {
  179.     { "color", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
  180.     { "c",     "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
  181.     COMMON_OPTIONS
  182.     { NULL }
  183. };
  184.  
  185. AVFILTER_DEFINE_CLASS(color);
  186.  
  187. static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
  188. {
  189.     TestSourceContext *test = ctx->priv;
  190.     ff_fill_rectangle(&test->draw, &test->color,
  191.                       picref->data, picref->linesize,
  192.                       0, 0, test->w, test->h);
  193. }
  194.  
  195. static av_cold int color_init(AVFilterContext *ctx)
  196. {
  197.     TestSourceContext *test = ctx->priv;
  198.     test->fill_picture_fn = color_fill_picture;
  199.     test->draw_once = 1;
  200.     return init(ctx);
  201. }
  202.  
  203. static int color_query_formats(AVFilterContext *ctx)
  204. {
  205.     return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
  206. }
  207.  
  208. static int color_config_props(AVFilterLink *inlink)
  209. {
  210.     AVFilterContext *ctx = inlink->src;
  211.     TestSourceContext *test = ctx->priv;
  212.     int ret;
  213.  
  214.     ff_draw_init(&test->draw, inlink->format, 0);
  215.     ff_draw_color(&test->draw, &test->color, test->color_rgba);
  216.  
  217.     test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
  218.     test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
  219.     if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
  220.         return AVERROR(EINVAL);
  221.  
  222.     if ((ret = config_props(inlink)) < 0)
  223.         return ret;
  224.  
  225.     return 0;
  226. }
  227.  
  228. static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
  229.                                  char *res, int res_len, int flags)
  230. {
  231.     TestSourceContext *test = ctx->priv;
  232.     int ret;
  233.  
  234.     if (!strcmp(cmd, "color") || !strcmp(cmd, "c")) {
  235.         uint8_t color_rgba[4];
  236.  
  237.         ret = av_parse_color(color_rgba, args, -1, ctx);
  238.         if (ret < 0)
  239.             return ret;
  240.  
  241.         memcpy(test->color_rgba, color_rgba, sizeof(color_rgba));
  242.         ff_draw_color(&test->draw, &test->color, test->color_rgba);
  243.         test->draw_once_reset = 1;
  244.         return 0;
  245.     }
  246.  
  247.     return AVERROR(ENOSYS);
  248. }
  249.  
  250. static const AVFilterPad color_outputs[] = {
  251.     {
  252.         .name          = "default",
  253.         .type          = AVMEDIA_TYPE_VIDEO,
  254.         .request_frame = request_frame,
  255.         .config_props  = color_config_props,
  256.     },
  257.     {  NULL }
  258. };
  259.  
  260. AVFilter ff_vsrc_color = {
  261.     .name            = "color",
  262.     .description     = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
  263.     .priv_class      = &color_class,
  264.     .priv_size       = sizeof(TestSourceContext),
  265.     .init            = color_init,
  266.     .uninit          = uninit,
  267.     .query_formats   = color_query_formats,
  268.     .inputs          = NULL,
  269.     .outputs         = color_outputs,
  270.     .process_command = color_process_command,
  271. };
  272.  
  273. #endif /* CONFIG_COLOR_FILTER */
  274.  
  275. #if CONFIG_HALDCLUTSRC_FILTER
  276.  
  277. static const AVOption haldclutsrc_options[] = {
  278.     { "level", "set level", OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 6}, 2, 8, FLAGS },
  279.     COMMON_OPTIONS_NOSIZE
  280.     { NULL }
  281. };
  282.  
  283. AVFILTER_DEFINE_CLASS(haldclutsrc);
  284.  
  285. static void haldclutsrc_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  286. {
  287.     int i, j, k, x = 0, y = 0, is16bit = 0, step;
  288.     uint32_t alpha = 0;
  289.     const TestSourceContext *hc = ctx->priv;
  290.     int level = hc->level;
  291.     float scale;
  292.     const int w = frame->width;
  293.     const int h = frame->height;
  294.     const uint8_t *data = frame->data[0];
  295.     const int linesize  = frame->linesize[0];
  296.     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
  297.     uint8_t rgba_map[4];
  298.  
  299.     av_assert0(w == h && w == level*level*level);
  300.  
  301.     ff_fill_rgba_map(rgba_map, frame->format);
  302.  
  303.     switch (frame->format) {
  304.     case AV_PIX_FMT_RGB48:
  305.     case AV_PIX_FMT_BGR48:
  306.     case AV_PIX_FMT_RGBA64:
  307.     case AV_PIX_FMT_BGRA64:
  308.         is16bit = 1;
  309.         alpha = 0xffff;
  310.         break;
  311.     case AV_PIX_FMT_RGBA:
  312.     case AV_PIX_FMT_BGRA:
  313.     case AV_PIX_FMT_ARGB:
  314.     case AV_PIX_FMT_ABGR:
  315.         alpha = 0xff;
  316.         break;
  317.     }
  318.  
  319.     step  = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
  320.     scale = ((float)(1 << (8*(is16bit+1))) - 1) / (level*level - 1);
  321.  
  322. #define LOAD_CLUT(nbits) do {                                                   \
  323.     uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step;   \
  324.     dst[rgba_map[0]] = av_clip_uint##nbits(i * scale);                          \
  325.     dst[rgba_map[1]] = av_clip_uint##nbits(j * scale);                          \
  326.     dst[rgba_map[2]] = av_clip_uint##nbits(k * scale);                          \
  327.     if (step == 4)                                                              \
  328.         dst[rgba_map[3]] = alpha;                                               \
  329. } while (0)
  330.  
  331.     level *= level;
  332.     for (k = 0; k < level; k++) {
  333.         for (j = 0; j < level; j++) {
  334.             for (i = 0; i < level; i++) {
  335.                 if (!is16bit)
  336.                     LOAD_CLUT(8);
  337.                 else
  338.                     LOAD_CLUT(16);
  339.                 if (++x == w) {
  340.                     x = 0;
  341.                     y++;
  342.                 }
  343.             }
  344.         }
  345.     }
  346. }
  347.  
  348. static av_cold int haldclutsrc_init(AVFilterContext *ctx)
  349. {
  350.     TestSourceContext *hc = ctx->priv;
  351.     hc->fill_picture_fn = haldclutsrc_fill_picture;
  352.     hc->draw_once = 1;
  353.     return init(ctx);
  354. }
  355.  
  356. static int haldclutsrc_query_formats(AVFilterContext *ctx)
  357. {
  358.     static const enum AVPixelFormat pix_fmts[] = {
  359.         AV_PIX_FMT_RGB24,  AV_PIX_FMT_BGR24,
  360.         AV_PIX_FMT_RGBA,   AV_PIX_FMT_BGRA,
  361.         AV_PIX_FMT_ARGB,   AV_PIX_FMT_ABGR,
  362.         AV_PIX_FMT_0RGB,   AV_PIX_FMT_0BGR,
  363.         AV_PIX_FMT_RGB0,   AV_PIX_FMT_BGR0,
  364.         AV_PIX_FMT_RGB48,  AV_PIX_FMT_BGR48,
  365.         AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
  366.         AV_PIX_FMT_NONE,
  367.     };
  368.  
  369.     AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  370.     if (!fmts_list)
  371.         return AVERROR(ENOMEM);
  372.     return ff_set_common_formats(ctx, fmts_list);
  373. }
  374.  
  375. static int haldclutsrc_config_props(AVFilterLink *outlink)
  376. {
  377.     AVFilterContext *ctx = outlink->src;
  378.     TestSourceContext *hc = ctx->priv;
  379.  
  380.     hc->w = hc->h = hc->level * hc->level * hc->level;
  381.     return config_props(outlink);
  382. }
  383.  
  384. static const AVFilterPad haldclutsrc_outputs[] = {
  385.     {
  386.         .name          = "default",
  387.         .type          = AVMEDIA_TYPE_VIDEO,
  388.         .request_frame = request_frame,
  389.         .config_props  = haldclutsrc_config_props,
  390.     },
  391.     {  NULL }
  392. };
  393.  
  394. AVFilter ff_vsrc_haldclutsrc = {
  395.     .name          = "haldclutsrc",
  396.     .description   = NULL_IF_CONFIG_SMALL("Provide an identity Hald CLUT."),
  397.     .priv_class    = &haldclutsrc_class,
  398.     .priv_size     = sizeof(TestSourceContext),
  399.     .init          = haldclutsrc_init,
  400.     .uninit        = uninit,
  401.     .query_formats = haldclutsrc_query_formats,
  402.     .inputs        = NULL,
  403.     .outputs       = haldclutsrc_outputs,
  404. };
  405. #endif /* CONFIG_HALDCLUTSRC_FILTER */
  406.  
  407. #if CONFIG_NULLSRC_FILTER
  408.  
  409. #define nullsrc_options options
  410. AVFILTER_DEFINE_CLASS(nullsrc);
  411.  
  412. static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
  413.  
  414. static av_cold int nullsrc_init(AVFilterContext *ctx)
  415. {
  416.     TestSourceContext *test = ctx->priv;
  417.  
  418.     test->fill_picture_fn = nullsrc_fill_picture;
  419.     return init(ctx);
  420. }
  421.  
  422. static const AVFilterPad nullsrc_outputs[] = {
  423.     {
  424.         .name          = "default",
  425.         .type          = AVMEDIA_TYPE_VIDEO,
  426.         .request_frame = request_frame,
  427.         .config_props  = config_props,
  428.     },
  429.     { NULL },
  430. };
  431.  
  432. AVFilter ff_vsrc_nullsrc = {
  433.     .name        = "nullsrc",
  434.     .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
  435.     .init        = nullsrc_init,
  436.     .uninit      = uninit,
  437.     .priv_size   = sizeof(TestSourceContext),
  438.     .priv_class  = &nullsrc_class,
  439.     .inputs      = NULL,
  440.     .outputs     = nullsrc_outputs,
  441. };
  442.  
  443. #endif /* CONFIG_NULLSRC_FILTER */
  444.  
  445. #if CONFIG_TESTSRC_FILTER
  446.  
  447. static const AVOption testsrc_options[] = {
  448.     COMMON_OPTIONS
  449.     { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0},  0, 17, FLAGS },
  450.     { "n",        "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0},  0, 17, FLAGS },
  451.     { NULL }
  452. };
  453.  
  454. AVFILTER_DEFINE_CLASS(testsrc);
  455.  
  456. /**
  457.  * Fill a rectangle with value val.
  458.  *
  459.  * @param val the RGB value to set
  460.  * @param dst pointer to the destination buffer to fill
  461.  * @param dst_linesize linesize of destination
  462.  * @param segment_width width of the segment
  463.  * @param x horizontal coordinate where to draw the rectangle in the destination buffer
  464.  * @param y horizontal coordinate where to draw the rectangle in the destination buffer
  465.  * @param w width  of the rectangle to draw, expressed as a number of segment_width units
  466.  * @param h height of the rectangle to draw, expressed as a number of segment_width units
  467.  */
  468. static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, int segment_width,
  469.                            int x, int y, int w, int h)
  470. {
  471.     int i;
  472.     int step = 3;
  473.  
  474.     dst += segment_width * (step * x + y * dst_linesize);
  475.     w *= segment_width * step;
  476.     h *= segment_width;
  477.     for (i = 0; i < h; i++) {
  478.         memset(dst, val, w);
  479.         dst += dst_linesize;
  480.     }
  481. }
  482.  
  483. static void draw_digit(int digit, uint8_t *dst, int dst_linesize,
  484.                        int segment_width)
  485. {
  486. #define TOP_HBAR        1
  487. #define MID_HBAR        2
  488. #define BOT_HBAR        4
  489. #define LEFT_TOP_VBAR   8
  490. #define LEFT_BOT_VBAR  16
  491. #define RIGHT_TOP_VBAR 32
  492. #define RIGHT_BOT_VBAR 64
  493.     struct segments {
  494.         int x, y, w, h;
  495.     } segments[] = {
  496.         { 1,  0, 5, 1 }, /* TOP_HBAR */
  497.         { 1,  6, 5, 1 }, /* MID_HBAR */
  498.         { 1, 12, 5, 1 }, /* BOT_HBAR */
  499.         { 0,  1, 1, 5 }, /* LEFT_TOP_VBAR */
  500.         { 0,  7, 1, 5 }, /* LEFT_BOT_VBAR */
  501.         { 6,  1, 1, 5 }, /* RIGHT_TOP_VBAR */
  502.         { 6,  7, 1, 5 }  /* RIGHT_BOT_VBAR */
  503.     };
  504.     static const unsigned char masks[10] = {
  505.         /* 0 */ TOP_HBAR         |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  506.         /* 1 */                                                        RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  507.         /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR                             |RIGHT_TOP_VBAR,
  508.         /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR                            |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  509.         /* 4 */          MID_HBAR         |LEFT_TOP_VBAR              |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  510.         /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR                             |RIGHT_BOT_VBAR,
  511.         /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR               |RIGHT_BOT_VBAR,
  512.         /* 7 */ TOP_HBAR                                              |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  513.         /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  514.         /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR              |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
  515.     };
  516.     unsigned mask = masks[digit];
  517.     int i;
  518.  
  519.     draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
  520.     for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
  521.         if (mask & (1<<i))
  522.             draw_rectangle(255, dst, dst_linesize, segment_width,
  523.                            segments[i].x, segments[i].y, segments[i].w, segments[i].h);
  524. }
  525.  
  526. #define GRADIENT_SIZE (6 * 256)
  527.  
  528. static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  529. {
  530.     TestSourceContext *test = ctx->priv;
  531.     uint8_t *p, *p0;
  532.     int x, y;
  533.     int color, color_rest;
  534.     int icolor;
  535.     int radius;
  536.     int quad0, quad;
  537.     int dquad_x, dquad_y;
  538.     int grad, dgrad, rgrad, drgrad;
  539.     int seg_size;
  540.     int second;
  541.     int i;
  542.     uint8_t *data = frame->data[0];
  543.     int width  = frame->width;
  544.     int height = frame->height;
  545.  
  546.     /* draw colored bars and circle */
  547.     radius = (width + height) / 4;
  548.     quad0 = width * width / 4 + height * height / 4 - radius * radius;
  549.     dquad_y = 1 - height;
  550.     p0 = data;
  551.     for (y = 0; y < height; y++) {
  552.         p = p0;
  553.         color = 0;
  554.         color_rest = 0;
  555.         quad = quad0;
  556.         dquad_x = 1 - width;
  557.         for (x = 0; x < width; x++) {
  558.             icolor = color;
  559.             if (quad < 0)
  560.                 icolor ^= 7;
  561.             quad += dquad_x;
  562.             dquad_x += 2;
  563.             *(p++) = icolor & 1 ? 255 : 0;
  564.             *(p++) = icolor & 2 ? 255 : 0;
  565.             *(p++) = icolor & 4 ? 255 : 0;
  566.             color_rest += 8;
  567.             if (color_rest >= width) {
  568.                 color_rest -= width;
  569.                 color++;
  570.             }
  571.         }
  572.         quad0 += dquad_y;
  573.         dquad_y += 2;
  574.         p0 += frame->linesize[0];
  575.     }
  576.  
  577.     /* draw sliding color line */
  578.     p0 = p = data + frame->linesize[0] * (height * 3/4);
  579.     grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
  580.         GRADIENT_SIZE;
  581.     rgrad = 0;
  582.     dgrad = GRADIENT_SIZE / width;
  583.     drgrad = GRADIENT_SIZE % width;
  584.     for (x = 0; x < width; x++) {
  585.         *(p++) =
  586.             grad < 256 || grad >= 5 * 256 ? 255 :
  587.             grad >= 2 * 256 && grad < 4 * 256 ? 0 :
  588.             grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
  589.         *(p++) =
  590.             grad >= 4 * 256 ? 0 :
  591.             grad >= 1 * 256 && grad < 3 * 256 ? 255 :
  592.             grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
  593.         *(p++) =
  594.             grad < 2 * 256 ? 0 :
  595.             grad >= 3 * 256 && grad < 5 * 256 ? 255 :
  596.             grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
  597.         grad += dgrad;
  598.         rgrad += drgrad;
  599.         if (rgrad >= GRADIENT_SIZE) {
  600.             grad++;
  601.             rgrad -= GRADIENT_SIZE;
  602.         }
  603.         if (grad >= GRADIENT_SIZE)
  604.             grad -= GRADIENT_SIZE;
  605.     }
  606.     p = p0;
  607.     for (y = height / 8; y > 0; y--) {
  608.         memcpy(p+frame->linesize[0], p, 3 * width);
  609.         p += frame->linesize[0];
  610.     }
  611.  
  612.     /* draw digits */
  613.     seg_size = width / 80;
  614.     if (seg_size >= 1 && height >= 13 * seg_size) {
  615.         int64_t p10decimals = 1;
  616.         double time = av_q2d(test->time_base) * test->nb_frame *
  617.                       pow(10, test->nb_decimals);
  618.         if (time >= INT_MAX)
  619.             return;
  620.  
  621.         for (x = 0; x < test->nb_decimals; x++)
  622.             p10decimals *= 10;
  623.  
  624.         second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
  625.         x = width - (width - seg_size * 64) / 2;
  626.         y = (height - seg_size * 13) / 2;
  627.         p = data + (x*3 + y * frame->linesize[0]);
  628.         for (i = 0; i < 8; i++) {
  629.             p -= 3 * 8 * seg_size;
  630.             draw_digit(second % 10, p, frame->linesize[0], seg_size);
  631.             second /= 10;
  632.             if (second == 0)
  633.                 break;
  634.         }
  635.     }
  636. }
  637.  
  638. static av_cold int test_init(AVFilterContext *ctx)
  639. {
  640.     TestSourceContext *test = ctx->priv;
  641.  
  642.     test->fill_picture_fn = test_fill_picture;
  643.     return init(ctx);
  644. }
  645.  
  646. static int test_query_formats(AVFilterContext *ctx)
  647. {
  648.     static const enum AVPixelFormat pix_fmts[] = {
  649.         AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
  650.     };
  651.  
  652.     AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  653.     if (!fmts_list)
  654.         return AVERROR(ENOMEM);
  655.     return ff_set_common_formats(ctx, fmts_list);
  656. }
  657.  
  658. static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
  659.     {
  660.         .name          = "default",
  661.         .type          = AVMEDIA_TYPE_VIDEO,
  662.         .request_frame = request_frame,
  663.         .config_props  = config_props,
  664.     },
  665.     { NULL }
  666. };
  667.  
  668. AVFilter ff_vsrc_testsrc = {
  669.     .name          = "testsrc",
  670.     .description   = NULL_IF_CONFIG_SMALL("Generate test pattern."),
  671.     .priv_size     = sizeof(TestSourceContext),
  672.     .priv_class    = &testsrc_class,
  673.     .init          = test_init,
  674.     .uninit        = uninit,
  675.     .query_formats = test_query_formats,
  676.     .inputs        = NULL,
  677.     .outputs       = avfilter_vsrc_testsrc_outputs,
  678. };
  679.  
  680. #endif /* CONFIG_TESTSRC_FILTER */
  681.  
  682. #if CONFIG_RGBTESTSRC_FILTER
  683.  
  684. #define rgbtestsrc_options options
  685. AVFILTER_DEFINE_CLASS(rgbtestsrc);
  686.  
  687. #define R 0
  688. #define G 1
  689. #define B 2
  690. #define A 3
  691.  
  692. static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
  693.                               int x, int y, int r, int g, int b, enum AVPixelFormat fmt,
  694.                               uint8_t rgba_map[4])
  695. {
  696.     int32_t v;
  697.     uint8_t *p;
  698.  
  699.     switch (fmt) {
  700.     case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
  701.     case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
  702.     case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
  703.     case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
  704.     case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
  705.     case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
  706.     case AV_PIX_FMT_RGB24:
  707.     case AV_PIX_FMT_BGR24:
  708.         v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
  709.         p = dst + 3*x + y*dst_linesize;
  710.         AV_WL24(p, v);
  711.         break;
  712.     case AV_PIX_FMT_RGBA:
  713.     case AV_PIX_FMT_BGRA:
  714.     case AV_PIX_FMT_ARGB:
  715.     case AV_PIX_FMT_ABGR:
  716.         v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
  717.         p = dst + 4*x + y*dst_linesize;
  718.         AV_WL32(p, v);
  719.         break;
  720.     }
  721. }
  722.  
  723. static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  724. {
  725.     TestSourceContext *test = ctx->priv;
  726.     int x, y, w = frame->width, h = frame->height;
  727.  
  728.     for (y = 0; y < h; y++) {
  729.          for (x = 0; x < w; x++) {
  730.              int c = 256*x/w;
  731.              int r = 0, g = 0, b = 0;
  732.  
  733.              if      (3*y < h  ) r = c;
  734.              else if (3*y < 2*h) g = c;
  735.              else                b = c;
  736.  
  737.              rgbtest_put_pixel(frame->data[0], frame->linesize[0], x, y, r, g, b,
  738.                                ctx->outputs[0]->format, test->rgba_map);
  739.          }
  740.      }
  741. }
  742.  
  743. static av_cold int rgbtest_init(AVFilterContext *ctx)
  744. {
  745.     TestSourceContext *test = ctx->priv;
  746.  
  747.     test->draw_once = 1;
  748.     test->fill_picture_fn = rgbtest_fill_picture;
  749.     return init(ctx);
  750. }
  751.  
  752. static int rgbtest_query_formats(AVFilterContext *ctx)
  753. {
  754.     static const enum AVPixelFormat pix_fmts[] = {
  755.         AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
  756.         AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
  757.         AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
  758.         AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
  759.         AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
  760.         AV_PIX_FMT_NONE
  761.     };
  762.  
  763.     AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  764.     if (!fmts_list)
  765.         return AVERROR(ENOMEM);
  766.     return ff_set_common_formats(ctx, fmts_list);
  767. }
  768.  
  769. static int rgbtest_config_props(AVFilterLink *outlink)
  770. {
  771.     TestSourceContext *test = outlink->src->priv;
  772.  
  773.     ff_fill_rgba_map(test->rgba_map, outlink->format);
  774.     return config_props(outlink);
  775. }
  776.  
  777. static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
  778.     {
  779.         .name          = "default",
  780.         .type          = AVMEDIA_TYPE_VIDEO,
  781.         .request_frame = request_frame,
  782.         .config_props  = rgbtest_config_props,
  783.     },
  784.     { NULL }
  785. };
  786.  
  787. AVFilter ff_vsrc_rgbtestsrc = {
  788.     .name          = "rgbtestsrc",
  789.     .description   = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
  790.     .priv_size     = sizeof(TestSourceContext),
  791.     .priv_class    = &rgbtestsrc_class,
  792.     .init          = rgbtest_init,
  793.     .uninit        = uninit,
  794.     .query_formats = rgbtest_query_formats,
  795.     .inputs        = NULL,
  796.     .outputs       = avfilter_vsrc_rgbtestsrc_outputs,
  797. };
  798.  
  799. #endif /* CONFIG_RGBTESTSRC_FILTER */
  800.  
  801. #if CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
  802.  
  803. static const uint8_t rainbow[7][4] = {
  804.     { 180, 128, 128, 255 },     /* 75% white */
  805.     { 161,  44, 141, 255 },     /* 75% yellow */
  806.     { 131, 156,  44, 255 },     /* 75% cyan */
  807.     { 112,  72,  57, 255 },     /* 75% green */
  808.     {  83, 183, 198, 255 },     /* 75% magenta */
  809.     {  65,  99, 212, 255 },     /* 75% red */
  810.     {  34, 212, 114, 255 },     /* 75% blue */
  811. };
  812.  
  813. static const uint8_t rainbowhd[7][4] = {
  814.     { 180, 128, 128, 255 },     /* 75% white */
  815.     { 168,  44, 136, 255 },     /* 75% yellow */
  816.     { 145, 147,  44, 255 },     /* 75% cyan */
  817.     { 133,  63,  52, 255 },     /* 75% green */
  818.     {  63, 193, 204, 255 },     /* 75% magenta */
  819.     {  51, 109, 212, 255 },     /* 75% red */
  820.     {  28, 212, 120, 255 },     /* 75% blue */
  821. };
  822.  
  823. static const uint8_t wobnair[7][4] = {
  824.     {  34, 212, 114, 255 },     /* 75% blue */
  825.     {  19, 128, 128, 255 },     /* 7.5% intensity black */
  826.     {  83, 183, 198, 255 },     /* 75% magenta */
  827.     {  19, 128, 128, 255 },     /* 7.5% intensity black */
  828.     { 131, 156,  44, 255 },     /* 75% cyan */
  829.     {  19, 128, 128, 255 },     /* 7.5% intensity black */
  830.     { 180, 128, 128, 255 },     /* 75% white */
  831. };
  832.  
  833. static const uint8_t white[4] = { 235, 128, 128, 255 };
  834.  
  835. /* pluge pulses */
  836. static const uint8_t neg4ire[4] = {  7, 128, 128, 255 };
  837. static const uint8_t pos4ire[4] = { 24, 128, 128, 255 };
  838.  
  839. /* fudged Q/-I */
  840. static const uint8_t i_pixel[4] = { 57, 156,  97, 255 };
  841. static const uint8_t q_pixel[4] = { 44, 171, 147, 255 };
  842.  
  843. static const uint8_t gray40[4] = { 104, 128, 128, 255 };
  844. static const uint8_t gray15[4] = {  49, 128, 128, 255 };
  845. static const uint8_t   cyan[4] = { 188, 154,  16, 255 };
  846. static const uint8_t yellow[4] = { 219,  16, 138, 255 };
  847. static const uint8_t   blue[4] = {  32, 240, 118, 255 };
  848. static const uint8_t    red[4] = {  63, 102, 240, 255 };
  849. static const uint8_t black0[4] = {  16, 128, 128, 255 };
  850. static const uint8_t black2[4] = {  20, 128, 128, 255 };
  851. static const uint8_t black4[4] = {  25, 128, 128, 255 };
  852. static const uint8_t   neg2[4] = {  12, 128, 128, 255 };
  853.  
  854. static void draw_bar(TestSourceContext *test, const uint8_t color[4],
  855.                      int x, int y, int w, int h,
  856.                      AVFrame *frame)
  857. {
  858.     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
  859.     uint8_t *p, *p0;
  860.     int plane;
  861.  
  862.     x = FFMIN(x, test->w - 1);
  863.     y = FFMIN(y, test->h - 1);
  864.     w = FFMIN(w, test->w - x);
  865.     h = FFMIN(h, test->h - y);
  866.  
  867.     av_assert0(x + w <= test->w);
  868.     av_assert0(y + h <= test->h);
  869.  
  870.     for (plane = 0; frame->data[plane]; plane++) {
  871.         const int c = color[plane];
  872.         const int linesize = frame->linesize[plane];
  873.         int i, px, py, pw, ph;
  874.  
  875.         if (plane == 1 || plane == 2) {
  876.             px = x >> desc->log2_chroma_w;
  877.             pw = FF_CEIL_RSHIFT(w, desc->log2_chroma_w);
  878.             py = y >> desc->log2_chroma_h;
  879.             ph = FF_CEIL_RSHIFT(h, desc->log2_chroma_h);
  880.         } else {
  881.             px = x;
  882.             pw = w;
  883.             py = y;
  884.             ph = h;
  885.         }
  886.  
  887.         p0 = p = frame->data[plane] + py * linesize + px;
  888.         memset(p, c, pw);
  889.         p += linesize;
  890.         for (i = 1; i < ph; i++, p += linesize)
  891.             memcpy(p, p0, pw);
  892.     }
  893. }
  894.  
  895. static int smptebars_query_formats(AVFilterContext *ctx)
  896. {
  897.     static const enum AVPixelFormat pix_fmts[] = {
  898.         AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
  899.         AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
  900.         AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
  901.         AV_PIX_FMT_NONE,
  902.     };
  903.  
  904.     AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  905.     if (!fmts_list)
  906.         return AVERROR(ENOMEM);
  907.     return ff_set_common_formats(ctx, fmts_list);
  908. }
  909.  
  910. static const AVFilterPad smptebars_outputs[] = {
  911.     {
  912.         .name          = "default",
  913.         .type          = AVMEDIA_TYPE_VIDEO,
  914.         .request_frame = request_frame,
  915.         .config_props  = config_props,
  916.     },
  917.     { NULL }
  918. };
  919.  
  920. #if CONFIG_SMPTEBARS_FILTER
  921.  
  922. #define smptebars_options options
  923. AVFILTER_DEFINE_CLASS(smptebars);
  924.  
  925. static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
  926. {
  927.     TestSourceContext *test = ctx->priv;
  928.     int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
  929.     const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
  930.  
  931.     av_frame_set_colorspace(picref, AVCOL_SPC_BT470BG);
  932.  
  933.     r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
  934.     r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
  935.     w_h = FFALIGN(test->h * 3 / 4 - r_h,  1 << pixdesc->log2_chroma_h);
  936.     p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
  937.     p_h = test->h - w_h - r_h;
  938.  
  939.     for (i = 0; i < 7; i++) {
  940.         draw_bar(test, rainbow[i], x, 0,   r_w, r_h, picref);
  941.         draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
  942.         x += r_w;
  943.     }
  944.     x = 0;
  945.     draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
  946.     x += p_w;
  947.     draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
  948.     x += p_w;
  949.     draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
  950.     x += p_w;
  951.     tmp = FFALIGN(5 * r_w - x,  1 << pixdesc->log2_chroma_w);
  952.     draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
  953.     x += tmp;
  954.     tmp = FFALIGN(r_w / 3,  1 << pixdesc->log2_chroma_w);
  955.     draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
  956.     x += tmp;
  957.     draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
  958.     x += tmp;
  959.     draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
  960.     x += tmp;
  961.     draw_bar(test, black0, x, r_h + w_h, test->w - x, p_h, picref);
  962. }
  963.  
  964. static av_cold int smptebars_init(AVFilterContext *ctx)
  965. {
  966.     TestSourceContext *test = ctx->priv;
  967.  
  968.     test->fill_picture_fn = smptebars_fill_picture;
  969.     test->draw_once = 1;
  970.     return init(ctx);
  971. }
  972.  
  973. AVFilter ff_vsrc_smptebars = {
  974.     .name          = "smptebars",
  975.     .description   = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
  976.     .priv_size     = sizeof(TestSourceContext),
  977.     .priv_class    = &smptebars_class,
  978.     .init          = smptebars_init,
  979.     .uninit        = uninit,
  980.     .query_formats = smptebars_query_formats,
  981.     .inputs        = NULL,
  982.     .outputs       = smptebars_outputs,
  983. };
  984.  
  985. #endif  /* CONFIG_SMPTEBARS_FILTER */
  986.  
  987. #if CONFIG_SMPTEHDBARS_FILTER
  988.  
  989. #define smptehdbars_options options
  990. AVFILTER_DEFINE_CLASS(smptehdbars);
  991.  
  992. static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
  993. {
  994.     TestSourceContext *test = ctx->priv;
  995.     int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
  996.     const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
  997.  
  998.     av_frame_set_colorspace(picref, AVCOL_SPC_BT709);
  999.  
  1000.     d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
  1001.     r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
  1002.     draw_bar(test, gray40, x, 0, d_w, r_h, picref);
  1003.     x += d_w;
  1004.  
  1005.     r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
  1006.     for (i = 0; i < 7; i++) {
  1007.         draw_bar(test, rainbowhd[i], x, 0, r_w, r_h, picref);
  1008.         x += r_w;
  1009.     }
  1010.     draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
  1011.     y = r_h;
  1012.     r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
  1013.     draw_bar(test, cyan, 0, y, d_w, r_h, picref);
  1014.     x = d_w;
  1015.     draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
  1016.     x += r_w;
  1017.     tmp = r_w * 6;
  1018.     draw_bar(test, rainbowhd[0], x, y, tmp, r_h, picref);
  1019.     x += tmp;
  1020.     l_w = x;
  1021.     draw_bar(test, blue, x, y, test->w - x, r_h, picref);
  1022.     y += r_h;
  1023.     draw_bar(test, yellow, 0, y, d_w, r_h, picref);
  1024.     x = d_w;
  1025.     draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
  1026.     x += r_w;
  1027.  
  1028.     for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
  1029.         uint8_t yramp[4] = {0};
  1030.  
  1031.         yramp[0] = i * 255 / tmp;
  1032.         yramp[1] = 128;
  1033.         yramp[2] = 128;
  1034.         yramp[3] = 255;
  1035.  
  1036.         draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
  1037.         x += 1 << pixdesc->log2_chroma_w;
  1038.     }
  1039.     draw_bar(test, red, x, y, test->w - x, r_h, picref);
  1040.     y += r_h;
  1041.     draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
  1042.     x = d_w;
  1043.     tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
  1044.     draw_bar(test, black0, x, y, tmp, test->h - y, picref);
  1045.     x += tmp;
  1046.     tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
  1047.     draw_bar(test, white, x, y, tmp, test->h - y, picref);
  1048.     x += tmp;
  1049.     tmp = FFALIGN(r_w * 5 / 6, 1 << pixdesc->log2_chroma_w);
  1050.     draw_bar(test, black0, x, y, tmp, test->h - y, picref);
  1051.     x += tmp;
  1052.     tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
  1053.     draw_bar(test,   neg2, x, y, tmp, test->h - y, picref);
  1054.     x += tmp;
  1055.     draw_bar(test, black0, x, y, tmp, test->h - y, picref);
  1056.     x += tmp;
  1057.     draw_bar(test, black2, x, y, tmp, test->h - y, picref);
  1058.     x += tmp;
  1059.     draw_bar(test, black0, x, y, tmp, test->h - y, picref);
  1060.     x += tmp;
  1061.     draw_bar(test, black4, x, y, tmp, test->h - y, picref);
  1062.     x += tmp;
  1063.     r_w = l_w - x;
  1064.     draw_bar(test, black0, x, y, r_w, test->h - y, picref);
  1065.     x += r_w;
  1066.     draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
  1067. }
  1068.  
  1069. static av_cold int smptehdbars_init(AVFilterContext *ctx)
  1070. {
  1071.     TestSourceContext *test = ctx->priv;
  1072.  
  1073.     test->fill_picture_fn = smptehdbars_fill_picture;
  1074.     test->draw_once = 1;
  1075.     return init(ctx);
  1076. }
  1077.  
  1078. AVFilter ff_vsrc_smptehdbars = {
  1079.     .name          = "smptehdbars",
  1080.     .description   = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
  1081.     .priv_size     = sizeof(TestSourceContext),
  1082.     .priv_class    = &smptehdbars_class,
  1083.     .init          = smptehdbars_init,
  1084.     .uninit        = uninit,
  1085.     .query_formats = smptebars_query_formats,
  1086.     .inputs        = NULL,
  1087.     .outputs       = smptebars_outputs,
  1088. };
  1089.  
  1090. #endif  /* CONFIG_SMPTEHDBARS_FILTER */
  1091. #endif  /* CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */
  1092.  
  1093. #if CONFIG_ALLYUV_FILTER
  1094.  
  1095. static const AVOption allyuv_options[] = {
  1096.     COMMON_OPTIONS_NOSIZE
  1097.     { NULL }
  1098. };
  1099.  
  1100. AVFILTER_DEFINE_CLASS(allyuv);
  1101.  
  1102. static void allyuv_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  1103. {
  1104.     const int ys = frame->linesize[0];
  1105.     const int us = frame->linesize[1];
  1106.     const int vs = frame->linesize[2];
  1107.     int x, y, j;
  1108.  
  1109.     for (y = 0; y < 4096; y++) {
  1110.         for (x = 0; x < 2048; x++) {
  1111.             frame->data[0][y * ys + x] = ((x / 8) % 256);
  1112.             frame->data[0][y * ys + 4095 - x] = ((x / 8) % 256);
  1113.         }
  1114.  
  1115.         for (x = 0; x < 2048; x+=8) {
  1116.             for (j = 0; j < 8; j++) {
  1117.                 frame->data[1][vs * y + x + j]        = (y%16 + (j % 8) * 16);
  1118.                 frame->data[1][vs * y + 4095 - x - j] = (128 + y%16 + (j % 8) * 16);
  1119.             }
  1120.         }
  1121.  
  1122.         for (x = 0; x < 4096; x++)
  1123.             frame->data[2][y * us + x] = 256 * y / 4096;
  1124.     }
  1125. }
  1126.  
  1127. static av_cold int allyuv_init(AVFilterContext *ctx)
  1128. {
  1129.     TestSourceContext *test = ctx->priv;
  1130.  
  1131.     test->w = test->h = 4096;
  1132.     test->draw_once = 1;
  1133.     test->fill_picture_fn = allyuv_fill_picture;
  1134.     return init(ctx);
  1135. }
  1136.  
  1137. static int allyuv_query_formats(AVFilterContext *ctx)
  1138. {
  1139.     static const enum AVPixelFormat pix_fmts[] = {
  1140.         AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP,
  1141.         AV_PIX_FMT_NONE
  1142.     };
  1143.  
  1144.     AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  1145.     if (!fmts_list)
  1146.         return AVERROR(ENOMEM);
  1147.     return ff_set_common_formats(ctx, fmts_list);
  1148. }
  1149.  
  1150. static const AVFilterPad avfilter_vsrc_allyuv_outputs[] = {
  1151.     {
  1152.         .name          = "default",
  1153.         .type          = AVMEDIA_TYPE_VIDEO,
  1154.         .request_frame = request_frame,
  1155.         .config_props  = config_props,
  1156.     },
  1157.     { NULL }
  1158. };
  1159.  
  1160. AVFilter ff_vsrc_allyuv = {
  1161.     .name          = "allyuv",
  1162.     .description   = NULL_IF_CONFIG_SMALL("Generate all yuv colors."),
  1163.     .priv_size     = sizeof(TestSourceContext),
  1164.     .priv_class    = &allyuv_class,
  1165.     .init          = allyuv_init,
  1166.     .uninit        = uninit,
  1167.     .query_formats = allyuv_query_formats,
  1168.     .inputs        = NULL,
  1169.     .outputs       = avfilter_vsrc_allyuv_outputs,
  1170. };
  1171.  
  1172. #endif /* CONFIG_ALLYUV_FILTER */
  1173.  
  1174. #if CONFIG_ALLRGB_FILTER
  1175.  
  1176. static const AVOption allrgb_options[] = {
  1177.     COMMON_OPTIONS_NOSIZE
  1178.     { NULL }
  1179. };
  1180.  
  1181. AVFILTER_DEFINE_CLASS(allrgb);
  1182.  
  1183. static void allrgb_fill_picture(AVFilterContext *ctx, AVFrame *frame)
  1184. {
  1185.     unsigned x, y;
  1186.     const int linesize = frame->linesize[0];
  1187.     uint8_t *line = frame->data[0];
  1188.  
  1189.     for (y = 0; y < 4096; y++) {
  1190.         uint8_t *dst = line;
  1191.  
  1192.         for (x = 0; x < 4096; x++) {
  1193.             *dst++ = x;
  1194.             *dst++ = y;
  1195.             *dst++ = (x >> 8) | ((y >> 8) << 4);
  1196.         }
  1197.         line += linesize;
  1198.     }
  1199. }
  1200.  
  1201. static av_cold int allrgb_init(AVFilterContext *ctx)
  1202. {
  1203.     TestSourceContext *test = ctx->priv;
  1204.  
  1205.     test->w = test->h = 4096;
  1206.     test->draw_once = 1;
  1207.     test->fill_picture_fn = allrgb_fill_picture;
  1208.     return init(ctx);
  1209. }
  1210.  
  1211. static int allrgb_config_props(AVFilterLink *outlink)
  1212. {
  1213.     TestSourceContext *test = outlink->src->priv;
  1214.  
  1215.     ff_fill_rgba_map(test->rgba_map, outlink->format);
  1216.     return config_props(outlink);
  1217. }
  1218.  
  1219. static int allrgb_query_formats(AVFilterContext *ctx)
  1220. {
  1221.     static const enum AVPixelFormat pix_fmts[] = {
  1222.         AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
  1223.     };
  1224.  
  1225.     AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  1226.     if (!fmts_list)
  1227.         return AVERROR(ENOMEM);
  1228.     return ff_set_common_formats(ctx, fmts_list);
  1229. }
  1230.  
  1231. static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
  1232.     {
  1233.         .name          = "default",
  1234.         .type          = AVMEDIA_TYPE_VIDEO,
  1235.         .request_frame = request_frame,
  1236.         .config_props  = allrgb_config_props,
  1237.     },
  1238.     { NULL }
  1239. };
  1240.  
  1241. AVFilter ff_vsrc_allrgb = {
  1242.     .name          = "allrgb",
  1243.     .description   = NULL_IF_CONFIG_SMALL("Generate all RGB colors."),
  1244.     .priv_size     = sizeof(TestSourceContext),
  1245.     .priv_class    = &allrgb_class,
  1246.     .init          = allrgb_init,
  1247.     .uninit        = uninit,
  1248.     .query_formats = allrgb_query_formats,
  1249.     .inputs        = NULL,
  1250.     .outputs       = avfilter_vsrc_allrgb_outputs,
  1251. };
  1252.  
  1253. #endif /* CONFIG_ALLRGB_FILTER */
  1254.