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/opt.h"
39 #include "libavutil/imgutils.h"
40 #include "libavutil/intreadwrite.h"
41 #include "libavutil/parseutils.h"
43 #include "drawutils.h"
51 unsigned int nb_frame;
54 char *rate; ///< video frame rate
55 char *duration; ///< total duration of the generated video
56 AVRational sar; ///< sample aspect ratio
58 int draw_once; ///< draw only the first frame, always put out the same picture
59 AVFilterBufferRef *picref; ///< cached reference containing the painted picture
61 void (* fill_picture_fn)(AVFilterContext *ctx, AVFilterBufferRef *picref);
63 /* only used by color */
67 uint8_t color_rgba[4];
69 /* only used by rgbtest */
73 #define OFFSET(x) offsetof(TestSourceContext, x)
75 static const AVOption options[] = {
76 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
77 { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0 },
78 { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
79 { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 },
80 { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
81 { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 },
82 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX },
84 /* only used by color */
85 { "color", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, CHAR_MIN, CHAR_MAX },
86 { "c", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, CHAR_MIN, CHAR_MAX },
88 /* only used by testsrc */
89 { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
90 { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
94 static av_cold int init(AVFilterContext *ctx, const char *args)
96 TestSourceContext *test = ctx->priv;
97 AVRational frame_rate_q;
98 int64_t duration = -1;
101 av_opt_set_defaults(test);
103 if ((ret = (av_set_options_string(test, args, "=", ":"))) < 0) {
104 av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
108 if ((ret = av_parse_video_rate(&frame_rate_q, test->rate)) < 0) {
109 av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", test->rate);
113 if (test->duration && (ret = av_parse_time(&duration, test->duration, 1)) < 0) {
114 av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration);
118 if (test->nb_decimals && strcmp(ctx->filter->name, "testsrc")) {
119 av_log(ctx, AV_LOG_WARNING,
120 "Option 'decimals' is ignored with source '%s'\n",
124 if (test->color_str && strcmp(ctx->filter->name, "color")) {
125 av_log(ctx, AV_LOG_WARNING,
126 "Option 'color' is ignored with source '%s'\n",
129 if ((ret = av_parse_color(test->color_rgba, test->color_str, -1, ctx)) < 0)
132 test->time_base.num = frame_rate_q.den;
133 test->time_base.den = frame_rate_q.num;
134 test->max_pts = duration >= 0 ?
135 av_rescale_q(duration, AV_TIME_BASE_Q, test->time_base) : -1;
139 av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
140 test->w, test->h, frame_rate_q.num, frame_rate_q.den,
141 duration < 0 ? -1 : test->max_pts * av_q2d(test->time_base),
142 test->sar.num, test->sar.den);
146 static av_cold void uninit(AVFilterContext *ctx)
148 TestSourceContext *test = ctx->priv;
151 avfilter_unref_bufferp(&test->picref);
154 static int config_props(AVFilterLink *outlink)
156 TestSourceContext *test = outlink->src->priv;
158 outlink->w = test->w;
159 outlink->h = test->h;
160 outlink->sample_aspect_ratio = test->sar;
161 outlink->time_base = test->time_base;
166 static int request_frame(AVFilterLink *outlink)
168 TestSourceContext *test = outlink->src->priv;
169 AVFilterBufferRef *outpicref;
172 if (test->max_pts >= 0 && test->pts >= test->max_pts)
175 if (test->draw_once) {
178 ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_PRESERVE|AV_PERM_REUSE,
181 return AVERROR(ENOMEM);
182 test->fill_picture_fn(outlink->src, test->picref);
184 outpicref = avfilter_ref_buffer(test->picref, ~AV_PERM_WRITE);
186 outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h);
189 return AVERROR(ENOMEM);
190 outpicref->pts = test->pts;
192 outpicref->video->key_frame = 1;
193 outpicref->video->interlaced = 0;
194 outpicref->video->pict_type = AV_PICTURE_TYPE_I;
195 outpicref->video->sample_aspect_ratio = test->sar;
196 if (!test->draw_once)
197 test->fill_picture_fn(outlink->src, outpicref);
202 if ((ret = ff_start_frame(outlink, outpicref)) < 0 ||
203 (ret = ff_draw_slice(outlink, 0, test->h, 1)) < 0 ||
204 (ret = ff_end_frame(outlink)) < 0)
210 #if CONFIG_COLOR_FILTER
212 #define color_options options
213 AVFILTER_DEFINE_CLASS(color);
215 static void color_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
217 TestSourceContext *test = ctx->priv;
218 ff_fill_rectangle(&test->draw, &test->color,
219 picref->data, picref->linesize,
220 0, 0, test->w, test->h);
223 static av_cold int color_init(AVFilterContext *ctx, const char *args)
225 TestSourceContext *test = ctx->priv;
226 test->class = &color_class;
227 test->fill_picture_fn = color_fill_picture;
229 return init(ctx, args);
232 static int color_query_formats(AVFilterContext *ctx)
234 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
238 static int color_config_props(AVFilterLink *inlink)
240 AVFilterContext *ctx = inlink->src;
241 TestSourceContext *test = ctx->priv;
244 ff_draw_init(&test->draw, inlink->format, 0);
245 ff_draw_color(&test->draw, &test->color, test->color_rgba);
247 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
248 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
249 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
250 return AVERROR(EINVAL);
252 if (ret = config_props(inlink) < 0)
255 av_log(ctx, AV_LOG_VERBOSE, "color:0x%02x%02x%02x%02x\n",
256 test->color_rgba[0], test->color_rgba[1], test->color_rgba[2], test->color_rgba[3]);
260 AVFilter avfilter_vsrc_color = {
262 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
264 .priv_size = sizeof(TestSourceContext),
268 .query_formats = color_query_formats,
270 .inputs = (const AVFilterPad[]) {
274 .outputs = (const AVFilterPad[]) {
277 .type = AVMEDIA_TYPE_VIDEO,
278 .request_frame = request_frame,
279 .config_props = color_config_props,
285 #endif /* CONFIG_COLOR_FILTER */
287 #if CONFIG_NULLSRC_FILTER
289 #define nullsrc_options options
290 AVFILTER_DEFINE_CLASS(nullsrc);
292 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) { }
294 static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args)
296 TestSourceContext *test = ctx->priv;
298 test->class = &nullsrc_class;
299 test->fill_picture_fn = nullsrc_fill_picture;
300 return init(ctx, args);
303 AVFilter avfilter_vsrc_nullsrc = {
305 .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
306 .init = nullsrc_init,
308 .priv_size = sizeof(TestSourceContext),
310 .inputs = (const AVFilterPad[]) {{ .name = NULL}},
311 .outputs = (const AVFilterPad[]) {{ .name = "default",
312 .type = AVMEDIA_TYPE_VIDEO,
313 .request_frame = request_frame,
314 .config_props = config_props, },
318 #endif /* CONFIG_NULLSRC_FILTER */
320 #if CONFIG_TESTSRC_FILTER
322 #define testsrc_options options
323 AVFILTER_DEFINE_CLASS(testsrc);
326 * Fill a rectangle with value val.
328 * @param val the RGB value to set
329 * @param dst pointer to the destination buffer to fill
330 * @param dst_linesize linesize of destination
331 * @param segment_width width of the segment
332 * @param x horizontal coordinate where to draw the rectangle in the destination buffer
333 * @param y horizontal coordinate where to draw the rectangle in the destination buffer
334 * @param w width of the rectangle to draw, expressed as a number of segment_width units
335 * @param h height of the rectangle to draw, expressed as a number of segment_width units
337 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, unsigned segment_width,
338 unsigned x, unsigned y, unsigned w, unsigned h)
343 dst += segment_width * (step * x + y * dst_linesize);
344 w *= segment_width * step;
346 for (i = 0; i < h; i++) {
352 static void draw_digit(int digit, uint8_t *dst, unsigned dst_linesize,
353 unsigned segment_width)
358 #define LEFT_TOP_VBAR 8
359 #define LEFT_BOT_VBAR 16
360 #define RIGHT_TOP_VBAR 32
361 #define RIGHT_BOT_VBAR 64
365 { 1, 0, 5, 1 }, /* TOP_HBAR */
366 { 1, 6, 5, 1 }, /* MID_HBAR */
367 { 1, 12, 5, 1 }, /* BOT_HBAR */
368 { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
369 { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
370 { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
371 { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
373 static const unsigned char masks[10] = {
374 /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
375 /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
376 /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
377 /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
378 /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
379 /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
380 /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
381 /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
382 /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
383 /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
385 unsigned mask = masks[digit];
388 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
389 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
391 draw_rectangle(255, dst, dst_linesize, segment_width,
392 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
395 #define GRADIENT_SIZE (6 * 256)
397 static void test_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
399 TestSourceContext *test = ctx->priv;
402 int color, color_rest;
406 int dquad_x, dquad_y;
407 int grad, dgrad, rgrad, drgrad;
411 uint8_t *data = picref->data[0];
412 int width = picref->video->w;
413 int height = picref->video->h;
415 /* draw colored bars and circle */
416 radius = (width + height) / 4;
417 quad0 = width * width / 4 + height * height / 4 - radius * radius;
418 dquad_y = 1 - height;
420 for (y = 0; y < height; y++) {
426 for (x = 0; x < width; x++) {
432 *(p++) = icolor & 1 ? 255 : 0;
433 *(p++) = icolor & 2 ? 255 : 0;
434 *(p++) = icolor & 4 ? 255 : 0;
436 if (color_rest >= width) {
443 p0 += picref->linesize[0];
446 /* draw sliding color line */
447 p0 = p = data + picref->linesize[0] * height * 3/4;
448 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
451 dgrad = GRADIENT_SIZE / width;
452 drgrad = GRADIENT_SIZE % width;
453 for (x = 0; x < width; x++) {
455 grad < 256 || grad >= 5 * 256 ? 255 :
456 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
457 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
459 grad >= 4 * 256 ? 0 :
460 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
461 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
464 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
465 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
468 if (rgrad >= GRADIENT_SIZE) {
470 rgrad -= GRADIENT_SIZE;
472 if (grad >= GRADIENT_SIZE)
473 grad -= GRADIENT_SIZE;
476 for (y = height / 8; y > 0; y--) {
477 memcpy(p+picref->linesize[0], p, 3 * width);
478 p += picref->linesize[0];
482 seg_size = width / 80;
483 if (seg_size >= 1 && height >= 13 * seg_size) {
484 double time = av_q2d(test->time_base) * test->nb_frame *
485 pow(10, test->nb_decimals);
489 x = width - (width - seg_size * 64) / 2;
490 y = (height - seg_size * 13) / 2;
491 p = data + (x*3 + y * picref->linesize[0]);
492 for (i = 0; i < 8; i++) {
493 p -= 3 * 8 * seg_size;
494 draw_digit(second % 10, p, picref->linesize[0], seg_size);
502 static av_cold int test_init(AVFilterContext *ctx, const char *args)
504 TestSourceContext *test = ctx->priv;
506 test->class = &testsrc_class;
507 test->fill_picture_fn = test_fill_picture;
508 return init(ctx, args);
511 static int test_query_formats(AVFilterContext *ctx)
513 static const enum PixelFormat pix_fmts[] = {
514 PIX_FMT_RGB24, PIX_FMT_NONE
516 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
520 AVFilter avfilter_vsrc_testsrc = {
522 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
523 .priv_size = sizeof(TestSourceContext),
527 .query_formats = test_query_formats,
529 .inputs = (const AVFilterPad[]) {{ .name = NULL}},
531 .outputs = (const AVFilterPad[]) {{ .name = "default",
532 .type = AVMEDIA_TYPE_VIDEO,
533 .request_frame = request_frame,
534 .config_props = config_props, },
538 #endif /* CONFIG_TESTSRC_FILTER */
540 #if CONFIG_RGBTESTSRC_FILTER
542 #define rgbtestsrc_options options
543 AVFILTER_DEFINE_CLASS(rgbtestsrc);
550 static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
551 int x, int y, int r, int g, int b, enum PixelFormat fmt,
558 case PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
559 case PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
560 case PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
561 case PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
562 case PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
563 case PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
566 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
567 p = dst + 3*x + y*dst_linesize;
574 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
575 p = dst + 4*x + y*dst_linesize;
581 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
583 TestSourceContext *test = ctx->priv;
584 int x, y, w = picref->video->w, h = picref->video->h;
586 for (y = 0; y < h; y++) {
587 for (x = 0; x < picref->video->w; x++) {
589 int r = 0, g = 0, b = 0;
592 else if (3*y < 2*h) g = c;
595 rgbtest_put_pixel(picref->data[0], picref->linesize[0], x, y, r, g, b,
596 ctx->outputs[0]->format, test->rgba_map);
601 static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args)
603 TestSourceContext *test = ctx->priv;
606 test->class = &rgbtestsrc_class;
607 test->fill_picture_fn = rgbtest_fill_picture;
608 return init(ctx, args);
611 static int rgbtest_query_formats(AVFilterContext *ctx)
613 static const enum PixelFormat pix_fmts[] = {
614 PIX_FMT_RGBA, PIX_FMT_ARGB, PIX_FMT_BGRA, PIX_FMT_ABGR,
615 PIX_FMT_BGR24, PIX_FMT_RGB24,
616 PIX_FMT_RGB444, PIX_FMT_BGR444,
617 PIX_FMT_RGB565, PIX_FMT_BGR565,
618 PIX_FMT_RGB555, PIX_FMT_BGR555,
621 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
625 static int rgbtest_config_props(AVFilterLink *outlink)
627 TestSourceContext *test = outlink->src->priv;
629 ff_fill_rgba_map(test->rgba_map, outlink->format);
630 return config_props(outlink);
633 AVFilter avfilter_vsrc_rgbtestsrc = {
634 .name = "rgbtestsrc",
635 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
636 .priv_size = sizeof(TestSourceContext),
637 .init = rgbtest_init,
640 .query_formats = rgbtest_query_formats,
642 .inputs = (const AVFilterPad[]) {{ .name = NULL}},
644 .outputs = (const AVFilterPad[]) {{ .name = "default",
645 .type = AVMEDIA_TYPE_VIDEO,
646 .request_frame = request_frame,
647 .config_props = rgbtest_config_props, },
651 #endif /* CONFIG_RGBTESTSRC_FILTER */
653 #if CONFIG_SMPTEBARS_FILTER
655 #define smptebars_options options
656 AVFILTER_DEFINE_CLASS(smptebars);
658 static const uint8_t rainbow[7][4] = {
659 { 191, 191, 191, 255 }, /* gray */
660 { 191, 191, 0, 255 }, /* yellow */
661 { 0, 191, 191, 255 }, /* cyan */
662 { 0, 191, 0, 255 }, /* green */
663 { 191, 0, 191, 255 }, /* magenta */
664 { 191, 0, 0, 255 }, /* red */
665 { 0, 0, 191, 255 }, /* blue */
668 static const uint8_t wobnair[7][4] = {
669 { 0, 0, 191, 255 }, /* blue */
670 { 19, 19, 19, 255 }, /* 7.5% intensity black */
671 { 191, 0, 191, 255 }, /* magenta */
672 { 19, 19, 19, 255 }, /* 7.5% intensity black */
673 { 0, 191, 191, 255 }, /* cyan */
674 { 19, 19, 19, 255 }, /* 7.5% intensity black */
675 { 191, 191, 191, 255 }, /* gray */
678 static const uint8_t white[4] = { 255, 255, 255, 255 };
679 static const uint8_t black[4] = { 19, 19, 19, 255 }; /* 7.5% intensity black */
682 static const uint8_t neg4ire[4] = { 9, 9, 9, 255 }; /* 3.5% intensity black */
683 static const uint8_t pos4ire[4] = { 29, 29, 29, 255 }; /* 11.5% intensity black */
686 static const uint8_t i_pixel[4] = { 0, 68, 130, 255 };
687 static const uint8_t q_pixel[4] = { 67, 0, 130, 255 };
689 static void smptebars_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref)
691 TestSourceContext *test = ctx->priv;
693 int r_w, r_h, w_h, p_w, p_h, i, x = 0;
695 r_w = (test->w + 6) / 7;
696 r_h = test->h * 2 / 3;
697 w_h = test->h * 3 / 4 - r_h;
699 p_h = test->h - w_h - r_h;
701 #define DRAW_COLOR(rgba, x, y, w, h) \
702 ff_draw_color(&test->draw, &color, rgba); \
703 ff_fill_rectangle(&test->draw, &color, \
704 picref->data, picref->linesize, x, y, w, h) \
706 for (i = 0; i < 7; i++) {
707 DRAW_COLOR(rainbow[i], x, 0, FFMIN(r_w, test->w - x), r_h);
708 DRAW_COLOR(wobnair[i], x, r_h, FFMIN(r_w, test->w - x), w_h);
712 DRAW_COLOR(i_pixel, x, r_h + w_h, p_w, p_h);
714 DRAW_COLOR(white, x, r_h + w_h, p_w, p_h);
716 DRAW_COLOR(q_pixel, x, r_h + w_h, p_w, p_h);
718 DRAW_COLOR(black, x, r_h + w_h, 5 * r_w - x, p_h);
720 DRAW_COLOR(neg4ire, x, r_h + w_h, r_w / 3, p_h);
722 DRAW_COLOR(black, x, r_h + w_h, r_w / 3, p_h);
724 DRAW_COLOR(pos4ire, x, r_h + w_h, r_w / 3, p_h);
726 DRAW_COLOR(black, x, r_h + w_h, test->w - x, p_h);
729 static av_cold int smptebars_init(AVFilterContext *ctx, const char *args)
731 TestSourceContext *test = ctx->priv;
733 test->class = &smptebars_class;
734 test->fill_picture_fn = smptebars_fill_picture;
736 return init(ctx, args);
739 static int smptebars_query_formats(AVFilterContext *ctx)
741 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
745 static int smptebars_config_props(AVFilterLink *outlink)
747 AVFilterContext *ctx = outlink->src;
748 TestSourceContext *test = ctx->priv;
750 ff_draw_init(&test->draw, outlink->format, 0);
752 return config_props(outlink);
755 AVFilter avfilter_vsrc_smptebars = {
757 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
758 .priv_size = sizeof(TestSourceContext),
759 .init = smptebars_init,
762 .query_formats = smptebars_query_formats,
764 .inputs = (const AVFilterPad[]) {
768 .outputs = (const AVFilterPad[]) {
771 .type = AVMEDIA_TYPE_VIDEO,
772 .request_frame = request_frame,
773 .config_props = smptebars_config_props,
779 #endif /* CONFIG_SMPTEBARS_FILTER */