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"
53 typedef struct TestSourceContext {
56 unsigned int nb_frame;
57 AVRational time_base, frame_rate;
59 int64_t duration; ///< duration expressed in microseconds
60 AVRational sar; ///< sample aspect ratio
61 int draw_once; ///< draw only the first frame, always put out the same picture
62 int draw_once_reset; ///< draw only the first frame or in case of reset
63 AVFrame *picref; ///< cached reference containing the painted picture
65 void (* fill_picture_fn)(AVFilterContext *ctx, AVFrame *frame);
67 /* only used by testsrc */
70 /* only used by testsrc2 */
73 /* only used by color */
76 uint8_t color_rgba[4];
78 /* only used by rgbtest */
83 /* only used by haldclut */
87 #define OFFSET(x) offsetof(TestSourceContext, x)
88 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
89 #define FLAGSR AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
91 #define SIZE_OPTIONS \
92 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
93 { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
95 #define COMMON_OPTIONS_NOSIZE \
96 { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
97 { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
98 { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
99 { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
100 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
102 #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
104 #define NOSIZE_OPTIONS_OFFSET 2
105 /* Filters using COMMON_OPTIONS_NOSIZE also use the following options
106 * via &options[NOSIZE_OPTIONS_OFFSET]. So don't break it. */
107 static const AVOption options[] = {
112 static av_cold int init(AVFilterContext *ctx)
114 TestSourceContext *test = ctx->priv;
116 test->time_base = av_inv_q(test->frame_rate);
120 av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
121 test->w, test->h, test->frame_rate.num, test->frame_rate.den,
122 test->duration < 0 ? -1 : (double)test->duration/1000000,
123 test->sar.num, test->sar.den);
127 static av_cold void uninit(AVFilterContext *ctx)
129 TestSourceContext *test = ctx->priv;
131 av_frame_free(&test->picref);
134 static int config_props(AVFilterLink *outlink)
136 TestSourceContext *test = outlink->src->priv;
138 outlink->w = test->w;
139 outlink->h = test->h;
140 outlink->sample_aspect_ratio = test->sar;
141 outlink->frame_rate = test->frame_rate;
142 outlink->time_base = test->time_base;
147 static int activate(AVFilterContext *ctx)
149 AVFilterLink *outlink = ctx->outputs[0];
150 TestSourceContext *test = ctx->priv;
153 if (!ff_outlink_frame_wanted(outlink))
154 return FFERROR_NOT_READY;
155 if (test->duration >= 0 &&
156 av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration) {
157 ff_outlink_set_status(outlink, AVERROR_EOF, test->pts);
161 if (test->draw_once) {
162 if (test->draw_once_reset) {
163 av_frame_free(&test->picref);
164 test->draw_once_reset = 0;
168 ff_get_video_buffer(outlink, test->w, test->h);
170 return AVERROR(ENOMEM);
171 test->fill_picture_fn(outlink->src, test->picref);
173 frame = av_frame_clone(test->picref);
175 frame = ff_get_video_buffer(outlink, test->w, test->h);
178 return AVERROR(ENOMEM);
179 frame->pts = test->pts;
180 frame->key_frame = 1;
181 frame->interlaced_frame = 0;
182 frame->pict_type = AV_PICTURE_TYPE_I;
183 frame->sample_aspect_ratio = test->sar;
184 if (!test->draw_once)
185 test->fill_picture_fn(outlink->src, frame);
190 return ff_filter_frame(outlink, frame);
193 #if CONFIG_COLOR_FILTER
195 static const AVOption color_options[] = {
196 { "color", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGSR },
197 { "c", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGSR },
202 AVFILTER_DEFINE_CLASS(color);
204 static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
206 TestSourceContext *test = ctx->priv;
207 ff_fill_rectangle(&test->draw, &test->color,
208 picref->data, picref->linesize,
209 0, 0, test->w, test->h);
212 static av_cold int color_init(AVFilterContext *ctx)
214 TestSourceContext *test = ctx->priv;
215 test->fill_picture_fn = color_fill_picture;
220 static int color_query_formats(AVFilterContext *ctx)
222 return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
225 static int color_config_props(AVFilterLink *inlink)
227 AVFilterContext *ctx = inlink->src;
228 TestSourceContext *test = ctx->priv;
231 ff_draw_init(&test->draw, inlink->format, 0);
232 ff_draw_color(&test->draw, &test->color, test->color_rgba);
234 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
235 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
236 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
237 return AVERROR(EINVAL);
239 if ((ret = config_props(inlink)) < 0)
245 static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
246 char *res, int res_len, int flags)
248 TestSourceContext *test = ctx->priv;
251 ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
255 ff_draw_color(&test->draw, &test->color, test->color_rgba);
256 test->draw_once_reset = 1;
260 static const AVFilterPad color_outputs[] = {
263 .type = AVMEDIA_TYPE_VIDEO,
264 .config_props = color_config_props,
269 AVFilter ff_vsrc_color = {
271 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
272 .priv_class = &color_class,
273 .priv_size = sizeof(TestSourceContext),
276 .activate = activate,
277 .query_formats = color_query_formats,
279 .outputs = color_outputs,
280 .process_command = color_process_command,
283 #endif /* CONFIG_COLOR_FILTER */
285 #if CONFIG_HALDCLUTSRC_FILTER
287 static const AVOption haldclutsrc_options[] = {
288 { "level", "set level", OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 6}, 2, 16, FLAGS },
289 COMMON_OPTIONS_NOSIZE
293 AVFILTER_DEFINE_CLASS(haldclutsrc);
295 static void haldclutsrc_fill_picture(AVFilterContext *ctx, AVFrame *frame)
297 int i, j, k, x = 0, y = 0, is16bit = 0, step;
299 const TestSourceContext *hc = ctx->priv;
300 int level = hc->level;
302 const int w = frame->width;
303 const int h = frame->height;
304 const uint8_t *data = frame->data[0];
305 const int linesize = frame->linesize[0];
306 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
309 av_assert0(w == h && w == level*level*level);
311 ff_fill_rgba_map(rgba_map, frame->format);
313 switch (frame->format) {
314 case AV_PIX_FMT_RGB48:
315 case AV_PIX_FMT_BGR48:
316 case AV_PIX_FMT_RGBA64:
317 case AV_PIX_FMT_BGRA64:
321 case AV_PIX_FMT_RGBA:
322 case AV_PIX_FMT_BGRA:
323 case AV_PIX_FMT_ARGB:
324 case AV_PIX_FMT_ABGR:
329 step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
330 scale = ((float)(1 << (8*(is16bit+1))) - 1) / (level*level - 1);
332 #define LOAD_CLUT(nbits) do { \
333 uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step; \
334 dst[rgba_map[0]] = av_clip_uint##nbits(i * scale); \
335 dst[rgba_map[1]] = av_clip_uint##nbits(j * scale); \
336 dst[rgba_map[2]] = av_clip_uint##nbits(k * scale); \
338 dst[rgba_map[3]] = alpha; \
342 for (k = 0; k < level; k++) {
343 for (j = 0; j < level; j++) {
344 for (i = 0; i < level; i++) {
358 static av_cold int haldclutsrc_init(AVFilterContext *ctx)
360 TestSourceContext *hc = ctx->priv;
361 hc->fill_picture_fn = haldclutsrc_fill_picture;
366 static int haldclutsrc_query_formats(AVFilterContext *ctx)
368 static const enum AVPixelFormat pix_fmts[] = {
369 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
370 AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA,
371 AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR,
372 AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR,
373 AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0,
374 AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48,
375 AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
379 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
381 return AVERROR(ENOMEM);
382 return ff_set_common_formats(ctx, fmts_list);
385 static int haldclutsrc_config_props(AVFilterLink *outlink)
387 AVFilterContext *ctx = outlink->src;
388 TestSourceContext *hc = ctx->priv;
390 hc->w = hc->h = hc->level * hc->level * hc->level;
391 return config_props(outlink);
394 static const AVFilterPad haldclutsrc_outputs[] = {
397 .type = AVMEDIA_TYPE_VIDEO,
398 .config_props = haldclutsrc_config_props,
403 AVFilter ff_vsrc_haldclutsrc = {
404 .name = "haldclutsrc",
405 .description = NULL_IF_CONFIG_SMALL("Provide an identity Hald CLUT."),
406 .priv_class = &haldclutsrc_class,
407 .priv_size = sizeof(TestSourceContext),
408 .init = haldclutsrc_init,
410 .query_formats = haldclutsrc_query_formats,
411 .activate = activate,
413 .outputs = haldclutsrc_outputs,
415 #endif /* CONFIG_HALDCLUTSRC_FILTER */
417 #if CONFIG_NULLSRC_FILTER
419 #define nullsrc_options options
420 AVFILTER_DEFINE_CLASS(nullsrc);
422 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
424 static av_cold int nullsrc_init(AVFilterContext *ctx)
426 TestSourceContext *test = ctx->priv;
428 test->fill_picture_fn = nullsrc_fill_picture;
432 static const AVFilterPad nullsrc_outputs[] = {
435 .type = AVMEDIA_TYPE_VIDEO,
436 .config_props = config_props,
441 AVFilter ff_vsrc_nullsrc = {
443 .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
444 .init = nullsrc_init,
446 .activate = activate,
447 .priv_size = sizeof(TestSourceContext),
448 .priv_class = &nullsrc_class,
450 .outputs = nullsrc_outputs,
453 #endif /* CONFIG_NULLSRC_FILTER */
455 #if CONFIG_TESTSRC_FILTER
457 static const AVOption testsrc_options[] = {
459 { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
460 { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
464 AVFILTER_DEFINE_CLASS(testsrc);
467 * Fill a rectangle with value val.
469 * @param val the RGB value to set
470 * @param dst pointer to the destination buffer to fill
471 * @param dst_linesize linesize of destination
472 * @param segment_width width of the segment
473 * @param x horizontal coordinate where to draw the rectangle in the destination buffer
474 * @param y horizontal coordinate where to draw the rectangle in the destination buffer
475 * @param w width of the rectangle to draw, expressed as a number of segment_width units
476 * @param h height of the rectangle to draw, expressed as a number of segment_width units
478 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, int segment_width,
479 int x, int y, int w, int h)
484 dst += segment_width * (step * x + y * dst_linesize);
485 w *= segment_width * step;
487 for (i = 0; i < h; i++) {
493 static void draw_digit(int digit, uint8_t *dst, int dst_linesize,
499 #define LEFT_TOP_VBAR 8
500 #define LEFT_BOT_VBAR 16
501 #define RIGHT_TOP_VBAR 32
502 #define RIGHT_BOT_VBAR 64
506 { 1, 0, 5, 1 }, /* TOP_HBAR */
507 { 1, 6, 5, 1 }, /* MID_HBAR */
508 { 1, 12, 5, 1 }, /* BOT_HBAR */
509 { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
510 { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
511 { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
512 { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
514 static const unsigned char masks[10] = {
515 /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
516 /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
517 /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
518 /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
519 /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
520 /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
521 /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
522 /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
523 /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
524 /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
526 unsigned mask = masks[digit];
529 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
530 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
532 draw_rectangle(255, dst, dst_linesize, segment_width,
533 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
536 #define GRADIENT_SIZE (6 * 256)
538 static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
540 TestSourceContext *test = ctx->priv;
543 int color, color_rest;
547 int dquad_x, dquad_y;
548 int grad, dgrad, rgrad, drgrad;
552 uint8_t *data = frame->data[0];
553 int width = frame->width;
554 int height = frame->height;
556 /* draw colored bars and circle */
557 radius = (width + height) / 4;
558 quad0 = width * width / 4 + height * height / 4 - radius * radius;
559 dquad_y = 1 - height;
561 for (y = 0; y < height; y++) {
567 for (x = 0; x < width; x++) {
573 *(p++) = icolor & 1 ? 255 : 0;
574 *(p++) = icolor & 2 ? 255 : 0;
575 *(p++) = icolor & 4 ? 255 : 0;
577 if (color_rest >= width) {
584 p0 += frame->linesize[0];
587 /* draw sliding color line */
588 p0 = p = data + frame->linesize[0] * (height * 3/4);
589 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
592 dgrad = GRADIENT_SIZE / width;
593 drgrad = GRADIENT_SIZE % width;
594 for (x = 0; x < width; x++) {
596 grad < 256 || grad >= 5 * 256 ? 255 :
597 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
598 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
600 grad >= 4 * 256 ? 0 :
601 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
602 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
605 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
606 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
609 if (rgrad >= GRADIENT_SIZE) {
611 rgrad -= GRADIENT_SIZE;
613 if (grad >= GRADIENT_SIZE)
614 grad -= GRADIENT_SIZE;
617 for (y = height / 8; y > 0; y--) {
618 memcpy(p+frame->linesize[0], p, 3 * width);
619 p += frame->linesize[0];
623 seg_size = width / 80;
624 if (seg_size >= 1 && height >= 13 * seg_size) {
625 int64_t p10decimals = 1;
626 double time = av_q2d(test->time_base) * test->nb_frame *
627 ff_exp10(test->nb_decimals);
631 for (x = 0; x < test->nb_decimals; x++)
634 second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
635 x = width - (width - seg_size * 64) / 2;
636 y = (height - seg_size * 13) / 2;
637 p = data + (x*3 + y * frame->linesize[0]);
638 for (i = 0; i < 8; i++) {
639 p -= 3 * 8 * seg_size;
640 draw_digit(second % 10, p, frame->linesize[0], seg_size);
648 static av_cold int test_init(AVFilterContext *ctx)
650 TestSourceContext *test = ctx->priv;
652 test->fill_picture_fn = test_fill_picture;
656 static int test_query_formats(AVFilterContext *ctx)
658 static const enum AVPixelFormat pix_fmts[] = {
659 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
662 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
664 return AVERROR(ENOMEM);
665 return ff_set_common_formats(ctx, fmts_list);
668 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
671 .type = AVMEDIA_TYPE_VIDEO,
672 .config_props = config_props,
677 AVFilter ff_vsrc_testsrc = {
679 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
680 .priv_size = sizeof(TestSourceContext),
681 .priv_class = &testsrc_class,
684 .query_formats = test_query_formats,
685 .activate = activate,
687 .outputs = avfilter_vsrc_testsrc_outputs,
690 #endif /* CONFIG_TESTSRC_FILTER */
692 #if CONFIG_TESTSRC2_FILTER
694 static const AVOption testsrc2_options[] = {
696 { "alpha", "set global alpha (opacity)", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 255}, 0, 255, FLAGS },
700 AVFILTER_DEFINE_CLASS(testsrc2);
702 static void set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
704 uint8_t rgba[4] = { (argb >> 16) & 0xFF,
707 (argb >> 24) & 0xFF, };
708 ff_draw_color(&s->draw, color, rgba);
711 static uint32_t color_gradient(unsigned index)
713 unsigned si = index & 0xFF, sd = 0xFF - si;
714 switch (index >> 8) {
715 case 0: return 0xFF0000 + (si << 8);
716 case 1: return 0x00FF00 + (sd << 16);
717 case 2: return 0x00FF00 + (si << 0);
718 case 3: return 0x0000FF + (sd << 8);
719 case 4: return 0x0000FF + (si << 16);
720 case 5: return 0xFF0000 + (sd << 0);
725 static void draw_text(TestSourceContext *s, AVFrame *frame, FFDrawColor *color,
726 int x0, int y0, const uint8_t *text)
730 for (; *text; text++) {
736 ff_blend_mask(&s->draw, color, frame->data, frame->linesize,
737 frame->width, frame->height,
738 avpriv_vga16_font + *text * 16, 1, 8, 16, 0, 0, x, y0);
743 static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame)
745 TestSourceContext *s = ctx->priv;
747 unsigned alpha = (uint32_t)s->alpha << 24;
749 /* colored background */
751 unsigned i, x = 0, x2;
754 for (i = 1; i < 7; i++) {
755 x2 = av_rescale(i, s->w, 6);
756 x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2);
757 set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) |
758 ((i & 2) ? 0x00FF00 : 0) |
759 ((i & 4) ? 0x0000FF : 0) |
761 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
762 x, 0, x2 - x, frame->height);
767 /* oblique gradient */
768 /* note: too slow if using blending */
770 unsigned x, dx, y0, y, g0, g;
772 dx = ff_draw_round_to_sub(&s->draw, 0, +1, 1);
773 y0 = av_rescale_q(s->pts, s->time_base, av_make_q(2, s->h - 16));
774 g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128));
775 for (x = 0; x < s->w; x += dx) {
776 g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256);
777 set_color(s, &color, color_gradient(g) | alpha);
778 y = y0 + av_rescale(x, s->h / 2, s->w);
779 y %= 2 * (s->h - 16);
781 y = 2 * (s->h - 16) - y;
782 y = ff_draw_round_to_sub(&s->draw, 1, 0, y);
783 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
788 /* top right: draw clock hands */
789 if (s->w >= 64 && s->h >= 64) {
790 int l = (FFMIN(s->w, s->h) - 32) >> 1;
791 int steps = FFMAX(4, l >> 5);
792 int xc = (s->w >> 2) + (s->w >> 1);
793 int yc = (s->h >> 2);
798 for (c = 0; c < 3; c++) {
799 set_color(s, &color, (0xBBBBBB ^ (0xFF << (c << 3))) | alpha);
800 pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle;
801 xh = pos < 1 * l ? pos :
803 pos < 3 * l ? 3 * l - pos : 0;
804 yh = pos < 1 * l ? 0 :
805 pos < 2 * l ? pos - l :
810 for (i = 1; i <= steps; i++) {
811 int x = av_rescale(xh, i, steps) + xc;
812 int y = av_rescale(yh, i, steps) + yc;
813 x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
814 y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
815 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
821 /* bottom left: beating rectangles */
822 if (s->w >= 64 && s->h >= 64) {
823 int l = (FFMIN(s->w, s->h) - 16) >> 2;
825 int xc = (s->w >> 2);
826 int yc = (s->h >> 2) + (s->h >> 1);
827 int xm1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 8);
828 int xm2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 8);
829 int ym1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 8);
830 int ym2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 8);
831 int size, step, x1, x2, y1, y2;
833 size = av_rescale_q(s->pts, s->time_base, av_make_q(4, cycle));
838 step = (step >> 1) & 3;
839 set_color(s, &color, 0xFF808080);
840 x1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 4 - size);
841 x2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 4 + size);
842 y1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 4 - size);
843 y2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 4 + size);
844 if (step == 0 || step == 2)
845 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
846 x1, ym1, x2 - x1, ym2 - ym1);
847 if (step == 1 || step == 2)
848 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
849 xm1, y1, xm2 - xm1, y2 - y1);
851 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
852 x1, y1, x2 - x1, y2 - y1);
855 /* bottom right: checker with random noise */
857 unsigned xmin = av_rescale(5, s->w, 8);
858 unsigned xmax = av_rescale(7, s->w, 8);
859 unsigned ymin = av_rescale(5, s->h, 8);
860 unsigned ymax = av_rescale(7, s->h, 8);
865 for (y = ymin; y + 15 < ymax; y += 16) {
866 for (x = xmin; x + 15 < xmax; x += 16) {
869 for (i = 0; i < 256; i++) {
870 r = r * 1664525 + 1013904223;
873 set_color(s, &color, 0xFF00FF80);
874 ff_blend_mask(&s->draw, &color, frame->data, frame->linesize,
875 frame->width, frame->height,
876 alpha, 16, 16, 16, 3, 0, x, y);
881 /* bouncing square */
882 if (s->w >= 16 && s->h >= 16) {
883 unsigned w = s->w - 8;
884 unsigned h = s->h - 8;
885 unsigned x = av_rescale_q(s->pts, s->time_base, av_make_q(233, 55 * w)) % (w << 1);
886 unsigned y = av_rescale_q(s->pts, s->time_base, av_make_q(233, 89 * h)) % (h << 1);
891 x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
892 y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
893 set_color(s, &color, 0xFF8000FF);
894 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
898 /* top right: draw frame time and frame number */
903 time = av_rescale_q(s->pts, s->time_base, av_make_q(1, 1000)) % 86400000;
904 set_color(s, &color, 0xC0000000);
905 ff_blend_rectangle(&s->draw, &color, frame->data, frame->linesize,
906 frame->width, frame->height,
908 set_color(s, &color, 0xFFFF8000);
909 snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%03d\n%12"PRIi64,
910 time / 3600000, (time / 60000) % 60, (time / 1000) % 60,
911 time % 1000, s->pts);
912 draw_text(s, frame, &color, 4, 4, buf);
915 static av_cold int test2_init(AVFilterContext *ctx)
917 TestSourceContext *s = ctx->priv;
919 s->fill_picture_fn = test2_fill_picture;
923 static int test2_query_formats(AVFilterContext *ctx)
925 return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
928 static int test2_config_props(AVFilterLink *inlink)
930 AVFilterContext *ctx = inlink->src;
931 TestSourceContext *s = ctx->priv;
933 av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0);
934 s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
935 s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
936 if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
937 return AVERROR(EINVAL);
938 return config_props(inlink);
941 static const AVFilterPad avfilter_vsrc_testsrc2_outputs[] = {
944 .type = AVMEDIA_TYPE_VIDEO,
945 .config_props = test2_config_props,
950 AVFilter ff_vsrc_testsrc2 = {
952 .description = NULL_IF_CONFIG_SMALL("Generate another test pattern."),
953 .priv_size = sizeof(TestSourceContext),
954 .priv_class = &testsrc2_class,
957 .query_formats = test2_query_formats,
958 .activate = activate,
960 .outputs = avfilter_vsrc_testsrc2_outputs,
963 #endif /* CONFIG_TESTSRC2_FILTER */
965 #if CONFIG_RGBTESTSRC_FILTER
967 static const AVOption rgbtestsrc_options[] = {
969 { "complement", "set complement colors", OFFSET(complement), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
970 { "co", "set complement colors", OFFSET(complement), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
974 AVFILTER_DEFINE_CLASS(rgbtestsrc);
981 static void rgbtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
982 int x, int y, unsigned r, unsigned g, unsigned b, enum AVPixelFormat fmt,
985 uint8_t *dst = dstp[0];
986 int dst_linesize = dst_linesizep[0];
992 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
993 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
994 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
995 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
996 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
997 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
998 case AV_PIX_FMT_RGB24:
999 case AV_PIX_FMT_BGR24:
1000 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
1001 p = dst + 3*x + y*dst_linesize;
1004 case AV_PIX_FMT_RGBA:
1005 case AV_PIX_FMT_BGRA:
1006 case AV_PIX_FMT_ARGB:
1007 case AV_PIX_FMT_ABGR:
1008 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255U << (rgba_map[A]*8));
1009 p = dst + 4*x + y*dst_linesize;
1012 case AV_PIX_FMT_GBRP:
1013 p = dstp[0] + x + y * dst_linesizep[0];
1015 p = dstp[1] + x + y * dst_linesizep[1];
1017 p = dstp[2] + x + y * dst_linesizep[2];
1020 case AV_PIX_FMT_GBRP9:
1021 case AV_PIX_FMT_GBRP10:
1022 case AV_PIX_FMT_GBRP12:
1023 case AV_PIX_FMT_GBRP14:
1024 case AV_PIX_FMT_GBRP16:
1025 p16 = (uint16_t *)(dstp[0] + x*2 + y * dst_linesizep[0]);
1027 p16 = (uint16_t *)(dstp[1] + x*2 + y * dst_linesizep[1]);
1029 p16 = (uint16_t *)(dstp[2] + x*2 + y * dst_linesizep[2]);
1035 static void rgbtest_fill_picture_complement(AVFilterContext *ctx, AVFrame *frame)
1037 TestSourceContext *test = ctx->priv;
1038 int x, y, w = frame->width, h = frame->height;
1040 for (y = 0; y < h; y++) {
1041 for (x = 0; x < w; x++) {
1042 int c = (1 << FFMAX(test->depth, 8))*x/w;
1043 int r = 0, g = 0, b = 0;
1045 if (6*y < h ) r = c;
1046 else if (6*y < 2*h) g = c, b = c;
1047 else if (6*y < 3*h) g = c;
1048 else if (6*y < 4*h) r = c, b = c;
1049 else if (6*y < 5*h) b = c;
1052 rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
1053 ctx->outputs[0]->format, test->rgba_map);
1058 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1060 TestSourceContext *test = ctx->priv;
1061 int x, y, w = frame->width, h = frame->height;
1063 for (y = 0; y < h; y++) {
1064 for (x = 0; x < w; x++) {
1065 int c = (1 << FFMAX(test->depth, 8))*x/w;
1066 int r = 0, g = 0, b = 0;
1068 if (3*y < h ) r = c;
1069 else if (3*y < 2*h) g = c;
1072 rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
1073 ctx->outputs[0]->format, test->rgba_map);
1078 static av_cold int rgbtest_init(AVFilterContext *ctx)
1080 TestSourceContext *test = ctx->priv;
1082 test->draw_once = 1;
1083 test->fill_picture_fn = test->complement ? rgbtest_fill_picture_complement : rgbtest_fill_picture;
1087 static int rgbtest_query_formats(AVFilterContext *ctx)
1089 static const enum AVPixelFormat pix_fmts[] = {
1090 AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
1091 AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
1092 AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
1093 AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
1094 AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
1095 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
1096 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
1100 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1102 return AVERROR(ENOMEM);
1103 return ff_set_common_formats(ctx, fmts_list);
1106 static int rgbtest_config_props(AVFilterLink *outlink)
1108 TestSourceContext *test = outlink->src->priv;
1109 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
1111 test->depth = desc->comp[0].depth;
1112 ff_fill_rgba_map(test->rgba_map, outlink->format);
1113 return config_props(outlink);
1116 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
1119 .type = AVMEDIA_TYPE_VIDEO,
1120 .config_props = rgbtest_config_props,
1125 AVFilter ff_vsrc_rgbtestsrc = {
1126 .name = "rgbtestsrc",
1127 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
1128 .priv_size = sizeof(TestSourceContext),
1129 .priv_class = &rgbtestsrc_class,
1130 .init = rgbtest_init,
1132 .query_formats = rgbtest_query_formats,
1133 .activate = activate,
1135 .outputs = avfilter_vsrc_rgbtestsrc_outputs,
1138 #endif /* CONFIG_RGBTESTSRC_FILTER */
1140 #if CONFIG_YUVTESTSRC_FILTER
1142 #define yuvtestsrc_options options
1143 AVFILTER_DEFINE_CLASS(yuvtestsrc);
1145 static void yuvtest_fill_picture8(AVFilterContext *ctx, AVFrame *frame)
1147 int x, y, w = frame->width, h = frame->height / 3;
1148 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1149 const int factor = 1 << desc->comp[0].depth;
1150 const int mid = 1 << (desc->comp[0].depth - 1);
1151 uint8_t *ydst = frame->data[0];
1152 uint8_t *udst = frame->data[1];
1153 uint8_t *vdst = frame->data[2];
1154 int ylinesize = frame->linesize[0];
1155 int ulinesize = frame->linesize[1];
1156 int vlinesize = frame->linesize[2];
1158 for (y = 0; y < h; y++) {
1159 for (x = 0; x < w; x++) {
1160 int c = factor * x / w;
1173 for (; y < h; y++) {
1174 for (x = 0; x < w; x++) {
1175 int c = factor * x / w;
1187 for (; y < frame->height; y++) {
1188 for (x = 0; x < w; x++) {
1189 int c = factor * x / w;
1202 static void yuvtest_fill_picture16(AVFilterContext *ctx, AVFrame *frame)
1204 int x, y, w = frame->width, h = frame->height / 3;
1205 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1206 const int factor = 1 << desc->comp[0].depth;
1207 const int mid = 1 << (desc->comp[0].depth - 1);
1208 uint16_t *ydst = (uint16_t *)frame->data[0];
1209 uint16_t *udst = (uint16_t *)frame->data[1];
1210 uint16_t *vdst = (uint16_t *)frame->data[2];
1211 int ylinesize = frame->linesize[0] / 2;
1212 int ulinesize = frame->linesize[1] / 2;
1213 int vlinesize = frame->linesize[2] / 2;
1215 for (y = 0; y < h; y++) {
1216 for (x = 0; x < w; x++) {
1217 int c = factor * x / w;
1230 for (; y < h; y++) {
1231 for (x = 0; x < w; x++) {
1232 int c = factor * x / w;
1244 for (; y < frame->height; y++) {
1245 for (x = 0; x < w; x++) {
1246 int c = factor * x / w;
1259 static av_cold int yuvtest_init(AVFilterContext *ctx)
1261 TestSourceContext *test = ctx->priv;
1263 test->draw_once = 1;
1267 static int yuvtest_query_formats(AVFilterContext *ctx)
1269 static const enum AVPixelFormat pix_fmts[] = {
1270 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
1271 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
1272 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14,
1273 AV_PIX_FMT_YUV444P16,
1277 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1279 return AVERROR(ENOMEM);
1280 return ff_set_common_formats(ctx, fmts_list);
1283 static int yuvtest_config_props(AVFilterLink *outlink)
1285 TestSourceContext *test = outlink->src->priv;
1286 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
1288 test->fill_picture_fn = desc->comp[0].depth > 8 ? yuvtest_fill_picture16 : yuvtest_fill_picture8;
1289 return config_props(outlink);
1292 static const AVFilterPad avfilter_vsrc_yuvtestsrc_outputs[] = {
1295 .type = AVMEDIA_TYPE_VIDEO,
1296 .config_props = yuvtest_config_props,
1301 AVFilter ff_vsrc_yuvtestsrc = {
1302 .name = "yuvtestsrc",
1303 .description = NULL_IF_CONFIG_SMALL("Generate YUV test pattern."),
1304 .priv_size = sizeof(TestSourceContext),
1305 .priv_class = &yuvtestsrc_class,
1306 .init = yuvtest_init,
1308 .query_formats = yuvtest_query_formats,
1309 .activate = activate,
1311 .outputs = avfilter_vsrc_yuvtestsrc_outputs,
1314 #endif /* CONFIG_YUVTESTSRC_FILTER */
1316 #if CONFIG_PAL75BARS_FILTER || CONFIG_PAL100BARS_FILTER || CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
1318 static const uint8_t rainbow[7][4] = {
1319 { 180, 128, 128, 255 }, /* 75% white */
1320 { 162, 44, 142, 255 }, /* 75% yellow */
1321 { 131, 156, 44, 255 }, /* 75% cyan */
1322 { 112, 72, 58, 255 }, /* 75% green */
1323 { 84, 184, 198, 255 }, /* 75% magenta */
1324 { 65, 100, 212, 255 }, /* 75% red */
1325 { 35, 212, 114, 255 }, /* 75% blue */
1328 static const uint8_t rainbow100[7][4] = {
1329 { 235, 128, 128, 255 }, /* 100% white */
1330 { 210, 16, 146, 255 }, /* 100% yellow */
1331 { 170, 166, 16, 255 }, /* 100% cyan */
1332 { 145, 54, 34, 255 }, /* 100% green */
1333 { 106, 202, 222, 255 }, /* 100% magenta */
1334 { 81, 90, 240, 255 }, /* 100% red */
1335 { 41, 240, 110, 255 }, /* 100% blue */
1338 static const uint8_t rainbowhd[7][4] = {
1339 { 180, 128, 128, 255 }, /* 75% white */
1340 { 168, 44, 136, 255 }, /* 75% yellow */
1341 { 145, 147, 44, 255 }, /* 75% cyan */
1342 { 133, 63, 52, 255 }, /* 75% green */
1343 { 63, 193, 204, 255 }, /* 75% magenta */
1344 { 51, 109, 212, 255 }, /* 75% red */
1345 { 28, 212, 120, 255 }, /* 75% blue */
1348 static const uint8_t wobnair[7][4] = {
1349 { 35, 212, 114, 255 }, /* 75% blue */
1350 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1351 { 84, 184, 198, 255 }, /* 75% magenta */
1352 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1353 { 131, 156, 44, 255 }, /* 75% cyan */
1354 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1355 { 180, 128, 128, 255 }, /* 75% white */
1358 static const uint8_t white[4] = { 235, 128, 128, 255 };
1361 static const uint8_t neg4ire[4] = { 7, 128, 128, 255 };
1362 static const uint8_t pos4ire[4] = { 24, 128, 128, 255 };
1365 static const uint8_t i_pixel[4] = { 57, 156, 97, 255 };
1366 static const uint8_t q_pixel[4] = { 44, 171, 147, 255 };
1368 static const uint8_t gray40[4] = { 104, 128, 128, 255 };
1369 static const uint8_t gray15[4] = { 49, 128, 128, 255 };
1370 static const uint8_t cyan[4] = { 188, 154, 16, 255 };
1371 static const uint8_t yellow[4] = { 219, 16, 138, 255 };
1372 static const uint8_t blue[4] = { 32, 240, 118, 255 };
1373 static const uint8_t red[4] = { 63, 102, 240, 255 };
1374 static const uint8_t black0[4] = { 16, 128, 128, 255 };
1375 static const uint8_t black2[4] = { 20, 128, 128, 255 };
1376 static const uint8_t black4[4] = { 25, 128, 128, 255 };
1377 static const uint8_t neg2[4] = { 12, 128, 128, 255 };
1379 static void draw_bar(TestSourceContext *test, const uint8_t color[4],
1380 int x, int y, int w, int h,
1383 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1387 x = FFMIN(x, test->w - 1);
1388 y = FFMIN(y, test->h - 1);
1389 w = FFMAX(FFMIN(w, test->w - x), 0);
1390 h = FFMAX(FFMIN(h, test->h - y), 0);
1392 av_assert0(x + w <= test->w);
1393 av_assert0(y + h <= test->h);
1395 for (plane = 0; frame->data[plane]; plane++) {
1396 const int c = color[plane];
1397 const int linesize = frame->linesize[plane];
1398 int i, px, py, pw, ph;
1400 if (plane == 1 || plane == 2) {
1401 px = x >> desc->log2_chroma_w;
1402 pw = AV_CEIL_RSHIFT(w, desc->log2_chroma_w);
1403 py = y >> desc->log2_chroma_h;
1404 ph = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
1412 p0 = p = frame->data[plane] + py * linesize + px;
1415 for (i = 1; i < ph; i++, p += linesize)
1420 static int smptebars_query_formats(AVFilterContext *ctx)
1422 static const enum AVPixelFormat pix_fmts[] = {
1423 AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
1424 AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
1425 AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
1429 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1431 return AVERROR(ENOMEM);
1432 return ff_set_common_formats(ctx, fmts_list);
1435 static const AVFilterPad smptebars_outputs[] = {
1438 .type = AVMEDIA_TYPE_VIDEO,
1439 .config_props = config_props,
1444 #if CONFIG_PAL75BARS_FILTER
1446 #define pal75bars_options options
1447 AVFILTER_DEFINE_CLASS(pal75bars);
1449 static void pal75bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1451 TestSourceContext *test = ctx->priv;
1453 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1455 picref->color_range = AVCOL_RANGE_MPEG;
1456 picref->colorspace = AVCOL_SPC_BT470BG;
1458 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1460 draw_bar(test, white, x, 0, r_w, test->h, picref);
1462 for (i = 1; i < 7; i++) {
1463 draw_bar(test, rainbow[i], x, 0, r_w, test->h, picref);
1466 draw_bar(test, black0, x, 0, r_w, test->h, picref);
1469 static av_cold int pal75bars_init(AVFilterContext *ctx)
1471 TestSourceContext *test = ctx->priv;
1473 test->fill_picture_fn = pal75bars_fill_picture;
1474 test->draw_once = 1;
1478 AVFilter ff_vsrc_pal75bars = {
1479 .name = "pal75bars",
1480 .description = NULL_IF_CONFIG_SMALL("Generate PAL 75% color bars."),
1481 .priv_size = sizeof(TestSourceContext),
1482 .priv_class = &pal75bars_class,
1483 .init = pal75bars_init,
1485 .query_formats = smptebars_query_formats,
1486 .activate = activate,
1488 .outputs = smptebars_outputs,
1491 #endif /* CONFIG_PAL75BARS_FILTER */
1493 #if CONFIG_PAL100BARS_FILTER
1495 #define pal100bars_options options
1496 AVFILTER_DEFINE_CLASS(pal100bars);
1498 static void pal100bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1500 TestSourceContext *test = ctx->priv;
1502 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1504 picref->color_range = AVCOL_RANGE_MPEG;
1505 picref->colorspace = AVCOL_SPC_BT470BG;
1507 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1509 for (i = 0; i < 7; i++) {
1510 draw_bar(test, rainbow100[i], x, 0, r_w, test->h, picref);
1513 draw_bar(test, black0, x, 0, r_w, test->h, picref);
1516 static av_cold int pal100bars_init(AVFilterContext *ctx)
1518 TestSourceContext *test = ctx->priv;
1520 test->fill_picture_fn = pal100bars_fill_picture;
1521 test->draw_once = 1;
1525 AVFilter ff_vsrc_pal100bars = {
1526 .name = "pal100bars",
1527 .description = NULL_IF_CONFIG_SMALL("Generate PAL 100% color bars."),
1528 .priv_size = sizeof(TestSourceContext),
1529 .priv_class = &pal100bars_class,
1530 .init = pal100bars_init,
1532 .query_formats = smptebars_query_formats,
1533 .activate = activate,
1535 .outputs = smptebars_outputs,
1538 #endif /* CONFIG_PAL100BARS_FILTER */
1540 #if CONFIG_SMPTEBARS_FILTER
1542 #define smptebars_options options
1543 AVFILTER_DEFINE_CLASS(smptebars);
1545 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1547 TestSourceContext *test = ctx->priv;
1548 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
1549 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1551 picref->colorspace = AVCOL_SPC_BT470BG;
1553 r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
1554 r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
1555 w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
1556 p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
1557 p_h = test->h - w_h - r_h;
1559 for (i = 0; i < 7; i++) {
1560 draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
1561 draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
1565 draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
1567 draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
1569 draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
1571 tmp = FFALIGN(5 * r_w - x, 1 << pixdesc->log2_chroma_w);
1572 draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1574 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1575 draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
1577 draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1579 draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
1581 draw_bar(test, black0, x, r_h + w_h, test->w - x, p_h, picref);
1584 static av_cold int smptebars_init(AVFilterContext *ctx)
1586 TestSourceContext *test = ctx->priv;
1588 test->fill_picture_fn = smptebars_fill_picture;
1589 test->draw_once = 1;
1593 AVFilter ff_vsrc_smptebars = {
1594 .name = "smptebars",
1595 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
1596 .priv_size = sizeof(TestSourceContext),
1597 .priv_class = &smptebars_class,
1598 .init = smptebars_init,
1600 .query_formats = smptebars_query_formats,
1601 .activate = activate,
1603 .outputs = smptebars_outputs,
1606 #endif /* CONFIG_SMPTEBARS_FILTER */
1608 #if CONFIG_SMPTEHDBARS_FILTER
1610 #define smptehdbars_options options
1611 AVFILTER_DEFINE_CLASS(smptehdbars);
1613 static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1615 TestSourceContext *test = ctx->priv;
1616 int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
1617 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1619 picref->colorspace = AVCOL_SPC_BT709;
1621 d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
1622 r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
1623 draw_bar(test, gray40, x, 0, d_w, r_h, picref);
1626 r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
1627 for (i = 0; i < 7; i++) {
1628 draw_bar(test, rainbowhd[i], x, 0, r_w, r_h, picref);
1631 draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
1633 r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
1634 draw_bar(test, cyan, 0, y, d_w, r_h, picref);
1636 draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
1639 draw_bar(test, rainbowhd[0], x, y, tmp, r_h, picref);
1642 draw_bar(test, blue, x, y, test->w - x, r_h, picref);
1644 draw_bar(test, yellow, 0, y, d_w, r_h, picref);
1646 draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
1649 for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
1650 uint8_t yramp[4] = {0};
1652 yramp[0] = i * 255 / tmp;
1657 draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
1658 x += 1 << pixdesc->log2_chroma_w;
1660 draw_bar(test, red, x, y, test->w - x, r_h, picref);
1662 draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
1664 tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
1665 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1667 tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
1668 draw_bar(test, white, x, y, tmp, test->h - y, picref);
1670 tmp = FFALIGN(r_w * 5 / 6, 1 << pixdesc->log2_chroma_w);
1671 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1673 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1674 draw_bar(test, neg2, x, y, tmp, test->h - y, picref);
1676 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1678 draw_bar(test, black2, x, y, tmp, test->h - y, picref);
1680 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1682 draw_bar(test, black4, x, y, tmp, test->h - y, picref);
1685 draw_bar(test, black0, x, y, r_w, test->h - y, picref);
1687 draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
1690 static av_cold int smptehdbars_init(AVFilterContext *ctx)
1692 TestSourceContext *test = ctx->priv;
1694 test->fill_picture_fn = smptehdbars_fill_picture;
1695 test->draw_once = 1;
1699 AVFilter ff_vsrc_smptehdbars = {
1700 .name = "smptehdbars",
1701 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
1702 .priv_size = sizeof(TestSourceContext),
1703 .priv_class = &smptehdbars_class,
1704 .init = smptehdbars_init,
1706 .query_formats = smptebars_query_formats,
1707 .activate = activate,
1709 .outputs = smptebars_outputs,
1712 #endif /* CONFIG_SMPTEHDBARS_FILTER */
1713 #endif /* CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */
1715 #if CONFIG_ALLYUV_FILTER
1717 #define allyuv_options &options[NOSIZE_OPTIONS_OFFSET]
1718 AVFILTER_DEFINE_CLASS(allyuv);
1720 static void allyuv_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1722 const int ys = frame->linesize[0];
1723 const int us = frame->linesize[1];
1724 const int vs = frame->linesize[2];
1727 for (y = 0; y < 4096; y++) {
1728 for (x = 0; x < 2048; x++) {
1729 frame->data[0][y * ys + x] = ((x / 8) % 256);
1730 frame->data[0][y * ys + 4095 - x] = ((x / 8) % 256);
1733 for (x = 0; x < 2048; x+=8) {
1734 for (j = 0; j < 8; j++) {
1735 frame->data[1][vs * y + x + j] = (y%16 + (j % 8) * 16);
1736 frame->data[1][vs * y + 4095 - x - j] = (128 + y%16 + (j % 8) * 16);
1740 for (x = 0; x < 4096; x++)
1741 frame->data[2][y * us + x] = 256 * y / 4096;
1745 static av_cold int allyuv_init(AVFilterContext *ctx)
1747 TestSourceContext *test = ctx->priv;
1749 test->w = test->h = 4096;
1750 test->draw_once = 1;
1751 test->fill_picture_fn = allyuv_fill_picture;
1755 static int allyuv_query_formats(AVFilterContext *ctx)
1757 static const enum AVPixelFormat pix_fmts[] = {
1758 AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP,
1762 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1764 return AVERROR(ENOMEM);
1765 return ff_set_common_formats(ctx, fmts_list);
1768 static const AVFilterPad avfilter_vsrc_allyuv_outputs[] = {
1771 .type = AVMEDIA_TYPE_VIDEO,
1772 .config_props = config_props,
1777 AVFilter ff_vsrc_allyuv = {
1779 .description = NULL_IF_CONFIG_SMALL("Generate all yuv colors."),
1780 .priv_size = sizeof(TestSourceContext),
1781 .priv_class = &allyuv_class,
1782 .init = allyuv_init,
1784 .query_formats = allyuv_query_formats,
1785 .activate = activate,
1787 .outputs = avfilter_vsrc_allyuv_outputs,
1790 #endif /* CONFIG_ALLYUV_FILTER */
1792 #if CONFIG_ALLRGB_FILTER
1794 #define allrgb_options &options[NOSIZE_OPTIONS_OFFSET]
1795 AVFILTER_DEFINE_CLASS(allrgb);
1797 static void allrgb_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1800 const int linesize = frame->linesize[0];
1801 uint8_t *line = frame->data[0];
1803 for (y = 0; y < 4096; y++) {
1804 uint8_t *dst = line;
1806 for (x = 0; x < 4096; x++) {
1809 *dst++ = (x >> 8) | ((y >> 8) << 4);
1815 static av_cold int allrgb_init(AVFilterContext *ctx)
1817 TestSourceContext *test = ctx->priv;
1819 test->w = test->h = 4096;
1820 test->draw_once = 1;
1821 test->fill_picture_fn = allrgb_fill_picture;
1825 static int allrgb_config_props(AVFilterLink *outlink)
1827 TestSourceContext *test = outlink->src->priv;
1829 ff_fill_rgba_map(test->rgba_map, outlink->format);
1830 return config_props(outlink);
1833 static int allrgb_query_formats(AVFilterContext *ctx)
1835 static const enum AVPixelFormat pix_fmts[] = {
1836 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
1839 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1841 return AVERROR(ENOMEM);
1842 return ff_set_common_formats(ctx, fmts_list);
1845 static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
1848 .type = AVMEDIA_TYPE_VIDEO,
1849 .config_props = allrgb_config_props,
1854 AVFilter ff_vsrc_allrgb = {
1856 .description = NULL_IF_CONFIG_SMALL("Generate all RGB colors."),
1857 .priv_size = sizeof(TestSourceContext),
1858 .priv_class = &allrgb_class,
1859 .init = allrgb_init,
1861 .query_formats = allrgb_query_formats,
1862 .activate = activate,
1864 .outputs = avfilter_vsrc_allrgb_outputs,
1867 #endif /* CONFIG_ALLRGB_FILTER */