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_str; ///< total duration of the generated video
57 int64_t duration; ///< duration expressed in microseconds
58 AVRational sar; ///< sample aspect ratio
60 int draw_once; ///< draw only the first frame, always put out the same picture
61 AVFrame *picref; ///< cached reference containing the painted picture
63 void (* fill_picture_fn)(AVFilterContext *ctx, AVFrame *frame);
65 /* only used by color */
69 uint8_t color_rgba[4];
71 /* only used by rgbtest */
75 #define OFFSET(x) offsetof(TestSourceContext, x)
76 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
78 static const AVOption options[] = {
79 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },
80 { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },
81 { "rate", "set video rate", OFFSET(frame_rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
82 { "r", "set video rate", OFFSET(frame_rate_str), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
83 { "duration", "set video duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
84 { "d", "set video duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
85 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
87 /* only used by color */
88 { "color", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
89 { "c", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
91 /* only used by testsrc */
92 { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS },
93 { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS },
97 static av_cold int init(AVFilterContext *ctx, const char *args)
99 TestSourceContext *test = ctx->priv;
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);
113 if (test->duration_str &&
114 (ret = av_parse_time(&test->duration, test->duration_str, 1)) < 0) {
115 av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration_str);
119 if (test->nb_decimals && strcmp(ctx->filter->name, "testsrc")) {
120 av_log(ctx, AV_LOG_WARNING,
121 "Option 'decimals' is ignored with source '%s'\n",
125 if (test->color_str) {
126 if (!strcmp(ctx->filter->name, "color")) {
127 ret = av_parse_color(test->color_rgba, test->color_str, -1, ctx);
131 av_log(ctx, AV_LOG_WARNING,
132 "Option 'color' is ignored with source '%s'\n",
137 test->time_base = av_inv_q(test->frame_rate);
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 test->duration < 0 ? -1 : (double)test->duration/1000000,
144 test->sar.num, test->sar.den);
148 static av_cold void uninit(AVFilterContext *ctx)
150 TestSourceContext *test = ctx->priv;
153 av_frame_free(&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;
174 if (test->duration >= 0 &&
175 av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration)
178 if (test->draw_once) {
181 ff_get_video_buffer(outlink, test->w, test->h);
183 return AVERROR(ENOMEM);
184 test->fill_picture_fn(outlink->src, test->picref);
186 frame = av_frame_clone(test->picref);
188 frame = ff_get_video_buffer(outlink, test->w, test->h);
191 return AVERROR(ENOMEM);
192 frame->pts = test->pts;
193 frame->key_frame = 1;
194 frame->interlaced_frame = 0;
195 frame->pict_type = AV_PICTURE_TYPE_I;
196 frame->sample_aspect_ratio = test->sar;
197 if (!test->draw_once)
198 test->fill_picture_fn(outlink->src, frame);
203 return ff_filter_frame(outlink, frame);
206 #if CONFIG_COLOR_FILTER
208 #define color_options options
209 AVFILTER_DEFINE_CLASS(color);
211 static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
213 TestSourceContext *test = ctx->priv;
214 ff_fill_rectangle(&test->draw, &test->color,
215 picref->data, picref->linesize,
216 0, 0, test->w, test->h);
219 static av_cold int color_init(AVFilterContext *ctx, const char *args)
221 TestSourceContext *test = ctx->priv;
222 test->class = &color_class;
223 test->fill_picture_fn = color_fill_picture;
225 av_opt_set(test, "color", "black", 0);
226 return init(ctx, args);
229 static int color_query_formats(AVFilterContext *ctx)
231 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
235 static int color_config_props(AVFilterLink *inlink)
237 AVFilterContext *ctx = inlink->src;
238 TestSourceContext *test = ctx->priv;
241 ff_draw_init(&test->draw, inlink->format, 0);
242 ff_draw_color(&test->draw, &test->color, test->color_rgba);
244 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
245 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
246 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
247 return AVERROR(EINVAL);
249 if ((ret = config_props(inlink)) < 0)
252 av_log(ctx, AV_LOG_VERBOSE, "color:0x%02x%02x%02x%02x\n",
253 test->color_rgba[0], test->color_rgba[1], test->color_rgba[2], test->color_rgba[3]);
257 static const AVFilterPad color_outputs[] = {
260 .type = AVMEDIA_TYPE_VIDEO,
261 .request_frame = request_frame,
262 .config_props = color_config_props,
267 AVFilter avfilter_vsrc_color = {
269 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
271 .priv_size = sizeof(TestSourceContext),
275 .query_formats = color_query_formats,
277 .outputs = color_outputs,
278 .priv_class = &color_class,
281 #endif /* CONFIG_COLOR_FILTER */
283 #if CONFIG_NULLSRC_FILTER
285 #define nullsrc_options options
286 AVFILTER_DEFINE_CLASS(nullsrc);
288 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
290 static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args)
292 TestSourceContext *test = ctx->priv;
294 test->class = &nullsrc_class;
295 test->fill_picture_fn = nullsrc_fill_picture;
296 return init(ctx, args);
299 static const AVFilterPad nullsrc_outputs[] = {
302 .type = AVMEDIA_TYPE_VIDEO,
303 .request_frame = request_frame,
304 .config_props = config_props,
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 .outputs = nullsrc_outputs,
317 .priv_class = &nullsrc_class,
320 #endif /* CONFIG_NULLSRC_FILTER */
322 #if CONFIG_TESTSRC_FILTER
324 #define testsrc_options options
325 AVFILTER_DEFINE_CLASS(testsrc);
328 * Fill a rectangle with value val.
330 * @param val the RGB value to set
331 * @param dst pointer to the destination buffer to fill
332 * @param dst_linesize linesize of destination
333 * @param segment_width width of the segment
334 * @param x horizontal coordinate where to draw the rectangle in the destination buffer
335 * @param y horizontal coordinate where to draw the rectangle in the destination buffer
336 * @param w width of the rectangle to draw, expressed as a number of segment_width units
337 * @param h height of the rectangle to draw, expressed as a number of segment_width units
339 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, unsigned segment_width,
340 unsigned x, unsigned y, unsigned w, unsigned h)
345 dst += segment_width * (step * x + y * dst_linesize);
346 w *= segment_width * step;
348 for (i = 0; i < h; i++) {
354 static void draw_digit(int digit, uint8_t *dst, unsigned dst_linesize,
355 unsigned segment_width)
360 #define LEFT_TOP_VBAR 8
361 #define LEFT_BOT_VBAR 16
362 #define RIGHT_TOP_VBAR 32
363 #define RIGHT_BOT_VBAR 64
367 { 1, 0, 5, 1 }, /* TOP_HBAR */
368 { 1, 6, 5, 1 }, /* MID_HBAR */
369 { 1, 12, 5, 1 }, /* BOT_HBAR */
370 { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
371 { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
372 { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
373 { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
375 static const unsigned char masks[10] = {
376 /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
377 /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
378 /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
379 /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
380 /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
381 /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
382 /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
383 /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
384 /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
385 /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
387 unsigned mask = masks[digit];
390 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
391 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
393 draw_rectangle(255, dst, dst_linesize, segment_width,
394 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
397 #define GRADIENT_SIZE (6 * 256)
399 static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
401 TestSourceContext *test = ctx->priv;
404 int color, color_rest;
408 int dquad_x, dquad_y;
409 int grad, dgrad, rgrad, drgrad;
413 uint8_t *data = frame->data[0];
414 int width = frame->width;
415 int height = frame->height;
417 /* draw colored bars and circle */
418 radius = (width + height) / 4;
419 quad0 = width * width / 4 + height * height / 4 - radius * radius;
420 dquad_y = 1 - height;
422 for (y = 0; y < height; y++) {
428 for (x = 0; x < width; x++) {
434 *(p++) = icolor & 1 ? 255 : 0;
435 *(p++) = icolor & 2 ? 255 : 0;
436 *(p++) = icolor & 4 ? 255 : 0;
438 if (color_rest >= width) {
445 p0 += frame->linesize[0];
448 /* draw sliding color line */
449 p0 = p = data + frame->linesize[0] * height * 3/4;
450 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
453 dgrad = GRADIENT_SIZE / width;
454 drgrad = GRADIENT_SIZE % width;
455 for (x = 0; x < width; x++) {
457 grad < 256 || grad >= 5 * 256 ? 255 :
458 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
459 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
461 grad >= 4 * 256 ? 0 :
462 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
463 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
466 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
467 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
470 if (rgrad >= GRADIENT_SIZE) {
472 rgrad -= GRADIENT_SIZE;
474 if (grad >= GRADIENT_SIZE)
475 grad -= GRADIENT_SIZE;
478 for (y = height / 8; y > 0; y--) {
479 memcpy(p+frame->linesize[0], p, 3 * width);
480 p += frame->linesize[0];
484 seg_size = width / 80;
485 if (seg_size >= 1 && height >= 13 * seg_size) {
486 double time = av_q2d(test->time_base) * test->nb_frame *
487 pow(10, test->nb_decimals);
491 x = width - (width - seg_size * 64) / 2;
492 y = (height - seg_size * 13) / 2;
493 p = data + (x*3 + y * frame->linesize[0]);
494 for (i = 0; i < 8; i++) {
495 p -= 3 * 8 * seg_size;
496 draw_digit(second % 10, p, frame->linesize[0], seg_size);
504 static av_cold int test_init(AVFilterContext *ctx, const char *args)
506 TestSourceContext *test = ctx->priv;
508 test->class = &testsrc_class;
509 test->fill_picture_fn = test_fill_picture;
510 return init(ctx, args);
513 static int test_query_formats(AVFilterContext *ctx)
515 static const enum AVPixelFormat pix_fmts[] = {
516 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
518 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
522 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
525 .type = AVMEDIA_TYPE_VIDEO,
526 .request_frame = request_frame,
527 .config_props = config_props,
532 AVFilter avfilter_vsrc_testsrc = {
534 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
535 .priv_size = sizeof(TestSourceContext),
539 .query_formats = test_query_formats,
542 .outputs = avfilter_vsrc_testsrc_outputs,
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 AVPixelFormat fmt,
566 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
567 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
568 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
569 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
570 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
571 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
572 case AV_PIX_FMT_RGB24:
573 case AV_PIX_FMT_BGR24:
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;
578 case AV_PIX_FMT_RGBA:
579 case AV_PIX_FMT_BGRA:
580 case AV_PIX_FMT_ARGB:
581 case AV_PIX_FMT_ABGR:
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, AVFrame *frame)
591 TestSourceContext *test = ctx->priv;
592 int x, y, w = frame->width, h = frame->height;
594 for (y = 0; y < h; y++) {
595 for (x = 0; x < w; x++) {
597 int r = 0, g = 0, b = 0;
600 else if (3*y < 2*h) g = c;
603 rgbtest_put_pixel(frame->data[0], frame->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 AVPixelFormat pix_fmts[] = {
622 AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
623 AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
624 AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
625 AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
626 AV_PIX_FMT_RGB555, AV_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 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
644 .type = AVMEDIA_TYPE_VIDEO,
645 .request_frame = request_frame,
646 .config_props = rgbtest_config_props,
651 AVFilter avfilter_vsrc_rgbtestsrc = {
652 .name = "rgbtestsrc",
653 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
654 .priv_size = sizeof(TestSourceContext),
655 .init = rgbtest_init,
658 .query_formats = rgbtest_query_formats,
662 .outputs = avfilter_vsrc_rgbtestsrc_outputs,
663 .priv_class = &rgbtestsrc_class,
666 #endif /* CONFIG_RGBTESTSRC_FILTER */
668 #if CONFIG_SMPTEBARS_FILTER
670 #define smptebars_options options
671 AVFILTER_DEFINE_CLASS(smptebars);
673 static const uint8_t rainbow[7][4] = {
674 { 191, 191, 191, 255 }, /* gray */
675 { 191, 191, 0, 255 }, /* yellow */
676 { 0, 191, 191, 255 }, /* cyan */
677 { 0, 191, 0, 255 }, /* green */
678 { 191, 0, 191, 255 }, /* magenta */
679 { 191, 0, 0, 255 }, /* red */
680 { 0, 0, 191, 255 }, /* blue */
683 static const uint8_t wobnair[7][4] = {
684 { 0, 0, 191, 255 }, /* blue */
685 { 19, 19, 19, 255 }, /* 7.5% intensity black */
686 { 191, 0, 191, 255 }, /* magenta */
687 { 19, 19, 19, 255 }, /* 7.5% intensity black */
688 { 0, 191, 191, 255 }, /* cyan */
689 { 19, 19, 19, 255 }, /* 7.5% intensity black */
690 { 191, 191, 191, 255 }, /* gray */
693 static const uint8_t white[4] = { 255, 255, 255, 255 };
694 static const uint8_t black[4] = { 19, 19, 19, 255 }; /* 7.5% intensity black */
697 static const uint8_t neg4ire[4] = { 9, 9, 9, 255 }; /* 3.5% intensity black */
698 static const uint8_t pos4ire[4] = { 29, 29, 29, 255 }; /* 11.5% intensity black */
701 static const uint8_t i_pixel[4] = { 0, 68, 130, 255 };
702 static const uint8_t q_pixel[4] = { 67, 0, 130, 255 };
704 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
706 TestSourceContext *test = ctx->priv;
708 int r_w, r_h, w_h, p_w, p_h, i, x = 0;
710 r_w = (test->w + 6) / 7;
711 r_h = test->h * 2 / 3;
712 w_h = test->h * 3 / 4 - r_h;
714 p_h = test->h - w_h - r_h;
716 #define DRAW_COLOR(rgba, x, y, w, h) \
717 ff_draw_color(&test->draw, &color, rgba); \
718 ff_fill_rectangle(&test->draw, &color, \
719 picref->data, picref->linesize, x, y, w, h) \
721 for (i = 0; i < 7; i++) {
722 DRAW_COLOR(rainbow[i], x, 0, FFMIN(r_w, test->w - x), r_h);
723 DRAW_COLOR(wobnair[i], x, r_h, FFMIN(r_w, test->w - x), w_h);
727 DRAW_COLOR(i_pixel, x, r_h + w_h, p_w, p_h);
729 DRAW_COLOR(white, x, r_h + w_h, p_w, p_h);
731 DRAW_COLOR(q_pixel, x, r_h + w_h, p_w, p_h);
733 DRAW_COLOR(black, x, r_h + w_h, 5 * r_w - x, p_h);
735 DRAW_COLOR(neg4ire, x, r_h + w_h, r_w / 3, p_h);
737 DRAW_COLOR(black, x, r_h + w_h, r_w / 3, p_h);
739 DRAW_COLOR(pos4ire, x, r_h + w_h, r_w / 3, p_h);
741 DRAW_COLOR(black, x, r_h + w_h, test->w - x, p_h);
744 static av_cold int smptebars_init(AVFilterContext *ctx, const char *args)
746 TestSourceContext *test = ctx->priv;
748 test->class = &smptebars_class;
749 test->fill_picture_fn = smptebars_fill_picture;
751 return init(ctx, args);
754 static int smptebars_query_formats(AVFilterContext *ctx)
756 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
760 static int smptebars_config_props(AVFilterLink *outlink)
762 AVFilterContext *ctx = outlink->src;
763 TestSourceContext *test = ctx->priv;
765 ff_draw_init(&test->draw, outlink->format, 0);
767 return config_props(outlink);
770 static const AVFilterPad smptebars_outputs[] = {
773 .type = AVMEDIA_TYPE_VIDEO,
774 .request_frame = request_frame,
775 .config_props = smptebars_config_props,
780 AVFilter avfilter_vsrc_smptebars = {
782 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
783 .priv_size = sizeof(TestSourceContext),
784 .init = smptebars_init,
787 .query_formats = smptebars_query_formats,
789 .outputs = smptebars_outputs,
790 .priv_class = &smptebars_class,
793 #endif /* CONFIG_SMPTEBARS_FILTER */