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/opt.h"
41 #include "libavutil/imgutils.h"
42 #include "libavutil/intreadwrite.h"
43 #include "libavutil/parseutils.h"
44 #include "libavutil/xga_font_data.h"
46 #include "drawutils.h"
51 typedef struct TestSourceContext {
54 unsigned int nb_frame;
55 AVRational time_base, frame_rate;
57 int64_t duration; ///< duration expressed in microseconds
58 AVRational sar; ///< sample aspect ratio
59 int draw_once; ///< draw only the first frame, always put out the same picture
60 int draw_once_reset; ///< draw only the first frame or in case of reset
61 AVFrame *picref; ///< cached reference containing the painted picture
63 void (* fill_picture_fn)(AVFilterContext *ctx, AVFrame *frame);
65 /* only used by testsrc */
68 /* only used by color */
71 uint8_t color_rgba[4];
73 /* only used by rgbtest */
76 /* only used by haldclut */
80 #define OFFSET(x) offsetof(TestSourceContext, x)
81 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
83 #define SIZE_OPTIONS \
84 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
85 { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
87 #define COMMON_OPTIONS_NOSIZE \
88 { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },\
89 { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },\
90 { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
91 { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
92 { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
94 #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
96 static const AVOption options[] = {
101 static av_cold int init(AVFilterContext *ctx)
103 TestSourceContext *test = ctx->priv;
105 test->time_base = av_inv_q(test->frame_rate);
109 av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
110 test->w, test->h, test->frame_rate.num, test->frame_rate.den,
111 test->duration < 0 ? -1 : (double)test->duration/1000000,
112 test->sar.num, test->sar.den);
116 static av_cold void uninit(AVFilterContext *ctx)
118 TestSourceContext *test = ctx->priv;
120 av_frame_free(&test->picref);
123 static int config_props(AVFilterLink *outlink)
125 TestSourceContext *test = outlink->src->priv;
127 outlink->w = test->w;
128 outlink->h = test->h;
129 outlink->sample_aspect_ratio = test->sar;
130 outlink->frame_rate = test->frame_rate;
131 outlink->time_base = test->time_base;
136 static int request_frame(AVFilterLink *outlink)
138 TestSourceContext *test = outlink->src->priv;
141 if (test->duration >= 0 &&
142 av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration)
145 if (test->draw_once) {
146 if (test->draw_once_reset) {
147 av_frame_free(&test->picref);
148 test->draw_once_reset = 0;
152 ff_get_video_buffer(outlink, test->w, test->h);
154 return AVERROR(ENOMEM);
155 test->fill_picture_fn(outlink->src, test->picref);
157 frame = av_frame_clone(test->picref);
159 frame = ff_get_video_buffer(outlink, test->w, test->h);
162 return AVERROR(ENOMEM);
163 frame->pts = test->pts;
164 frame->key_frame = 1;
165 frame->interlaced_frame = 0;
166 frame->pict_type = AV_PICTURE_TYPE_I;
167 frame->sample_aspect_ratio = test->sar;
168 if (!test->draw_once)
169 test->fill_picture_fn(outlink->src, frame);
174 return ff_filter_frame(outlink, frame);
177 #if CONFIG_COLOR_FILTER
179 static const AVOption color_options[] = {
180 { "color", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
181 { "c", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, FLAGS },
186 AVFILTER_DEFINE_CLASS(color);
188 static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
190 TestSourceContext *test = ctx->priv;
191 ff_fill_rectangle(&test->draw, &test->color,
192 picref->data, picref->linesize,
193 0, 0, test->w, test->h);
196 static av_cold int color_init(AVFilterContext *ctx)
198 TestSourceContext *test = ctx->priv;
199 test->fill_picture_fn = color_fill_picture;
204 static int color_query_formats(AVFilterContext *ctx)
206 return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
209 static int color_config_props(AVFilterLink *inlink)
211 AVFilterContext *ctx = inlink->src;
212 TestSourceContext *test = ctx->priv;
215 ff_draw_init(&test->draw, inlink->format, 0);
216 ff_draw_color(&test->draw, &test->color, test->color_rgba);
218 test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
219 test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
220 if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
221 return AVERROR(EINVAL);
223 if ((ret = config_props(inlink)) < 0)
229 static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
230 char *res, int res_len, int flags)
232 TestSourceContext *test = ctx->priv;
235 if (!strcmp(cmd, "color") || !strcmp(cmd, "c")) {
236 uint8_t color_rgba[4];
238 ret = av_parse_color(color_rgba, args, -1, ctx);
242 memcpy(test->color_rgba, color_rgba, sizeof(color_rgba));
243 ff_draw_color(&test->draw, &test->color, test->color_rgba);
244 test->draw_once_reset = 1;
248 return AVERROR(ENOSYS);
251 static const AVFilterPad color_outputs[] = {
254 .type = AVMEDIA_TYPE_VIDEO,
255 .request_frame = request_frame,
256 .config_props = color_config_props,
261 AVFilter ff_vsrc_color = {
263 .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
264 .priv_class = &color_class,
265 .priv_size = sizeof(TestSourceContext),
268 .query_formats = color_query_formats,
270 .outputs = color_outputs,
271 .process_command = color_process_command,
274 #endif /* CONFIG_COLOR_FILTER */
276 #if CONFIG_HALDCLUTSRC_FILTER
278 static const AVOption haldclutsrc_options[] = {
279 { "level", "set level", OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 6}, 2, 8, FLAGS },
280 COMMON_OPTIONS_NOSIZE
284 AVFILTER_DEFINE_CLASS(haldclutsrc);
286 static void haldclutsrc_fill_picture(AVFilterContext *ctx, AVFrame *frame)
288 int i, j, k, x = 0, y = 0, is16bit = 0, step;
290 const TestSourceContext *hc = ctx->priv;
291 int level = hc->level;
293 const int w = frame->width;
294 const int h = frame->height;
295 const uint8_t *data = frame->data[0];
296 const int linesize = frame->linesize[0];
297 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
300 av_assert0(w == h && w == level*level*level);
302 ff_fill_rgba_map(rgba_map, frame->format);
304 switch (frame->format) {
305 case AV_PIX_FMT_RGB48:
306 case AV_PIX_FMT_BGR48:
307 case AV_PIX_FMT_RGBA64:
308 case AV_PIX_FMT_BGRA64:
312 case AV_PIX_FMT_RGBA:
313 case AV_PIX_FMT_BGRA:
314 case AV_PIX_FMT_ARGB:
315 case AV_PIX_FMT_ABGR:
320 step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
321 scale = ((float)(1 << (8*(is16bit+1))) - 1) / (level*level - 1);
323 #define LOAD_CLUT(nbits) do { \
324 uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step; \
325 dst[rgba_map[0]] = av_clip_uint##nbits(i * scale); \
326 dst[rgba_map[1]] = av_clip_uint##nbits(j * scale); \
327 dst[rgba_map[2]] = av_clip_uint##nbits(k * scale); \
329 dst[rgba_map[3]] = alpha; \
333 for (k = 0; k < level; k++) {
334 for (j = 0; j < level; j++) {
335 for (i = 0; i < level; i++) {
349 static av_cold int haldclutsrc_init(AVFilterContext *ctx)
351 TestSourceContext *hc = ctx->priv;
352 hc->fill_picture_fn = haldclutsrc_fill_picture;
357 static int haldclutsrc_query_formats(AVFilterContext *ctx)
359 static const enum AVPixelFormat pix_fmts[] = {
360 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
361 AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA,
362 AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR,
363 AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR,
364 AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0,
365 AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48,
366 AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
370 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
372 return AVERROR(ENOMEM);
373 return ff_set_common_formats(ctx, fmts_list);
376 static int haldclutsrc_config_props(AVFilterLink *outlink)
378 AVFilterContext *ctx = outlink->src;
379 TestSourceContext *hc = ctx->priv;
381 hc->w = hc->h = hc->level * hc->level * hc->level;
382 return config_props(outlink);
385 static const AVFilterPad haldclutsrc_outputs[] = {
388 .type = AVMEDIA_TYPE_VIDEO,
389 .request_frame = request_frame,
390 .config_props = haldclutsrc_config_props,
395 AVFilter ff_vsrc_haldclutsrc = {
396 .name = "haldclutsrc",
397 .description = NULL_IF_CONFIG_SMALL("Provide an identity Hald CLUT."),
398 .priv_class = &haldclutsrc_class,
399 .priv_size = sizeof(TestSourceContext),
400 .init = haldclutsrc_init,
402 .query_formats = haldclutsrc_query_formats,
404 .outputs = haldclutsrc_outputs,
406 #endif /* CONFIG_HALDCLUTSRC_FILTER */
408 #if CONFIG_NULLSRC_FILTER
410 #define nullsrc_options options
411 AVFILTER_DEFINE_CLASS(nullsrc);
413 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
415 static av_cold int nullsrc_init(AVFilterContext *ctx)
417 TestSourceContext *test = ctx->priv;
419 test->fill_picture_fn = nullsrc_fill_picture;
423 static const AVFilterPad nullsrc_outputs[] = {
426 .type = AVMEDIA_TYPE_VIDEO,
427 .request_frame = request_frame,
428 .config_props = config_props,
433 AVFilter ff_vsrc_nullsrc = {
435 .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
436 .init = nullsrc_init,
438 .priv_size = sizeof(TestSourceContext),
439 .priv_class = &nullsrc_class,
441 .outputs = nullsrc_outputs,
444 #endif /* CONFIG_NULLSRC_FILTER */
446 #if CONFIG_TESTSRC_FILTER
448 static const AVOption testsrc_options[] = {
450 { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
451 { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
455 AVFILTER_DEFINE_CLASS(testsrc);
458 * Fill a rectangle with value val.
460 * @param val the RGB value to set
461 * @param dst pointer to the destination buffer to fill
462 * @param dst_linesize linesize of destination
463 * @param segment_width width of the segment
464 * @param x horizontal coordinate where to draw the rectangle in the destination buffer
465 * @param y horizontal coordinate where to draw the rectangle in the destination buffer
466 * @param w width of the rectangle to draw, expressed as a number of segment_width units
467 * @param h height of the rectangle to draw, expressed as a number of segment_width units
469 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, int segment_width,
470 int x, int y, int w, int h)
475 dst += segment_width * (step * x + y * dst_linesize);
476 w *= segment_width * step;
478 for (i = 0; i < h; i++) {
484 static void draw_digit(int digit, uint8_t *dst, int dst_linesize,
490 #define LEFT_TOP_VBAR 8
491 #define LEFT_BOT_VBAR 16
492 #define RIGHT_TOP_VBAR 32
493 #define RIGHT_BOT_VBAR 64
497 { 1, 0, 5, 1 }, /* TOP_HBAR */
498 { 1, 6, 5, 1 }, /* MID_HBAR */
499 { 1, 12, 5, 1 }, /* BOT_HBAR */
500 { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
501 { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
502 { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
503 { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
505 static const unsigned char masks[10] = {
506 /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
507 /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
508 /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
509 /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
510 /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
511 /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
512 /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
513 /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
514 /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
515 /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
517 unsigned mask = masks[digit];
520 draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
521 for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
523 draw_rectangle(255, dst, dst_linesize, segment_width,
524 segments[i].x, segments[i].y, segments[i].w, segments[i].h);
527 #define GRADIENT_SIZE (6 * 256)
529 static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
531 TestSourceContext *test = ctx->priv;
534 int color, color_rest;
538 int dquad_x, dquad_y;
539 int grad, dgrad, rgrad, drgrad;
543 uint8_t *data = frame->data[0];
544 int width = frame->width;
545 int height = frame->height;
547 /* draw colored bars and circle */
548 radius = (width + height) / 4;
549 quad0 = width * width / 4 + height * height / 4 - radius * radius;
550 dquad_y = 1 - height;
552 for (y = 0; y < height; y++) {
558 for (x = 0; x < width; x++) {
564 *(p++) = icolor & 1 ? 255 : 0;
565 *(p++) = icolor & 2 ? 255 : 0;
566 *(p++) = icolor & 4 ? 255 : 0;
568 if (color_rest >= width) {
575 p0 += frame->linesize[0];
578 /* draw sliding color line */
579 p0 = p = data + frame->linesize[0] * (height * 3/4);
580 grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
583 dgrad = GRADIENT_SIZE / width;
584 drgrad = GRADIENT_SIZE % width;
585 for (x = 0; x < width; x++) {
587 grad < 256 || grad >= 5 * 256 ? 255 :
588 grad >= 2 * 256 && grad < 4 * 256 ? 0 :
589 grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
591 grad >= 4 * 256 ? 0 :
592 grad >= 1 * 256 && grad < 3 * 256 ? 255 :
593 grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
596 grad >= 3 * 256 && grad < 5 * 256 ? 255 :
597 grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
600 if (rgrad >= GRADIENT_SIZE) {
602 rgrad -= GRADIENT_SIZE;
604 if (grad >= GRADIENT_SIZE)
605 grad -= GRADIENT_SIZE;
608 for (y = height / 8; y > 0; y--) {
609 memcpy(p+frame->linesize[0], p, 3 * width);
610 p += frame->linesize[0];
614 seg_size = width / 80;
615 if (seg_size >= 1 && height >= 13 * seg_size) {
616 int64_t p10decimals = 1;
617 double time = av_q2d(test->time_base) * test->nb_frame *
618 ff_exp10(test->nb_decimals);
622 for (x = 0; x < test->nb_decimals; x++)
625 second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
626 x = width - (width - seg_size * 64) / 2;
627 y = (height - seg_size * 13) / 2;
628 p = data + (x*3 + y * frame->linesize[0]);
629 for (i = 0; i < 8; i++) {
630 p -= 3 * 8 * seg_size;
631 draw_digit(second % 10, p, frame->linesize[0], seg_size);
639 static av_cold int test_init(AVFilterContext *ctx)
641 TestSourceContext *test = ctx->priv;
643 test->fill_picture_fn = test_fill_picture;
647 static int test_query_formats(AVFilterContext *ctx)
649 static const enum AVPixelFormat pix_fmts[] = {
650 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
653 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
655 return AVERROR(ENOMEM);
656 return ff_set_common_formats(ctx, fmts_list);
659 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
662 .type = AVMEDIA_TYPE_VIDEO,
663 .request_frame = request_frame,
664 .config_props = config_props,
669 AVFilter ff_vsrc_testsrc = {
671 .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
672 .priv_size = sizeof(TestSourceContext),
673 .priv_class = &testsrc_class,
676 .query_formats = test_query_formats,
678 .outputs = avfilter_vsrc_testsrc_outputs,
681 #endif /* CONFIG_TESTSRC_FILTER */
683 #if CONFIG_TESTSRC2_FILTER
685 static const AVOption testsrc2_options[] = {
690 AVFILTER_DEFINE_CLASS(testsrc2);
692 static void set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
694 uint8_t rgba[4] = { (argb >> 16) & 0xFF,
697 (argb >> 24) & 0xFF, };
698 ff_draw_color(&s->draw, color, rgba);
701 static uint32_t color_gradient(unsigned index)
703 unsigned si = index & 0xFF, sd = 0xFF - si;
704 switch (index >> 8) {
705 case 0: return 0xFF0000 + (si << 8);
706 case 1: return 0x00FF00 + (sd << 16);
707 case 2: return 0x00FF00 + (si << 0);
708 case 3: return 0x0000FF + (sd << 8);
709 case 4: return 0x0000FF + (si << 16);
710 case 5: return 0xFF0000 + (sd << 0);
715 static void draw_text(TestSourceContext *s, AVFrame *frame, FFDrawColor *color,
716 int x0, int y0, const uint8_t *text)
720 for (; *text; text++) {
726 ff_blend_mask(&s->draw, color, frame->data, frame->linesize,
727 frame->width, frame->height,
728 avpriv_vga16_font + *text * 16, 1, 8, 16, 0, 0, x, y0);
733 static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame)
735 TestSourceContext *s = ctx->priv;
738 /* colored background */
740 unsigned i, x = 0, x2;
743 for (i = 1; i < 7; i++) {
744 x2 = av_rescale(i, s->w, 6);
745 x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2);
746 set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) |
747 ((i & 2) ? 0x00FF00 : 0) |
748 ((i & 4) ? 0x0000FF : 0));
749 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
750 x, 0, x2 - x, frame->height);
755 /* oblique gradient */
756 /* note: too slow if using blending */
758 unsigned x, dx, y0, y, g0, g;
760 dx = ff_draw_round_to_sub(&s->draw, 0, +1, 1);
761 y0 = av_rescale_q(s->pts, s->time_base, av_make_q(2, s->h - 16));
762 g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128));
763 for (x = 0; x < s->w; x += dx) {
764 g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256);
765 set_color(s, &color, color_gradient(g));
766 y = y0 + av_rescale(x, s->h / 2, s->w);
767 y %= 2 * (s->h - 16);
769 y = 2 * (s->h - 16) - y;
770 y = ff_draw_round_to_sub(&s->draw, 1, 0, y);
771 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
776 /* top right: draw clock hands */
777 if (s->w >= 64 && s->h >= 64) {
778 int l = (FFMIN(s->w, s->h) - 32) >> 1;
779 int steps = FFMAX(4, l >> 5);
780 int xc = (s->w >> 2) + (s->w >> 1);
781 int yc = (s->h >> 2);
786 for (c = 0; c < 3; c++) {
787 set_color(s, &color, 0xBBBBBB ^ (0xFF << (c << 3)));
788 pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle;
789 xh = pos < 1 * l ? pos :
791 pos < 3 * l ? 3 * l - pos : 0;
792 yh = pos < 1 * l ? 0 :
793 pos < 2 * l ? pos - l :
798 for (i = 1; i <= steps; i++) {
799 int x = av_rescale(xh, i, steps) + xc;
800 int y = av_rescale(yh, i, steps) + yc;
801 x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
802 y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
803 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
809 /* bottom left: beating rectangles */
810 if (s->w >= 64 && s->h >= 64) {
811 int l = (FFMIN(s->w, s->h) - 16) >> 2;
813 int xc = (s->w >> 2);
814 int yc = (s->h >> 2) + (s->h >> 1);
815 int xm1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 8);
816 int xm2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 8);
817 int ym1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 8);
818 int ym2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 8);
819 int size, step, x1, x2, y1, y2;
821 size = av_rescale_q(s->pts, s->time_base, av_make_q(4, cycle));
826 step = (step >> 1) & 3;
827 set_color(s, &color, 0xFF808080);
828 x1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 4 - size);
829 x2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 4 + size);
830 y1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 4 - size);
831 y2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 4 + size);
832 if (step == 0 || step == 2)
833 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
834 x1, ym1, x2 - x1, ym2 - ym1);
835 if (step == 1 || step == 2)
836 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
837 xm1, y1, xm2 - xm1, y2 - y1);
839 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
840 x1, y1, x2 - x1, y2 - y1);
843 /* bottom right: checker with random noise */
845 unsigned xmin = av_rescale(5, s->w, 8);
846 unsigned xmax = av_rescale(7, s->w, 8);
847 unsigned ymin = av_rescale(5, s->h, 8);
848 unsigned ymax = av_rescale(7, s->h, 8);
853 for (y = ymin; y < ymax - 15; y += 16) {
854 for (x = xmin; x < xmax - 15; x += 16) {
857 for (i = 0; i < 256; i++) {
858 r = r * 1664525 + 1013904223;
861 set_color(s, &color, 0xFF00FF80);
862 ff_blend_mask(&s->draw, &color, frame->data, frame->linesize,
863 frame->width, frame->height,
864 alpha, 16, 16, 16, 3, 0, x, y);
869 /* bouncing square */
870 if (s->w >= 16 && s->h >= 16) {
871 unsigned w = s->w - 8;
872 unsigned h = s->h - 8;
873 unsigned x = av_rescale_q(s->pts, s->time_base, av_make_q(233, 55 * w)) % (w << 1);
874 unsigned y = av_rescale_q(s->pts, s->time_base, av_make_q(233, 89 * h)) % (h << 1);
879 x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
880 y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
881 set_color(s, &color, 0xFF8000FF);
882 ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
886 /* top right: draw frame time and frame number */
891 time = av_rescale_q(s->pts, s->time_base, av_make_q(1, 1000)) % 86400000;
892 set_color(s, &color, 0xC0000000);
893 ff_blend_rectangle(&s->draw, &color, frame->data, frame->linesize,
894 frame->width, frame->height,
896 set_color(s, &color, 0xFFFF8000);
897 snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%03d\n%12"PRIi64,
898 time / 3600000, (time / 60000) % 60, (time / 1000) % 60,
899 time % 1000, s->pts);
900 draw_text(s, frame, &color, 4, 4, buf);
903 static av_cold int test2_init(AVFilterContext *ctx)
905 TestSourceContext *s = ctx->priv;
907 s->fill_picture_fn = test2_fill_picture;
911 static int test2_query_formats(AVFilterContext *ctx)
913 return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
916 static int test2_config_props(AVFilterLink *inlink)
918 AVFilterContext *ctx = inlink->src;
919 TestSourceContext *s = ctx->priv;
921 av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0);
922 s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
923 s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
924 if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
925 return AVERROR(EINVAL);
926 return config_props(inlink);
929 static const AVFilterPad avfilter_vsrc_testsrc2_outputs[] = {
932 .type = AVMEDIA_TYPE_VIDEO,
933 .request_frame = request_frame,
934 .config_props = test2_config_props,
939 AVFilter ff_vsrc_testsrc2 = {
941 .description = NULL_IF_CONFIG_SMALL("Generate another test pattern."),
942 .priv_size = sizeof(TestSourceContext),
943 .priv_class = &testsrc2_class,
946 .query_formats = test2_query_formats,
948 .outputs = avfilter_vsrc_testsrc2_outputs,
951 #endif /* CONFIG_TESTSRC2_FILTER */
953 #if CONFIG_RGBTESTSRC_FILTER
955 #define rgbtestsrc_options options
956 AVFILTER_DEFINE_CLASS(rgbtestsrc);
963 static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize,
964 int x, int y, int r, int g, int b, enum AVPixelFormat fmt,
971 case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
972 case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
973 case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
974 case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
975 case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
976 case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
977 case AV_PIX_FMT_RGB24:
978 case AV_PIX_FMT_BGR24:
979 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
980 p = dst + 3*x + y*dst_linesize;
983 case AV_PIX_FMT_RGBA:
984 case AV_PIX_FMT_BGRA:
985 case AV_PIX_FMT_ARGB:
986 case AV_PIX_FMT_ABGR:
987 v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8));
988 p = dst + 4*x + y*dst_linesize;
994 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
996 TestSourceContext *test = ctx->priv;
997 int x, y, w = frame->width, h = frame->height;
999 for (y = 0; y < h; y++) {
1000 for (x = 0; x < w; x++) {
1002 int r = 0, g = 0, b = 0;
1004 if (3*y < h ) r = c;
1005 else if (3*y < 2*h) g = c;
1008 rgbtest_put_pixel(frame->data[0], frame->linesize[0], x, y, r, g, b,
1009 ctx->outputs[0]->format, test->rgba_map);
1014 static av_cold int rgbtest_init(AVFilterContext *ctx)
1016 TestSourceContext *test = ctx->priv;
1018 test->draw_once = 1;
1019 test->fill_picture_fn = rgbtest_fill_picture;
1023 static int rgbtest_query_formats(AVFilterContext *ctx)
1025 static const enum AVPixelFormat pix_fmts[] = {
1026 AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB, AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
1027 AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
1028 AV_PIX_FMT_RGB444, AV_PIX_FMT_BGR444,
1029 AV_PIX_FMT_RGB565, AV_PIX_FMT_BGR565,
1030 AV_PIX_FMT_RGB555, AV_PIX_FMT_BGR555,
1034 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1036 return AVERROR(ENOMEM);
1037 return ff_set_common_formats(ctx, fmts_list);
1040 static int rgbtest_config_props(AVFilterLink *outlink)
1042 TestSourceContext *test = outlink->src->priv;
1044 ff_fill_rgba_map(test->rgba_map, outlink->format);
1045 return config_props(outlink);
1048 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
1051 .type = AVMEDIA_TYPE_VIDEO,
1052 .request_frame = request_frame,
1053 .config_props = rgbtest_config_props,
1058 AVFilter ff_vsrc_rgbtestsrc = {
1059 .name = "rgbtestsrc",
1060 .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
1061 .priv_size = sizeof(TestSourceContext),
1062 .priv_class = &rgbtestsrc_class,
1063 .init = rgbtest_init,
1065 .query_formats = rgbtest_query_formats,
1067 .outputs = avfilter_vsrc_rgbtestsrc_outputs,
1070 #endif /* CONFIG_RGBTESTSRC_FILTER */
1072 #if CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
1074 static const uint8_t rainbow[7][4] = {
1075 { 180, 128, 128, 255 }, /* 75% white */
1076 { 161, 44, 141, 255 }, /* 75% yellow */
1077 { 131, 156, 44, 255 }, /* 75% cyan */
1078 { 112, 72, 57, 255 }, /* 75% green */
1079 { 83, 183, 198, 255 }, /* 75% magenta */
1080 { 65, 99, 212, 255 }, /* 75% red */
1081 { 34, 212, 114, 255 }, /* 75% blue */
1084 static const uint8_t rainbowhd[7][4] = {
1085 { 180, 128, 128, 255 }, /* 75% white */
1086 { 168, 44, 136, 255 }, /* 75% yellow */
1087 { 145, 147, 44, 255 }, /* 75% cyan */
1088 { 133, 63, 52, 255 }, /* 75% green */
1089 { 63, 193, 204, 255 }, /* 75% magenta */
1090 { 51, 109, 212, 255 }, /* 75% red */
1091 { 28, 212, 120, 255 }, /* 75% blue */
1094 static const uint8_t wobnair[7][4] = {
1095 { 34, 212, 114, 255 }, /* 75% blue */
1096 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1097 { 83, 183, 198, 255 }, /* 75% magenta */
1098 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1099 { 131, 156, 44, 255 }, /* 75% cyan */
1100 { 19, 128, 128, 255 }, /* 7.5% intensity black */
1101 { 180, 128, 128, 255 }, /* 75% white */
1104 static const uint8_t white[4] = { 235, 128, 128, 255 };
1107 static const uint8_t neg4ire[4] = { 7, 128, 128, 255 };
1108 static const uint8_t pos4ire[4] = { 24, 128, 128, 255 };
1111 static const uint8_t i_pixel[4] = { 57, 156, 97, 255 };
1112 static const uint8_t q_pixel[4] = { 44, 171, 147, 255 };
1114 static const uint8_t gray40[4] = { 104, 128, 128, 255 };
1115 static const uint8_t gray15[4] = { 49, 128, 128, 255 };
1116 static const uint8_t cyan[4] = { 188, 154, 16, 255 };
1117 static const uint8_t yellow[4] = { 219, 16, 138, 255 };
1118 static const uint8_t blue[4] = { 32, 240, 118, 255 };
1119 static const uint8_t red[4] = { 63, 102, 240, 255 };
1120 static const uint8_t black0[4] = { 16, 128, 128, 255 };
1121 static const uint8_t black2[4] = { 20, 128, 128, 255 };
1122 static const uint8_t black4[4] = { 25, 128, 128, 255 };
1123 static const uint8_t neg2[4] = { 12, 128, 128, 255 };
1125 static void draw_bar(TestSourceContext *test, const uint8_t color[4],
1126 int x, int y, int w, int h,
1129 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1133 x = FFMIN(x, test->w - 1);
1134 y = FFMIN(y, test->h - 1);
1135 w = FFMIN(w, test->w - x);
1136 h = FFMIN(h, test->h - y);
1138 av_assert0(x + w <= test->w);
1139 av_assert0(y + h <= test->h);
1141 for (plane = 0; frame->data[plane]; plane++) {
1142 const int c = color[plane];
1143 const int linesize = frame->linesize[plane];
1144 int i, px, py, pw, ph;
1146 if (plane == 1 || plane == 2) {
1147 px = x >> desc->log2_chroma_w;
1148 pw = FF_CEIL_RSHIFT(w, desc->log2_chroma_w);
1149 py = y >> desc->log2_chroma_h;
1150 ph = FF_CEIL_RSHIFT(h, desc->log2_chroma_h);
1158 p0 = p = frame->data[plane] + py * linesize + px;
1161 for (i = 1; i < ph; i++, p += linesize)
1166 static int smptebars_query_formats(AVFilterContext *ctx)
1168 static const enum AVPixelFormat pix_fmts[] = {
1169 AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
1170 AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
1171 AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
1175 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1177 return AVERROR(ENOMEM);
1178 return ff_set_common_formats(ctx, fmts_list);
1181 static const AVFilterPad smptebars_outputs[] = {
1184 .type = AVMEDIA_TYPE_VIDEO,
1185 .request_frame = request_frame,
1186 .config_props = config_props,
1191 #if CONFIG_SMPTEBARS_FILTER
1193 #define smptebars_options options
1194 AVFILTER_DEFINE_CLASS(smptebars);
1196 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1198 TestSourceContext *test = ctx->priv;
1199 int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
1200 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1202 av_frame_set_colorspace(picref, AVCOL_SPC_BT470BG);
1204 r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
1205 r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
1206 w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
1207 p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
1208 p_h = test->h - w_h - r_h;
1210 for (i = 0; i < 7; i++) {
1211 draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
1212 draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
1216 draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
1218 draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
1220 draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
1222 tmp = FFALIGN(5 * r_w - x, 1 << pixdesc->log2_chroma_w);
1223 draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1225 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1226 draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
1228 draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1230 draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
1232 draw_bar(test, black0, x, r_h + w_h, test->w - x, p_h, picref);
1235 static av_cold int smptebars_init(AVFilterContext *ctx)
1237 TestSourceContext *test = ctx->priv;
1239 test->fill_picture_fn = smptebars_fill_picture;
1240 test->draw_once = 1;
1244 AVFilter ff_vsrc_smptebars = {
1245 .name = "smptebars",
1246 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
1247 .priv_size = sizeof(TestSourceContext),
1248 .priv_class = &smptebars_class,
1249 .init = smptebars_init,
1251 .query_formats = smptebars_query_formats,
1253 .outputs = smptebars_outputs,
1256 #endif /* CONFIG_SMPTEBARS_FILTER */
1258 #if CONFIG_SMPTEHDBARS_FILTER
1260 #define smptehdbars_options options
1261 AVFILTER_DEFINE_CLASS(smptehdbars);
1263 static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1265 TestSourceContext *test = ctx->priv;
1266 int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
1267 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1269 av_frame_set_colorspace(picref, AVCOL_SPC_BT709);
1271 d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
1272 r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
1273 draw_bar(test, gray40, x, 0, d_w, r_h, picref);
1276 r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
1277 for (i = 0; i < 7; i++) {
1278 draw_bar(test, rainbowhd[i], x, 0, r_w, r_h, picref);
1281 draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
1283 r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
1284 draw_bar(test, cyan, 0, y, d_w, r_h, picref);
1286 draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
1289 draw_bar(test, rainbowhd[0], x, y, tmp, r_h, picref);
1292 draw_bar(test, blue, x, y, test->w - x, r_h, picref);
1294 draw_bar(test, yellow, 0, y, d_w, r_h, picref);
1296 draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
1299 for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
1300 uint8_t yramp[4] = {0};
1302 yramp[0] = i * 255 / tmp;
1307 draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
1308 x += 1 << pixdesc->log2_chroma_w;
1310 draw_bar(test, red, x, y, test->w - x, r_h, picref);
1312 draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
1314 tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
1315 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1317 tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
1318 draw_bar(test, white, x, y, tmp, test->h - y, picref);
1320 tmp = FFALIGN(r_w * 5 / 6, 1 << pixdesc->log2_chroma_w);
1321 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1323 tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1324 draw_bar(test, neg2, x, y, tmp, test->h - y, picref);
1326 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1328 draw_bar(test, black2, x, y, tmp, test->h - y, picref);
1330 draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1332 draw_bar(test, black4, x, y, tmp, test->h - y, picref);
1335 draw_bar(test, black0, x, y, r_w, test->h - y, picref);
1337 draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
1340 static av_cold int smptehdbars_init(AVFilterContext *ctx)
1342 TestSourceContext *test = ctx->priv;
1344 test->fill_picture_fn = smptehdbars_fill_picture;
1345 test->draw_once = 1;
1349 AVFilter ff_vsrc_smptehdbars = {
1350 .name = "smptehdbars",
1351 .description = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
1352 .priv_size = sizeof(TestSourceContext),
1353 .priv_class = &smptehdbars_class,
1354 .init = smptehdbars_init,
1356 .query_formats = smptebars_query_formats,
1358 .outputs = smptebars_outputs,
1361 #endif /* CONFIG_SMPTEHDBARS_FILTER */
1362 #endif /* CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */
1364 #if CONFIG_ALLYUV_FILTER
1366 static const AVOption allyuv_options[] = {
1367 COMMON_OPTIONS_NOSIZE
1371 AVFILTER_DEFINE_CLASS(allyuv);
1373 static void allyuv_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1375 const int ys = frame->linesize[0];
1376 const int us = frame->linesize[1];
1377 const int vs = frame->linesize[2];
1380 for (y = 0; y < 4096; y++) {
1381 for (x = 0; x < 2048; x++) {
1382 frame->data[0][y * ys + x] = ((x / 8) % 256);
1383 frame->data[0][y * ys + 4095 - x] = ((x / 8) % 256);
1386 for (x = 0; x < 2048; x+=8) {
1387 for (j = 0; j < 8; j++) {
1388 frame->data[1][vs * y + x + j] = (y%16 + (j % 8) * 16);
1389 frame->data[1][vs * y + 4095 - x - j] = (128 + y%16 + (j % 8) * 16);
1393 for (x = 0; x < 4096; x++)
1394 frame->data[2][y * us + x] = 256 * y / 4096;
1398 static av_cold int allyuv_init(AVFilterContext *ctx)
1400 TestSourceContext *test = ctx->priv;
1402 test->w = test->h = 4096;
1403 test->draw_once = 1;
1404 test->fill_picture_fn = allyuv_fill_picture;
1408 static int allyuv_query_formats(AVFilterContext *ctx)
1410 static const enum AVPixelFormat pix_fmts[] = {
1411 AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP,
1415 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1417 return AVERROR(ENOMEM);
1418 return ff_set_common_formats(ctx, fmts_list);
1421 static const AVFilterPad avfilter_vsrc_allyuv_outputs[] = {
1424 .type = AVMEDIA_TYPE_VIDEO,
1425 .request_frame = request_frame,
1426 .config_props = config_props,
1431 AVFilter ff_vsrc_allyuv = {
1433 .description = NULL_IF_CONFIG_SMALL("Generate all yuv colors."),
1434 .priv_size = sizeof(TestSourceContext),
1435 .priv_class = &allyuv_class,
1436 .init = allyuv_init,
1438 .query_formats = allyuv_query_formats,
1440 .outputs = avfilter_vsrc_allyuv_outputs,
1443 #endif /* CONFIG_ALLYUV_FILTER */
1445 #if CONFIG_ALLRGB_FILTER
1447 static const AVOption allrgb_options[] = {
1448 COMMON_OPTIONS_NOSIZE
1452 AVFILTER_DEFINE_CLASS(allrgb);
1454 static void allrgb_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1457 const int linesize = frame->linesize[0];
1458 uint8_t *line = frame->data[0];
1460 for (y = 0; y < 4096; y++) {
1461 uint8_t *dst = line;
1463 for (x = 0; x < 4096; x++) {
1466 *dst++ = (x >> 8) | ((y >> 8) << 4);
1472 static av_cold int allrgb_init(AVFilterContext *ctx)
1474 TestSourceContext *test = ctx->priv;
1476 test->w = test->h = 4096;
1477 test->draw_once = 1;
1478 test->fill_picture_fn = allrgb_fill_picture;
1482 static int allrgb_config_props(AVFilterLink *outlink)
1484 TestSourceContext *test = outlink->src->priv;
1486 ff_fill_rgba_map(test->rgba_map, outlink->format);
1487 return config_props(outlink);
1490 static int allrgb_query_formats(AVFilterContext *ctx)
1492 static const enum AVPixelFormat pix_fmts[] = {
1493 AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
1496 AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
1498 return AVERROR(ENOMEM);
1499 return ff_set_common_formats(ctx, fmts_list);
1502 static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
1505 .type = AVMEDIA_TYPE_VIDEO,
1506 .request_frame = request_frame,
1507 .config_props = allrgb_config_props,
1512 AVFilter ff_vsrc_allrgb = {
1514 .description = NULL_IF_CONFIG_SMALL("Generate all RGB colors."),
1515 .priv_size = sizeof(TestSourceContext),
1516 .priv_class = &allrgb_class,
1517 .init = allrgb_init,
1519 .query_formats = allrgb_query_formats,
1521 .outputs = avfilter_vsrc_allrgb_outputs,
1524 #endif /* CONFIG_ALLRGB_FILTER */