2 * Copyright (c) 2007 Nicolas George <nicolas.george@normalesup.org>
3 * Copyright (c) 2011 Stefano Sabatini
4 * Copyright (c) 2012 Paul B Mahol
6 * This file is part of FFmpeg.
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.
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.
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
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
30 * rgbtestsrc is ported from MPlayer libmpcodecs/vf_rgbtest.c by
31 * Michael Niedermayer.
33 * smptebars is by Paul B Mahol.
38 #include "libavutil/common.h"
39 #include "libavutil/opt.h"
40 #include "libavutil/imgutils.h"
41 #include "libavutil/intreadwrite.h"
42 #include "libavutil/parseutils.h"
44 #include "drawutils.h"
52 unsigned int nb_frame;
53 AVRational time_base, frame_rate;
55 char *frame_rate_str; ///< video frame rate
56 char *duration; ///< total duration of the generated video
57 AVRational sar; ///< sample aspect ratio
59 int draw_once; ///< draw only the first frame, always put out the same picture
60 AVFilterBufferRef *picref; ///< cached reference containing the painted picture
62 void (* fill_picture_fn)(AVFilterContext *ctx, AVFilterBufferRef *picref);
64 /* only used by color */
68 uint8_t color_rgba[4];
70 /* only used by rgbtest */
74 #define OFFSET(x) offsetof(TestSourceContext, x)
75 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
77 static const AVOption 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 { "rate", "set video rate", OFFSET(frame_rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
81 { "r", "set video rate", OFFSET(frame_rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
82 { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
83 { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
84 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
86 /* only used by color */
87 { "color", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
88 { "c", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
90 /* only used by testsrc */
91 { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX, FLAGS },
92 { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX, FLAGS },
96 static av_cold int init(AVFilterContext *ctx, const char *args)
98 TestSourceContext *test = ctx->priv;
99 int64_t duration = -1;
102 av_opt_set_defaults(test);
104 if ((ret = (av_set_options_string(test, args, "=", ":"))) < 0)
107 if ((ret = av_parse_video_rate(&test->frame_rate, test->frame_rate_str)) < 0) {
108 av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", test->frame_rate_str);
112 if (test->duration && (ret = av_parse_time(&duration, test->duration, 1)) < 0) {
113 av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration);
117 if (test->nb_decimals && strcmp(ctx->filter->name, "testsrc")) {
118 av_log(ctx, AV_LOG_WARNING,
119 "Option 'decimals' is ignored with source '%s'\n",
123 if (test->color_str) {
124 if (!strcmp(ctx->filter->name, "color")) {
125 ret = av_parse_color(test->color_rgba, test->color_str, -1, ctx);
129 av_log(ctx, AV_LOG_WARNING,
130 "Option 'color' is ignored with source '%s'\n",
135 test->time_base = av_inv_q(test->frame_rate);
136 test->max_pts = duration >= 0 ?
137 av_rescale_q(duration, AV_TIME_BASE_Q, test->time_base) : -1;
141 av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
142 test->w, test->h, test->frame_rate.num, test->frame_rate.den,
143 duration < 0 ? -1 : test->max_pts * av_q2d(test->time_base),
144 test->sar.num, test->sar.den);
148 static av_cold void uninit(AVFilterContext *ctx)
150 TestSourceContext *test = ctx->priv;
153 avfilter_unref_bufferp(&test->picref);
156 static int config_props(AVFilterLink *outlink)
158 TestSourceContext *test = outlink->src->priv;
160 outlink->w = test->w;
161 outlink->h = test->h;
162 outlink->sample_aspect_ratio = test->sar;
163 outlink->frame_rate = test->frame_rate;
164 outlink->time_base = test->time_base;
169 static int request_frame(AVFilterLink *outlink)
171 TestSourceContext *test = outlink->src->priv;
172 AVFilterBufferRef *outpicref;
175 if (test->max_pts >= 0 && test->pts >= test->max_pts)
178 if (test->draw_once) {
181 ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_PRESERVE|AV_PERM_REUSE,
184 return AVERROR(ENOMEM);
185 test->fill_picture_fn(outlink->src, test->picref);
187 outpicref = avfilter_ref_buffer(test->picref, ~AV_PERM_WRITE);
189 outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h);
192 return AVERROR(ENOMEM);
193 outpicref->pts = test->pts;
195 outpicref->video->key_frame = 1;
196 outpicref->video->interlaced = 0;
197 outpicref->video->pict_type = AV_PICTURE_TYPE_I;
198 outpicref->video->sample_aspect_ratio = test->sar;
199 if (!test->draw_once)
200 test->fill_picture_fn(outlink->src, outpicref);
205 if ((ret = ff_start_frame(outlink, outpicref)) < 0 ||
206 (ret = ff_draw_slice(outlink, 0, test->h, 1)) < 0 ||
207 (ret = ff_end_frame(outlink)) < 0)
213 #if CONFIG_COLOR_FILTER
215 #define color_options options
216 AVFILTER_DEFINE_CLASS(color);
218 static void color_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
220 TestSourceContext *test = ctx->priv;
221 ff_fill_rectangle(&test->draw, &test->color,
222 picref->data, picref->linesize,
223 0, 0, test->w, test->h);
226 static av_cold int color_init(AVFilterContext *ctx, const char *args)
228 TestSourceContext *test = ctx->priv;
229 test->class = &color_class;
230 test->fill_picture_fn = color_fill_picture;
232 av_opt_set(test, "color", "black", 0);
233 return init(ctx, args);
236 static int color_query_formats(AVFilterContext *ctx)
238 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
242 static int color_config_props(AVFilterLink *inlink)
244 AVFilterContext *ctx = inlink->src;
245 TestSourceContext *test = ctx->priv;
248 ff_draw_init(&test->draw, inlink->format, 0);
249 ff_draw_color(&test->draw, &test->color, test->color_rgba);
251 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
252 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
253 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
254 return AVERROR(EINVAL);
256 if (ret = config_props(inlink) < 0)
259 av_log(ctx, AV_LOG_VERBOSE, "color:0x%02x%02x%02x%02x\n",
260 test->color_rgba[0], test->color_rgba[1], test->color_rgba[2], test->color_rgba[3]);
264 AVFilter avfilter_vsrc_color = {
266 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
268 .priv_size = sizeof(TestSourceContext),
272 .query_formats = color_query_formats,
274 .inputs = (const AVFilterPad[]) {
278 .outputs = (const AVFilterPad[]) {
281 .type = AVMEDIA_TYPE_VIDEO,
282 .request_frame = request_frame,
283 .config_props = color_config_props,
288 .priv_class = &color_class,
291 #endif /* CONFIG_COLOR_FILTER */
293 #if CONFIG_NULLSRC_FILTER
295 #define nullsrc_options options
296 AVFILTER_DEFINE_CLASS(nullsrc);
298 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) { }
300 static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args)
302 TestSourceContext *test = ctx->priv;
304 test->class = &nullsrc_class;
305 test->fill_picture_fn = nullsrc_fill_picture;
306 return init(ctx, args);
309 AVFilter avfilter_vsrc_nullsrc = {
311 .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
312 .init = nullsrc_init,
314 .priv_size = sizeof(TestSourceContext),
316 .inputs = (const AVFilterPad[]) {{ .name = NULL}},
317 .outputs = (const AVFilterPad[]) {{ .name = "default",
318 .type = AVMEDIA_TYPE_VIDEO,
319 .request_frame = request_frame,
320 .config_props = config_props, },
322 .priv_class = &nullsrc_class,
325 #endif /* CONFIG_NULLSRC_FILTER */
327 #if CONFIG_TESTSRC_FILTER
329 #define testsrc_options options
330 AVFILTER_DEFINE_CLASS(testsrc);
333 * Fill a rectangle with value val.
335 * @param val the RGB value to set
336 * @param dst pointer to the destination buffer to fill
337 * @param dst_linesize linesize of destination
338 * @param segment_width width of the segment
339 * @param x horizontal coordinate where to draw the rectangle in the destination buffer
340 * @param y horizontal coordinate where to draw the rectangle in the destination buffer
341 * @param w width of the rectangle to draw, expressed as a number of segment_width units
342 * @param h height of the rectangle to draw, expressed as a number of segment_width units
344 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, unsigned segment_width,
345 unsigned x, unsigned y, unsigned w, unsigned h)
350 dst += segment_width * (step * x + y * dst_linesize);
351 w *= segment_width * step;
353 for (i = 0; i < h; i++) {
359 static void draw_digit(int digit, uint8_t *dst, unsigned dst_linesize,
360 unsigned segment_width)
365 #define LEFT_TOP_VBAR 8
366 #define LEFT_BOT_VBAR 16
367 #define RIGHT_TOP_VBAR 32
368 #define RIGHT_BOT_VBAR 64
372 { 1, 0, 5, 1 }, /* TOP_HBAR */
373 { 1, 6, 5, 1 }, /* MID_HBAR */
374 { 1, 12, 5, 1 }, /* BOT_HBAR */
375 { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
376 { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
377 { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
378 { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
380 static const unsigned char masks[10] = {
381 /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
382 /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
383 /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
384 /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
385 /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
386 /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
387 /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
388 /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
389 /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
390 /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
392 unsigned mask = masks[digit];
395 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
396 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
398 draw_rectangle(255, dst, dst_linesize, segment_width,
399 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
402 #define GRADIENT_SIZE (6 * 256)
404 static void test_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
406 TestSourceContext *test = ctx->priv;
409 int color, color_rest;
413 int dquad_x, dquad_y;
414 int grad, dgrad, rgrad, drgrad;
418 uint8_t *data = picref->data[0];
419 int width = picref->video->w;
420 int height = picref->video->h;
422 /* draw colored bars and circle */
423 radius = (width + height) / 4;
424 quad0 = width * width / 4 + height * height / 4 - radius * radius;
425 dquad_y = 1 - height;
427 for (y = 0; y < height; y++) {
433 for (x = 0; x < width; x++) {
439 *(p++) = icolor & 1 ? 255 : 0;
440 *(p++) = icolor & 2 ? 255 : 0;
441 *(p++) = icolor & 4 ? 255 : 0;
443 if (color_rest >= width) {
450 p0 += picref->linesize[0];
453 /* draw sliding color line */
454 p0 = p = data + picref->linesize[0] * height * 3/4;
455 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
458 dgrad = GRADIENT_SIZE / width;
459 drgrad = GRADIENT_SIZE % width;
460 for (x = 0; x < width; x++) {
462 grad < 256 || grad >= 5 * 256 ? 255 :
463 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
464 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
466 grad >= 4 * 256 ? 0 :
467 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
468 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
471 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
472 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
475 if (rgrad >= GRADIENT_SIZE) {
477 rgrad -= GRADIENT_SIZE;
479 if (grad >= GRADIENT_SIZE)
480 grad -= GRADIENT_SIZE;
483 for (y = height / 8; y > 0; y--) {
484 memcpy(p+picref->linesize[0], p, 3 * width);
485 p += picref->linesize[0];
489 seg_size = width / 80;
490 if (seg_size >= 1 && height >= 13 * seg_size) {
491 double time = av_q2d(test->time_base) * test->nb_frame *
492 pow(10, test->nb_decimals);
496 x = width - (width - seg_size * 64) / 2;
497 y = (height - seg_size * 13) / 2;
498 p = data + (x*3 + y * picref->linesize[0]);
499 for (i = 0; i < 8; i++) {
500 p -= 3 * 8 * seg_size;
501 draw_digit(second % 10, p, picref->linesize[0], seg_size);
509 static av_cold int test_init(AVFilterContext *ctx, const char *args)
511 TestSourceContext *test = ctx->priv;
513 test->class = &testsrc_class;
514 test->fill_picture_fn = test_fill_picture;
515 return init(ctx, args);
518 static int test_query_formats(AVFilterContext *ctx)
520 static const enum PixelFormat pix_fmts[] = {
521 PIX_FMT_RGB24, PIX_FMT_NONE
523 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
527 AVFilter avfilter_vsrc_testsrc = {
529 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
530 .priv_size = sizeof(TestSourceContext),
534 .query_formats = test_query_formats,
536 .inputs = (const AVFilterPad[]) {{ .name = NULL}},
538 .outputs = (const AVFilterPad[]) {{ .name = "default",
539 .type = AVMEDIA_TYPE_VIDEO,
540 .request_frame = request_frame,
541 .config_props = config_props, },
543 .priv_class = &testsrc_class,
546 #endif /* CONFIG_TESTSRC_FILTER */
548 #if CONFIG_RGBTESTSRC_FILTER
550 #define rgbtestsrc_options options
551 AVFILTER_DEFINE_CLASS(rgbtestsrc);
558 static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
559 int x, int y, int r, int g, int b, enum PixelFormat fmt,
566 case PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
567 case PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
568 case PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
569 case PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
570 case PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
571 case PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
574 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
575 p = dst + 3*x + y*dst_linesize;
582 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
583 p = dst + 4*x + y*dst_linesize;
589 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
591 TestSourceContext *test = ctx->priv;
592 int x, y, w = picref->video->w, h = picref->video->h;
594 for (y = 0; y < h; y++) {
595 for (x = 0; x < picref->video->w; x++) {
597 int r = 0, g = 0, b = 0;
600 else if (3*y < 2*h) g = c;
603 rgbtest_put_pixel(picref->data[0], picref->linesize[0], x, y, r, g, b,
604 ctx->outputs[0]->format, test->rgba_map);
609 static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args)
611 TestSourceContext *test = ctx->priv;
614 test->class = &rgbtestsrc_class;
615 test->fill_picture_fn = rgbtest_fill_picture;
616 return init(ctx, args);
619 static int rgbtest_query_formats(AVFilterContext *ctx)
621 static const enum PixelFormat pix_fmts[] = {
622 PIX_FMT_RGBA, PIX_FMT_ARGB, PIX_FMT_BGRA, PIX_FMT_ABGR,
623 PIX_FMT_BGR24, PIX_FMT_RGB24,
624 PIX_FMT_RGB444, PIX_FMT_BGR444,
625 PIX_FMT_RGB565, PIX_FMT_BGR565,
626 PIX_FMT_RGB555, PIX_FMT_BGR555,
629 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
633 static int rgbtest_config_props(AVFilterLink *outlink)
635 TestSourceContext *test = outlink->src->priv;
637 ff_fill_rgba_map(test->rgba_map, outlink->format);
638 return config_props(outlink);
641 AVFilter avfilter_vsrc_rgbtestsrc = {
642 .name = "rgbtestsrc",
643 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
644 .priv_size = sizeof(TestSourceContext),
645 .init = rgbtest_init,
648 .query_formats = rgbtest_query_formats,
650 .inputs = (const AVFilterPad[]) {{ .name = NULL}},
652 .outputs = (const AVFilterPad[]) {{ .name = "default",
653 .type = AVMEDIA_TYPE_VIDEO,
654 .request_frame = request_frame,
655 .config_props = rgbtest_config_props, },
657 .priv_class = &rgbtestsrc_class,
660 #endif /* CONFIG_RGBTESTSRC_FILTER */
662 #if CONFIG_SMPTEBARS_FILTER
664 #define smptebars_options options
665 AVFILTER_DEFINE_CLASS(smptebars);
667 static const uint8_t rainbow[7][4] = {
668 { 191, 191, 191, 255 }, /* gray */
669 { 191, 191, 0, 255 }, /* yellow */
670 { 0, 191, 191, 255 }, /* cyan */
671 { 0, 191, 0, 255 }, /* green */
672 { 191, 0, 191, 255 }, /* magenta */
673 { 191, 0, 0, 255 }, /* red */
674 { 0, 0, 191, 255 }, /* blue */
677 static const uint8_t wobnair[7][4] = {
678 { 0, 0, 191, 255 }, /* blue */
679 { 19, 19, 19, 255 }, /* 7.5% intensity black */
680 { 191, 0, 191, 255 }, /* magenta */
681 { 19, 19, 19, 255 }, /* 7.5% intensity black */
682 { 0, 191, 191, 255 }, /* cyan */
683 { 19, 19, 19, 255 }, /* 7.5% intensity black */
684 { 191, 191, 191, 255 }, /* gray */
687 static const uint8_t white[4] = { 255, 255, 255, 255 };
688 static const uint8_t black[4] = { 19, 19, 19, 255 }; /* 7.5% intensity black */
691 static const uint8_t neg4ire[4] = { 9, 9, 9, 255 }; /* 3.5% intensity black */
692 static const uint8_t pos4ire[4] = { 29, 29, 29, 255 }; /* 11.5% intensity black */
695 static const uint8_t i_pixel[4] = { 0, 68, 130, 255 };
696 static const uint8_t q_pixel[4] = { 67, 0, 130, 255 };
698 static void smptebars_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
700 TestSourceContext *test = ctx->priv;
702 int r_w, r_h, w_h, p_w, p_h, i, x = 0;
704 r_w = (test->w + 6) / 7;
705 r_h = test->h * 2 / 3;
706 w_h = test->h * 3 / 4 - r_h;
708 p_h = test->h - w_h - r_h;
710 #define DRAW_COLOR(rgba, x, y, w, h) \
711 ff_draw_color(&test->draw, &color, rgba); \
712 ff_fill_rectangle(&test->draw, &color, \
713 picref->data, picref->linesize, x, y, w, h) \
715 for (i = 0; i < 7; i++) {
716 DRAW_COLOR(rainbow[i], x, 0, FFMIN(r_w, test->w - x), r_h);
717 DRAW_COLOR(wobnair[i], x, r_h, FFMIN(r_w, test->w - x), w_h);
721 DRAW_COLOR(i_pixel, x, r_h + w_h, p_w, p_h);
723 DRAW_COLOR(white, x, r_h + w_h, p_w, p_h);
725 DRAW_COLOR(q_pixel, x, r_h + w_h, p_w, p_h);
727 DRAW_COLOR(black, x, r_h + w_h, 5 * r_w - x, p_h);
729 DRAW_COLOR(neg4ire, x, r_h + w_h, r_w / 3, p_h);
731 DRAW_COLOR(black, x, r_h + w_h, r_w / 3, p_h);
733 DRAW_COLOR(pos4ire, x, r_h + w_h, r_w / 3, p_h);
735 DRAW_COLOR(black, x, r_h + w_h, test->w - x, p_h);
738 static av_cold int smptebars_init(AVFilterContext *ctx, const char *args)
740 TestSourceContext *test = ctx->priv;
742 test->class = &smptebars_class;
743 test->fill_picture_fn = smptebars_fill_picture;
745 return init(ctx, args);
748 static int smptebars_query_formats(AVFilterContext *ctx)
750 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
754 static int smptebars_config_props(AVFilterLink *outlink)
756 AVFilterContext *ctx = outlink->src;
757 TestSourceContext *test = ctx->priv;
759 ff_draw_init(&test->draw, outlink->format, 0);
761 return config_props(outlink);
764 AVFilter avfilter_vsrc_smptebars = {
766 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
767 .priv_size = sizeof(TestSourceContext),
768 .init = smptebars_init,
771 .query_formats = smptebars_query_formats,
773 .inputs = (const AVFilterPad[]) {
777 .outputs = (const AVFilterPad[]) {
780 .type = AVMEDIA_TYPE_VIDEO,
781 .request_frame = request_frame,
782 .config_props = smptebars_config_props,
787 .priv_class = &smptebars_class,
790 #endif /* CONFIG_SMPTEBARS_FILTER */