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 */
82 /* only used by haldclut */
86 #define OFFSET(x) offsetof(TestSourceContext, x)
87 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
88 #define FLAGSR AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
90 #define SIZE_OPTIONS \
91 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
92 { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
94 #define COMMON_OPTIONS_NOSIZE \
95 { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
96 { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
97 { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
98 { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
99 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
101 #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
103 #define NOSIZE_OPTIONS_OFFSET 2
104 /* Filters using COMMON_OPTIONS_NOSIZE also use the following options
105 * via &options[NOSIZE_OPTIONS_OFFSET]. So don't break it. */
106 static const AVOption options[] = {
111 static av_cold int init(AVFilterContext *ctx)
113 TestSourceContext *test = ctx->priv;
115 test->time_base = av_inv_q(test->frame_rate);
119 av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
120 test->w, test->h, test->frame_rate.num, test->frame_rate.den,
121 test->duration < 0 ? -1 : (double)test->duration/1000000,
122 test->sar.num, test->sar.den);
126 static av_cold void uninit(AVFilterContext *ctx)
128 TestSourceContext *test = ctx->priv;
130 av_frame_free(&test->picref);
133 static int config_props(AVFilterLink *outlink)
135 TestSourceContext *test = outlink->src->priv;
137 outlink->w = test->w;
138 outlink->h = test->h;
139 outlink->sample_aspect_ratio = test->sar;
140 outlink->frame_rate = test->frame_rate;
141 outlink->time_base = test->time_base;
146 static int activate(AVFilterContext *ctx)
148 AVFilterLink *outlink = ctx->outputs[0];
149 TestSourceContext *test = ctx->priv;
152 if (!ff_outlink_frame_wanted(outlink))
153 return FFERROR_NOT_READY;
154 if (test->duration >= 0 &&
155 av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration) {
156 ff_outlink_set_status(outlink, AVERROR_EOF, test->pts);
160 if (test->draw_once) {
161 if (test->draw_once_reset) {
162 av_frame_free(&test->picref);
163 test->draw_once_reset = 0;
167 ff_get_video_buffer(outlink, test->w, test->h);
169 return AVERROR(ENOMEM);
170 test->fill_picture_fn(outlink->src, test->picref);
172 frame = av_frame_clone(test->picref);
174 frame = ff_get_video_buffer(outlink, test->w, test->h);
177 return AVERROR(ENOMEM);
178 frame->pts = test->pts;
179 frame->key_frame = 1;
180 frame->interlaced_frame = 0;
181 frame->pict_type = AV_PICTURE_TYPE_I;
182 frame->sample_aspect_ratio = test->sar;
183 if (!test->draw_once)
184 test->fill_picture_fn(outlink->src, frame);
189 return ff_filter_frame(outlink, frame);
192 #if CONFIG_COLOR_FILTER
194 static const AVOption color_options[] = {
195 { "color", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGSR },
196 { "c", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGSR },
201 AVFILTER_DEFINE_CLASS(color);
203 static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
205 TestSourceContext *test = ctx->priv;
206 ff_fill_rectangle(&test->draw, &test->color,
207 picref->data, picref->linesize,
208 0, 0, test->w, test->h);
211 static av_cold int color_init(AVFilterContext *ctx)
213 TestSourceContext *test = ctx->priv;
214 test->fill_picture_fn = color_fill_picture;
219 static int color_query_formats(AVFilterContext *ctx)
221 return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
224 static int color_config_props(AVFilterLink *inlink)
226 AVFilterContext *ctx = inlink->src;
227 TestSourceContext *test = ctx->priv;
230 ff_draw_init(&test->draw, inlink->format, 0);
231 ff_draw_color(&test->draw, &test->color, test->color_rgba);
233 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
234 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
235 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
236 return AVERROR(EINVAL);
238 if ((ret = config_props(inlink)) < 0)
244 static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
245 char *res, int res_len, int flags)
247 TestSourceContext *test = ctx->priv;
250 ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
254 ff_draw_color(&test->draw, &test->color, test->color_rgba);
255 test->draw_once_reset = 1;
259 static const AVFilterPad color_outputs[] = {
262 .type = AVMEDIA_TYPE_VIDEO,
263 .config_props = color_config_props,
268 AVFilter ff_vsrc_color = {
270 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
271 .priv_class = &color_class,
272 .priv_size = sizeof(TestSourceContext),
275 .activate = activate,
276 .query_formats = color_query_formats,
278 .outputs = color_outputs,
279 .process_command = color_process_command,
282 #endif /* CONFIG_COLOR_FILTER */
284 #if CONFIG_HALDCLUTSRC_FILTER
286 static const AVOption haldclutsrc_options[] = {
287 { "level", "set level", OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 6}, 2, 16, FLAGS },
288 COMMON_OPTIONS_NOSIZE
292 AVFILTER_DEFINE_CLASS(haldclutsrc);
294 static void haldclutsrc_fill_picture(AVFilterContext *ctx, AVFrame *frame)
296 int i, j, k, x = 0, y = 0, is16bit = 0, step;
298 const TestSourceContext *hc = ctx->priv;
299 int level = hc->level;
301 const int w = frame->width;
302 const int h = frame->height;
303 const uint8_t *data = frame->data[0];
304 const int linesize = frame->linesize[0];
305 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
308 av_assert0(w == h && w == level*level*level);
310 ff_fill_rgba_map(rgba_map, frame->format);
312 switch (frame->format) {
313 case AV_PIX_FMT_RGB48:
314 case AV_PIX_FMT_BGR48:
315 case AV_PIX_FMT_RGBA64:
316 case AV_PIX_FMT_BGRA64:
320 case AV_PIX_FMT_RGBA:
321 case AV_PIX_FMT_BGRA:
322 case AV_PIX_FMT_ARGB:
323 case AV_PIX_FMT_ABGR:
328 step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
329 scale = ((float)(1 << (8*(is16bit+1))) - 1) / (level*level - 1);
331 #define LOAD_CLUT(nbits) do { \
332 uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step; \
333 dst[rgba_map[0]] = av_clip_uint##nbits(i * scale); \
334 dst[rgba_map[1]] = av_clip_uint##nbits(j * scale); \
335 dst[rgba_map[2]] = av_clip_uint##nbits(k * scale); \
337 dst[rgba_map[3]] = alpha; \
341 for (k = 0; k < level; k++) {
342 for (j = 0; j < level; j++) {
343 for (i = 0; i < level; i++) {
357 static av_cold int haldclutsrc_init(AVFilterContext *ctx)
359 TestSourceContext *hc = ctx->priv;
360 hc->fill_picture_fn = haldclutsrc_fill_picture;
365 static int haldclutsrc_query_formats(AVFilterContext *ctx)
367 static const enum AVPixelFormat pix_fmts[] = {
368 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
369 AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA,
370 AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR,
371 AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR,
372 AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0,
373 AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48,
374 AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
378 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
380 return AVERROR(ENOMEM);
381 return ff_set_common_formats(ctx, fmts_list);
384 static int haldclutsrc_config_props(AVFilterLink *outlink)
386 AVFilterContext *ctx = outlink->src;
387 TestSourceContext *hc = ctx->priv;
389 hc->w = hc->h = hc->level * hc->level * hc->level;
390 return config_props(outlink);
393 static const AVFilterPad haldclutsrc_outputs[] = {
396 .type = AVMEDIA_TYPE_VIDEO,
397 .config_props = haldclutsrc_config_props,
402 AVFilter ff_vsrc_haldclutsrc = {
403 .name = "haldclutsrc",
404 .description = NULL_IF_CONFIG_SMALL("Provide an identity Hald CLUT."),
405 .priv_class = &haldclutsrc_class,
406 .priv_size = sizeof(TestSourceContext),
407 .init = haldclutsrc_init,
409 .query_formats = haldclutsrc_query_formats,
410 .activate = activate,
412 .outputs = haldclutsrc_outputs,
414 #endif /* CONFIG_HALDCLUTSRC_FILTER */
416 #if CONFIG_NULLSRC_FILTER
418 #define nullsrc_options options
419 AVFILTER_DEFINE_CLASS(nullsrc);
421 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
423 static av_cold int nullsrc_init(AVFilterContext *ctx)
425 TestSourceContext *test = ctx->priv;
427 test->fill_picture_fn = nullsrc_fill_picture;
431 static const AVFilterPad nullsrc_outputs[] = {
434 .type = AVMEDIA_TYPE_VIDEO,
435 .config_props = config_props,
440 AVFilter ff_vsrc_nullsrc = {
442 .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
443 .init = nullsrc_init,
445 .activate = activate,
446 .priv_size = sizeof(TestSourceContext),
447 .priv_class = &nullsrc_class,
449 .outputs = nullsrc_outputs,
452 #endif /* CONFIG_NULLSRC_FILTER */
454 #if CONFIG_TESTSRC_FILTER
456 static const AVOption testsrc_options[] = {
458 { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
459 { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
463 AVFILTER_DEFINE_CLASS(testsrc);
466 * Fill a rectangle with value val.
468 * @param val the RGB value to set
469 * @param dst pointer to the destination buffer to fill
470 * @param dst_linesize linesize of destination
471 * @param segment_width width of the segment
472 * @param x horizontal coordinate where to draw the rectangle in the destination buffer
473 * @param y horizontal coordinate where to draw the rectangle in the destination buffer
474 * @param w width of the rectangle to draw, expressed as a number of segment_width units
475 * @param h height of the rectangle to draw, expressed as a number of segment_width units
477 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, int segment_width,
478 int x, int y, int w, int h)
483 dst += segment_width * (step * x + y * dst_linesize);
484 w *= segment_width * step;
486 for (i = 0; i < h; i++) {
492 static void draw_digit(int digit, uint8_t *dst, int dst_linesize,
498 #define LEFT_TOP_VBAR 8
499 #define LEFT_BOT_VBAR 16
500 #define RIGHT_TOP_VBAR 32
501 #define RIGHT_BOT_VBAR 64
505 { 1, 0, 5, 1 }, /* TOP_HBAR */
506 { 1, 6, 5, 1 }, /* MID_HBAR */
507 { 1, 12, 5, 1 }, /* BOT_HBAR */
508 { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
509 { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
510 { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
511 { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
513 static const unsigned char masks[10] = {
514 /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
515 /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
516 /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
517 /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
518 /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
519 /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
520 /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
521 /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
522 /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
523 /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
525 unsigned mask = masks[digit];
528 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
529 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
531 draw_rectangle(255, dst, dst_linesize, segment_width,
532 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
535 #define GRADIENT_SIZE (6 * 256)
537 static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
539 TestSourceContext *test = ctx->priv;
542 int color, color_rest;
546 int dquad_x, dquad_y;
547 int grad, dgrad, rgrad, drgrad;
551 uint8_t *data = frame->data[0];
552 int width = frame->width;
553 int height = frame->height;
555 /* draw colored bars and circle */
556 radius = (width + height) / 4;
557 quad0 = width * width / 4 + height * height / 4 - radius * radius;
558 dquad_y = 1 - height;
560 for (y = 0; y < height; y++) {
566 for (x = 0; x < width; x++) {
572 *(p++) = icolor & 1 ? 255 : 0;
573 *(p++) = icolor & 2 ? 255 : 0;
574 *(p++) = icolor & 4 ? 255 : 0;
576 if (color_rest >= width) {
583 p0 += frame->linesize[0];
586 /* draw sliding color line */
587 p0 = p = data + frame->linesize[0] * (height * 3/4);
588 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
591 dgrad = GRADIENT_SIZE / width;
592 drgrad = GRADIENT_SIZE % width;
593 for (x = 0; x < width; x++) {
595 grad < 256 || grad >= 5 * 256 ? 255 :
596 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
597 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
599 grad >= 4 * 256 ? 0 :
600 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
601 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
604 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
605 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
608 if (rgrad >= GRADIENT_SIZE) {
610 rgrad -= GRADIENT_SIZE;
612 if (grad >= GRADIENT_SIZE)
613 grad -= GRADIENT_SIZE;
616 for (y = height / 8; y > 0; y--) {
617 memcpy(p+frame->linesize[0], p, 3 * width);
618 p += frame->linesize[0];
622 seg_size = width / 80;
623 if (seg_size >= 1 && height >= 13 * seg_size) {
624 int64_t p10decimals = 1;
625 double time = av_q2d(test->time_base) * test->nb_frame *
626 ff_exp10(test->nb_decimals);
630 for (x = 0; x < test->nb_decimals; x++)
633 second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
634 x = width - (width - seg_size * 64) / 2;
635 y = (height - seg_size * 13) / 2;
636 p = data + (x*3 + y * frame->linesize[0]);
637 for (i = 0; i < 8; i++) {
638 p -= 3 * 8 * seg_size;
639 draw_digit(second % 10, p, frame->linesize[0], seg_size);
647 static av_cold int test_init(AVFilterContext *ctx)
649 TestSourceContext *test = ctx->priv;
651 test->fill_picture_fn = test_fill_picture;
655 static int test_query_formats(AVFilterContext *ctx)
657 static const enum AVPixelFormat pix_fmts[] = {
658 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
661 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
663 return AVERROR(ENOMEM);
664 return ff_set_common_formats(ctx, fmts_list);
667 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
670 .type = AVMEDIA_TYPE_VIDEO,
671 .config_props = config_props,
676 AVFilter ff_vsrc_testsrc = {
678 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
679 .priv_size = sizeof(TestSourceContext),
680 .priv_class = &testsrc_class,
683 .query_formats = test_query_formats,
684 .activate = activate,
686 .outputs = avfilter_vsrc_testsrc_outputs,
689 #endif /* CONFIG_TESTSRC_FILTER */
691 #if CONFIG_TESTSRC2_FILTER
693 static const AVOption testsrc2_options[] = {
695 { "alpha", "set global alpha (opacity)", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 255}, 0, 255, FLAGS },
699 AVFILTER_DEFINE_CLASS(testsrc2);
701 static void set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
703 uint8_t rgba[4] = { (argb >> 16) & 0xFF,
706 (argb >> 24) & 0xFF, };
707 ff_draw_color(&s->draw, color, rgba);
710 static uint32_t color_gradient(unsigned index)
712 unsigned si = index & 0xFF, sd = 0xFF - si;
713 switch (index >> 8) {
714 case 0: return 0xFF0000 + (si << 8);
715 case 1: return 0x00FF00 + (sd << 16);
716 case 2: return 0x00FF00 + (si << 0);
717 case 3: return 0x0000FF + (sd << 8);
718 case 4: return 0x0000FF + (si << 16);
719 case 5: return 0xFF0000 + (sd << 0);
724 static void draw_text(TestSourceContext *s, AVFrame *frame, FFDrawColor *color,
725 int x0, int y0, const uint8_t *text)
729 for (; *text; text++) {
735 ff_blend_mask(&s->draw, color, frame->data, frame->linesize,
736 frame->width, frame->height,
737 avpriv_vga16_font + *text * 16, 1, 8, 16, 0, 0, x, y0);
742 static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame)
744 TestSourceContext *s = ctx->priv;
746 unsigned alpha = (uint32_t)s->alpha << 24;
748 /* colored background */
750 unsigned i, x = 0, x2;
753 for (i = 1; i < 7; i++) {
754 x2 = av_rescale(i, s->w, 6);
755 x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2);
756 set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) |
757 ((i & 2) ? 0x00FF00 : 0) |
758 ((i & 4) ? 0x0000FF : 0) |
760 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
761 x, 0, x2 - x, frame->height);
766 /* oblique gradient */
767 /* note: too slow if using blending */
769 unsigned x, dx, y0, y, g0, g;
771 dx = ff_draw_round_to_sub(&s->draw, 0, +1, 1);
772 y0 = av_rescale_q(s->pts, s->time_base, av_make_q(2, s->h - 16));
773 g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128));
774 for (x = 0; x < s->w; x += dx) {
775 g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256);
776 set_color(s, &color, color_gradient(g) | alpha);
777 y = y0 + av_rescale(x, s->h / 2, s->w);
778 y %= 2 * (s->h - 16);
780 y = 2 * (s->h - 16) - y;
781 y = ff_draw_round_to_sub(&s->draw, 1, 0, y);
782 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
787 /* top right: draw clock hands */
788 if (s->w >= 64 && s->h >= 64) {
789 int l = (FFMIN(s->w, s->h) - 32) >> 1;
790 int steps = FFMAX(4, l >> 5);
791 int xc = (s->w >> 2) + (s->w >> 1);
792 int yc = (s->h >> 2);
797 for (c = 0; c < 3; c++) {
798 set_color(s, &color, (0xBBBBBB ^ (0xFF << (c << 3))) | alpha);
799 pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle;
800 xh = pos < 1 * l ? pos :
802 pos < 3 * l ? 3 * l - pos : 0;
803 yh = pos < 1 * l ? 0 :
804 pos < 2 * l ? pos - l :
809 for (i = 1; i <= steps; i++) {
810 int x = av_rescale(xh, i, steps) + xc;
811 int y = av_rescale(yh, i, steps) + yc;
812 x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
813 y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
814 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
820 /* bottom left: beating rectangles */
821 if (s->w >= 64 && s->h >= 64) {
822 int l = (FFMIN(s->w, s->h) - 16) >> 2;
824 int xc = (s->w >> 2);
825 int yc = (s->h >> 2) + (s->h >> 1);
826 int xm1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 8);
827 int xm2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 8);
828 int ym1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 8);
829 int ym2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 8);
830 int size, step, x1, x2, y1, y2;
832 size = av_rescale_q(s->pts, s->time_base, av_make_q(4, cycle));
837 step = (step >> 1) & 3;
838 set_color(s, &color, 0xFF808080);
839 x1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 4 - size);
840 x2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 4 + size);
841 y1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 4 - size);
842 y2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 4 + size);
843 if (step == 0 || step == 2)
844 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
845 x1, ym1, x2 - x1, ym2 - ym1);
846 if (step == 1 || step == 2)
847 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
848 xm1, y1, xm2 - xm1, y2 - y1);
850 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
851 x1, y1, x2 - x1, y2 - y1);
854 /* bottom right: checker with random noise */
856 unsigned xmin = av_rescale(5, s->w, 8);
857 unsigned xmax = av_rescale(7, s->w, 8);
858 unsigned ymin = av_rescale(5, s->h, 8);
859 unsigned ymax = av_rescale(7, s->h, 8);
864 for (y = ymin; y + 15 < ymax; y += 16) {
865 for (x = xmin; x + 15 < xmax; x += 16) {
868 for (i = 0; i < 256; i++) {
869 r = r * 1664525 + 1013904223;
872 set_color(s, &color, 0xFF00FF80);
873 ff_blend_mask(&s->draw, &color, frame->data, frame->linesize,
874 frame->width, frame->height,
875 alpha, 16, 16, 16, 3, 0, x, y);
880 /* bouncing square */
881 if (s->w >= 16 && s->h >= 16) {
882 unsigned w = s->w - 8;
883 unsigned h = s->h - 8;
884 unsigned x = av_rescale_q(s->pts, s->time_base, av_make_q(233, 55 * w)) % (w << 1);
885 unsigned y = av_rescale_q(s->pts, s->time_base, av_make_q(233, 89 * h)) % (h << 1);
890 x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
891 y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
892 set_color(s, &color, 0xFF8000FF);
893 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
897 /* top right: draw frame time and frame number */
902 time = av_rescale_q(s->pts, s->time_base, av_make_q(1, 1000)) % 86400000;
903 set_color(s, &color, 0xC0000000);
904 ff_blend_rectangle(&s->draw, &color, frame->data, frame->linesize,
905 frame->width, frame->height,
907 set_color(s, &color, 0xFFFF8000);
908 snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%03d\n%12"PRIi64,
909 time / 3600000, (time / 60000) % 60, (time / 1000) % 60,
910 time % 1000, s->pts);
911 draw_text(s, frame, &color, 4, 4, buf);
914 static av_cold int test2_init(AVFilterContext *ctx)
916 TestSourceContext *s = ctx->priv;
918 s->fill_picture_fn = test2_fill_picture;
922 static int test2_query_formats(AVFilterContext *ctx)
924 return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
927 static int test2_config_props(AVFilterLink *inlink)
929 AVFilterContext *ctx = inlink->src;
930 TestSourceContext *s = ctx->priv;
932 av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0);
933 s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
934 s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
935 if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
936 return AVERROR(EINVAL);
937 return config_props(inlink);
940 static const AVFilterPad avfilter_vsrc_testsrc2_outputs[] = {
943 .type = AVMEDIA_TYPE_VIDEO,
944 .config_props = test2_config_props,
949 AVFilter ff_vsrc_testsrc2 = {
951 .description = NULL_IF_CONFIG_SMALL("Generate another test pattern."),
952 .priv_size = sizeof(TestSourceContext),
953 .priv_class = &testsrc2_class,
956 .query_formats = test2_query_formats,
957 .activate = activate,
959 .outputs = avfilter_vsrc_testsrc2_outputs,
962 #endif /* CONFIG_TESTSRC2_FILTER */
964 #if CONFIG_RGBTESTSRC_FILTER
966 #define rgbtestsrc_options options
967 AVFILTER_DEFINE_CLASS(rgbtestsrc);
974 static void rgbtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
975 int x, int y, unsigned r, unsigned g, unsigned b, enum AVPixelFormat fmt,
978 uint8_t *dst = dstp[0];
979 int dst_linesize = dst_linesizep[0];
985 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
986 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
987 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
988 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
989 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
990 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
991 case AV_PIX_FMT_RGB24:
992 case AV_PIX_FMT_BGR24:
993 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
994 p = dst + 3*x + y*dst_linesize;
997 case AV_PIX_FMT_RGBA:
998 case AV_PIX_FMT_BGRA:
999 case AV_PIX_FMT_ARGB:
1000 case AV_PIX_FMT_ABGR:
1001 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255U << (rgba_map[A]*8));
1002 p = dst + 4*x + y*dst_linesize;
1005 case AV_PIX_FMT_GBRP:
1006 p = dstp[0] + x + y * dst_linesizep[0];
1008 p = dstp[1] + x + y * dst_linesizep[1];
1010 p = dstp[2] + x + y * dst_linesizep[2];
1012 case AV_PIX_FMT_GBRP9:
1013 case AV_PIX_FMT_GBRP10:
1014 case AV_PIX_FMT_GBRP12:
1015 case AV_PIX_FMT_GBRP14:
1016 case AV_PIX_FMT_GBRP16:
1017 p16 = (uint16_t *)(dstp[0] + x*2 + y * dst_linesizep[0]);
1019 p16 = (uint16_t *)(dstp[1] + x*2 + y * dst_linesizep[1]);
1021 p16 = (uint16_t *)(dstp[2] + x*2 + y * dst_linesizep[2]);
1027 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1029 TestSourceContext *test = ctx->priv;
1030 int x, y, w = frame->width, h = frame->height;
1032 for (y = 0; y < h; y++) {
1033 for (x = 0; x < w; x++) {
1034 int c = (1 << FFMAX(test->depth, 8))*x/w;
1035 int r = 0, g = 0, b = 0;
1037 if (3*y < h ) r = c;
1038 else if (3*y < 2*h) g = c;
1041 rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
1042 ctx->outputs[0]->format, test->rgba_map);
1047 static av_cold int rgbtest_init(AVFilterContext *ctx)
1049 TestSourceContext *test = ctx->priv;
1051 test->draw_once = 1;
1052 test->fill_picture_fn = rgbtest_fill_picture;
1056 static int rgbtest_query_formats(AVFilterContext *ctx)
1058 static const enum AVPixelFormat pix_fmts[] = {
1059 AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
1060 AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
1061 AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
1062 AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
1063 AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
1064 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
1065 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
1069 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1071 return AVERROR(ENOMEM);
1072 return ff_set_common_formats(ctx, fmts_list);
1075 static int rgbtest_config_props(AVFilterLink *outlink)
1077 TestSourceContext *test = outlink->src->priv;
1078 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
1080 test->depth = desc->comp[0].depth;
1081 ff_fill_rgba_map(test->rgba_map, outlink->format);
1082 return config_props(outlink);
1085 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
1088 .type = AVMEDIA_TYPE_VIDEO,
1089 .config_props = rgbtest_config_props,
1094 AVFilter ff_vsrc_rgbtestsrc = {
1095 .name = "rgbtestsrc",
1096 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
1097 .priv_size = sizeof(TestSourceContext),
1098 .priv_class = &rgbtestsrc_class,
1099 .init = rgbtest_init,
1101 .query_formats = rgbtest_query_formats,
1102 .activate = activate,
1104 .outputs = avfilter_vsrc_rgbtestsrc_outputs,
1107 #endif /* CONFIG_RGBTESTSRC_FILTER */
1109 #if CONFIG_YUVTESTSRC_FILTER
1111 #define yuvtestsrc_options options
1112 AVFILTER_DEFINE_CLASS(yuvtestsrc);
1114 static void yuvtest_fill_picture8(AVFilterContext *ctx, AVFrame *frame)
1116 int x, y, w = frame->width, h = frame->height / 3;
1117 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1118 const int factor = 1 << desc->comp[0].depth;
1119 const int mid = 1 << (desc->comp[0].depth - 1);
1120 uint8_t *ydst = frame->data[0];
1121 uint8_t *udst = frame->data[1];
1122 uint8_t *vdst = frame->data[2];
1123 int ylinesize = frame->linesize[0];
1124 int ulinesize = frame->linesize[1];
1125 int vlinesize = frame->linesize[2];
1127 for (y = 0; y < h; y++) {
1128 for (x = 0; x < w; x++) {
1129 int c = factor * x / w;
1142 for (; y < h; y++) {
1143 for (x = 0; x < w; x++) {
1144 int c = factor * x / w;
1156 for (; y < frame->height; y++) {
1157 for (x = 0; x < w; x++) {
1158 int c = factor * x / w;
1171 static void yuvtest_fill_picture16(AVFilterContext *ctx, AVFrame *frame)
1173 int x, y, w = frame->width, h = frame->height / 3;
1174 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1175 const int factor = 1 << desc->comp[0].depth;
1176 const int mid = 1 << (desc->comp[0].depth - 1);
1177 uint16_t *ydst = (uint16_t *)frame->data[0];
1178 uint16_t *udst = (uint16_t *)frame->data[1];
1179 uint16_t *vdst = (uint16_t *)frame->data[2];
1180 int ylinesize = frame->linesize[0] / 2;
1181 int ulinesize = frame->linesize[1] / 2;
1182 int vlinesize = frame->linesize[2] / 2;
1184 for (y = 0; y < h; y++) {
1185 for (x = 0; x < w; x++) {
1186 int c = factor * x / w;
1199 for (; y < h; y++) {
1200 for (x = 0; x < w; x++) {
1201 int c = factor * x / w;
1213 for (; y < frame->height; y++) {
1214 for (x = 0; x < w; x++) {
1215 int c = factor * x / w;
1228 static av_cold int yuvtest_init(AVFilterContext *ctx)
1230 TestSourceContext *test = ctx->priv;
1232 test->draw_once = 1;
1236 static int yuvtest_query_formats(AVFilterContext *ctx)
1238 static const enum AVPixelFormat pix_fmts[] = {
1239 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
1240 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
1241 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14,
1242 AV_PIX_FMT_YUV444P16,
1246 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1248 return AVERROR(ENOMEM);
1249 return ff_set_common_formats(ctx, fmts_list);
1252 static int yuvtest_config_props(AVFilterLink *outlink)
1254 TestSourceContext *test = outlink->src->priv;
1255 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
1257 test->fill_picture_fn = desc->comp[0].depth > 8 ? yuvtest_fill_picture16 : yuvtest_fill_picture8;
1258 return config_props(outlink);
1261 static const AVFilterPad avfilter_vsrc_yuvtestsrc_outputs[] = {
1264 .type = AVMEDIA_TYPE_VIDEO,
1265 .config_props = yuvtest_config_props,
1270 AVFilter ff_vsrc_yuvtestsrc = {
1271 .name = "yuvtestsrc",
1272 .description = NULL_IF_CONFIG_SMALL("Generate YUV test pattern."),
1273 .priv_size = sizeof(TestSourceContext),
1274 .priv_class = &yuvtestsrc_class,
1275 .init = yuvtest_init,
1277 .query_formats = yuvtest_query_formats,
1278 .activate = activate,
1280 .outputs = avfilter_vsrc_yuvtestsrc_outputs,
1283 #endif /* CONFIG_YUVTESTSRC_FILTER */
1285 #if CONFIG_PAL75BARS_FILTER || CONFIG_PAL100BARS_FILTER || CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
1287 static const uint8_t rainbow[7][4] = {
1288 { 180, 128, 128, 255 }, /* 75% white */
1289 { 162, 44, 142, 255 }, /* 75% yellow */
1290 { 131, 156, 44, 255 }, /* 75% cyan */
1291 { 112, 72, 58, 255 }, /* 75% green */
1292 { 84, 184, 198, 255 }, /* 75% magenta */
1293 { 65, 100, 212, 255 }, /* 75% red */
1294 { 35, 212, 114, 255 }, /* 75% blue */
1297 static const uint8_t rainbow100[7][4] = {
1298 { 235, 128, 128, 255 }, /* 100% white */
1299 { 210, 16, 146, 255 }, /* 100% yellow */
1300 { 170, 166, 16, 255 }, /* 100% cyan */
1301 { 145, 54, 34, 255 }, /* 100% green */
1302 { 106, 202, 222, 255 }, /* 100% magenta */
1303 { 81, 90, 240, 255 }, /* 100% red */
1304 { 41, 240, 110, 255 }, /* 100% blue */
1307 static const uint8_t rainbowhd[7][4] = {
1308 { 180, 128, 128, 255 }, /* 75% white */
1309 { 168, 44, 136, 255 }, /* 75% yellow */
1310 { 145, 147, 44, 255 }, /* 75% cyan */
1311 { 133, 63, 52, 255 }, /* 75% green */
1312 { 63, 193, 204, 255 }, /* 75% magenta */
1313 { 51, 109, 212, 255 }, /* 75% red */
1314 { 28, 212, 120, 255 }, /* 75% blue */
1317 static const uint8_t wobnair[7][4] = {
1318 { 35, 212, 114, 255 }, /* 75% blue */
1319 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1320 { 84, 184, 198, 255 }, /* 75% magenta */
1321 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1322 { 131, 156, 44, 255 }, /* 75% cyan */
1323 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1324 { 180, 128, 128, 255 }, /* 75% white */
1327 static const uint8_t white[4] = { 235, 128, 128, 255 };
1330 static const uint8_t neg4ire[4] = { 7, 128, 128, 255 };
1331 static const uint8_t pos4ire[4] = { 24, 128, 128, 255 };
1334 static const uint8_t i_pixel[4] = { 57, 156, 97, 255 };
1335 static const uint8_t q_pixel[4] = { 44, 171, 147, 255 };
1337 static const uint8_t gray40[4] = { 104, 128, 128, 255 };
1338 static const uint8_t gray15[4] = { 49, 128, 128, 255 };
1339 static const uint8_t cyan[4] = { 188, 154, 16, 255 };
1340 static const uint8_t yellow[4] = { 219, 16, 138, 255 };
1341 static const uint8_t blue[4] = { 32, 240, 118, 255 };
1342 static const uint8_t red[4] = { 63, 102, 240, 255 };
1343 static const uint8_t black0[4] = { 16, 128, 128, 255 };
1344 static const uint8_t black2[4] = { 20, 128, 128, 255 };
1345 static const uint8_t black4[4] = { 25, 128, 128, 255 };
1346 static const uint8_t neg2[4] = { 12, 128, 128, 255 };
1348 static void draw_bar(TestSourceContext *test, const uint8_t color[4],
1349 int x, int y, int w, int h,
1352 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1356 x = FFMIN(x, test->w - 1);
1357 y = FFMIN(y, test->h - 1);
1358 w = FFMAX(FFMIN(w, test->w - x), 0);
1359 h = FFMAX(FFMIN(h, test->h - y), 0);
1361 av_assert0(x + w <= test->w);
1362 av_assert0(y + h <= test->h);
1364 for (plane = 0; frame->data[plane]; plane++) {
1365 const int c = color[plane];
1366 const int linesize = frame->linesize[plane];
1367 int i, px, py, pw, ph;
1369 if (plane == 1 || plane == 2) {
1370 px = x >> desc->log2_chroma_w;
1371 pw = AV_CEIL_RSHIFT(w, desc->log2_chroma_w);
1372 py = y >> desc->log2_chroma_h;
1373 ph = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
1381 p0 = p = frame->data[plane] + py * linesize + px;
1384 for (i = 1; i < ph; i++, p += linesize)
1389 static int smptebars_query_formats(AVFilterContext *ctx)
1391 static const enum AVPixelFormat pix_fmts[] = {
1392 AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
1393 AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
1394 AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
1398 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1400 return AVERROR(ENOMEM);
1401 return ff_set_common_formats(ctx, fmts_list);
1404 static const AVFilterPad smptebars_outputs[] = {
1407 .type = AVMEDIA_TYPE_VIDEO,
1408 .config_props = config_props,
1413 #if CONFIG_PAL75BARS_FILTER
1415 #define pal75bars_options options
1416 AVFILTER_DEFINE_CLASS(pal75bars);
1418 static void pal75bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1420 TestSourceContext *test = ctx->priv;
1422 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1424 picref->color_range = AVCOL_RANGE_MPEG;
1425 picref->colorspace = AVCOL_SPC_BT470BG;
1427 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1429 draw_bar(test, white, x, 0, r_w, test->h, picref);
1431 for (i = 1; i < 7; i++) {
1432 draw_bar(test, rainbow[i], x, 0, r_w, test->h, picref);
1435 draw_bar(test, black0, x, 0, r_w, test->h, picref);
1438 static av_cold int pal75bars_init(AVFilterContext *ctx)
1440 TestSourceContext *test = ctx->priv;
1442 test->fill_picture_fn = pal75bars_fill_picture;
1443 test->draw_once = 1;
1447 AVFilter ff_vsrc_pal75bars = {
1448 .name = "pal75bars",
1449 .description = NULL_IF_CONFIG_SMALL("Generate PAL 75% color bars."),
1450 .priv_size = sizeof(TestSourceContext),
1451 .priv_class = &pal75bars_class,
1452 .init = pal75bars_init,
1454 .query_formats = smptebars_query_formats,
1455 .activate = activate,
1457 .outputs = smptebars_outputs,
1460 #endif /* CONFIG_PAL75BARS_FILTER */
1462 #if CONFIG_PAL100BARS_FILTER
1464 #define pal100bars_options options
1465 AVFILTER_DEFINE_CLASS(pal100bars);
1467 static void pal100bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1469 TestSourceContext *test = ctx->priv;
1471 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1473 picref->color_range = AVCOL_RANGE_MPEG;
1474 picref->colorspace = AVCOL_SPC_BT470BG;
1476 r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1478 for (i = 0; i < 7; i++) {
1479 draw_bar(test, rainbow100[i], x, 0, r_w, test->h, picref);
1482 draw_bar(test, black0, x, 0, r_w, test->h, picref);
1485 static av_cold int pal100bars_init(AVFilterContext *ctx)
1487 TestSourceContext *test = ctx->priv;
1489 test->fill_picture_fn = pal100bars_fill_picture;
1490 test->draw_once = 1;
1494 AVFilter ff_vsrc_pal100bars = {
1495 .name = "pal100bars",
1496 .description = NULL_IF_CONFIG_SMALL("Generate PAL 100% color bars."),
1497 .priv_size = sizeof(TestSourceContext),
1498 .priv_class = &pal100bars_class,
1499 .init = pal100bars_init,
1501 .query_formats = smptebars_query_formats,
1502 .activate = activate,
1504 .outputs = smptebars_outputs,
1507 #endif /* CONFIG_PAL100BARS_FILTER */
1509 #if CONFIG_SMPTEBARS_FILTER
1511 #define smptebars_options options
1512 AVFILTER_DEFINE_CLASS(smptebars);
1514 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1516 TestSourceContext *test = ctx->priv;
1517 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
1518 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1520 picref->colorspace = AVCOL_SPC_BT470BG;
1522 r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
1523 r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
1524 w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
1525 p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
1526 p_h = test->h - w_h - r_h;
1528 for (i = 0; i < 7; i++) {
1529 draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
1530 draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
1534 draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
1536 draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
1538 draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
1540 tmp = FFALIGN(5 * r_w - x, 1 << pixdesc->log2_chroma_w);
1541 draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1543 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1544 draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
1546 draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1548 draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
1550 draw_bar(test, black0, x, r_h + w_h, test->w - x, p_h, picref);
1553 static av_cold int smptebars_init(AVFilterContext *ctx)
1555 TestSourceContext *test = ctx->priv;
1557 test->fill_picture_fn = smptebars_fill_picture;
1558 test->draw_once = 1;
1562 AVFilter ff_vsrc_smptebars = {
1563 .name = "smptebars",
1564 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
1565 .priv_size = sizeof(TestSourceContext),
1566 .priv_class = &smptebars_class,
1567 .init = smptebars_init,
1569 .query_formats = smptebars_query_formats,
1570 .activate = activate,
1572 .outputs = smptebars_outputs,
1575 #endif /* CONFIG_SMPTEBARS_FILTER */
1577 #if CONFIG_SMPTEHDBARS_FILTER
1579 #define smptehdbars_options options
1580 AVFILTER_DEFINE_CLASS(smptehdbars);
1582 static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1584 TestSourceContext *test = ctx->priv;
1585 int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
1586 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1588 picref->colorspace = AVCOL_SPC_BT709;
1590 d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
1591 r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
1592 draw_bar(test, gray40, x, 0, d_w, r_h, picref);
1595 r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
1596 for (i = 0; i < 7; i++) {
1597 draw_bar(test, rainbowhd[i], x, 0, r_w, r_h, picref);
1600 draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
1602 r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
1603 draw_bar(test, cyan, 0, y, d_w, r_h, picref);
1605 draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
1608 draw_bar(test, rainbowhd[0], x, y, tmp, r_h, picref);
1611 draw_bar(test, blue, x, y, test->w - x, r_h, picref);
1613 draw_bar(test, yellow, 0, y, d_w, r_h, picref);
1615 draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
1618 for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
1619 uint8_t yramp[4] = {0};
1621 yramp[0] = i * 255 / tmp;
1626 draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
1627 x += 1 << pixdesc->log2_chroma_w;
1629 draw_bar(test, red, x, y, test->w - x, r_h, picref);
1631 draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
1633 tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
1634 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1636 tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
1637 draw_bar(test, white, x, y, tmp, test->h - y, picref);
1639 tmp = FFALIGN(r_w * 5 / 6, 1 << pixdesc->log2_chroma_w);
1640 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1642 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1643 draw_bar(test, neg2, x, y, tmp, test->h - y, picref);
1645 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1647 draw_bar(test, black2, x, y, tmp, test->h - y, picref);
1649 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1651 draw_bar(test, black4, x, y, tmp, test->h - y, picref);
1654 draw_bar(test, black0, x, y, r_w, test->h - y, picref);
1656 draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
1659 static av_cold int smptehdbars_init(AVFilterContext *ctx)
1661 TestSourceContext *test = ctx->priv;
1663 test->fill_picture_fn = smptehdbars_fill_picture;
1664 test->draw_once = 1;
1668 AVFilter ff_vsrc_smptehdbars = {
1669 .name = "smptehdbars",
1670 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
1671 .priv_size = sizeof(TestSourceContext),
1672 .priv_class = &smptehdbars_class,
1673 .init = smptehdbars_init,
1675 .query_formats = smptebars_query_formats,
1676 .activate = activate,
1678 .outputs = smptebars_outputs,
1681 #endif /* CONFIG_SMPTEHDBARS_FILTER */
1682 #endif /* CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */
1684 #if CONFIG_ALLYUV_FILTER
1686 #define allyuv_options &options[NOSIZE_OPTIONS_OFFSET]
1687 AVFILTER_DEFINE_CLASS(allyuv);
1689 static void allyuv_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1691 const int ys = frame->linesize[0];
1692 const int us = frame->linesize[1];
1693 const int vs = frame->linesize[2];
1696 for (y = 0; y < 4096; y++) {
1697 for (x = 0; x < 2048; x++) {
1698 frame->data[0][y * ys + x] = ((x / 8) % 256);
1699 frame->data[0][y * ys + 4095 - x] = ((x / 8) % 256);
1702 for (x = 0; x < 2048; x+=8) {
1703 for (j = 0; j < 8; j++) {
1704 frame->data[1][vs * y + x + j] = (y%16 + (j % 8) * 16);
1705 frame->data[1][vs * y + 4095 - x - j] = (128 + y%16 + (j % 8) * 16);
1709 for (x = 0; x < 4096; x++)
1710 frame->data[2][y * us + x] = 256 * y / 4096;
1714 static av_cold int allyuv_init(AVFilterContext *ctx)
1716 TestSourceContext *test = ctx->priv;
1718 test->w = test->h = 4096;
1719 test->draw_once = 1;
1720 test->fill_picture_fn = allyuv_fill_picture;
1724 static int allyuv_query_formats(AVFilterContext *ctx)
1726 static const enum AVPixelFormat pix_fmts[] = {
1727 AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP,
1731 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1733 return AVERROR(ENOMEM);
1734 return ff_set_common_formats(ctx, fmts_list);
1737 static const AVFilterPad avfilter_vsrc_allyuv_outputs[] = {
1740 .type = AVMEDIA_TYPE_VIDEO,
1741 .config_props = config_props,
1746 AVFilter ff_vsrc_allyuv = {
1748 .description = NULL_IF_CONFIG_SMALL("Generate all yuv colors."),
1749 .priv_size = sizeof(TestSourceContext),
1750 .priv_class = &allyuv_class,
1751 .init = allyuv_init,
1753 .query_formats = allyuv_query_formats,
1754 .activate = activate,
1756 .outputs = avfilter_vsrc_allyuv_outputs,
1759 #endif /* CONFIG_ALLYUV_FILTER */
1761 #if CONFIG_ALLRGB_FILTER
1763 #define allrgb_options &options[NOSIZE_OPTIONS_OFFSET]
1764 AVFILTER_DEFINE_CLASS(allrgb);
1766 static void allrgb_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1769 const int linesize = frame->linesize[0];
1770 uint8_t *line = frame->data[0];
1772 for (y = 0; y < 4096; y++) {
1773 uint8_t *dst = line;
1775 for (x = 0; x < 4096; x++) {
1778 *dst++ = (x >> 8) | ((y >> 8) << 4);
1784 static av_cold int allrgb_init(AVFilterContext *ctx)
1786 TestSourceContext *test = ctx->priv;
1788 test->w = test->h = 4096;
1789 test->draw_once = 1;
1790 test->fill_picture_fn = allrgb_fill_picture;
1794 static int allrgb_config_props(AVFilterLink *outlink)
1796 TestSourceContext *test = outlink->src->priv;
1798 ff_fill_rgba_map(test->rgba_map, outlink->format);
1799 return config_props(outlink);
1802 static int allrgb_query_formats(AVFilterContext *ctx)
1804 static const enum AVPixelFormat pix_fmts[] = {
1805 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
1808 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1810 return AVERROR(ENOMEM);
1811 return ff_set_common_formats(ctx, fmts_list);
1814 static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
1817 .type = AVMEDIA_TYPE_VIDEO,
1818 .config_props = allrgb_config_props,
1823 AVFilter ff_vsrc_allrgb = {
1825 .description = NULL_IF_CONFIG_SMALL("Generate all RGB colors."),
1826 .priv_size = sizeof(TestSourceContext),
1827 .priv_class = &allrgb_class,
1828 .init = allrgb_init,
1830 .query_formats = allrgb_query_formats,
1831 .activate = activate,
1833 .outputs = avfilter_vsrc_allrgb_outputs,
1836 #endif /* CONFIG_ALLRGB_FILTER */