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/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"
45 #include "drawutils.h"
53 unsigned int nb_frame;
54 AVRational time_base, 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 #define COMMON_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), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },\
82 { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.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 },
88 static const AVOption color_options[] = {
89 /* only used by color */
90 { "color", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
91 { "c", "set color", OFFSET(color_str), AV_OPT_TYPE_STRING, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
97 static const AVOption options[] = {
99 /* only used by testsrc */
100 { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
101 { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
106 static av_cold int init(AVFilterContext *ctx)
108 TestSourceContext *test = ctx->priv;
112 if (test->duration_str &&
113 (ret = av_parse_time(&test->duration, test->duration_str, 1)) < 0) {
114 av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration_str);
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) {
125 if (!strcmp(ctx->filter->name, "color")) {
126 ret = av_parse_color(test->color_rgba, test->color_str, -1, ctx);
130 av_log(ctx, AV_LOG_WARNING,
131 "Option 'color' is ignored with source '%s'\n",
136 test->time_base = av_inv_q(test->frame_rate);
140 av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
141 test->w, test->h, test->frame_rate.num, test->frame_rate.den,
142 test->duration < 0 ? -1 : (double)test->duration/1000000,
143 test->sar.num, test->sar.den);
147 static av_cold void uninit(AVFilterContext *ctx)
149 TestSourceContext *test = ctx->priv;
151 av_frame_free(&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->frame_rate = test->frame_rate;
162 outlink->time_base = test->time_base;
167 static int request_frame(AVFilterLink *outlink)
169 TestSourceContext *test = outlink->src->priv;
172 if (test->duration >= 0 &&
173 av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration)
176 if (test->draw_once) {
179 ff_get_video_buffer(outlink, test->w, test->h);
181 return AVERROR(ENOMEM);
182 test->fill_picture_fn(outlink->src, test->picref);
184 frame = av_frame_clone(test->picref);
186 frame = ff_get_video_buffer(outlink, test->w, test->h);
189 return AVERROR(ENOMEM);
190 frame->pts = test->pts;
191 frame->key_frame = 1;
192 frame->interlaced_frame = 0;
193 frame->pict_type = AV_PICTURE_TYPE_I;
194 frame->sample_aspect_ratio = test->sar;
195 if (!test->draw_once)
196 test->fill_picture_fn(outlink->src, frame);
201 return ff_filter_frame(outlink, frame);
204 #if CONFIG_COLOR_FILTER
206 AVFILTER_DEFINE_CLASS(color);
208 static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
210 TestSourceContext *test = ctx->priv;
211 ff_fill_rectangle(&test->draw, &test->color,
212 picref->data, picref->linesize,
213 0, 0, test->w, test->h);
216 static av_cold int color_init(AVFilterContext *ctx, const char *args)
218 TestSourceContext *test = ctx->priv;
219 test->fill_picture_fn = color_fill_picture;
224 static int color_query_formats(AVFilterContext *ctx)
226 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
230 static int color_config_props(AVFilterLink *inlink)
232 AVFilterContext *ctx = inlink->src;
233 TestSourceContext *test = ctx->priv;
236 ff_draw_init(&test->draw, inlink->format, 0);
237 ff_draw_color(&test->draw, &test->color, test->color_rgba);
239 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
240 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
241 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
242 return AVERROR(EINVAL);
244 if ((ret = config_props(inlink)) < 0)
247 av_log(ctx, AV_LOG_VERBOSE, "color:0x%02x%02x%02x%02x\n",
248 test->color_rgba[0], test->color_rgba[1], test->color_rgba[2], test->color_rgba[3]);
252 static const AVFilterPad color_outputs[] = {
255 .type = AVMEDIA_TYPE_VIDEO,
256 .request_frame = request_frame,
257 .config_props = color_config_props,
262 AVFilter avfilter_vsrc_color = {
264 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
266 .priv_class = &color_class,
267 .priv_size = sizeof(TestSourceContext),
271 .query_formats = color_query_formats,
273 .outputs = color_outputs,
276 #endif /* CONFIG_COLOR_FILTER */
278 #if CONFIG_NULLSRC_FILTER
280 #define nullsrc_options options
281 AVFILTER_DEFINE_CLASS(nullsrc);
283 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
285 static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args)
287 TestSourceContext *test = ctx->priv;
289 test->fill_picture_fn = nullsrc_fill_picture;
293 static const AVFilterPad nullsrc_outputs[] = {
296 .type = AVMEDIA_TYPE_VIDEO,
297 .request_frame = request_frame,
298 .config_props = config_props,
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),
309 .priv_class = &nullsrc_class,
311 .outputs = nullsrc_outputs,
314 #endif /* CONFIG_NULLSRC_FILTER */
316 #if CONFIG_TESTSRC_FILTER
318 #define testsrc_options options
319 AVFILTER_DEFINE_CLASS(testsrc);
322 * Fill a rectangle with value val.
324 * @param val the RGB value to set
325 * @param dst pointer to the destination buffer to fill
326 * @param dst_linesize linesize of destination
327 * @param segment_width width of the segment
328 * @param x horizontal coordinate where to draw the rectangle in the destination buffer
329 * @param y horizontal coordinate where to draw the rectangle in the destination buffer
330 * @param w width of the rectangle to draw, expressed as a number of segment_width units
331 * @param h height of the rectangle to draw, expressed as a number of segment_width units
333 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, unsigned segment_width,
334 unsigned x, unsigned y, unsigned w, unsigned h)
339 dst += segment_width * (step * x + y * dst_linesize);
340 w *= segment_width * step;
342 for (i = 0; i < h; i++) {
348 static void draw_digit(int digit, uint8_t *dst, unsigned dst_linesize,
349 unsigned segment_width)
354 #define LEFT_TOP_VBAR 8
355 #define LEFT_BOT_VBAR 16
356 #define RIGHT_TOP_VBAR 32
357 #define RIGHT_BOT_VBAR 64
361 { 1, 0, 5, 1 }, /* TOP_HBAR */
362 { 1, 6, 5, 1 }, /* MID_HBAR */
363 { 1, 12, 5, 1 }, /* BOT_HBAR */
364 { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
365 { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
366 { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
367 { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
369 static const unsigned char masks[10] = {
370 /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
371 /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
372 /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
373 /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
374 /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
375 /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
376 /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
377 /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
378 /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
379 /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
381 unsigned mask = masks[digit];
384 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
385 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
387 draw_rectangle(255, dst, dst_linesize, segment_width,
388 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
391 #define GRADIENT_SIZE (6 * 256)
393 static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
395 TestSourceContext *test = ctx->priv;
398 int color, color_rest;
402 int dquad_x, dquad_y;
403 int grad, dgrad, rgrad, drgrad;
407 uint8_t *data = frame->data[0];
408 int width = frame->width;
409 int height = frame->height;
411 /* draw colored bars and circle */
412 radius = (width + height) / 4;
413 quad0 = width * width / 4 + height * height / 4 - radius * radius;
414 dquad_y = 1 - height;
416 for (y = 0; y < height; y++) {
422 for (x = 0; x < width; x++) {
428 *(p++) = icolor & 1 ? 255 : 0;
429 *(p++) = icolor & 2 ? 255 : 0;
430 *(p++) = icolor & 4 ? 255 : 0;
432 if (color_rest >= width) {
439 p0 += frame->linesize[0];
442 /* draw sliding color line */
443 p0 = p = data + frame->linesize[0] * height * 3/4;
444 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
447 dgrad = GRADIENT_SIZE / width;
448 drgrad = GRADIENT_SIZE % width;
449 for (x = 0; x < width; x++) {
451 grad < 256 || grad >= 5 * 256 ? 255 :
452 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
453 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
455 grad >= 4 * 256 ? 0 :
456 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
457 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
460 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
461 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
464 if (rgrad >= GRADIENT_SIZE) {
466 rgrad -= GRADIENT_SIZE;
468 if (grad >= GRADIENT_SIZE)
469 grad -= GRADIENT_SIZE;
472 for (y = height / 8; y > 0; y--) {
473 memcpy(p+frame->linesize[0], p, 3 * width);
474 p += frame->linesize[0];
478 seg_size = width / 80;
479 if (seg_size >= 1 && height >= 13 * seg_size) {
480 int64_t p10decimals = 1;
481 double time = av_q2d(test->time_base) * test->nb_frame *
482 pow(10, test->nb_decimals);
486 for(x=0; x<test->nb_decimals; x++)
489 second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
490 x = width - (width - seg_size * 64) / 2;
491 y = (height - seg_size * 13) / 2;
492 p = data + (x*3 + y * frame->linesize[0]);
493 for (i = 0; i < 8; i++) {
494 p -= 3 * 8 * seg_size;
495 draw_digit(second % 10, p, frame->linesize[0], seg_size);
503 static av_cold int test_init(AVFilterContext *ctx, const char *args)
505 TestSourceContext *test = ctx->priv;
507 test->fill_picture_fn = test_fill_picture;
511 static int test_query_formats(AVFilterContext *ctx)
513 static const enum AVPixelFormat pix_fmts[] = {
514 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
516 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
520 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
523 .type = AVMEDIA_TYPE_VIDEO,
524 .request_frame = request_frame,
525 .config_props = config_props,
530 AVFilter avfilter_vsrc_testsrc = {
532 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
533 .priv_size = sizeof(TestSourceContext),
534 .priv_class = &testsrc_class,
538 .query_formats = test_query_formats,
541 .outputs = avfilter_vsrc_testsrc_outputs,
544 #endif /* CONFIG_TESTSRC_FILTER */
546 #if CONFIG_RGBTESTSRC_FILTER
548 #define rgbtestsrc_options options
549 AVFILTER_DEFINE_CLASS(rgbtestsrc);
556 static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
557 int x, int y, int r, int g, int b, enum AVPixelFormat fmt,
564 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
565 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
566 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
567 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
568 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
569 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
570 case AV_PIX_FMT_RGB24:
571 case AV_PIX_FMT_BGR24:
572 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
573 p = dst + 3*x + y*dst_linesize;
576 case AV_PIX_FMT_RGBA:
577 case AV_PIX_FMT_BGRA:
578 case AV_PIX_FMT_ARGB:
579 case AV_PIX_FMT_ABGR:
580 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
581 p = dst + 4*x + y*dst_linesize;
587 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
589 TestSourceContext *test = ctx->priv;
590 int x, y, w = frame->width, h = frame->height;
592 for (y = 0; y < h; y++) {
593 for (x = 0; x < w; x++) {
595 int r = 0, g = 0, b = 0;
598 else if (3*y < 2*h) g = c;
601 rgbtest_put_pixel(frame->data[0], frame->linesize[0], x, y, r, g, b,
602 ctx->outputs[0]->format, test->rgba_map);
607 static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args)
609 TestSourceContext *test = ctx->priv;
612 test->fill_picture_fn = rgbtest_fill_picture;
616 static int rgbtest_query_formats(AVFilterContext *ctx)
618 static const enum AVPixelFormat pix_fmts[] = {
619 AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
620 AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
621 AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
622 AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
623 AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
626 ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
630 static int rgbtest_config_props(AVFilterLink *outlink)
632 TestSourceContext *test = outlink->src->priv;
634 ff_fill_rgba_map(test->rgba_map, outlink->format);
635 return config_props(outlink);
638 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
641 .type = AVMEDIA_TYPE_VIDEO,
642 .request_frame = request_frame,
643 .config_props = rgbtest_config_props,
648 AVFilter avfilter_vsrc_rgbtestsrc = {
649 .name = "rgbtestsrc",
650 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
651 .priv_size = sizeof(TestSourceContext),
652 .priv_class = &rgbtestsrc_class,
653 .init = rgbtest_init,
656 .query_formats = rgbtest_query_formats,
660 .outputs = avfilter_vsrc_rgbtestsrc_outputs,
663 #endif /* CONFIG_RGBTESTSRC_FILTER */
665 #if CONFIG_SMPTEBARS_FILTER
667 #define smptebars_options options
668 AVFILTER_DEFINE_CLASS(smptebars);
670 static const uint8_t rainbow[7][4] = {
671 { 191, 191, 191, 255 }, /* gray */
672 { 191, 191, 0, 255 }, /* yellow */
673 { 0, 191, 191, 255 }, /* cyan */
674 { 0, 191, 0, 255 }, /* green */
675 { 191, 0, 191, 255 }, /* magenta */
676 { 191, 0, 0, 255 }, /* red */
677 { 0, 0, 191, 255 }, /* blue */
680 static const uint8_t wobnair[7][4] = {
681 { 0, 0, 191, 255 }, /* blue */
682 { 19, 19, 19, 255 }, /* 7.5% intensity black */
683 { 191, 0, 191, 255 }, /* magenta */
684 { 19, 19, 19, 255 }, /* 7.5% intensity black */
685 { 0, 191, 191, 255 }, /* cyan */
686 { 19, 19, 19, 255 }, /* 7.5% intensity black */
687 { 191, 191, 191, 255 }, /* gray */
690 static const uint8_t white[4] = { 255, 255, 255, 255 };
691 static const uint8_t black[4] = { 19, 19, 19, 255 }; /* 7.5% intensity black */
694 static const uint8_t neg4ire[4] = { 9, 9, 9, 255 }; /* 3.5% intensity black */
695 static const uint8_t pos4ire[4] = { 29, 29, 29, 255 }; /* 11.5% intensity black */
698 static const uint8_t i_pixel[4] = { 0, 68, 130, 255 };
699 static const uint8_t q_pixel[4] = { 67, 0, 130, 255 };
701 static void inline draw_bar(TestSourceContext *test, const uint8_t *color,
702 unsigned x, unsigned y, unsigned w, unsigned h,
705 FFDrawColor draw_color;
707 x = FFMIN(x, test->w - 1);
708 y = FFMIN(y, test->h - 1);
709 w = FFMIN(w, test->w - x);
710 h = FFMIN(h, test->h - y);
712 av_assert0(x + w <= test->w);
713 av_assert0(y + h <= test->h);
715 ff_draw_color(&test->draw, &draw_color, color);
716 ff_fill_rectangle(&test->draw, &draw_color,
717 frame->data, frame->linesize, x, y, w, h);
720 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
722 TestSourceContext *test = ctx->priv;
723 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
724 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
726 r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
727 r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
728 w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
729 p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
730 p_h = test->h - w_h - r_h;
732 for (i = 0; i < 7; i++) {
733 draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
734 draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
738 draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
740 draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
742 draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
744 tmp = FFALIGN(5 * r_w - x, 1 << pixdesc->log2_chroma_w);
745 draw_bar(test, black, x, r_h + w_h, tmp, p_h, picref);
747 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
748 draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
750 draw_bar(test, black, x, r_h + w_h, tmp, p_h, picref);
752 draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
754 draw_bar(test, black, x, r_h + w_h, test->w - x, p_h, picref);
757 static av_cold int smptebars_init(AVFilterContext *ctx, const char *args)
759 TestSourceContext *test = ctx->priv;
761 test->fill_picture_fn = smptebars_fill_picture;
766 static int smptebars_query_formats(AVFilterContext *ctx)
768 ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
772 static int smptebars_config_props(AVFilterLink *outlink)
774 AVFilterContext *ctx = outlink->src;
775 TestSourceContext *test = ctx->priv;
777 ff_draw_init(&test->draw, outlink->format, 0);
779 return config_props(outlink);
782 static const AVFilterPad smptebars_outputs[] = {
785 .type = AVMEDIA_TYPE_VIDEO,
786 .request_frame = request_frame,
787 .config_props = smptebars_config_props,
792 AVFilter avfilter_vsrc_smptebars = {
794 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
795 .priv_size = sizeof(TestSourceContext),
796 .init = smptebars_init,
799 .query_formats = smptebars_query_formats,
801 .outputs = smptebars_outputs,
802 .priv_class = &smptebars_class,
805 #endif /* CONFIG_SMPTEBARS_FILTER */