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 * allyuv, smptebars and smptehdbars are by Paul B Mahol.
38 #include "libavutil/avassert.h"
39 #include "libavutil/common.h"
40 #include "libavutil/ffmath.h"
41 #include "libavutil/opt.h"
42 #include "libavutil/imgutils.h"
43 #include "libavutil/intreadwrite.h"
44 #include "libavutil/parseutils.h"
45 #include "libavutil/xga_font_data.h"
47 #include "drawutils.h"
52 typedef struct TestSourceContext {
55 unsigned int nb_frame;
56 AVRational time_base, frame_rate;
58 int64_t duration; ///< duration expressed in microseconds
59 AVRational sar; ///< sample aspect ratio
60 int draw_once; ///< draw only the first frame, always put out the same picture
61 int draw_once_reset; ///< draw only the first frame or in case of reset
62 AVFrame *picref; ///< cached reference containing the painted picture
64 void (* fill_picture_fn)(AVFilterContext *ctx, AVFrame *frame);
66 /* only used by testsrc */
69 /* only used by color */
72 uint8_t color_rgba[4];
74 /* only used by rgbtest */
77 /* only used by haldclut */
81 #define OFFSET(x) offsetof(TestSourceContext, x)
82 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
84 #define SIZE_OPTIONS \
85 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
86 { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
88 #define COMMON_OPTIONS_NOSIZE \
89 { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
90 { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
91 { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
92 { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
93 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
95 #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
97 static const AVOption options[] = {
102 static av_cold int init(AVFilterContext *ctx)
104 TestSourceContext *test = ctx->priv;
106 test->time_base = av_inv_q(test->frame_rate);
110 av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
111 test->w, test->h, test->frame_rate.num, test->frame_rate.den,
112 test->duration < 0 ? -1 : (double)test->duration/1000000,
113 test->sar.num, test->sar.den);
117 static av_cold void uninit(AVFilterContext *ctx)
119 TestSourceContext *test = ctx->priv;
121 av_frame_free(&test->picref);
124 static int config_props(AVFilterLink *outlink)
126 TestSourceContext *test = outlink->src->priv;
128 outlink->w = test->w;
129 outlink->h = test->h;
130 outlink->sample_aspect_ratio = test->sar;
131 outlink->frame_rate = test->frame_rate;
132 outlink->time_base = test->time_base;
137 static int request_frame(AVFilterLink *outlink)
139 TestSourceContext *test = outlink->src->priv;
142 if (test->duration >= 0 &&
143 av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration)
146 if (test->draw_once) {
147 if (test->draw_once_reset) {
148 av_frame_free(&test->picref);
149 test->draw_once_reset = 0;
153 ff_get_video_buffer(outlink, test->w, test->h);
155 return AVERROR(ENOMEM);
156 test->fill_picture_fn(outlink->src, test->picref);
158 frame = av_frame_clone(test->picref);
160 frame = ff_get_video_buffer(outlink, test->w, test->h);
163 return AVERROR(ENOMEM);
164 frame->pts = test->pts;
165 frame->key_frame = 1;
166 frame->interlaced_frame = 0;
167 frame->pict_type = AV_PICTURE_TYPE_I;
168 frame->sample_aspect_ratio = test->sar;
169 if (!test->draw_once)
170 test->fill_picture_fn(outlink->src, frame);
175 return ff_filter_frame(outlink, frame);
178 #if CONFIG_COLOR_FILTER
180 static const AVOption color_options[] = {
181 { "color", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
182 { "c", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
187 AVFILTER_DEFINE_CLASS(color);
189 static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
191 TestSourceContext *test = ctx->priv;
192 ff_fill_rectangle(&test->draw, &test->color,
193 picref->data, picref->linesize,
194 0, 0, test->w, test->h);
197 static av_cold int color_init(AVFilterContext *ctx)
199 TestSourceContext *test = ctx->priv;
200 test->fill_picture_fn = color_fill_picture;
205 static int color_query_formats(AVFilterContext *ctx)
207 return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
210 static int color_config_props(AVFilterLink *inlink)
212 AVFilterContext *ctx = inlink->src;
213 TestSourceContext *test = ctx->priv;
216 ff_draw_init(&test->draw, inlink->format, 0);
217 ff_draw_color(&test->draw, &test->color, test->color_rgba);
219 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
220 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
221 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
222 return AVERROR(EINVAL);
224 if ((ret = config_props(inlink)) < 0)
230 static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
231 char *res, int res_len, int flags)
233 TestSourceContext *test = ctx->priv;
236 if (!strcmp(cmd, "color") || !strcmp(cmd, "c")) {
237 uint8_t color_rgba[4];
239 ret = av_parse_color(color_rgba, args, -1, ctx);
243 memcpy(test->color_rgba, color_rgba, sizeof(color_rgba));
244 ff_draw_color(&test->draw, &test->color, test->color_rgba);
245 test->draw_once_reset = 1;
249 return AVERROR(ENOSYS);
252 static const AVFilterPad color_outputs[] = {
255 .type = AVMEDIA_TYPE_VIDEO,
256 .request_frame = request_frame,
257 .config_props = color_config_props,
262 AVFilter ff_vsrc_color = {
264 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
265 .priv_class = &color_class,
266 .priv_size = sizeof(TestSourceContext),
269 .query_formats = color_query_formats,
271 .outputs = color_outputs,
272 .process_command = color_process_command,
275 #endif /* CONFIG_COLOR_FILTER */
277 #if CONFIG_HALDCLUTSRC_FILTER
279 static const AVOption haldclutsrc_options[] = {
280 { "level", "set level", OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 6}, 2, 8, FLAGS },
281 COMMON_OPTIONS_NOSIZE
285 AVFILTER_DEFINE_CLASS(haldclutsrc);
287 static void haldclutsrc_fill_picture(AVFilterContext *ctx, AVFrame *frame)
289 int i, j, k, x = 0, y = 0, is16bit = 0, step;
291 const TestSourceContext *hc = ctx->priv;
292 int level = hc->level;
294 const int w = frame->width;
295 const int h = frame->height;
296 const uint8_t *data = frame->data[0];
297 const int linesize = frame->linesize[0];
298 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
301 av_assert0(w == h && w == level*level*level);
303 ff_fill_rgba_map(rgba_map, frame->format);
305 switch (frame->format) {
306 case AV_PIX_FMT_RGB48:
307 case AV_PIX_FMT_BGR48:
308 case AV_PIX_FMT_RGBA64:
309 case AV_PIX_FMT_BGRA64:
313 case AV_PIX_FMT_RGBA:
314 case AV_PIX_FMT_BGRA:
315 case AV_PIX_FMT_ARGB:
316 case AV_PIX_FMT_ABGR:
321 step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
322 scale = ((float)(1 << (8*(is16bit+1))) - 1) / (level*level - 1);
324 #define LOAD_CLUT(nbits) do { \
325 uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step; \
326 dst[rgba_map[0]] = av_clip_uint##nbits(i * scale); \
327 dst[rgba_map[1]] = av_clip_uint##nbits(j * scale); \
328 dst[rgba_map[2]] = av_clip_uint##nbits(k * scale); \
330 dst[rgba_map[3]] = alpha; \
334 for (k = 0; k < level; k++) {
335 for (j = 0; j < level; j++) {
336 for (i = 0; i < level; i++) {
350 static av_cold int haldclutsrc_init(AVFilterContext *ctx)
352 TestSourceContext *hc = ctx->priv;
353 hc->fill_picture_fn = haldclutsrc_fill_picture;
358 static int haldclutsrc_query_formats(AVFilterContext *ctx)
360 static const enum AVPixelFormat pix_fmts[] = {
361 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
362 AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA,
363 AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR,
364 AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR,
365 AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0,
366 AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48,
367 AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
371 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
373 return AVERROR(ENOMEM);
374 return ff_set_common_formats(ctx, fmts_list);
377 static int haldclutsrc_config_props(AVFilterLink *outlink)
379 AVFilterContext *ctx = outlink->src;
380 TestSourceContext *hc = ctx->priv;
382 hc->w = hc->h = hc->level * hc->level * hc->level;
383 return config_props(outlink);
386 static const AVFilterPad haldclutsrc_outputs[] = {
389 .type = AVMEDIA_TYPE_VIDEO,
390 .request_frame = request_frame,
391 .config_props = haldclutsrc_config_props,
396 AVFilter ff_vsrc_haldclutsrc = {
397 .name = "haldclutsrc",
398 .description = NULL_IF_CONFIG_SMALL("Provide an identity Hald CLUT."),
399 .priv_class = &haldclutsrc_class,
400 .priv_size = sizeof(TestSourceContext),
401 .init = haldclutsrc_init,
403 .query_formats = haldclutsrc_query_formats,
405 .outputs = haldclutsrc_outputs,
407 #endif /* CONFIG_HALDCLUTSRC_FILTER */
409 #if CONFIG_NULLSRC_FILTER
411 #define nullsrc_options options
412 AVFILTER_DEFINE_CLASS(nullsrc);
414 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
416 static av_cold int nullsrc_init(AVFilterContext *ctx)
418 TestSourceContext *test = ctx->priv;
420 test->fill_picture_fn = nullsrc_fill_picture;
424 static const AVFilterPad nullsrc_outputs[] = {
427 .type = AVMEDIA_TYPE_VIDEO,
428 .request_frame = request_frame,
429 .config_props = config_props,
434 AVFilter ff_vsrc_nullsrc = {
436 .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
437 .init = nullsrc_init,
439 .priv_size = sizeof(TestSourceContext),
440 .priv_class = &nullsrc_class,
442 .outputs = nullsrc_outputs,
445 #endif /* CONFIG_NULLSRC_FILTER */
447 #if CONFIG_TESTSRC_FILTER
449 static const AVOption testsrc_options[] = {
451 { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
452 { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
456 AVFILTER_DEFINE_CLASS(testsrc);
459 * Fill a rectangle with value val.
461 * @param val the RGB value to set
462 * @param dst pointer to the destination buffer to fill
463 * @param dst_linesize linesize of destination
464 * @param segment_width width of the segment
465 * @param x horizontal coordinate where to draw the rectangle in the destination buffer
466 * @param y horizontal coordinate where to draw the rectangle in the destination buffer
467 * @param w width of the rectangle to draw, expressed as a number of segment_width units
468 * @param h height of the rectangle to draw, expressed as a number of segment_width units
470 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, int segment_width,
471 int x, int y, int w, int h)
476 dst += segment_width * (step * x + y * dst_linesize);
477 w *= segment_width * step;
479 for (i = 0; i < h; i++) {
485 static void draw_digit(int digit, uint8_t *dst, int dst_linesize,
491 #define LEFT_TOP_VBAR 8
492 #define LEFT_BOT_VBAR 16
493 #define RIGHT_TOP_VBAR 32
494 #define RIGHT_BOT_VBAR 64
498 { 1, 0, 5, 1 }, /* TOP_HBAR */
499 { 1, 6, 5, 1 }, /* MID_HBAR */
500 { 1, 12, 5, 1 }, /* BOT_HBAR */
501 { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
502 { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
503 { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
504 { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
506 static const unsigned char masks[10] = {
507 /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
508 /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
509 /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
510 /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
511 /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
512 /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
513 /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
514 /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
515 /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
516 /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
518 unsigned mask = masks[digit];
521 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
522 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
524 draw_rectangle(255, dst, dst_linesize, segment_width,
525 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
528 #define GRADIENT_SIZE (6 * 256)
530 static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
532 TestSourceContext *test = ctx->priv;
535 int color, color_rest;
539 int dquad_x, dquad_y;
540 int grad, dgrad, rgrad, drgrad;
544 uint8_t *data = frame->data[0];
545 int width = frame->width;
546 int height = frame->height;
548 /* draw colored bars and circle */
549 radius = (width + height) / 4;
550 quad0 = width * width / 4 + height * height / 4 - radius * radius;
551 dquad_y = 1 - height;
553 for (y = 0; y < height; y++) {
559 for (x = 0; x < width; x++) {
565 *(p++) = icolor & 1 ? 255 : 0;
566 *(p++) = icolor & 2 ? 255 : 0;
567 *(p++) = icolor & 4 ? 255 : 0;
569 if (color_rest >= width) {
576 p0 += frame->linesize[0];
579 /* draw sliding color line */
580 p0 = p = data + frame->linesize[0] * (height * 3/4);
581 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
584 dgrad = GRADIENT_SIZE / width;
585 drgrad = GRADIENT_SIZE % width;
586 for (x = 0; x < width; x++) {
588 grad < 256 || grad >= 5 * 256 ? 255 :
589 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
590 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
592 grad >= 4 * 256 ? 0 :
593 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
594 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
597 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
598 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
601 if (rgrad >= GRADIENT_SIZE) {
603 rgrad -= GRADIENT_SIZE;
605 if (grad >= GRADIENT_SIZE)
606 grad -= GRADIENT_SIZE;
609 for (y = height / 8; y > 0; y--) {
610 memcpy(p+frame->linesize[0], p, 3 * width);
611 p += frame->linesize[0];
615 seg_size = width / 80;
616 if (seg_size >= 1 && height >= 13 * seg_size) {
617 int64_t p10decimals = 1;
618 double time = av_q2d(test->time_base) * test->nb_frame *
619 ff_exp10(test->nb_decimals);
623 for (x = 0; x < test->nb_decimals; x++)
626 second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
627 x = width - (width - seg_size * 64) / 2;
628 y = (height - seg_size * 13) / 2;
629 p = data + (x*3 + y * frame->linesize[0]);
630 for (i = 0; i < 8; i++) {
631 p -= 3 * 8 * seg_size;
632 draw_digit(second % 10, p, frame->linesize[0], seg_size);
640 static av_cold int test_init(AVFilterContext *ctx)
642 TestSourceContext *test = ctx->priv;
644 test->fill_picture_fn = test_fill_picture;
648 static int test_query_formats(AVFilterContext *ctx)
650 static const enum AVPixelFormat pix_fmts[] = {
651 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
654 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
656 return AVERROR(ENOMEM);
657 return ff_set_common_formats(ctx, fmts_list);
660 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
663 .type = AVMEDIA_TYPE_VIDEO,
664 .request_frame = request_frame,
665 .config_props = config_props,
670 AVFilter ff_vsrc_testsrc = {
672 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
673 .priv_size = sizeof(TestSourceContext),
674 .priv_class = &testsrc_class,
677 .query_formats = test_query_formats,
679 .outputs = avfilter_vsrc_testsrc_outputs,
682 #endif /* CONFIG_TESTSRC_FILTER */
684 #if CONFIG_TESTSRC2_FILTER
686 static const AVOption testsrc2_options[] = {
691 AVFILTER_DEFINE_CLASS(testsrc2);
693 static void set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
695 uint8_t rgba[4] = { (argb >> 16) & 0xFF,
698 (argb >> 24) & 0xFF, };
699 ff_draw_color(&s->draw, color, rgba);
702 static uint32_t color_gradient(unsigned index)
704 unsigned si = index & 0xFF, sd = 0xFF - si;
705 switch (index >> 8) {
706 case 0: return 0xFF0000 + (si << 8);
707 case 1: return 0x00FF00 + (sd << 16);
708 case 2: return 0x00FF00 + (si << 0);
709 case 3: return 0x0000FF + (sd << 8);
710 case 4: return 0x0000FF + (si << 16);
711 case 5: return 0xFF0000 + (sd << 0);
716 static void draw_text(TestSourceContext *s, AVFrame *frame, FFDrawColor *color,
717 int x0, int y0, const uint8_t *text)
721 for (; *text; text++) {
727 ff_blend_mask(&s->draw, color, frame->data, frame->linesize,
728 frame->width, frame->height,
729 avpriv_vga16_font + *text * 16, 1, 8, 16, 0, 0, x, y0);
734 static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame)
736 TestSourceContext *s = ctx->priv;
739 /* colored background */
741 unsigned i, x = 0, x2;
744 for (i = 1; i < 7; i++) {
745 x2 = av_rescale(i, s->w, 6);
746 x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2);
747 set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) |
748 ((i & 2) ? 0x00FF00 : 0) |
749 ((i & 4) ? 0x0000FF : 0));
750 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
751 x, 0, x2 - x, frame->height);
756 /* oblique gradient */
757 /* note: too slow if using blending */
759 unsigned x, dx, y0, y, g0, g;
761 dx = ff_draw_round_to_sub(&s->draw, 0, +1, 1);
762 y0 = av_rescale_q(s->pts, s->time_base, av_make_q(2, s->h - 16));
763 g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128));
764 for (x = 0; x < s->w; x += dx) {
765 g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256);
766 set_color(s, &color, color_gradient(g));
767 y = y0 + av_rescale(x, s->h / 2, s->w);
768 y %= 2 * (s->h - 16);
770 y = 2 * (s->h - 16) - y;
771 y = ff_draw_round_to_sub(&s->draw, 1, 0, y);
772 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
777 /* top right: draw clock hands */
778 if (s->w >= 64 && s->h >= 64) {
779 int l = (FFMIN(s->w, s->h) - 32) >> 1;
780 int steps = FFMAX(4, l >> 5);
781 int xc = (s->w >> 2) + (s->w >> 1);
782 int yc = (s->h >> 2);
787 for (c = 0; c < 3; c++) {
788 set_color(s, &color, 0xBBBBBB ^ (0xFF << (c << 3)));
789 pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle;
790 xh = pos < 1 * l ? pos :
792 pos < 3 * l ? 3 * l - pos : 0;
793 yh = pos < 1 * l ? 0 :
794 pos < 2 * l ? pos - l :
799 for (i = 1; i <= steps; i++) {
800 int x = av_rescale(xh, i, steps) + xc;
801 int y = av_rescale(yh, i, steps) + yc;
802 x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
803 y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
804 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
810 /* bottom left: beating rectangles */
811 if (s->w >= 64 && s->h >= 64) {
812 int l = (FFMIN(s->w, s->h) - 16) >> 2;
814 int xc = (s->w >> 2);
815 int yc = (s->h >> 2) + (s->h >> 1);
816 int xm1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 8);
817 int xm2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 8);
818 int ym1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 8);
819 int ym2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 8);
820 int size, step, x1, x2, y1, y2;
822 size = av_rescale_q(s->pts, s->time_base, av_make_q(4, cycle));
827 step = (step >> 1) & 3;
828 set_color(s, &color, 0xFF808080);
829 x1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 4 - size);
830 x2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 4 + size);
831 y1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 4 - size);
832 y2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 4 + size);
833 if (step == 0 || step == 2)
834 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
835 x1, ym1, x2 - x1, ym2 - ym1);
836 if (step == 1 || step == 2)
837 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
838 xm1, y1, xm2 - xm1, y2 - y1);
840 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
841 x1, y1, x2 - x1, y2 - y1);
844 /* bottom right: checker with random noise */
846 unsigned xmin = av_rescale(5, s->w, 8);
847 unsigned xmax = av_rescale(7, s->w, 8);
848 unsigned ymin = av_rescale(5, s->h, 8);
849 unsigned ymax = av_rescale(7, s->h, 8);
854 for (y = ymin; y < ymax - 15; y += 16) {
855 for (x = xmin; x < xmax - 15; x += 16) {
858 for (i = 0; i < 256; i++) {
859 r = r * 1664525 + 1013904223;
862 set_color(s, &color, 0xFF00FF80);
863 ff_blend_mask(&s->draw, &color, frame->data, frame->linesize,
864 frame->width, frame->height,
865 alpha, 16, 16, 16, 3, 0, x, y);
870 /* bouncing square */
871 if (s->w >= 16 && s->h >= 16) {
872 unsigned w = s->w - 8;
873 unsigned h = s->h - 8;
874 unsigned x = av_rescale_q(s->pts, s->time_base, av_make_q(233, 55 * w)) % (w << 1);
875 unsigned y = av_rescale_q(s->pts, s->time_base, av_make_q(233, 89 * h)) % (h << 1);
880 x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
881 y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
882 set_color(s, &color, 0xFF8000FF);
883 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
887 /* top right: draw frame time and frame number */
892 time = av_rescale_q(s->pts, s->time_base, av_make_q(1, 1000)) % 86400000;
893 set_color(s, &color, 0xC0000000);
894 ff_blend_rectangle(&s->draw, &color, frame->data, frame->linesize,
895 frame->width, frame->height,
897 set_color(s, &color, 0xFFFF8000);
898 snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%03d\n%12"PRIi64,
899 time / 3600000, (time / 60000) % 60, (time / 1000) % 60,
900 time % 1000, s->pts);
901 draw_text(s, frame, &color, 4, 4, buf);
904 static av_cold int test2_init(AVFilterContext *ctx)
906 TestSourceContext *s = ctx->priv;
908 s->fill_picture_fn = test2_fill_picture;
912 static int test2_query_formats(AVFilterContext *ctx)
914 return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
917 static int test2_config_props(AVFilterLink *inlink)
919 AVFilterContext *ctx = inlink->src;
920 TestSourceContext *s = ctx->priv;
922 av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0);
923 s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
924 s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
925 if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
926 return AVERROR(EINVAL);
927 return config_props(inlink);
930 static const AVFilterPad avfilter_vsrc_testsrc2_outputs[] = {
933 .type = AVMEDIA_TYPE_VIDEO,
934 .request_frame = request_frame,
935 .config_props = test2_config_props,
940 AVFilter ff_vsrc_testsrc2 = {
942 .description = NULL_IF_CONFIG_SMALL("Generate another test pattern."),
943 .priv_size = sizeof(TestSourceContext),
944 .priv_class = &testsrc2_class,
947 .query_formats = test2_query_formats,
949 .outputs = avfilter_vsrc_testsrc2_outputs,
952 #endif /* CONFIG_TESTSRC2_FILTER */
954 #if CONFIG_RGBTESTSRC_FILTER
956 #define rgbtestsrc_options options
957 AVFILTER_DEFINE_CLASS(rgbtestsrc);
964 static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
965 int x, int y, int r, int g, int b, enum AVPixelFormat fmt,
972 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
973 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
974 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
975 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
976 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
977 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
978 case AV_PIX_FMT_RGB24:
979 case AV_PIX_FMT_BGR24:
980 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
981 p = dst + 3*x + y*dst_linesize;
984 case AV_PIX_FMT_RGBA:
985 case AV_PIX_FMT_BGRA:
986 case AV_PIX_FMT_ARGB:
987 case AV_PIX_FMT_ABGR:
988 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
989 p = dst + 4*x + y*dst_linesize;
995 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
997 TestSourceContext *test = ctx->priv;
998 int x, y, w = frame->width, h = frame->height;
1000 for (y = 0; y < h; y++) {
1001 for (x = 0; x < w; x++) {
1003 int r = 0, g = 0, b = 0;
1005 if (3*y < h ) r = c;
1006 else if (3*y < 2*h) g = c;
1009 rgbtest_put_pixel(frame->data[0], frame->linesize[0], x, y, r, g, b,
1010 ctx->outputs[0]->format, test->rgba_map);
1015 static av_cold int rgbtest_init(AVFilterContext *ctx)
1017 TestSourceContext *test = ctx->priv;
1019 test->draw_once = 1;
1020 test->fill_picture_fn = rgbtest_fill_picture;
1024 static int rgbtest_query_formats(AVFilterContext *ctx)
1026 static const enum AVPixelFormat pix_fmts[] = {
1027 AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
1028 AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
1029 AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
1030 AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
1031 AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
1035 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1037 return AVERROR(ENOMEM);
1038 return ff_set_common_formats(ctx, fmts_list);
1041 static int rgbtest_config_props(AVFilterLink *outlink)
1043 TestSourceContext *test = outlink->src->priv;
1045 ff_fill_rgba_map(test->rgba_map, outlink->format);
1046 return config_props(outlink);
1049 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
1052 .type = AVMEDIA_TYPE_VIDEO,
1053 .request_frame = request_frame,
1054 .config_props = rgbtest_config_props,
1059 AVFilter ff_vsrc_rgbtestsrc = {
1060 .name = "rgbtestsrc",
1061 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
1062 .priv_size = sizeof(TestSourceContext),
1063 .priv_class = &rgbtestsrc_class,
1064 .init = rgbtest_init,
1066 .query_formats = rgbtest_query_formats,
1068 .outputs = avfilter_vsrc_rgbtestsrc_outputs,
1071 #endif /* CONFIG_RGBTESTSRC_FILTER */
1073 #if CONFIG_YUVTESTSRC_FILTER
1075 #define yuvtestsrc_options options
1076 AVFILTER_DEFINE_CLASS(yuvtestsrc);
1078 static void yuvtest_fill_picture8(AVFilterContext *ctx, AVFrame *frame)
1080 int x, y, w = frame->width, h = frame->height / 3;
1081 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1082 const int factor = 1 << desc->comp[0].depth;
1083 const int mid = 1 << (desc->comp[0].depth - 1);
1084 uint8_t *ydst = frame->data[0];
1085 uint8_t *udst = frame->data[1];
1086 uint8_t *vdst = frame->data[2];
1087 int ylinesize = frame->linesize[0];
1088 int ulinesize = frame->linesize[1];
1089 int vlinesize = frame->linesize[2];
1091 for (y = 0; y < h; y++) {
1092 for (x = 0; x < w; x++) {
1093 int c = factor * x / w;
1106 for (; y < h; y++) {
1107 for (x = 0; x < w; x++) {
1108 int c = factor * x / w;
1120 for (; y < frame->height; y++) {
1121 for (x = 0; x < w; x++) {
1122 int c = factor * x / w;
1135 static void yuvtest_fill_picture16(AVFilterContext *ctx, AVFrame *frame)
1137 int x, y, w = frame->width, h = frame->height / 3;
1138 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1139 const int factor = 1 << desc->comp[0].depth;
1140 const int mid = 1 << (desc->comp[0].depth - 1);
1141 uint16_t *ydst = (uint16_t *)frame->data[0];
1142 uint16_t *udst = (uint16_t *)frame->data[1];
1143 uint16_t *vdst = (uint16_t *)frame->data[2];
1144 int ylinesize = frame->linesize[0] / 2;
1145 int ulinesize = frame->linesize[1] / 2;
1146 int vlinesize = frame->linesize[2] / 2;
1148 for (y = 0; y < h; y++) {
1149 for (x = 0; x < w; x++) {
1150 int c = factor * x / w;
1163 for (; y < h; y++) {
1164 for (x = 0; x < w; x++) {
1165 int c = factor * x / w;
1177 for (; y < frame->height; y++) {
1178 for (x = 0; x < w; x++) {
1179 int c = factor * x / w;
1192 static av_cold int yuvtest_init(AVFilterContext *ctx)
1194 TestSourceContext *test = ctx->priv;
1196 test->draw_once = 1;
1200 static int yuvtest_query_formats(AVFilterContext *ctx)
1202 static const enum AVPixelFormat pix_fmts[] = {
1203 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
1204 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
1205 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14,
1206 AV_PIX_FMT_YUV444P16,
1210 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1212 return AVERROR(ENOMEM);
1213 return ff_set_common_formats(ctx, fmts_list);
1216 static int yuvtest_config_props(AVFilterLink *outlink)
1218 TestSourceContext *test = outlink->src->priv;
1219 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
1221 test->fill_picture_fn = desc->comp[0].depth > 8 ? yuvtest_fill_picture16 : yuvtest_fill_picture8;
1222 return config_props(outlink);
1225 static const AVFilterPad avfilter_vsrc_yuvtestsrc_outputs[] = {
1228 .type = AVMEDIA_TYPE_VIDEO,
1229 .request_frame = request_frame,
1230 .config_props = yuvtest_config_props,
1235 AVFilter ff_vsrc_yuvtestsrc = {
1236 .name = "yuvtestsrc",
1237 .description = NULL_IF_CONFIG_SMALL("Generate YUV test pattern."),
1238 .priv_size = sizeof(TestSourceContext),
1239 .priv_class = &yuvtestsrc_class,
1240 .init = yuvtest_init,
1242 .query_formats = yuvtest_query_formats,
1244 .outputs = avfilter_vsrc_yuvtestsrc_outputs,
1247 #endif /* CONFIG_YUVTESTSRC_FILTER */
1249 #if CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
1251 static const uint8_t rainbow[7][4] = {
1252 { 180, 128, 128, 255 }, /* 75% white */
1253 { 162, 44, 142, 255 }, /* 75% yellow */
1254 { 131, 156, 44, 255 }, /* 75% cyan */
1255 { 112, 72, 58, 255 }, /* 75% green */
1256 { 84, 184, 198, 255 }, /* 75% magenta */
1257 { 65, 100, 212, 255 }, /* 75% red */
1258 { 35, 212, 114, 255 }, /* 75% blue */
1261 static const uint8_t rainbowhd[7][4] = {
1262 { 180, 128, 128, 255 }, /* 75% white */
1263 { 168, 44, 136, 255 }, /* 75% yellow */
1264 { 145, 147, 44, 255 }, /* 75% cyan */
1265 { 133, 63, 52, 255 }, /* 75% green */
1266 { 63, 193, 204, 255 }, /* 75% magenta */
1267 { 51, 109, 212, 255 }, /* 75% red */
1268 { 28, 212, 120, 255 }, /* 75% blue */
1271 static const uint8_t wobnair[7][4] = {
1272 { 35, 212, 114, 255 }, /* 75% blue */
1273 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1274 { 84, 184, 198, 255 }, /* 75% magenta */
1275 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1276 { 131, 156, 44, 255 }, /* 75% cyan */
1277 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1278 { 180, 128, 128, 255 }, /* 75% white */
1281 static const uint8_t white[4] = { 235, 128, 128, 255 };
1284 static const uint8_t neg4ire[4] = { 7, 128, 128, 255 };
1285 static const uint8_t pos4ire[4] = { 24, 128, 128, 255 };
1288 static const uint8_t i_pixel[4] = { 57, 156, 97, 255 };
1289 static const uint8_t q_pixel[4] = { 44, 171, 147, 255 };
1291 static const uint8_t gray40[4] = { 104, 128, 128, 255 };
1292 static const uint8_t gray15[4] = { 49, 128, 128, 255 };
1293 static const uint8_t cyan[4] = { 188, 154, 16, 255 };
1294 static const uint8_t yellow[4] = { 219, 16, 138, 255 };
1295 static const uint8_t blue[4] = { 32, 240, 118, 255 };
1296 static const uint8_t red[4] = { 63, 102, 240, 255 };
1297 static const uint8_t black0[4] = { 16, 128, 128, 255 };
1298 static const uint8_t black2[4] = { 20, 128, 128, 255 };
1299 static const uint8_t black4[4] = { 25, 128, 128, 255 };
1300 static const uint8_t neg2[4] = { 12, 128, 128, 255 };
1302 static void draw_bar(TestSourceContext *test, const uint8_t color[4],
1303 int x, int y, int w, int h,
1306 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1310 x = FFMIN(x, test->w - 1);
1311 y = FFMIN(y, test->h - 1);
1312 w = FFMAX(FFMIN(w, test->w - x), 0);
1313 h = FFMAX(FFMIN(h, test->h - y), 0);
1315 av_assert0(x + w <= test->w);
1316 av_assert0(y + h <= test->h);
1318 for (plane = 0; frame->data[plane]; plane++) {
1319 const int c = color[plane];
1320 const int linesize = frame->linesize[plane];
1321 int i, px, py, pw, ph;
1323 if (plane == 1 || plane == 2) {
1324 px = x >> desc->log2_chroma_w;
1325 pw = AV_CEIL_RSHIFT(w, desc->log2_chroma_w);
1326 py = y >> desc->log2_chroma_h;
1327 ph = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
1335 p0 = p = frame->data[plane] + py * linesize + px;
1338 for (i = 1; i < ph; i++, p += linesize)
1343 static int smptebars_query_formats(AVFilterContext *ctx)
1345 static const enum AVPixelFormat pix_fmts[] = {
1346 AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
1347 AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
1348 AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
1352 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1354 return AVERROR(ENOMEM);
1355 return ff_set_common_formats(ctx, fmts_list);
1358 static const AVFilterPad smptebars_outputs[] = {
1361 .type = AVMEDIA_TYPE_VIDEO,
1362 .request_frame = request_frame,
1363 .config_props = config_props,
1368 #if CONFIG_SMPTEBARS_FILTER
1370 #define smptebars_options options
1371 AVFILTER_DEFINE_CLASS(smptebars);
1373 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1375 TestSourceContext *test = ctx->priv;
1376 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
1377 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1379 picref->colorspace = AVCOL_SPC_BT470BG;
1381 r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
1382 r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
1383 w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
1384 p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
1385 p_h = test->h - w_h - r_h;
1387 for (i = 0; i < 7; i++) {
1388 draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
1389 draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
1393 draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
1395 draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
1397 draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
1399 tmp = FFALIGN(5 * r_w - x, 1 << pixdesc->log2_chroma_w);
1400 draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1402 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1403 draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
1405 draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1407 draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
1409 draw_bar(test, black0, x, r_h + w_h, test->w - x, p_h, picref);
1412 static av_cold int smptebars_init(AVFilterContext *ctx)
1414 TestSourceContext *test = ctx->priv;
1416 test->fill_picture_fn = smptebars_fill_picture;
1417 test->draw_once = 1;
1421 AVFilter ff_vsrc_smptebars = {
1422 .name = "smptebars",
1423 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
1424 .priv_size = sizeof(TestSourceContext),
1425 .priv_class = &smptebars_class,
1426 .init = smptebars_init,
1428 .query_formats = smptebars_query_formats,
1430 .outputs = smptebars_outputs,
1433 #endif /* CONFIG_SMPTEBARS_FILTER */
1435 #if CONFIG_SMPTEHDBARS_FILTER
1437 #define smptehdbars_options options
1438 AVFILTER_DEFINE_CLASS(smptehdbars);
1440 static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1442 TestSourceContext *test = ctx->priv;
1443 int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
1444 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1446 picref->colorspace = AVCOL_SPC_BT709;
1448 d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
1449 r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
1450 draw_bar(test, gray40, x, 0, d_w, r_h, picref);
1453 r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
1454 for (i = 0; i < 7; i++) {
1455 draw_bar(test, rainbowhd[i], x, 0, r_w, r_h, picref);
1458 draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
1460 r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
1461 draw_bar(test, cyan, 0, y, d_w, r_h, picref);
1463 draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
1466 draw_bar(test, rainbowhd[0], x, y, tmp, r_h, picref);
1469 draw_bar(test, blue, x, y, test->w - x, r_h, picref);
1471 draw_bar(test, yellow, 0, y, d_w, r_h, picref);
1473 draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
1476 for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
1477 uint8_t yramp[4] = {0};
1479 yramp[0] = i * 255 / tmp;
1484 draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
1485 x += 1 << pixdesc->log2_chroma_w;
1487 draw_bar(test, red, x, y, test->w - x, r_h, picref);
1489 draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
1491 tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
1492 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1494 tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
1495 draw_bar(test, white, x, y, tmp, test->h - y, picref);
1497 tmp = FFALIGN(r_w * 5 / 6, 1 << pixdesc->log2_chroma_w);
1498 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1500 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1501 draw_bar(test, neg2, x, y, tmp, test->h - y, picref);
1503 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1505 draw_bar(test, black2, x, y, tmp, test->h - y, picref);
1507 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1509 draw_bar(test, black4, x, y, tmp, test->h - y, picref);
1512 draw_bar(test, black0, x, y, r_w, test->h - y, picref);
1514 draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
1517 static av_cold int smptehdbars_init(AVFilterContext *ctx)
1519 TestSourceContext *test = ctx->priv;
1521 test->fill_picture_fn = smptehdbars_fill_picture;
1522 test->draw_once = 1;
1526 AVFilter ff_vsrc_smptehdbars = {
1527 .name = "smptehdbars",
1528 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
1529 .priv_size = sizeof(TestSourceContext),
1530 .priv_class = &smptehdbars_class,
1531 .init = smptehdbars_init,
1533 .query_formats = smptebars_query_formats,
1535 .outputs = smptebars_outputs,
1538 #endif /* CONFIG_SMPTEHDBARS_FILTER */
1539 #endif /* CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */
1541 #if CONFIG_ALLYUV_FILTER
1543 static const AVOption allyuv_options[] = {
1544 COMMON_OPTIONS_NOSIZE
1548 AVFILTER_DEFINE_CLASS(allyuv);
1550 static void allyuv_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1552 const int ys = frame->linesize[0];
1553 const int us = frame->linesize[1];
1554 const int vs = frame->linesize[2];
1557 for (y = 0; y < 4096; y++) {
1558 for (x = 0; x < 2048; x++) {
1559 frame->data[0][y * ys + x] = ((x / 8) % 256);
1560 frame->data[0][y * ys + 4095 - x] = ((x / 8) % 256);
1563 for (x = 0; x < 2048; x+=8) {
1564 for (j = 0; j < 8; j++) {
1565 frame->data[1][vs * y + x + j] = (y%16 + (j % 8) * 16);
1566 frame->data[1][vs * y + 4095 - x - j] = (128 + y%16 + (j % 8) * 16);
1570 for (x = 0; x < 4096; x++)
1571 frame->data[2][y * us + x] = 256 * y / 4096;
1575 static av_cold int allyuv_init(AVFilterContext *ctx)
1577 TestSourceContext *test = ctx->priv;
1579 test->w = test->h = 4096;
1580 test->draw_once = 1;
1581 test->fill_picture_fn = allyuv_fill_picture;
1585 static int allyuv_query_formats(AVFilterContext *ctx)
1587 static const enum AVPixelFormat pix_fmts[] = {
1588 AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP,
1592 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1594 return AVERROR(ENOMEM);
1595 return ff_set_common_formats(ctx, fmts_list);
1598 static const AVFilterPad avfilter_vsrc_allyuv_outputs[] = {
1601 .type = AVMEDIA_TYPE_VIDEO,
1602 .request_frame = request_frame,
1603 .config_props = config_props,
1608 AVFilter ff_vsrc_allyuv = {
1610 .description = NULL_IF_CONFIG_SMALL("Generate all yuv colors."),
1611 .priv_size = sizeof(TestSourceContext),
1612 .priv_class = &allyuv_class,
1613 .init = allyuv_init,
1615 .query_formats = allyuv_query_formats,
1617 .outputs = avfilter_vsrc_allyuv_outputs,
1620 #endif /* CONFIG_ALLYUV_FILTER */
1622 #if CONFIG_ALLRGB_FILTER
1624 static const AVOption allrgb_options[] = {
1625 COMMON_OPTIONS_NOSIZE
1629 AVFILTER_DEFINE_CLASS(allrgb);
1631 static void allrgb_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1634 const int linesize = frame->linesize[0];
1635 uint8_t *line = frame->data[0];
1637 for (y = 0; y < 4096; y++) {
1638 uint8_t *dst = line;
1640 for (x = 0; x < 4096; x++) {
1643 *dst++ = (x >> 8) | ((y >> 8) << 4);
1649 static av_cold int allrgb_init(AVFilterContext *ctx)
1651 TestSourceContext *test = ctx->priv;
1653 test->w = test->h = 4096;
1654 test->draw_once = 1;
1655 test->fill_picture_fn = allrgb_fill_picture;
1659 static int allrgb_config_props(AVFilterLink *outlink)
1661 TestSourceContext *test = outlink->src->priv;
1663 ff_fill_rgba_map(test->rgba_map, outlink->format);
1664 return config_props(outlink);
1667 static int allrgb_query_formats(AVFilterContext *ctx)
1669 static const enum AVPixelFormat pix_fmts[] = {
1670 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
1673 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1675 return AVERROR(ENOMEM);
1676 return ff_set_common_formats(ctx, fmts_list);
1679 static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
1682 .type = AVMEDIA_TYPE_VIDEO,
1683 .request_frame = request_frame,
1684 .config_props = allrgb_config_props,
1689 AVFilter ff_vsrc_allrgb = {
1691 .description = NULL_IF_CONFIG_SMALL("Generate all RGB colors."),
1692 .priv_size = sizeof(TestSourceContext),
1693 .priv_class = &allrgb_class,
1694 .init = allrgb_init,
1696 .query_formats = allrgb_query_formats,
1698 .outputs = avfilter_vsrc_allrgb_outputs,
1701 #endif /* CONFIG_ALLRGB_FILTER */