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 testsrc2 */
72 /* only used by color */
75 uint8_t color_rgba[4];
77 /* only used by rgbtest */
80 /* only used by haldclut */
84 #define OFFSET(x) offsetof(TestSourceContext, x)
85 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
87 #define SIZE_OPTIONS \
88 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
89 { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
91 #define COMMON_OPTIONS_NOSIZE \
92 { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
93 { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
94 { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
95 { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
96 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
98 #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
100 static const AVOption options[] = {
105 static av_cold int init(AVFilterContext *ctx)
107 TestSourceContext *test = ctx->priv;
109 test->time_base = av_inv_q(test->frame_rate);
113 av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
114 test->w, test->h, test->frame_rate.num, test->frame_rate.den,
115 test->duration < 0 ? -1 : (double)test->duration/1000000,
116 test->sar.num, test->sar.den);
120 static av_cold void uninit(AVFilterContext *ctx)
122 TestSourceContext *test = ctx->priv;
124 av_frame_free(&test->picref);
127 static int config_props(AVFilterLink *outlink)
129 TestSourceContext *test = outlink->src->priv;
131 outlink->w = test->w;
132 outlink->h = test->h;
133 outlink->sample_aspect_ratio = test->sar;
134 outlink->frame_rate = test->frame_rate;
135 outlink->time_base = test->time_base;
140 static int request_frame(AVFilterLink *outlink)
142 TestSourceContext *test = outlink->src->priv;
145 if (test->duration >= 0 &&
146 av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration)
149 if (test->draw_once) {
150 if (test->draw_once_reset) {
151 av_frame_free(&test->picref);
152 test->draw_once_reset = 0;
156 ff_get_video_buffer(outlink, test->w, test->h);
158 return AVERROR(ENOMEM);
159 test->fill_picture_fn(outlink->src, test->picref);
161 frame = av_frame_clone(test->picref);
163 frame = ff_get_video_buffer(outlink, test->w, test->h);
166 return AVERROR(ENOMEM);
167 frame->pts = test->pts;
168 frame->key_frame = 1;
169 frame->interlaced_frame = 0;
170 frame->pict_type = AV_PICTURE_TYPE_I;
171 frame->sample_aspect_ratio = test->sar;
172 if (!test->draw_once)
173 test->fill_picture_fn(outlink->src, frame);
178 return ff_filter_frame(outlink, frame);
181 #if CONFIG_COLOR_FILTER
183 static const AVOption color_options[] = {
184 { "color", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
185 { "c", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
190 AVFILTER_DEFINE_CLASS(color);
192 static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
194 TestSourceContext *test = ctx->priv;
195 ff_fill_rectangle(&test->draw, &test->color,
196 picref->data, picref->linesize,
197 0, 0, test->w, test->h);
200 static av_cold int color_init(AVFilterContext *ctx)
202 TestSourceContext *test = ctx->priv;
203 test->fill_picture_fn = color_fill_picture;
208 static int color_query_formats(AVFilterContext *ctx)
210 return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
213 static int color_config_props(AVFilterLink *inlink)
215 AVFilterContext *ctx = inlink->src;
216 TestSourceContext *test = ctx->priv;
219 ff_draw_init(&test->draw, inlink->format, 0);
220 ff_draw_color(&test->draw, &test->color, test->color_rgba);
222 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
223 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
224 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
225 return AVERROR(EINVAL);
227 if ((ret = config_props(inlink)) < 0)
233 static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
234 char *res, int res_len, int flags)
236 TestSourceContext *test = ctx->priv;
239 if (!strcmp(cmd, "color") || !strcmp(cmd, "c")) {
240 uint8_t color_rgba[4];
242 ret = av_parse_color(color_rgba, args, -1, ctx);
246 memcpy(test->color_rgba, color_rgba, sizeof(color_rgba));
247 ff_draw_color(&test->draw, &test->color, test->color_rgba);
248 test->draw_once_reset = 1;
252 return AVERROR(ENOSYS);
255 static const AVFilterPad color_outputs[] = {
258 .type = AVMEDIA_TYPE_VIDEO,
259 .request_frame = request_frame,
260 .config_props = color_config_props,
265 AVFilter ff_vsrc_color = {
267 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
268 .priv_class = &color_class,
269 .priv_size = sizeof(TestSourceContext),
272 .query_formats = color_query_formats,
274 .outputs = color_outputs,
275 .process_command = color_process_command,
278 #endif /* CONFIG_COLOR_FILTER */
280 #if CONFIG_HALDCLUTSRC_FILTER
282 static const AVOption haldclutsrc_options[] = {
283 { "level", "set level", OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 6}, 2, 8, FLAGS },
284 COMMON_OPTIONS_NOSIZE
288 AVFILTER_DEFINE_CLASS(haldclutsrc);
290 static void haldclutsrc_fill_picture(AVFilterContext *ctx, AVFrame *frame)
292 int i, j, k, x = 0, y = 0, is16bit = 0, step;
294 const TestSourceContext *hc = ctx->priv;
295 int level = hc->level;
297 const int w = frame->width;
298 const int h = frame->height;
299 const uint8_t *data = frame->data[0];
300 const int linesize = frame->linesize[0];
301 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
304 av_assert0(w == h && w == level*level*level);
306 ff_fill_rgba_map(rgba_map, frame->format);
308 switch (frame->format) {
309 case AV_PIX_FMT_RGB48:
310 case AV_PIX_FMT_BGR48:
311 case AV_PIX_FMT_RGBA64:
312 case AV_PIX_FMT_BGRA64:
316 case AV_PIX_FMT_RGBA:
317 case AV_PIX_FMT_BGRA:
318 case AV_PIX_FMT_ARGB:
319 case AV_PIX_FMT_ABGR:
324 step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
325 scale = ((float)(1 << (8*(is16bit+1))) - 1) / (level*level - 1);
327 #define LOAD_CLUT(nbits) do { \
328 uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step; \
329 dst[rgba_map[0]] = av_clip_uint##nbits(i * scale); \
330 dst[rgba_map[1]] = av_clip_uint##nbits(j * scale); \
331 dst[rgba_map[2]] = av_clip_uint##nbits(k * scale); \
333 dst[rgba_map[3]] = alpha; \
337 for (k = 0; k < level; k++) {
338 for (j = 0; j < level; j++) {
339 for (i = 0; i < level; i++) {
353 static av_cold int haldclutsrc_init(AVFilterContext *ctx)
355 TestSourceContext *hc = ctx->priv;
356 hc->fill_picture_fn = haldclutsrc_fill_picture;
361 static int haldclutsrc_query_formats(AVFilterContext *ctx)
363 static const enum AVPixelFormat pix_fmts[] = {
364 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
365 AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA,
366 AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR,
367 AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR,
368 AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0,
369 AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48,
370 AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
374 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
376 return AVERROR(ENOMEM);
377 return ff_set_common_formats(ctx, fmts_list);
380 static int haldclutsrc_config_props(AVFilterLink *outlink)
382 AVFilterContext *ctx = outlink->src;
383 TestSourceContext *hc = ctx->priv;
385 hc->w = hc->h = hc->level * hc->level * hc->level;
386 return config_props(outlink);
389 static const AVFilterPad haldclutsrc_outputs[] = {
392 .type = AVMEDIA_TYPE_VIDEO,
393 .request_frame = request_frame,
394 .config_props = haldclutsrc_config_props,
399 AVFilter ff_vsrc_haldclutsrc = {
400 .name = "haldclutsrc",
401 .description = NULL_IF_CONFIG_SMALL("Provide an identity Hald CLUT."),
402 .priv_class = &haldclutsrc_class,
403 .priv_size = sizeof(TestSourceContext),
404 .init = haldclutsrc_init,
406 .query_formats = haldclutsrc_query_formats,
408 .outputs = haldclutsrc_outputs,
410 #endif /* CONFIG_HALDCLUTSRC_FILTER */
412 #if CONFIG_NULLSRC_FILTER
414 #define nullsrc_options options
415 AVFILTER_DEFINE_CLASS(nullsrc);
417 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
419 static av_cold int nullsrc_init(AVFilterContext *ctx)
421 TestSourceContext *test = ctx->priv;
423 test->fill_picture_fn = nullsrc_fill_picture;
427 static const AVFilterPad nullsrc_outputs[] = {
430 .type = AVMEDIA_TYPE_VIDEO,
431 .request_frame = request_frame,
432 .config_props = config_props,
437 AVFilter ff_vsrc_nullsrc = {
439 .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
440 .init = nullsrc_init,
442 .priv_size = sizeof(TestSourceContext),
443 .priv_class = &nullsrc_class,
445 .outputs = nullsrc_outputs,
448 #endif /* CONFIG_NULLSRC_FILTER */
450 #if CONFIG_TESTSRC_FILTER
452 static const AVOption testsrc_options[] = {
454 { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
455 { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
459 AVFILTER_DEFINE_CLASS(testsrc);
462 * Fill a rectangle with value val.
464 * @param val the RGB value to set
465 * @param dst pointer to the destination buffer to fill
466 * @param dst_linesize linesize of destination
467 * @param segment_width width of the segment
468 * @param x horizontal coordinate where to draw the rectangle in the destination buffer
469 * @param y horizontal coordinate where to draw the rectangle in the destination buffer
470 * @param w width of the rectangle to draw, expressed as a number of segment_width units
471 * @param h height of the rectangle to draw, expressed as a number of segment_width units
473 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, int segment_width,
474 int x, int y, int w, int h)
479 dst += segment_width * (step * x + y * dst_linesize);
480 w *= segment_width * step;
482 for (i = 0; i < h; i++) {
488 static void draw_digit(int digit, uint8_t *dst, int dst_linesize,
494 #define LEFT_TOP_VBAR 8
495 #define LEFT_BOT_VBAR 16
496 #define RIGHT_TOP_VBAR 32
497 #define RIGHT_BOT_VBAR 64
501 { 1, 0, 5, 1 }, /* TOP_HBAR */
502 { 1, 6, 5, 1 }, /* MID_HBAR */
503 { 1, 12, 5, 1 }, /* BOT_HBAR */
504 { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
505 { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
506 { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
507 { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
509 static const unsigned char masks[10] = {
510 /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
511 /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
512 /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
513 /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
514 /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
515 /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
516 /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
517 /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
518 /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
519 /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
521 unsigned mask = masks[digit];
524 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
525 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
527 draw_rectangle(255, dst, dst_linesize, segment_width,
528 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
531 #define GRADIENT_SIZE (6 * 256)
533 static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
535 TestSourceContext *test = ctx->priv;
538 int color, color_rest;
542 int dquad_x, dquad_y;
543 int grad, dgrad, rgrad, drgrad;
547 uint8_t *data = frame->data[0];
548 int width = frame->width;
549 int height = frame->height;
551 /* draw colored bars and circle */
552 radius = (width + height) / 4;
553 quad0 = width * width / 4 + height * height / 4 - radius * radius;
554 dquad_y = 1 - height;
556 for (y = 0; y < height; y++) {
562 for (x = 0; x < width; x++) {
568 *(p++) = icolor & 1 ? 255 : 0;
569 *(p++) = icolor & 2 ? 255 : 0;
570 *(p++) = icolor & 4 ? 255 : 0;
572 if (color_rest >= width) {
579 p0 += frame->linesize[0];
582 /* draw sliding color line */
583 p0 = p = data + frame->linesize[0] * (height * 3/4);
584 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
587 dgrad = GRADIENT_SIZE / width;
588 drgrad = GRADIENT_SIZE % width;
589 for (x = 0; x < width; x++) {
591 grad < 256 || grad >= 5 * 256 ? 255 :
592 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
593 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
595 grad >= 4 * 256 ? 0 :
596 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
597 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
600 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
601 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
604 if (rgrad >= GRADIENT_SIZE) {
606 rgrad -= GRADIENT_SIZE;
608 if (grad >= GRADIENT_SIZE)
609 grad -= GRADIENT_SIZE;
612 for (y = height / 8; y > 0; y--) {
613 memcpy(p+frame->linesize[0], p, 3 * width);
614 p += frame->linesize[0];
618 seg_size = width / 80;
619 if (seg_size >= 1 && height >= 13 * seg_size) {
620 int64_t p10decimals = 1;
621 double time = av_q2d(test->time_base) * test->nb_frame *
622 ff_exp10(test->nb_decimals);
626 for (x = 0; x < test->nb_decimals; x++)
629 second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
630 x = width - (width - seg_size * 64) / 2;
631 y = (height - seg_size * 13) / 2;
632 p = data + (x*3 + y * frame->linesize[0]);
633 for (i = 0; i < 8; i++) {
634 p -= 3 * 8 * seg_size;
635 draw_digit(second % 10, p, frame->linesize[0], seg_size);
643 static av_cold int test_init(AVFilterContext *ctx)
645 TestSourceContext *test = ctx->priv;
647 test->fill_picture_fn = test_fill_picture;
651 static int test_query_formats(AVFilterContext *ctx)
653 static const enum AVPixelFormat pix_fmts[] = {
654 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
657 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
659 return AVERROR(ENOMEM);
660 return ff_set_common_formats(ctx, fmts_list);
663 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
666 .type = AVMEDIA_TYPE_VIDEO,
667 .request_frame = request_frame,
668 .config_props = config_props,
673 AVFilter ff_vsrc_testsrc = {
675 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
676 .priv_size = sizeof(TestSourceContext),
677 .priv_class = &testsrc_class,
680 .query_formats = test_query_formats,
682 .outputs = avfilter_vsrc_testsrc_outputs,
685 #endif /* CONFIG_TESTSRC_FILTER */
687 #if CONFIG_TESTSRC2_FILTER
689 static const AVOption testsrc2_options[] = {
691 { "alpha", "set global alpha (opacity)", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 255}, 0, 255, FLAGS },
695 AVFILTER_DEFINE_CLASS(testsrc2);
697 static void set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
699 uint8_t rgba[4] = { (argb >> 16) & 0xFF,
702 (argb >> 24) & 0xFF, };
703 ff_draw_color(&s->draw, color, rgba);
706 static uint32_t color_gradient(unsigned index)
708 unsigned si = index & 0xFF, sd = 0xFF - si;
709 switch (index >> 8) {
710 case 0: return 0xFF0000 + (si << 8);
711 case 1: return 0x00FF00 + (sd << 16);
712 case 2: return 0x00FF00 + (si << 0);
713 case 3: return 0x0000FF + (sd << 8);
714 case 4: return 0x0000FF + (si << 16);
715 case 5: return 0xFF0000 + (sd << 0);
720 static void draw_text(TestSourceContext *s, AVFrame *frame, FFDrawColor *color,
721 int x0, int y0, const uint8_t *text)
725 for (; *text; text++) {
731 ff_blend_mask(&s->draw, color, frame->data, frame->linesize,
732 frame->width, frame->height,
733 avpriv_vga16_font + *text * 16, 1, 8, 16, 0, 0, x, y0);
738 static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame)
740 TestSourceContext *s = ctx->priv;
742 unsigned alpha = (uint32_t)s->alpha << 24;
744 /* colored background */
746 unsigned i, x = 0, x2;
749 for (i = 1; i < 7; i++) {
750 x2 = av_rescale(i, s->w, 6);
751 x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2);
752 set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) |
753 ((i & 2) ? 0x00FF00 : 0) |
754 ((i & 4) ? 0x0000FF : 0) |
756 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
757 x, 0, x2 - x, frame->height);
762 /* oblique gradient */
763 /* note: too slow if using blending */
765 unsigned x, dx, y0, y, g0, g;
767 dx = ff_draw_round_to_sub(&s->draw, 0, +1, 1);
768 y0 = av_rescale_q(s->pts, s->time_base, av_make_q(2, s->h - 16));
769 g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128));
770 for (x = 0; x < s->w; x += dx) {
771 g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256);
772 set_color(s, &color, color_gradient(g) | alpha);
773 y = y0 + av_rescale(x, s->h / 2, s->w);
774 y %= 2 * (s->h - 16);
776 y = 2 * (s->h - 16) - y;
777 y = ff_draw_round_to_sub(&s->draw, 1, 0, y);
778 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
783 /* top right: draw clock hands */
784 if (s->w >= 64 && s->h >= 64) {
785 int l = (FFMIN(s->w, s->h) - 32) >> 1;
786 int steps = FFMAX(4, l >> 5);
787 int xc = (s->w >> 2) + (s->w >> 1);
788 int yc = (s->h >> 2);
793 for (c = 0; c < 3; c++) {
794 set_color(s, &color, (0xBBBBBB ^ (0xFF << (c << 3))) | alpha);
795 pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle;
796 xh = pos < 1 * l ? pos :
798 pos < 3 * l ? 3 * l - pos : 0;
799 yh = pos < 1 * l ? 0 :
800 pos < 2 * l ? pos - l :
805 for (i = 1; i <= steps; i++) {
806 int x = av_rescale(xh, i, steps) + xc;
807 int y = av_rescale(yh, i, steps) + yc;
808 x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
809 y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
810 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
816 /* bottom left: beating rectangles */
817 if (s->w >= 64 && s->h >= 64) {
818 int l = (FFMIN(s->w, s->h) - 16) >> 2;
820 int xc = (s->w >> 2);
821 int yc = (s->h >> 2) + (s->h >> 1);
822 int xm1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 8);
823 int xm2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 8);
824 int ym1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 8);
825 int ym2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 8);
826 int size, step, x1, x2, y1, y2;
828 size = av_rescale_q(s->pts, s->time_base, av_make_q(4, cycle));
833 step = (step >> 1) & 3;
834 set_color(s, &color, 0xFF808080);
835 x1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 4 - size);
836 x2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 4 + size);
837 y1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 4 - size);
838 y2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 4 + size);
839 if (step == 0 || step == 2)
840 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
841 x1, ym1, x2 - x1, ym2 - ym1);
842 if (step == 1 || step == 2)
843 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
844 xm1, y1, xm2 - xm1, y2 - y1);
846 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
847 x1, y1, x2 - x1, y2 - y1);
850 /* bottom right: checker with random noise */
852 unsigned xmin = av_rescale(5, s->w, 8);
853 unsigned xmax = av_rescale(7, s->w, 8);
854 unsigned ymin = av_rescale(5, s->h, 8);
855 unsigned ymax = av_rescale(7, s->h, 8);
860 for (y = ymin; y + 15 < ymax; y += 16) {
861 for (x = xmin; x + 15 < xmax; x += 16) {
864 for (i = 0; i < 256; i++) {
865 r = r * 1664525 + 1013904223;
868 set_color(s, &color, 0xFF00FF80);
869 ff_blend_mask(&s->draw, &color, frame->data, frame->linesize,
870 frame->width, frame->height,
871 alpha, 16, 16, 16, 3, 0, x, y);
876 /* bouncing square */
877 if (s->w >= 16 && s->h >= 16) {
878 unsigned w = s->w - 8;
879 unsigned h = s->h - 8;
880 unsigned x = av_rescale_q(s->pts, s->time_base, av_make_q(233, 55 * w)) % (w << 1);
881 unsigned y = av_rescale_q(s->pts, s->time_base, av_make_q(233, 89 * h)) % (h << 1);
886 x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
887 y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
888 set_color(s, &color, 0xFF8000FF);
889 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
893 /* top right: draw frame time and frame number */
898 time = av_rescale_q(s->pts, s->time_base, av_make_q(1, 1000)) % 86400000;
899 set_color(s, &color, 0xC0000000);
900 ff_blend_rectangle(&s->draw, &color, frame->data, frame->linesize,
901 frame->width, frame->height,
903 set_color(s, &color, 0xFFFF8000);
904 snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%03d\n%12"PRIi64,
905 time / 3600000, (time / 60000) % 60, (time / 1000) % 60,
906 time % 1000, s->pts);
907 draw_text(s, frame, &color, 4, 4, buf);
910 static av_cold int test2_init(AVFilterContext *ctx)
912 TestSourceContext *s = ctx->priv;
914 s->fill_picture_fn = test2_fill_picture;
918 static int test2_query_formats(AVFilterContext *ctx)
920 return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
923 static int test2_config_props(AVFilterLink *inlink)
925 AVFilterContext *ctx = inlink->src;
926 TestSourceContext *s = ctx->priv;
928 av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0);
929 s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
930 s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
931 if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
932 return AVERROR(EINVAL);
933 return config_props(inlink);
936 static const AVFilterPad avfilter_vsrc_testsrc2_outputs[] = {
939 .type = AVMEDIA_TYPE_VIDEO,
940 .request_frame = request_frame,
941 .config_props = test2_config_props,
946 AVFilter ff_vsrc_testsrc2 = {
948 .description = NULL_IF_CONFIG_SMALL("Generate another test pattern."),
949 .priv_size = sizeof(TestSourceContext),
950 .priv_class = &testsrc2_class,
953 .query_formats = test2_query_formats,
955 .outputs = avfilter_vsrc_testsrc2_outputs,
958 #endif /* CONFIG_TESTSRC2_FILTER */
960 #if CONFIG_RGBTESTSRC_FILTER
962 #define rgbtestsrc_options options
963 AVFILTER_DEFINE_CLASS(rgbtestsrc);
970 static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
971 int x, int y, int r, int g, int b, enum AVPixelFormat fmt,
978 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
979 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
980 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
981 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
982 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
983 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
984 case AV_PIX_FMT_RGB24:
985 case AV_PIX_FMT_BGR24:
986 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
987 p = dst + 3*x + y*dst_linesize;
990 case AV_PIX_FMT_RGBA:
991 case AV_PIX_FMT_BGRA:
992 case AV_PIX_FMT_ARGB:
993 case AV_PIX_FMT_ABGR:
994 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
995 p = dst + 4*x + y*dst_linesize;
1001 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1003 TestSourceContext *test = ctx->priv;
1004 int x, y, w = frame->width, h = frame->height;
1006 for (y = 0; y < h; y++) {
1007 for (x = 0; x < w; x++) {
1009 int r = 0, g = 0, b = 0;
1011 if (3*y < h ) r = c;
1012 else if (3*y < 2*h) g = c;
1015 rgbtest_put_pixel(frame->data[0], frame->linesize[0], x, y, r, g, b,
1016 ctx->outputs[0]->format, test->rgba_map);
1021 static av_cold int rgbtest_init(AVFilterContext *ctx)
1023 TestSourceContext *test = ctx->priv;
1025 test->draw_once = 1;
1026 test->fill_picture_fn = rgbtest_fill_picture;
1030 static int rgbtest_query_formats(AVFilterContext *ctx)
1032 static const enum AVPixelFormat pix_fmts[] = {
1033 AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
1034 AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
1035 AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
1036 AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
1037 AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
1041 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1043 return AVERROR(ENOMEM);
1044 return ff_set_common_formats(ctx, fmts_list);
1047 static int rgbtest_config_props(AVFilterLink *outlink)
1049 TestSourceContext *test = outlink->src->priv;
1051 ff_fill_rgba_map(test->rgba_map, outlink->format);
1052 return config_props(outlink);
1055 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
1058 .type = AVMEDIA_TYPE_VIDEO,
1059 .request_frame = request_frame,
1060 .config_props = rgbtest_config_props,
1065 AVFilter ff_vsrc_rgbtestsrc = {
1066 .name = "rgbtestsrc",
1067 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
1068 .priv_size = sizeof(TestSourceContext),
1069 .priv_class = &rgbtestsrc_class,
1070 .init = rgbtest_init,
1072 .query_formats = rgbtest_query_formats,
1074 .outputs = avfilter_vsrc_rgbtestsrc_outputs,
1077 #endif /* CONFIG_RGBTESTSRC_FILTER */
1079 #if CONFIG_YUVTESTSRC_FILTER
1081 #define yuvtestsrc_options options
1082 AVFILTER_DEFINE_CLASS(yuvtestsrc);
1084 static void yuvtest_fill_picture8(AVFilterContext *ctx, AVFrame *frame)
1086 int x, y, w = frame->width, h = frame->height / 3;
1087 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1088 const int factor = 1 << desc->comp[0].depth;
1089 const int mid = 1 << (desc->comp[0].depth - 1);
1090 uint8_t *ydst = frame->data[0];
1091 uint8_t *udst = frame->data[1];
1092 uint8_t *vdst = frame->data[2];
1093 int ylinesize = frame->linesize[0];
1094 int ulinesize = frame->linesize[1];
1095 int vlinesize = frame->linesize[2];
1097 for (y = 0; y < h; y++) {
1098 for (x = 0; x < w; x++) {
1099 int c = factor * x / w;
1112 for (; y < h; y++) {
1113 for (x = 0; x < w; x++) {
1114 int c = factor * x / w;
1126 for (; y < frame->height; y++) {
1127 for (x = 0; x < w; x++) {
1128 int c = factor * x / w;
1141 static void yuvtest_fill_picture16(AVFilterContext *ctx, AVFrame *frame)
1143 int x, y, w = frame->width, h = frame->height / 3;
1144 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1145 const int factor = 1 << desc->comp[0].depth;
1146 const int mid = 1 << (desc->comp[0].depth - 1);
1147 uint16_t *ydst = (uint16_t *)frame->data[0];
1148 uint16_t *udst = (uint16_t *)frame->data[1];
1149 uint16_t *vdst = (uint16_t *)frame->data[2];
1150 int ylinesize = frame->linesize[0] / 2;
1151 int ulinesize = frame->linesize[1] / 2;
1152 int vlinesize = frame->linesize[2] / 2;
1154 for (y = 0; y < h; y++) {
1155 for (x = 0; x < w; x++) {
1156 int c = factor * x / w;
1169 for (; y < h; y++) {
1170 for (x = 0; x < w; x++) {
1171 int c = factor * x / w;
1183 for (; y < frame->height; y++) {
1184 for (x = 0; x < w; x++) {
1185 int c = factor * x / w;
1198 static av_cold int yuvtest_init(AVFilterContext *ctx)
1200 TestSourceContext *test = ctx->priv;
1202 test->draw_once = 1;
1206 static int yuvtest_query_formats(AVFilterContext *ctx)
1208 static const enum AVPixelFormat pix_fmts[] = {
1209 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
1210 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
1211 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14,
1212 AV_PIX_FMT_YUV444P16,
1216 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1218 return AVERROR(ENOMEM);
1219 return ff_set_common_formats(ctx, fmts_list);
1222 static int yuvtest_config_props(AVFilterLink *outlink)
1224 TestSourceContext *test = outlink->src->priv;
1225 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
1227 test->fill_picture_fn = desc->comp[0].depth > 8 ? yuvtest_fill_picture16 : yuvtest_fill_picture8;
1228 return config_props(outlink);
1231 static const AVFilterPad avfilter_vsrc_yuvtestsrc_outputs[] = {
1234 .type = AVMEDIA_TYPE_VIDEO,
1235 .request_frame = request_frame,
1236 .config_props = yuvtest_config_props,
1241 AVFilter ff_vsrc_yuvtestsrc = {
1242 .name = "yuvtestsrc",
1243 .description = NULL_IF_CONFIG_SMALL("Generate YUV test pattern."),
1244 .priv_size = sizeof(TestSourceContext),
1245 .priv_class = &yuvtestsrc_class,
1246 .init = yuvtest_init,
1248 .query_formats = yuvtest_query_formats,
1250 .outputs = avfilter_vsrc_yuvtestsrc_outputs,
1253 #endif /* CONFIG_YUVTESTSRC_FILTER */
1255 #if CONFIG_PAL75BARS_FILTER || CONFIG_PAL100BARS_FILTER || CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
1257 static const uint8_t rainbow[7][4] = {
1258 { 180, 128, 128, 255 }, /* 75% white */
1259 { 162, 44, 142, 255 }, /* 75% yellow */
1260 { 131, 156, 44, 255 }, /* 75% cyan */
1261 { 112, 72, 58, 255 }, /* 75% green */
1262 { 84, 184, 198, 255 }, /* 75% magenta */
1263 { 65, 100, 212, 255 }, /* 75% red */
1264 { 35, 212, 114, 255 }, /* 75% blue */
1267 static const uint8_t rainbow100[7][4] = {
1268 { 235, 128, 128, 255 }, /* 100% white */
1269 { 210, 16, 146, 255 }, /* 100% yellow */
1270 { 170, 166, 16, 255 }, /* 100% cyan */
1271 { 145, 54, 34, 255 }, /* 100% green */
1272 { 106, 202, 222, 255 }, /* 100% magenta */
1273 { 81, 90, 240, 255 }, /* 100% red */
1274 { 41, 240, 110, 255 }, /* 100% blue */
1277 static const uint8_t rainbowhd[7][4] = {
1278 { 180, 128, 128, 255 }, /* 75% white */
1279 { 168, 44, 136, 255 }, /* 75% yellow */
1280 { 145, 147, 44, 255 }, /* 75% cyan */
1281 { 133, 63, 52, 255 }, /* 75% green */
1282 { 63, 193, 204, 255 }, /* 75% magenta */
1283 { 51, 109, 212, 255 }, /* 75% red */
1284 { 28, 212, 120, 255 }, /* 75% blue */
1287 static const uint8_t wobnair[7][4] = {
1288 { 35, 212, 114, 255 }, /* 75% blue */
1289 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1290 { 84, 184, 198, 255 }, /* 75% magenta */
1291 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1292 { 131, 156, 44, 255 }, /* 75% cyan */
1293 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1294 { 180, 128, 128, 255 }, /* 75% white */
1297 static const uint8_t white[4] = { 235, 128, 128, 255 };
1300 static const uint8_t neg4ire[4] = { 7, 128, 128, 255 };
1301 static const uint8_t pos4ire[4] = { 24, 128, 128, 255 };
1304 static const uint8_t i_pixel[4] = { 57, 156, 97, 255 };
1305 static const uint8_t q_pixel[4] = { 44, 171, 147, 255 };
1307 static const uint8_t gray40[4] = { 104, 128, 128, 255 };
1308 static const uint8_t gray15[4] = { 49, 128, 128, 255 };
1309 static const uint8_t cyan[4] = { 188, 154, 16, 255 };
1310 static const uint8_t yellow[4] = { 219, 16, 138, 255 };
1311 static const uint8_t blue[4] = { 32, 240, 118, 255 };
1312 static const uint8_t red[4] = { 63, 102, 240, 255 };
1313 static const uint8_t black0[4] = { 16, 128, 128, 255 };
1314 static const uint8_t black2[4] = { 20, 128, 128, 255 };
1315 static const uint8_t black4[4] = { 25, 128, 128, 255 };
1316 static const uint8_t neg2[4] = { 12, 128, 128, 255 };
1318 static void draw_bar(TestSourceContext *test, const uint8_t color[4],
1319 int x, int y, int w, int h,
1322 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1326 x = FFMIN(x, test->w - 1);
1327 y = FFMIN(y, test->h - 1);
1328 w = FFMAX(FFMIN(w, test->w - x), 0);
1329 h = FFMAX(FFMIN(h, test->h - y), 0);
1331 av_assert0(x + w <= test->w);
1332 av_assert0(y + h <= test->h);
1334 for (plane = 0; frame->data[plane]; plane++) {
1335 const int c = color[plane];
1336 const int linesize = frame->linesize[plane];
1337 int i, px, py, pw, ph;
1339 if (plane == 1 || plane == 2) {
1340 px = x >> desc->log2_chroma_w;
1341 pw = AV_CEIL_RSHIFT(w, desc->log2_chroma_w);
1342 py = y >> desc->log2_chroma_h;
1343 ph = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
1351 p0 = p = frame->data[plane] + py * linesize + px;
1354 for (i = 1; i < ph; i++, p += linesize)
1359 static int smptebars_query_formats(AVFilterContext *ctx)
1361 static const enum AVPixelFormat pix_fmts[] = {
1362 AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
1363 AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
1364 AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
1368 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1370 return AVERROR(ENOMEM);
1371 return ff_set_common_formats(ctx, fmts_list);
1374 static const AVFilterPad smptebars_outputs[] = {
1377 .type = AVMEDIA_TYPE_VIDEO,
1378 .request_frame = request_frame,
1379 .config_props = config_props,
1384 #if CONFIG_PAL75BARS_FILTER
1386 #define pal75bars_options options
1387 AVFILTER_DEFINE_CLASS(pal75bars);
1389 static void pal75bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1391 TestSourceContext *test = ctx->priv;
1393 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1395 picref->color_range = AVCOL_RANGE_MPEG;
1396 picref->colorspace = AVCOL_SPC_BT470BG;
1398 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1400 draw_bar(test, white, x, 0, r_w, test->h, picref);
1402 for (i = 1; i < 7; i++) {
1403 draw_bar(test, rainbow[i], x, 0, r_w, test->h, picref);
1406 draw_bar(test, black0, x, 0, r_w, test->h, picref);
1409 static av_cold int pal75bars_init(AVFilterContext *ctx)
1411 TestSourceContext *test = ctx->priv;
1413 test->fill_picture_fn = pal75bars_fill_picture;
1414 test->draw_once = 1;
1418 AVFilter ff_vsrc_pal75bars = {
1419 .name = "pal75bars",
1420 .description = NULL_IF_CONFIG_SMALL("Generate PAL 75% color bars."),
1421 .priv_size = sizeof(TestSourceContext),
1422 .priv_class = &pal75bars_class,
1423 .init = pal75bars_init,
1425 .query_formats = smptebars_query_formats,
1427 .outputs = smptebars_outputs,
1430 #endif /* CONFIG_PAL75BARS_FILTER */
1432 #if CONFIG_PAL100BARS_FILTER
1434 #define pal100bars_options options
1435 AVFILTER_DEFINE_CLASS(pal100bars);
1437 static void pal100bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1439 TestSourceContext *test = ctx->priv;
1441 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1443 picref->color_range = AVCOL_RANGE_MPEG;
1444 picref->colorspace = AVCOL_SPC_BT470BG;
1446 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1448 for (i = 0; i < 7; i++) {
1449 draw_bar(test, rainbow100[i], x, 0, r_w, test->h, picref);
1452 draw_bar(test, black0, x, 0, r_w, test->h, picref);
1455 static av_cold int pal100bars_init(AVFilterContext *ctx)
1457 TestSourceContext *test = ctx->priv;
1459 test->fill_picture_fn = pal100bars_fill_picture;
1460 test->draw_once = 1;
1464 AVFilter ff_vsrc_pal100bars = {
1465 .name = "pal100bars",
1466 .description = NULL_IF_CONFIG_SMALL("Generate PAL 100% color bars."),
1467 .priv_size = sizeof(TestSourceContext),
1468 .priv_class = &pal100bars_class,
1469 .init = pal100bars_init,
1471 .query_formats = smptebars_query_formats,
1473 .outputs = smptebars_outputs,
1476 #endif /* CONFIG_PAL100BARS_FILTER */
1478 #if CONFIG_SMPTEBARS_FILTER
1480 #define smptebars_options options
1481 AVFILTER_DEFINE_CLASS(smptebars);
1483 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1485 TestSourceContext *test = ctx->priv;
1486 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
1487 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1489 picref->colorspace = AVCOL_SPC_BT470BG;
1491 r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
1492 r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
1493 w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
1494 p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
1495 p_h = test->h - w_h - r_h;
1497 for (i = 0; i < 7; i++) {
1498 draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
1499 draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
1503 draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
1505 draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
1507 draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
1509 tmp = FFALIGN(5 * r_w - x, 1 << pixdesc->log2_chroma_w);
1510 draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1512 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1513 draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
1515 draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1517 draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
1519 draw_bar(test, black0, x, r_h + w_h, test->w - x, p_h, picref);
1522 static av_cold int smptebars_init(AVFilterContext *ctx)
1524 TestSourceContext *test = ctx->priv;
1526 test->fill_picture_fn = smptebars_fill_picture;
1527 test->draw_once = 1;
1531 AVFilter ff_vsrc_smptebars = {
1532 .name = "smptebars",
1533 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
1534 .priv_size = sizeof(TestSourceContext),
1535 .priv_class = &smptebars_class,
1536 .init = smptebars_init,
1538 .query_formats = smptebars_query_formats,
1540 .outputs = smptebars_outputs,
1543 #endif /* CONFIG_SMPTEBARS_FILTER */
1545 #if CONFIG_SMPTEHDBARS_FILTER
1547 #define smptehdbars_options options
1548 AVFILTER_DEFINE_CLASS(smptehdbars);
1550 static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1552 TestSourceContext *test = ctx->priv;
1553 int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
1554 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1556 picref->colorspace = AVCOL_SPC_BT709;
1558 d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
1559 r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
1560 draw_bar(test, gray40, x, 0, d_w, r_h, picref);
1563 r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
1564 for (i = 0; i < 7; i++) {
1565 draw_bar(test, rainbowhd[i], x, 0, r_w, r_h, picref);
1568 draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
1570 r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
1571 draw_bar(test, cyan, 0, y, d_w, r_h, picref);
1573 draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
1576 draw_bar(test, rainbowhd[0], x, y, tmp, r_h, picref);
1579 draw_bar(test, blue, x, y, test->w - x, r_h, picref);
1581 draw_bar(test, yellow, 0, y, d_w, r_h, picref);
1583 draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
1586 for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
1587 uint8_t yramp[4] = {0};
1589 yramp[0] = i * 255 / tmp;
1594 draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
1595 x += 1 << pixdesc->log2_chroma_w;
1597 draw_bar(test, red, x, y, test->w - x, r_h, picref);
1599 draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
1601 tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
1602 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1604 tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
1605 draw_bar(test, white, x, y, tmp, test->h - y, picref);
1607 tmp = FFALIGN(r_w * 5 / 6, 1 << pixdesc->log2_chroma_w);
1608 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1610 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1611 draw_bar(test, neg2, x, y, tmp, test->h - y, picref);
1613 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1615 draw_bar(test, black2, x, y, tmp, test->h - y, picref);
1617 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1619 draw_bar(test, black4, x, y, tmp, test->h - y, picref);
1622 draw_bar(test, black0, x, y, r_w, test->h - y, picref);
1624 draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
1627 static av_cold int smptehdbars_init(AVFilterContext *ctx)
1629 TestSourceContext *test = ctx->priv;
1631 test->fill_picture_fn = smptehdbars_fill_picture;
1632 test->draw_once = 1;
1636 AVFilter ff_vsrc_smptehdbars = {
1637 .name = "smptehdbars",
1638 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
1639 .priv_size = sizeof(TestSourceContext),
1640 .priv_class = &smptehdbars_class,
1641 .init = smptehdbars_init,
1643 .query_formats = smptebars_query_formats,
1645 .outputs = smptebars_outputs,
1648 #endif /* CONFIG_SMPTEHDBARS_FILTER */
1649 #endif /* CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */
1651 #if CONFIG_ALLYUV_FILTER
1653 static const AVOption allyuv_options[] = {
1654 COMMON_OPTIONS_NOSIZE
1658 AVFILTER_DEFINE_CLASS(allyuv);
1660 static void allyuv_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1662 const int ys = frame->linesize[0];
1663 const int us = frame->linesize[1];
1664 const int vs = frame->linesize[2];
1667 for (y = 0; y < 4096; y++) {
1668 for (x = 0; x < 2048; x++) {
1669 frame->data[0][y * ys + x] = ((x / 8) % 256);
1670 frame->data[0][y * ys + 4095 - x] = ((x / 8) % 256);
1673 for (x = 0; x < 2048; x+=8) {
1674 for (j = 0; j < 8; j++) {
1675 frame->data[1][vs * y + x + j] = (y%16 + (j % 8) * 16);
1676 frame->data[1][vs * y + 4095 - x - j] = (128 + y%16 + (j % 8) * 16);
1680 for (x = 0; x < 4096; x++)
1681 frame->data[2][y * us + x] = 256 * y / 4096;
1685 static av_cold int allyuv_init(AVFilterContext *ctx)
1687 TestSourceContext *test = ctx->priv;
1689 test->w = test->h = 4096;
1690 test->draw_once = 1;
1691 test->fill_picture_fn = allyuv_fill_picture;
1695 static int allyuv_query_formats(AVFilterContext *ctx)
1697 static const enum AVPixelFormat pix_fmts[] = {
1698 AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP,
1702 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1704 return AVERROR(ENOMEM);
1705 return ff_set_common_formats(ctx, fmts_list);
1708 static const AVFilterPad avfilter_vsrc_allyuv_outputs[] = {
1711 .type = AVMEDIA_TYPE_VIDEO,
1712 .request_frame = request_frame,
1713 .config_props = config_props,
1718 AVFilter ff_vsrc_allyuv = {
1720 .description = NULL_IF_CONFIG_SMALL("Generate all yuv colors."),
1721 .priv_size = sizeof(TestSourceContext),
1722 .priv_class = &allyuv_class,
1723 .init = allyuv_init,
1725 .query_formats = allyuv_query_formats,
1727 .outputs = avfilter_vsrc_allyuv_outputs,
1730 #endif /* CONFIG_ALLYUV_FILTER */
1732 #if CONFIG_ALLRGB_FILTER
1734 static const AVOption allrgb_options[] = {
1735 COMMON_OPTIONS_NOSIZE
1739 AVFILTER_DEFINE_CLASS(allrgb);
1741 static void allrgb_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1744 const int linesize = frame->linesize[0];
1745 uint8_t *line = frame->data[0];
1747 for (y = 0; y < 4096; y++) {
1748 uint8_t *dst = line;
1750 for (x = 0; x < 4096; x++) {
1753 *dst++ = (x >> 8) | ((y >> 8) << 4);
1759 static av_cold int allrgb_init(AVFilterContext *ctx)
1761 TestSourceContext *test = ctx->priv;
1763 test->w = test->h = 4096;
1764 test->draw_once = 1;
1765 test->fill_picture_fn = allrgb_fill_picture;
1769 static int allrgb_config_props(AVFilterLink *outlink)
1771 TestSourceContext *test = outlink->src->priv;
1773 ff_fill_rgba_map(test->rgba_map, outlink->format);
1774 return config_props(outlink);
1777 static int allrgb_query_formats(AVFilterContext *ctx)
1779 static const enum AVPixelFormat pix_fmts[] = {
1780 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
1783 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1785 return AVERROR(ENOMEM);
1786 return ff_set_common_formats(ctx, fmts_list);
1789 static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
1792 .type = AVMEDIA_TYPE_VIDEO,
1793 .request_frame = request_frame,
1794 .config_props = allrgb_config_props,
1799 AVFilter ff_vsrc_allrgb = {
1801 .description = NULL_IF_CONFIG_SMALL("Generate all RGB colors."),
1802 .priv_size = sizeof(TestSourceContext),
1803 .priv_class = &allrgb_class,
1804 .init = allrgb_init,
1806 .query_formats = allrgb_query_formats,
1808 .outputs = avfilter_vsrc_allrgb_outputs,
1811 #endif /* CONFIG_ALLRGB_FILTER */