FFmpeg  4.4.9
vsrc_testsrc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Nicolas George <nicolas.george@normalesup.org>
3  * Copyright (c) 2011 Stefano Sabatini
4  * Copyright (c) 2012 Paul B Mahol
5  *
6  * This file is part of FFmpeg.
7  *
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.
12  *
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.
17  *
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
21  */
22 
23 /**
24  * @file
25  * Misc test sources.
26  *
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
29  *
30  * rgbtestsrc is ported from MPlayer libmpcodecs/vf_rgbtest.c by
31  * Michael Niedermayer.
32  *
33  * allyuv, smptebars and smptehdbars are by Paul B Mahol.
34  */
35 
36 #include <float.h>
37 
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"
46 #include "avfilter.h"
47 #include "drawutils.h"
48 #include "filters.h"
49 #include "formats.h"
50 #include "internal.h"
51 #include "video.h"
52 
53 typedef struct TestSourceContext {
54  const AVClass *class;
55  int w, h;
56  unsigned int nb_frame;
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
64 
66 
67  /* only used by testsrc */
69 
70  /* only used by testsrc2 */
71  int alpha;
72 
73  /* only used by color */
77 
78  /* only used by rgbtest */
81  int depth;
82 
83  /* only used by haldclut */
84  int level;
86 
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
90 
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 },\
94 
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 },
101 
102 #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
103 
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[] = {
109  { NULL }
110 };
111 
113 {
114  TestSourceContext *test = ctx->priv;
115 
116  test->time_base = av_inv_q(test->frame_rate);
117  test->nb_frame = 0;
118  test->pts = 0;
119 
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);
124  return 0;
125 }
126 
128 {
129  TestSourceContext *test = ctx->priv;
130 
131  av_frame_free(&test->picref);
132 }
133 
134 static int config_props(AVFilterLink *outlink)
135 {
136  TestSourceContext *test = outlink->src->priv;
137 
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;
143 
144  return 0;
145 }
146 
148 {
149  AVFilterLink *outlink = ctx->outputs[0];
150  TestSourceContext *test = ctx->priv;
151  AVFrame *frame;
152 
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);
158  return 0;
159  }
160 
161  if (test->draw_once) {
162  if (test->draw_once_reset) {
163  av_frame_free(&test->picref);
164  test->draw_once_reset = 0;
165  }
166  if (!test->picref) {
167  test->picref =
168  ff_get_video_buffer(outlink, test->w, test->h);
169  if (!test->picref)
170  return AVERROR(ENOMEM);
171  test->fill_picture_fn(outlink->src, test->picref);
172  }
173  frame = av_frame_clone(test->picref);
174  } else
175  frame = ff_get_video_buffer(outlink, test->w, test->h);
176 
177  if (!frame)
178  return AVERROR(ENOMEM);
179  frame->pts = test->pts;
180  frame->key_frame = 1;
181  frame->interlaced_frame = 0;
184  if (!test->draw_once)
185  test->fill_picture_fn(outlink->src, frame);
186 
187  test->pts++;
188  test->nb_frame++;
189 
190  return ff_filter_frame(outlink, frame);
191 }
192 
193 #if CONFIG_COLOR_FILTER
194 
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 },
199  { NULL }
200 };
201 
203 
204 static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
205 {
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);
210 }
211 
212 static av_cold int color_init(AVFilterContext *ctx)
213 {
214  TestSourceContext *test = ctx->priv;
215  test->fill_picture_fn = color_fill_picture;
216  test->draw_once = 1;
217  return init(ctx);
218 }
219 
220 static int color_query_formats(AVFilterContext *ctx)
221 {
223 }
224 
225 static int color_config_props(AVFilterLink *inlink)
226 {
227  AVFilterContext *ctx = inlink->src;
228  TestSourceContext *test = ctx->priv;
229  int ret;
230 
231  ret = ff_draw_init(&test->draw, inlink->format, 0);
232  if (ret < 0) {
233  av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n");
234  return ret;
235  }
236 
237  ff_draw_color(&test->draw, &test->color, test->color_rgba);
238 
239  test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w);
240  test->h = ff_draw_round_to_sub(&test->draw, 1, -1, test->h);
241  if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
242  return AVERROR(EINVAL);
243 
244  if ((ret = config_props(inlink)) < 0)
245  return ret;
246 
247  return 0;
248 }
249 
250 static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
251  char *res, int res_len, int flags)
252 {
253  TestSourceContext *test = ctx->priv;
254  int ret;
255 
256  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
257  if (ret < 0)
258  return ret;
259 
260  ff_draw_color(&test->draw, &test->color, test->color_rgba);
261  test->draw_once_reset = 1;
262  return 0;
263 }
264 
265 static const AVFilterPad color_outputs[] = {
266  {
267  .name = "default",
268  .type = AVMEDIA_TYPE_VIDEO,
269  .config_props = color_config_props,
270  },
271  { NULL }
272 };
273 
275  .name = "color",
276  .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
277  .priv_class = &color_class,
278  .priv_size = sizeof(TestSourceContext),
279  .init = color_init,
280  .uninit = uninit,
281  .activate = activate,
282  .query_formats = color_query_formats,
283  .inputs = NULL,
284  .outputs = color_outputs,
285  .process_command = color_process_command,
286 };
287 
288 #endif /* CONFIG_COLOR_FILTER */
289 
290 #if CONFIG_HALDCLUTSRC_FILTER
291 
292 static const AVOption haldclutsrc_options[] = {
293  { "level", "set level", OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 6}, 2, 16, FLAGS },
295  { NULL }
296 };
297 
298 AVFILTER_DEFINE_CLASS(haldclutsrc);
299 
300 static void haldclutsrc_fill_picture(AVFilterContext *ctx, AVFrame *frame)
301 {
302  int i, j, k, x = 0, y = 0, is16bit = 0, step;
303  uint32_t alpha = 0;
304  const TestSourceContext *hc = ctx->priv;
305  int level = hc->level;
306  float scale;
307  const int w = frame->width;
308  const int h = frame->height;
309  const uint8_t *data = frame->data[0];
310  const int linesize = frame->linesize[0];
312  uint8_t rgba_map[4];
313 
314  av_assert0(w == h && w == level*level*level);
315 
316  ff_fill_rgba_map(rgba_map, frame->format);
317 
318  switch (frame->format) {
319  case AV_PIX_FMT_RGB48:
320  case AV_PIX_FMT_BGR48:
321  case AV_PIX_FMT_RGBA64:
322  case AV_PIX_FMT_BGRA64:
323  is16bit = 1;
324  alpha = 0xffff;
325  break;
326  case AV_PIX_FMT_RGBA:
327  case AV_PIX_FMT_BGRA:
328  case AV_PIX_FMT_ARGB:
329  case AV_PIX_FMT_ABGR:
330  alpha = 0xff;
331  break;
332  }
333 
334  step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
335  scale = ((float)(1 << (8*(is16bit+1))) - 1) / (level*level - 1);
336 
337 #define LOAD_CLUT(nbits) do { \
338  uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step; \
339  dst[rgba_map[0]] = av_clip_uint##nbits(i * scale); \
340  dst[rgba_map[1]] = av_clip_uint##nbits(j * scale); \
341  dst[rgba_map[2]] = av_clip_uint##nbits(k * scale); \
342  if (step == 4) \
343  dst[rgba_map[3]] = alpha; \
344 } while (0)
345 
346  level *= level;
347  for (k = 0; k < level; k++) {
348  for (j = 0; j < level; j++) {
349  for (i = 0; i < level; i++) {
350  if (!is16bit)
351  LOAD_CLUT(8);
352  else
353  LOAD_CLUT(16);
354  if (++x == w) {
355  x = 0;
356  y++;
357  }
358  }
359  }
360  }
361 }
362 
363 static av_cold int haldclutsrc_init(AVFilterContext *ctx)
364 {
365  TestSourceContext *hc = ctx->priv;
366  hc->fill_picture_fn = haldclutsrc_fill_picture;
367  hc->draw_once = 1;
368  return init(ctx);
369 }
370 
371 static int haldclutsrc_query_formats(AVFilterContext *ctx)
372 {
373  static const enum AVPixelFormat pix_fmts[] = {
382  };
383 
385  if (!fmts_list)
386  return AVERROR(ENOMEM);
387  return ff_set_common_formats(ctx, fmts_list);
388 }
389 
390 static int haldclutsrc_config_props(AVFilterLink *outlink)
391 {
392  AVFilterContext *ctx = outlink->src;
393  TestSourceContext *hc = ctx->priv;
394 
395  hc->w = hc->h = hc->level * hc->level * hc->level;
396  return config_props(outlink);
397 }
398 
399 static const AVFilterPad haldclutsrc_outputs[] = {
400  {
401  .name = "default",
402  .type = AVMEDIA_TYPE_VIDEO,
403  .config_props = haldclutsrc_config_props,
404  },
405  { NULL }
406 };
407 
409  .name = "haldclutsrc",
410  .description = NULL_IF_CONFIG_SMALL("Provide an identity Hald CLUT."),
411  .priv_class = &haldclutsrc_class,
412  .priv_size = sizeof(TestSourceContext),
413  .init = haldclutsrc_init,
414  .uninit = uninit,
415  .query_formats = haldclutsrc_query_formats,
416  .activate = activate,
417  .inputs = NULL,
418  .outputs = haldclutsrc_outputs,
419 };
420 #endif /* CONFIG_HALDCLUTSRC_FILTER */
421 
422 #if CONFIG_NULLSRC_FILTER
423 
424 #define nullsrc_options options
425 AVFILTER_DEFINE_CLASS(nullsrc);
426 
427 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
428 
429 static av_cold int nullsrc_init(AVFilterContext *ctx)
430 {
431  TestSourceContext *test = ctx->priv;
432 
433  test->fill_picture_fn = nullsrc_fill_picture;
434  return init(ctx);
435 }
436 
437 static const AVFilterPad nullsrc_outputs[] = {
438  {
439  .name = "default",
440  .type = AVMEDIA_TYPE_VIDEO,
441  .config_props = config_props,
442  },
443  { NULL },
444 };
445 
447  .name = "nullsrc",
448  .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
449  .init = nullsrc_init,
450  .uninit = uninit,
451  .activate = activate,
452  .priv_size = sizeof(TestSourceContext),
453  .priv_class = &nullsrc_class,
454  .inputs = NULL,
455  .outputs = nullsrc_outputs,
456 };
457 
458 #endif /* CONFIG_NULLSRC_FILTER */
459 
460 #if CONFIG_TESTSRC_FILTER
461 
462 static const AVOption testsrc_options[] = {
464  { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
465  { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
466  { NULL }
467 };
468 
469 AVFILTER_DEFINE_CLASS(testsrc);
470 
471 /**
472  * Fill a rectangle with value val.
473  *
474  * @param val the RGB value to set
475  * @param dst pointer to the destination buffer to fill
476  * @param dst_linesize linesize of destination
477  * @param segment_width width of the segment
478  * @param x horizontal coordinate where to draw the rectangle in the destination buffer
479  * @param y horizontal coordinate where to draw the rectangle in the destination buffer
480  * @param w width of the rectangle to draw, expressed as a number of segment_width units
481  * @param h height of the rectangle to draw, expressed as a number of segment_width units
482  */
483 static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, int segment_width,
484  int x, int y, int w, int h)
485 {
486  int i;
487  int step = 3;
488 
489  dst += segment_width * (step * x + y * dst_linesize);
490  w *= segment_width * step;
491  h *= segment_width;
492  for (i = 0; i < h; i++) {
493  memset(dst, val, w);
494  dst += dst_linesize;
495  }
496 }
497 
498 static void draw_digit(int digit, uint8_t *dst, int dst_linesize,
499  int segment_width)
500 {
501 #define TOP_HBAR 1
502 #define MID_HBAR 2
503 #define BOT_HBAR 4
504 #define LEFT_TOP_VBAR 8
505 #define LEFT_BOT_VBAR 16
506 #define RIGHT_TOP_VBAR 32
507 #define RIGHT_BOT_VBAR 64
508  struct segments {
509  int x, y, w, h;
510  } segments[] = {
511  { 1, 0, 5, 1 }, /* TOP_HBAR */
512  { 1, 6, 5, 1 }, /* MID_HBAR */
513  { 1, 12, 5, 1 }, /* BOT_HBAR */
514  { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
515  { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
516  { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
517  { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
518  };
519  static const unsigned char masks[10] = {
520  /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
521  /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
522  /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
523  /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
524  /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
525  /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
526  /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
527  /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
528  /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
529  /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
530  };
531  unsigned mask = masks[digit];
532  int i;
533 
534  draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
535  for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
536  if (mask & (1<<i))
537  draw_rectangle(255, dst, dst_linesize, segment_width,
538  segments[i].x, segments[i].y, segments[i].w, segments[i].h);
539 }
540 
541 #define GRADIENT_SIZE (6 * 256)
542 
543 static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
544 {
545  TestSourceContext *test = ctx->priv;
546  uint8_t *p, *p0;
547  int x, y;
548  int color, color_rest;
549  int icolor;
550  int radius;
551  int quad0, quad;
552  int dquad_x, dquad_y;
553  int grad, dgrad, rgrad, drgrad;
554  int seg_size;
555  int second;
556  int i;
557  uint8_t *data = frame->data[0];
558  int width = frame->width;
559  int height = frame->height;
560 
561  /* draw colored bars and circle */
562  radius = (width + height) / 4;
563  quad0 = width * width / 4 + height * height / 4 - radius * radius;
564  dquad_y = 1 - height;
565  p0 = data;
566  for (y = 0; y < height; y++) {
567  p = p0;
568  color = 0;
569  color_rest = 0;
570  quad = quad0;
571  dquad_x = 1 - width;
572  for (x = 0; x < width; x++) {
573  icolor = color;
574  if (quad < 0)
575  icolor ^= 7;
576  quad += dquad_x;
577  dquad_x += 2;
578  *(p++) = icolor & 1 ? 255 : 0;
579  *(p++) = icolor & 2 ? 255 : 0;
580  *(p++) = icolor & 4 ? 255 : 0;
581  color_rest += 8;
582  if (color_rest >= width) {
583  color_rest -= width;
584  color++;
585  }
586  }
587  quad0 += dquad_y;
588  dquad_y += 2;
589  p0 += frame->linesize[0];
590  }
591 
592  /* draw sliding color line */
593  p0 = p = data + frame->linesize[0] * (height * 3/4);
594  grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
595  GRADIENT_SIZE;
596  rgrad = 0;
597  dgrad = GRADIENT_SIZE / width;
598  drgrad = GRADIENT_SIZE % width;
599  for (x = 0; x < width; x++) {
600  *(p++) =
601  grad < 256 || grad >= 5 * 256 ? 255 :
602  grad >= 2 * 256 && grad < 4 * 256 ? 0 :
603  grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
604  *(p++) =
605  grad >= 4 * 256 ? 0 :
606  grad >= 1 * 256 && grad < 3 * 256 ? 255 :
607  grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
608  *(p++) =
609  grad < 2 * 256 ? 0 :
610  grad >= 3 * 256 && grad < 5 * 256 ? 255 :
611  grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
612  grad += dgrad;
613  rgrad += drgrad;
614  if (rgrad >= GRADIENT_SIZE) {
615  grad++;
616  rgrad -= GRADIENT_SIZE;
617  }
618  if (grad >= GRADIENT_SIZE)
619  grad -= GRADIENT_SIZE;
620  }
621  p = p0;
622  for (y = height / 8; y > 0; y--) {
623  memcpy(p+frame->linesize[0], p, 3 * width);
624  p += frame->linesize[0];
625  }
626 
627  /* draw digits */
628  seg_size = width / 80;
629  if (seg_size >= 1 && height >= 13 * seg_size) {
630  int64_t p10decimals = 1;
631  double time = av_q2d(test->time_base) * test->nb_frame *
632  ff_exp10(test->nb_decimals);
633  if (time >= INT_MAX)
634  return;
635 
636  for (x = 0; x < test->nb_decimals; x++)
637  p10decimals *= 10;
638 
639  second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
640  x = width - (width - seg_size * 64) / 2;
641  y = (height - seg_size * 13) / 2;
642  p = data + (x*3 + y * frame->linesize[0]);
643  for (i = 0; i < 8; i++) {
644  p -= 3 * 8 * seg_size;
645  draw_digit(second % 10, p, frame->linesize[0], seg_size);
646  second /= 10;
647  if (second == 0)
648  break;
649  }
650  }
651 }
652 
653 static av_cold int test_init(AVFilterContext *ctx)
654 {
655  TestSourceContext *test = ctx->priv;
656 
657  test->fill_picture_fn = test_fill_picture;
658  return init(ctx);
659 }
660 
661 static int test_query_formats(AVFilterContext *ctx)
662 {
663  static const enum AVPixelFormat pix_fmts[] = {
665  };
666 
668  if (!fmts_list)
669  return AVERROR(ENOMEM);
670  return ff_set_common_formats(ctx, fmts_list);
671 }
672 
673 static const AVFilterPad avfilter_vsrc_testsrc_outputs[] = {
674  {
675  .name = "default",
676  .type = AVMEDIA_TYPE_VIDEO,
677  .config_props = config_props,
678  },
679  { NULL }
680 };
681 
683  .name = "testsrc",
684  .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
685  .priv_size = sizeof(TestSourceContext),
686  .priv_class = &testsrc_class,
687  .init = test_init,
688  .uninit = uninit,
689  .query_formats = test_query_formats,
690  .activate = activate,
691  .inputs = NULL,
692  .outputs = avfilter_vsrc_testsrc_outputs,
693 };
694 
695 #endif /* CONFIG_TESTSRC_FILTER */
696 
697 static void av_unused set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
698 {
699  uint8_t rgba[4] = { (argb >> 16) & 0xFF,
700  (argb >> 8) & 0xFF,
701  (argb >> 0) & 0xFF,
702  (argb >> 24) & 0xFF, };
703  ff_draw_color(&s->draw, color, rgba);
704 }
705 
706 #if CONFIG_TESTSRC2_FILTER
707 
708 static const AVOption testsrc2_options[] = {
710  { "alpha", "set global alpha (opacity)", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 255}, 0, 255, FLAGS },
711  { NULL }
712 };
713 
714 AVFILTER_DEFINE_CLASS(testsrc2);
715 
716 static uint32_t color_gradient(unsigned index)
717 {
718  unsigned si = index & 0xFF, sd = 0xFF - si;
719  switch (index >> 8) {
720  case 0: return 0xFF0000 + (si << 8);
721  case 1: return 0x00FF00 + (sd << 16);
722  case 2: return 0x00FF00 + (si << 0);
723  case 3: return 0x0000FF + (sd << 8);
724  case 4: return 0x0000FF + (si << 16);
725  case 5: return 0xFF0000 + (sd << 0);
726  }
727  av_assert0(0);
728 }
729 
731  int x0, int y0, const uint8_t *text)
732 {
733  int x = x0;
734 
735  for (; *text; text++) {
736  if (*text == '\n') {
737  x = x0;
738  y0 += 16;
739  continue;
740  }
742  frame->width, frame->height,
743  avpriv_vga16_font + *text * 16, 1, 8, 16, 0, 0, x, y0);
744  x += 8;
745  }
746 }
747 
748 static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame)
749 {
750  TestSourceContext *s = ctx->priv;
752  unsigned alpha = (uint32_t)s->alpha << 24;
753 
754  /* colored background */
755  {
756  unsigned i, x = 0, x2;
757 
758  x = 0;
759  for (i = 1; i < 7; i++) {
760  x2 = av_rescale(i, s->w, 6);
761  x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2);
762  set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) |
763  ((i & 2) ? 0x00FF00 : 0) |
764  ((i & 4) ? 0x0000FF : 0) |
765  alpha);
767  x, 0, x2 - x, frame->height);
768  x = x2;
769  }
770  }
771 
772  /* oblique gradient */
773  /* note: too slow if using blending */
774  if (s->h >= 64) {
775  unsigned x, dx, y0, y, g0, g;
776 
777  dx = ff_draw_round_to_sub(&s->draw, 0, +1, 1);
778  y0 = av_rescale_q(s->pts, s->time_base, av_make_q(2, s->h - 16));
779  g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128));
780  for (x = 0; x < s->w; x += dx) {
781  g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256);
782  set_color(s, &color, color_gradient(g) | alpha);
783  y = y0 + av_rescale(x, s->h / 2, s->w);
784  y %= 2 * (s->h - 16);
785  if (y > s->h - 16)
786  y = 2 * (s->h - 16) - y;
787  y = ff_draw_round_to_sub(&s->draw, 1, 0, y);
789  x, y, dx, 16);
790  }
791  }
792 
793  /* top right: draw clock hands */
794  if (s->w >= 64 && s->h >= 64) {
795  int l = (FFMIN(s->w, s->h) - 32) >> 1;
796  int steps = FFMAX(4, l >> 5);
797  int xc = (s->w >> 2) + (s->w >> 1);
798  int yc = (s->h >> 2);
799  int cycle = l << 2;
800  int pos, xh, yh;
801  int c, i;
802 
803  for (c = 0; c < 3; c++) {
804  set_color(s, &color, (0xBBBBBB ^ (0xFF << (c << 3))) | alpha);
805  pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle;
806  xh = pos < 1 * l ? pos :
807  pos < 2 * l ? l :
808  pos < 3 * l ? 3 * l - pos : 0;
809  yh = pos < 1 * l ? 0 :
810  pos < 2 * l ? pos - l :
811  pos < 3 * l ? l :
812  cycle - pos;
813  xh -= l >> 1;
814  yh -= l >> 1;
815  for (i = 1; i <= steps; i++) {
816  int x = av_rescale(xh, i, steps) + xc;
817  int y = av_rescale(yh, i, steps) + yc;
818  x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
819  y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
821  x, y, 8, 8);
822  }
823  }
824  }
825 
826  /* bottom left: beating rectangles */
827  if (s->w >= 64 && s->h >= 64) {
828  int l = (FFMIN(s->w, s->h) - 16) >> 2;
829  int cycle = l << 3;
830  int xc = (s->w >> 2);
831  int yc = (s->h >> 2) + (s->h >> 1);
832  int xm1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 8);
833  int xm2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 8);
834  int ym1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 8);
835  int ym2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 8);
836  int size, step, x1, x2, y1, y2;
837 
838  size = av_rescale_q(s->pts, s->time_base, av_make_q(4, cycle));
839  step = size / l;
840  size %= l;
841  if (step & 1)
842  size = l - size;
843  step = (step >> 1) & 3;
844  set_color(s, &color, 0xFF808080);
845  x1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 4 - size);
846  x2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 4 + size);
847  y1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 4 - size);
848  y2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 4 + size);
849  if (step == 0 || step == 2)
851  x1, ym1, x2 - x1, ym2 - ym1);
852  if (step == 1 || step == 2)
854  xm1, y1, xm2 - xm1, y2 - y1);
855  if (step == 3)
857  x1, y1, x2 - x1, y2 - y1);
858  }
859 
860  /* bottom right: checker with random noise */
861  {
862  unsigned xmin = av_rescale(5, s->w, 8);
863  unsigned xmax = av_rescale(7, s->w, 8);
864  unsigned ymin = av_rescale(5, s->h, 8);
865  unsigned ymax = av_rescale(7, s->h, 8);
866  unsigned x, y, i, r;
867  uint8_t alpha[256];
868 
869  r = s->pts;
870  for (y = ymin; y + 15 < ymax; y += 16) {
871  for (x = xmin; x + 15 < xmax; x += 16) {
872  if ((x ^ y) & 16)
873  continue;
874  for (i = 0; i < 256; i++) {
875  r = r * 1664525 + 1013904223;
876  alpha[i] = r >> 24;
877  }
878  set_color(s, &color, 0xFF00FF80);
880  frame->width, frame->height,
881  alpha, 16, 16, 16, 3, 0, x, y);
882  }
883  }
884  }
885 
886  /* bouncing square */
887  if (s->w >= 16 && s->h >= 16) {
888  unsigned w = s->w - 8;
889  unsigned h = s->h - 8;
890  unsigned x = av_rescale_q(s->pts, s->time_base, av_make_q(233, 55 * w)) % (w << 1);
891  unsigned y = av_rescale_q(s->pts, s->time_base, av_make_q(233, 89 * h)) % (h << 1);
892  if (x > w)
893  x = (w << 1) - x;
894  if (y > h)
895  y = (h << 1) - y;
896  x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
897  y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
898  set_color(s, &color, 0xFF8000FF);
900  x, y, 8, 8);
901  }
902 
903  /* top right: draw frame time and frame number */
904  {
905  char buf[256];
906  unsigned time;
907 
908  time = av_rescale_q(s->pts, s->time_base, av_make_q(1, 1000)) % 86400000;
909  set_color(s, &color, 0xC0000000);
911  frame->width, frame->height,
912  2, 2, 100, 36);
913  set_color(s, &color, 0xFFFF8000);
914  snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%03d\n%12"PRIi64,
915  time / 3600000, (time / 60000) % 60, (time / 1000) % 60,
916  time % 1000, s->pts);
917  draw_text(s, frame, &color, 4, 4, buf);
918  }
919 }
920 static av_cold int test2_init(AVFilterContext *ctx)
921 {
922  TestSourceContext *s = ctx->priv;
923 
924  s->fill_picture_fn = test2_fill_picture;
925  return init(ctx);
926 }
927 
928 static int test2_query_formats(AVFilterContext *ctx)
929 {
931 }
932 
933 static int test2_config_props(AVFilterLink *inlink)
934 {
935  AVFilterContext *ctx = inlink->src;
936  TestSourceContext *s = ctx->priv;
937 
938  av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0);
939  s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
940  s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
941  if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
942  return AVERROR(EINVAL);
943  return config_props(inlink);
944 }
945 
946 static const AVFilterPad avfilter_vsrc_testsrc2_outputs[] = {
947  {
948  .name = "default",
949  .type = AVMEDIA_TYPE_VIDEO,
950  .config_props = test2_config_props,
951  },
952  { NULL }
953 };
954 
956  .name = "testsrc2",
957  .description = NULL_IF_CONFIG_SMALL("Generate another test pattern."),
958  .priv_size = sizeof(TestSourceContext),
959  .priv_class = &testsrc2_class,
960  .init = test2_init,
961  .uninit = uninit,
962  .query_formats = test2_query_formats,
963  .activate = activate,
964  .inputs = NULL,
965  .outputs = avfilter_vsrc_testsrc2_outputs,
966 };
967 
968 #endif /* CONFIG_TESTSRC2_FILTER */
969 
970 #if CONFIG_RGBTESTSRC_FILTER
971 
972 static const AVOption rgbtestsrc_options[] = {
974  { "complement", "set complement colors", OFFSET(complement), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
975  { "co", "set complement colors", OFFSET(complement), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
976  { NULL }
977 };
978 
979 AVFILTER_DEFINE_CLASS(rgbtestsrc);
980 
981 #define R 0
982 #define G 1
983 #define B 2
984 #define A 3
985 
986 static void rgbtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
987  int x, int y, unsigned r, unsigned g, unsigned b, enum AVPixelFormat fmt,
988  uint8_t rgba_map[4])
989 {
990  uint8_t *dst = dstp[0];
991  int dst_linesize = dst_linesizep[0];
992  uint32_t v;
993  uint8_t *p;
994  uint16_t *p16;
995 
996  switch (fmt) {
997  case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
998  case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
999  case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
1000  case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
1001  case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
1002  case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
1003  case AV_PIX_FMT_RGB24:
1004  case AV_PIX_FMT_BGR24:
1005  v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
1006  p = dst + 3*x + y*dst_linesize;
1007  AV_WL24(p, v);
1008  break;
1009  case AV_PIX_FMT_RGBA:
1010  case AV_PIX_FMT_BGRA:
1011  case AV_PIX_FMT_ARGB:
1012  case AV_PIX_FMT_ABGR:
1013  v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255U << (rgba_map[A]*8));
1014  p = dst + 4*x + y*dst_linesize;
1015  AV_WL32(p, v);
1016  break;
1017  case AV_PIX_FMT_GBRP:
1018  p = dstp[0] + x + y * dst_linesizep[0];
1019  p[0] = g;
1020  p = dstp[1] + x + y * dst_linesizep[1];
1021  p[0] = b;
1022  p = dstp[2] + x + y * dst_linesizep[2];
1023  p[0] = r;
1024  break;
1025  case AV_PIX_FMT_GBRP9:
1026  case AV_PIX_FMT_GBRP10:
1027  case AV_PIX_FMT_GBRP12:
1028  case AV_PIX_FMT_GBRP14:
1029  case AV_PIX_FMT_GBRP16:
1030  p16 = (uint16_t *)(dstp[0] + x*2 + y * dst_linesizep[0]);
1031  p16[0] = g;
1032  p16 = (uint16_t *)(dstp[1] + x*2 + y * dst_linesizep[1]);
1033  p16[0] = b;
1034  p16 = (uint16_t *)(dstp[2] + x*2 + y * dst_linesizep[2]);
1035  p16[0] = r;
1036  break;
1037  }
1038 }
1039 
1040 static void rgbtest_fill_picture_complement(AVFilterContext *ctx, AVFrame *frame)
1041 {
1042  TestSourceContext *test = ctx->priv;
1043  int x, y, w = frame->width, h = frame->height;
1044 
1045  for (y = 0; y < h; y++) {
1046  for (x = 0; x < w; x++) {
1047  int c = (1 << FFMAX(test->depth, 8))*x/w;
1048  int r = 0, g = 0, b = 0;
1049 
1050  if (6*y < h ) r = c;
1051  else if (6*y < 2*h) g = c, b = c;
1052  else if (6*y < 3*h) g = c;
1053  else if (6*y < 4*h) r = c, b = c;
1054  else if (6*y < 5*h) b = c;
1055  else r = c, g = c;
1056 
1057  rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
1058  ctx->outputs[0]->format, test->rgba_map);
1059  }
1060  }
1061 }
1062 
1063 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1064 {
1065  TestSourceContext *test = ctx->priv;
1066  int x, y, w = frame->width, h = frame->height;
1067 
1068  for (y = 0; y < h; y++) {
1069  for (x = 0; x < w; x++) {
1070  int c = (1 << FFMAX(test->depth, 8))*x/w;
1071  int r = 0, g = 0, b = 0;
1072 
1073  if (3*y < h ) r = c;
1074  else if (3*y < 2*h) g = c;
1075  else b = c;
1076 
1077  rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
1078  ctx->outputs[0]->format, test->rgba_map);
1079  }
1080  }
1081 }
1082 
1083 static av_cold int rgbtest_init(AVFilterContext *ctx)
1084 {
1085  TestSourceContext *test = ctx->priv;
1086 
1087  test->draw_once = 1;
1088  test->fill_picture_fn = test->complement ? rgbtest_fill_picture_complement : rgbtest_fill_picture;
1089  return init(ctx);
1090 }
1091 
1092 static int rgbtest_query_formats(AVFilterContext *ctx)
1093 {
1094  static const enum AVPixelFormat pix_fmts[] = {
1103  };
1104 
1106  if (!fmts_list)
1107  return AVERROR(ENOMEM);
1108  return ff_set_common_formats(ctx, fmts_list);
1109 }
1110 
1111 static int rgbtest_config_props(AVFilterLink *outlink)
1112 {
1113  TestSourceContext *test = outlink->src->priv;
1115 
1116  test->depth = desc->comp[0].depth;
1117  ff_fill_rgba_map(test->rgba_map, outlink->format);
1118  return config_props(outlink);
1119 }
1120 
1121 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
1122  {
1123  .name = "default",
1124  .type = AVMEDIA_TYPE_VIDEO,
1125  .config_props = rgbtest_config_props,
1126  },
1127  { NULL }
1128 };
1129 
1131  .name = "rgbtestsrc",
1132  .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
1133  .priv_size = sizeof(TestSourceContext),
1134  .priv_class = &rgbtestsrc_class,
1135  .init = rgbtest_init,
1136  .uninit = uninit,
1137  .query_formats = rgbtest_query_formats,
1138  .activate = activate,
1139  .inputs = NULL,
1140  .outputs = avfilter_vsrc_rgbtestsrc_outputs,
1141 };
1142 
1143 #endif /* CONFIG_RGBTESTSRC_FILTER */
1144 
1145 #if CONFIG_YUVTESTSRC_FILTER
1146 
1147 #define yuvtestsrc_options options
1148 AVFILTER_DEFINE_CLASS(yuvtestsrc);
1149 
1150 static void yuvtest_fill_picture8(AVFilterContext *ctx, AVFrame *frame)
1151 {
1152  int x, y, w = frame->width, h = frame->height / 3;
1154  const int factor = 1 << desc->comp[0].depth;
1155  const int mid = 1 << (desc->comp[0].depth - 1);
1156  uint8_t *ydst = frame->data[0];
1157  uint8_t *udst = frame->data[1];
1158  uint8_t *vdst = frame->data[2];
1159  int ylinesize = frame->linesize[0];
1160  int ulinesize = frame->linesize[1];
1161  int vlinesize = frame->linesize[2];
1162 
1163  for (y = 0; y < h; y++) {
1164  for (x = 0; x < w; x++) {
1165  int c = factor * x / w;
1166 
1167  ydst[x] = c;
1168  udst[x] = mid;
1169  vdst[x] = mid;
1170  }
1171 
1172  ydst += ylinesize;
1173  udst += ulinesize;
1174  vdst += vlinesize;
1175  }
1176 
1177  h += h;
1178  for (; y < h; y++) {
1179  for (x = 0; x < w; x++) {
1180  int c = factor * x / w;
1181 
1182  ydst[x] = mid;
1183  udst[x] = c;
1184  vdst[x] = mid;
1185  }
1186 
1187  ydst += ylinesize;
1188  udst += ulinesize;
1189  vdst += vlinesize;
1190  }
1191 
1192  for (; y < frame->height; y++) {
1193  for (x = 0; x < w; x++) {
1194  int c = factor * x / w;
1195 
1196  ydst[x] = mid;
1197  udst[x] = mid;
1198  vdst[x] = c;
1199  }
1200 
1201  ydst += ylinesize;
1202  udst += ulinesize;
1203  vdst += vlinesize;
1204  }
1205 }
1206 
1207 static void yuvtest_fill_picture16(AVFilterContext *ctx, AVFrame *frame)
1208 {
1209  int x, y, w = frame->width, h = frame->height / 3;
1211  const int factor = 1 << desc->comp[0].depth;
1212  const int mid = 1 << (desc->comp[0].depth - 1);
1213  uint16_t *ydst = (uint16_t *)frame->data[0];
1214  uint16_t *udst = (uint16_t *)frame->data[1];
1215  uint16_t *vdst = (uint16_t *)frame->data[2];
1216  int ylinesize = frame->linesize[0] / 2;
1217  int ulinesize = frame->linesize[1] / 2;
1218  int vlinesize = frame->linesize[2] / 2;
1219 
1220  for (y = 0; y < h; y++) {
1221  for (x = 0; x < w; x++) {
1222  int c = factor * x / w;
1223 
1224  ydst[x] = c;
1225  udst[x] = mid;
1226  vdst[x] = mid;
1227  }
1228 
1229  ydst += ylinesize;
1230  udst += ulinesize;
1231  vdst += vlinesize;
1232  }
1233 
1234  h += h;
1235  for (; y < h; y++) {
1236  for (x = 0; x < w; x++) {
1237  int c = factor * x / w;
1238 
1239  ydst[x] = mid;
1240  udst[x] = c;
1241  vdst[x] = mid;
1242  }
1243 
1244  ydst += ylinesize;
1245  udst += ulinesize;
1246  vdst += vlinesize;
1247  }
1248 
1249  for (; y < frame->height; y++) {
1250  for (x = 0; x < w; x++) {
1251  int c = factor * x / w;
1252 
1253  ydst[x] = mid;
1254  udst[x] = mid;
1255  vdst[x] = c;
1256  }
1257 
1258  ydst += ylinesize;
1259  udst += ulinesize;
1260  vdst += vlinesize;
1261  }
1262 }
1263 
1264 static av_cold int yuvtest_init(AVFilterContext *ctx)
1265 {
1266  TestSourceContext *test = ctx->priv;
1267 
1268  test->draw_once = 1;
1269  return init(ctx);
1270 }
1271 
1272 static int yuvtest_query_formats(AVFilterContext *ctx)
1273 {
1274  static const enum AVPixelFormat pix_fmts[] = {
1280  };
1281 
1283  if (!fmts_list)
1284  return AVERROR(ENOMEM);
1285  return ff_set_common_formats(ctx, fmts_list);
1286 }
1287 
1288 static int yuvtest_config_props(AVFilterLink *outlink)
1289 {
1290  TestSourceContext *test = outlink->src->priv;
1292 
1293  test->fill_picture_fn = desc->comp[0].depth > 8 ? yuvtest_fill_picture16 : yuvtest_fill_picture8;
1294  return config_props(outlink);
1295 }
1296 
1297 static const AVFilterPad avfilter_vsrc_yuvtestsrc_outputs[] = {
1298  {
1299  .name = "default",
1300  .type = AVMEDIA_TYPE_VIDEO,
1301  .config_props = yuvtest_config_props,
1302  },
1303  { NULL }
1304 };
1305 
1307  .name = "yuvtestsrc",
1308  .description = NULL_IF_CONFIG_SMALL("Generate YUV test pattern."),
1309  .priv_size = sizeof(TestSourceContext),
1310  .priv_class = &yuvtestsrc_class,
1311  .init = yuvtest_init,
1312  .uninit = uninit,
1313  .query_formats = yuvtest_query_formats,
1314  .activate = activate,
1315  .inputs = NULL,
1316  .outputs = avfilter_vsrc_yuvtestsrc_outputs,
1317 };
1318 
1319 #endif /* CONFIG_YUVTESTSRC_FILTER */
1320 
1321 #if CONFIG_PAL75BARS_FILTER || CONFIG_PAL100BARS_FILTER || CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
1322 
1323 static const uint8_t rainbow[7][4] = {
1324  { 180, 128, 128, 255 }, /* 75% white */
1325  { 162, 44, 142, 255 }, /* 75% yellow */
1326  { 131, 156, 44, 255 }, /* 75% cyan */
1327  { 112, 72, 58, 255 }, /* 75% green */
1328  { 84, 184, 198, 255 }, /* 75% magenta */
1329  { 65, 100, 212, 255 }, /* 75% red */
1330  { 35, 212, 114, 255 }, /* 75% blue */
1331 };
1332 
1333 static const uint8_t rainbow100[7][4] = {
1334  { 235, 128, 128, 255 }, /* 100% white */
1335  { 210, 16, 146, 255 }, /* 100% yellow */
1336  { 170, 166, 16, 255 }, /* 100% cyan */
1337  { 145, 54, 34, 255 }, /* 100% green */
1338  { 106, 202, 222, 255 }, /* 100% magenta */
1339  { 81, 90, 240, 255 }, /* 100% red */
1340  { 41, 240, 110, 255 }, /* 100% blue */
1341 };
1342 
1343 static const uint8_t rainbowhd[7][4] = {
1344  { 180, 128, 128, 255 }, /* 75% white */
1345  { 168, 44, 136, 255 }, /* 75% yellow */
1346  { 145, 147, 44, 255 }, /* 75% cyan */
1347  { 133, 63, 52, 255 }, /* 75% green */
1348  { 63, 193, 204, 255 }, /* 75% magenta */
1349  { 51, 109, 212, 255 }, /* 75% red */
1350  { 28, 212, 120, 255 }, /* 75% blue */
1351 };
1352 
1353 static const uint8_t wobnair[7][4] = {
1354  { 35, 212, 114, 255 }, /* 75% blue */
1355  { 19, 128, 128, 255 }, /* 7.5% intensity black */
1356  { 84, 184, 198, 255 }, /* 75% magenta */
1357  { 19, 128, 128, 255 }, /* 7.5% intensity black */
1358  { 131, 156, 44, 255 }, /* 75% cyan */
1359  { 19, 128, 128, 255 }, /* 7.5% intensity black */
1360  { 180, 128, 128, 255 }, /* 75% white */
1361 };
1362 
1363 static const uint8_t white[4] = { 235, 128, 128, 255 };
1364 
1365 /* pluge pulses */
1366 static const uint8_t neg4ire[4] = { 7, 128, 128, 255 };
1367 static const uint8_t pos4ire[4] = { 24, 128, 128, 255 };
1368 
1369 /* fudged Q/-I */
1370 static const uint8_t i_pixel[4] = { 57, 156, 97, 255 };
1371 static const uint8_t q_pixel[4] = { 44, 171, 147, 255 };
1372 
1373 static const uint8_t gray40[4] = { 104, 128, 128, 255 };
1374 static const uint8_t gray15[4] = { 49, 128, 128, 255 };
1375 static const uint8_t cyan[4] = { 188, 154, 16, 255 };
1376 static const uint8_t yellow[4] = { 219, 16, 138, 255 };
1377 static const uint8_t blue[4] = { 32, 240, 118, 255 };
1378 static const uint8_t red[4] = { 63, 102, 240, 255 };
1379 static const uint8_t black0[4] = { 16, 128, 128, 255 };
1380 static const uint8_t black2[4] = { 20, 128, 128, 255 };
1381 static const uint8_t black4[4] = { 25, 128, 128, 255 };
1382 static const uint8_t neg2[4] = { 12, 128, 128, 255 };
1383 
1384 static void draw_bar(TestSourceContext *test, const uint8_t color[4],
1385  int x, int y, int w, int h,
1386  AVFrame *frame)
1387 {
1389  uint8_t *p, *p0;
1390  int plane;
1391 
1392  x = FFMIN(x, test->w - 1);
1393  y = FFMIN(y, test->h - 1);
1394  w = FFMAX(FFMIN(w, test->w - x), 0);
1395  h = FFMAX(FFMIN(h, test->h - y), 0);
1396 
1397  av_assert0(x + w <= test->w);
1398  av_assert0(y + h <= test->h);
1399 
1400  for (plane = 0; frame->data[plane]; plane++) {
1401  const int c = color[plane];
1402  const int linesize = frame->linesize[plane];
1403  int i, px, py, pw, ph;
1404 
1405  if (plane == 1 || plane == 2) {
1406  px = x >> desc->log2_chroma_w;
1407  pw = AV_CEIL_RSHIFT(w, desc->log2_chroma_w);
1408  py = y >> desc->log2_chroma_h;
1409  ph = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
1410  } else {
1411  px = x;
1412  pw = w;
1413  py = y;
1414  ph = h;
1415  }
1416 
1417  p0 = p = frame->data[plane] + py * linesize + px;
1418  memset(p, c, pw);
1419  p += linesize;
1420  for (i = 1; i < ph; i++, p += linesize)
1421  memcpy(p, p0, pw);
1422  }
1423 }
1424 
1425 static int smptebars_query_formats(AVFilterContext *ctx)
1426 {
1427  static const enum AVPixelFormat pix_fmts[] = {
1432  };
1433 
1435  if (!fmts_list)
1436  return AVERROR(ENOMEM);
1437  return ff_set_common_formats(ctx, fmts_list);
1438 }
1439 
1440 static const AVFilterPad smptebars_outputs[] = {
1441  {
1442  .name = "default",
1443  .type = AVMEDIA_TYPE_VIDEO,
1444  .config_props = config_props,
1445  },
1446  { NULL }
1447 };
1448 
1449 #if CONFIG_PAL75BARS_FILTER
1450 
1451 #define pal75bars_options options
1452 AVFILTER_DEFINE_CLASS(pal75bars);
1453 
1454 static void pal75bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1455 {
1456  TestSourceContext *test = ctx->priv;
1457  int r_w, i, x = 0;
1458  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1459 
1460  picref->color_range = AVCOL_RANGE_MPEG;
1461  picref->colorspace = AVCOL_SPC_BT470BG;
1462 
1463  r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1464 
1465  draw_bar(test, white, x, 0, r_w, test->h, picref);
1466  x += r_w;
1467  for (i = 1; i < 7; i++) {
1468  draw_bar(test, rainbow[i], x, 0, r_w, test->h, picref);
1469  x += r_w;
1470  }
1471  draw_bar(test, black0, x, 0, r_w, test->h, picref);
1472 }
1473 
1474 static av_cold int pal75bars_init(AVFilterContext *ctx)
1475 {
1476  TestSourceContext *test = ctx->priv;
1477 
1478  test->fill_picture_fn = pal75bars_fill_picture;
1479  test->draw_once = 1;
1480  return init(ctx);
1481 }
1482 
1484  .name = "pal75bars",
1485  .description = NULL_IF_CONFIG_SMALL("Generate PAL 75% color bars."),
1486  .priv_size = sizeof(TestSourceContext),
1487  .priv_class = &pal75bars_class,
1488  .init = pal75bars_init,
1489  .uninit = uninit,
1490  .query_formats = smptebars_query_formats,
1491  .activate = activate,
1492  .inputs = NULL,
1493  .outputs = smptebars_outputs,
1494 };
1495 
1496 #endif /* CONFIG_PAL75BARS_FILTER */
1497 
1498 #if CONFIG_PAL100BARS_FILTER
1499 
1500 #define pal100bars_options options
1501 AVFILTER_DEFINE_CLASS(pal100bars);
1502 
1503 static void pal100bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1504 {
1505  TestSourceContext *test = ctx->priv;
1506  int r_w, i, x = 0;
1507  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1508 
1509  picref->color_range = AVCOL_RANGE_MPEG;
1510  picref->colorspace = AVCOL_SPC_BT470BG;
1511 
1512  r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1513 
1514  for (i = 0; i < 7; i++) {
1515  draw_bar(test, rainbow100[i], x, 0, r_w, test->h, picref);
1516  x += r_w;
1517  }
1518  draw_bar(test, black0, x, 0, r_w, test->h, picref);
1519 }
1520 
1521 static av_cold int pal100bars_init(AVFilterContext *ctx)
1522 {
1523  TestSourceContext *test = ctx->priv;
1524 
1525  test->fill_picture_fn = pal100bars_fill_picture;
1526  test->draw_once = 1;
1527  return init(ctx);
1528 }
1529 
1531  .name = "pal100bars",
1532  .description = NULL_IF_CONFIG_SMALL("Generate PAL 100% color bars."),
1533  .priv_size = sizeof(TestSourceContext),
1534  .priv_class = &pal100bars_class,
1535  .init = pal100bars_init,
1536  .uninit = uninit,
1537  .query_formats = smptebars_query_formats,
1538  .activate = activate,
1539  .inputs = NULL,
1540  .outputs = smptebars_outputs,
1541 };
1542 
1543 #endif /* CONFIG_PAL100BARS_FILTER */
1544 
1545 #if CONFIG_SMPTEBARS_FILTER
1546 
1547 #define smptebars_options options
1548 AVFILTER_DEFINE_CLASS(smptebars);
1549 
1550 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1551 {
1552  TestSourceContext *test = ctx->priv;
1553  int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
1554  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1555 
1556  picref->colorspace = AVCOL_SPC_BT470BG;
1557 
1558  r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
1559  r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
1560  w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
1561  p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
1562  p_h = test->h - w_h - r_h;
1563 
1564  for (i = 0; i < 7; i++) {
1565  draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
1566  draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
1567  x += r_w;
1568  }
1569  x = 0;
1570  draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
1571  x += p_w;
1572  draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
1573  x += p_w;
1574  draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
1575  x += p_w;
1576  tmp = FFALIGN(5 * r_w - x, 1 << pixdesc->log2_chroma_w);
1577  draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1578  x += tmp;
1579  tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1580  draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
1581  x += tmp;
1582  draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1583  x += tmp;
1584  draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
1585  x += tmp;
1586  draw_bar(test, black0, x, r_h + w_h, test->w - x, p_h, picref);
1587 }
1588 
1589 static av_cold int smptebars_init(AVFilterContext *ctx)
1590 {
1591  TestSourceContext *test = ctx->priv;
1592 
1593  test->fill_picture_fn = smptebars_fill_picture;
1594  test->draw_once = 1;
1595  return init(ctx);
1596 }
1597 
1599  .name = "smptebars",
1600  .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
1601  .priv_size = sizeof(TestSourceContext),
1602  .priv_class = &smptebars_class,
1603  .init = smptebars_init,
1604  .uninit = uninit,
1605  .query_formats = smptebars_query_formats,
1606  .activate = activate,
1607  .inputs = NULL,
1608  .outputs = smptebars_outputs,
1609 };
1610 
1611 #endif /* CONFIG_SMPTEBARS_FILTER */
1612 
1613 #if CONFIG_SMPTEHDBARS_FILTER
1614 
1615 #define smptehdbars_options options
1616 AVFILTER_DEFINE_CLASS(smptehdbars);
1617 
1618 static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1619 {
1620  TestSourceContext *test = ctx->priv;
1621  int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
1622  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1623 
1624  picref->colorspace = AVCOL_SPC_BT709;
1625 
1626  d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
1627  r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
1628  draw_bar(test, gray40, x, 0, d_w, r_h, picref);
1629  x += d_w;
1630 
1631  r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
1632  for (i = 0; i < 7; i++) {
1633  draw_bar(test, rainbowhd[i], x, 0, r_w, r_h, picref);
1634  x += r_w;
1635  }
1636  draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
1637  y = r_h;
1638  r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
1639  draw_bar(test, cyan, 0, y, d_w, r_h, picref);
1640  x = d_w;
1641  draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
1642  x += r_w;
1643  tmp = r_w * 6;
1644  draw_bar(test, rainbowhd[0], x, y, tmp, r_h, picref);
1645  x += tmp;
1646  l_w = x;
1647  draw_bar(test, blue, x, y, test->w - x, r_h, picref);
1648  y += r_h;
1649  draw_bar(test, yellow, 0, y, d_w, r_h, picref);
1650  x = d_w;
1651  draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
1652  x += r_w;
1653 
1654  for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
1655  uint8_t yramp[4] = {0};
1656 
1657  yramp[0] = i * 255 / tmp;
1658  yramp[1] = 128;
1659  yramp[2] = 128;
1660  yramp[3] = 255;
1661 
1662  draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
1663  x += 1 << pixdesc->log2_chroma_w;
1664  }
1665  draw_bar(test, red, x, y, test->w - x, r_h, picref);
1666  y += r_h;
1667  draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
1668  x = d_w;
1669  tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
1670  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1671  x += tmp;
1672  tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
1673  draw_bar(test, white, x, y, tmp, test->h - y, picref);
1674  x += tmp;
1675  tmp = FFALIGN(r_w * 5 / 6, 1 << pixdesc->log2_chroma_w);
1676  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1677  x += tmp;
1678  tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1679  draw_bar(test, neg2, x, y, tmp, test->h - y, picref);
1680  x += tmp;
1681  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1682  x += tmp;
1683  draw_bar(test, black2, x, y, tmp, test->h - y, picref);
1684  x += tmp;
1685  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1686  x += tmp;
1687  draw_bar(test, black4, x, y, tmp, test->h - y, picref);
1688  x += tmp;
1689  r_w = l_w - x;
1690  draw_bar(test, black0, x, y, r_w, test->h - y, picref);
1691  x += r_w;
1692  draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
1693 }
1694 
1695 static av_cold int smptehdbars_init(AVFilterContext *ctx)
1696 {
1697  TestSourceContext *test = ctx->priv;
1698 
1699  test->fill_picture_fn = smptehdbars_fill_picture;
1700  test->draw_once = 1;
1701  return init(ctx);
1702 }
1703 
1705  .name = "smptehdbars",
1706  .description = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
1707  .priv_size = sizeof(TestSourceContext),
1708  .priv_class = &smptehdbars_class,
1709  .init = smptehdbars_init,
1710  .uninit = uninit,
1711  .query_formats = smptebars_query_formats,
1712  .activate = activate,
1713  .inputs = NULL,
1714  .outputs = smptebars_outputs,
1715 };
1716 
1717 #endif /* CONFIG_SMPTEHDBARS_FILTER */
1718 #endif /* CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */
1719 
1720 #if CONFIG_ALLYUV_FILTER
1721 
1722 #define allyuv_options &options[NOSIZE_OPTIONS_OFFSET]
1723 AVFILTER_DEFINE_CLASS(allyuv);
1724 
1725 static void allyuv_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1726 {
1727  const int ys = frame->linesize[0];
1728  const int us = frame->linesize[1];
1729  const int vs = frame->linesize[2];
1730  int x, y, j;
1731 
1732  for (y = 0; y < 4096; y++) {
1733  for (x = 0; x < 2048; x++) {
1734  frame->data[0][y * ys + x] = ((x / 8) % 256);
1735  frame->data[0][y * ys + 4095 - x] = ((x / 8) % 256);
1736  }
1737 
1738  for (x = 0; x < 2048; x+=8) {
1739  for (j = 0; j < 8; j++) {
1740  frame->data[1][vs * y + x + j] = (y%16 + (j % 8) * 16);
1741  frame->data[1][vs * y + 4095 - x - j] = (128 + y%16 + (j % 8) * 16);
1742  }
1743  }
1744 
1745  for (x = 0; x < 4096; x++)
1746  frame->data[2][y * us + x] = 256 * y / 4096;
1747  }
1748 }
1749 
1750 static av_cold int allyuv_init(AVFilterContext *ctx)
1751 {
1752  TestSourceContext *test = ctx->priv;
1753 
1754  test->w = test->h = 4096;
1755  test->draw_once = 1;
1756  test->fill_picture_fn = allyuv_fill_picture;
1757  return init(ctx);
1758 }
1759 
1760 static int allyuv_query_formats(AVFilterContext *ctx)
1761 {
1762  static const enum AVPixelFormat pix_fmts[] = {
1765  };
1766 
1768  if (!fmts_list)
1769  return AVERROR(ENOMEM);
1770  return ff_set_common_formats(ctx, fmts_list);
1771 }
1772 
1773 static const AVFilterPad avfilter_vsrc_allyuv_outputs[] = {
1774  {
1775  .name = "default",
1776  .type = AVMEDIA_TYPE_VIDEO,
1777  .config_props = config_props,
1778  },
1779  { NULL }
1780 };
1781 
1783  .name = "allyuv",
1784  .description = NULL_IF_CONFIG_SMALL("Generate all yuv colors."),
1785  .priv_size = sizeof(TestSourceContext),
1786  .priv_class = &allyuv_class,
1787  .init = allyuv_init,
1788  .uninit = uninit,
1789  .query_formats = allyuv_query_formats,
1790  .activate = activate,
1791  .inputs = NULL,
1792  .outputs = avfilter_vsrc_allyuv_outputs,
1793 };
1794 
1795 #endif /* CONFIG_ALLYUV_FILTER */
1796 
1797 #if CONFIG_ALLRGB_FILTER
1798 
1799 #define allrgb_options &options[NOSIZE_OPTIONS_OFFSET]
1800 AVFILTER_DEFINE_CLASS(allrgb);
1801 
1802 static void allrgb_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1803 {
1804  unsigned x, y;
1805  const int linesize = frame->linesize[0];
1806  uint8_t *line = frame->data[0];
1807 
1808  for (y = 0; y < 4096; y++) {
1809  uint8_t *dst = line;
1810 
1811  for (x = 0; x < 4096; x++) {
1812  *dst++ = x;
1813  *dst++ = y;
1814  *dst++ = (x >> 8) | ((y >> 8) << 4);
1815  }
1816  line += linesize;
1817  }
1818 }
1819 
1820 static av_cold int allrgb_init(AVFilterContext *ctx)
1821 {
1822  TestSourceContext *test = ctx->priv;
1823 
1824  test->w = test->h = 4096;
1825  test->draw_once = 1;
1826  test->fill_picture_fn = allrgb_fill_picture;
1827  return init(ctx);
1828 }
1829 
1830 static int allrgb_config_props(AVFilterLink *outlink)
1831 {
1832  TestSourceContext *test = outlink->src->priv;
1833 
1834  ff_fill_rgba_map(test->rgba_map, outlink->format);
1835  return config_props(outlink);
1836 }
1837 
1838 static int allrgb_query_formats(AVFilterContext *ctx)
1839 {
1840  static const enum AVPixelFormat pix_fmts[] = {
1842  };
1843 
1845  if (!fmts_list)
1846  return AVERROR(ENOMEM);
1847  return ff_set_common_formats(ctx, fmts_list);
1848 }
1849 
1850 static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
1851  {
1852  .name = "default",
1853  .type = AVMEDIA_TYPE_VIDEO,
1854  .config_props = allrgb_config_props,
1855  },
1856  { NULL }
1857 };
1858 
1860  .name = "allrgb",
1861  .description = NULL_IF_CONFIG_SMALL("Generate all RGB colors."),
1862  .priv_size = sizeof(TestSourceContext),
1863  .priv_class = &allrgb_class,
1864  .init = allrgb_init,
1865  .uninit = uninit,
1866  .query_formats = allrgb_query_formats,
1867  .activate = activate,
1868  .inputs = NULL,
1869  .outputs = avfilter_vsrc_allrgb_outputs,
1870 };
1871 
1872 #endif /* CONFIG_ALLRGB_FILTER */
static double val(void *priv, double ch)
Definition: aeval.c:76
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_acrusher.c:336
AVFilter ff_vsrc_smptebars
AVFilter ff_vsrc_rgbtestsrc
AVFilter ff_vsrc_allrgb
AVFilter ff_vsrc_testsrc2
AVFilter ff_vsrc_pal100bars
AVFilter ff_vsrc_allyuv
AVFilter ff_vsrc_haldclutsrc
AVFilter ff_vsrc_smptehdbars
AVFilter ff_vsrc_nullsrc
AVFilter ff_vsrc_pal75bars
AVFilter ff_vsrc_color
AVFilter ff_vsrc_yuvtestsrc
AVFilter ff_vsrc_testsrc
#define A(x)
Definition: vp56_arith.h:28
#define av_unused
Definition: attributes.h:131
#define av_cold
Definition: attributes.h:88
uint8_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:885
Main libavfilter public API header.
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:288
#define s(width, name)
Definition: cbs_vp9.c:257
common internal and external API header
#define FFMIN(a, b)
Definition: common.h:105
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define FFMAX(a, b)
Definition: common.h:103
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
static AVFrame * frame
void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, int x0, int y0, int w, int h)
Blend a rectangle with an uniform color.
Definition: drawutils.c:358
int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir, int value)
Round a dimension according to subsampling.
Definition: drawutils.c:632
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:84
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:144
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:35
void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_x, int dst_y, int w, int h)
Fill a rectangle with an uniform color.
Definition: drawutils.c:231
void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, const uint8_t *mask, int mask_linesize, int mask_w, int mask_h, int l2depth, unsigned endianness, int x0, int y0)
Blend an alpha mask with an uniform color.
Definition: drawutils.c:535
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:644
misc drawing utilities
internal math functions header
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:200
#define FFERROR_NOT_READY
Filters implementation helper functions.
Definition: filters.h:34
static int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
Definition: filters.h:183
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
@ AV_OPT_TYPE_COLOR
Definition: opt.h:240
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AVERROR(e)
Definition: error.h:43
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:540
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
Definition: mathematics.c:58
@ AV_ROUND_ZERO
Round toward zero.
Definition: mathematics.h:80
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:320
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
int index
Definition: gxfenc.c:89
for(j=16;j >0;--j)
#define B
Definition: huffyuvdsp.h:32
#define R
Definition: huffyuvdsp.h:34
#define G
Definition: huffyuvdsp.h:33
static const int16_t alpha[]
Definition: ilbcdata.h:55
misc image utilities
int i
Definition: input.c:407
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
#define AV_WL24(p, d)
Definition: intreadwrite.h:464
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:288
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
const char * desc
Definition: libsvtav1.c:83
uint8_t w
Definition: llviddspenc.c:39
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:92
static const uint16_t mask[17]
Definition: lzw.c:38
#define FFALIGN(x, a)
Definition: macros.h:48
const char data[16]
Definition: mxf.c:142
static void test(const char *pattern, const char *host)
Definition: noproxy.c:23
AVOptions.
misc parsing utilities
int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel for the pixel format described by pixdesc, including any padding ...
Definition: pixdesc.c:2538
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:414
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:569
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:393
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:392
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:390
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:415
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:389
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:416
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:385
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:240
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:239
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:238
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:237
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:391
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:386
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:394
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:388
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:418
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:409
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:417
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:387
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:514
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition: pixfmt.h:518
typedef void(RENAME(mix_any_func_type))
#define FF_ARRAY_ELEMS(a)
#define snprintf
Definition: snprintf.h:34
unsigned int pos
Definition: spdifenc.c:412
Describe the class of an AVClass context structure.
Definition: log.h:67
An instance of a filter.
Definition: avfilter.h:341
void * priv
private data for use by the filter
Definition: avfilter.h:356
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:411
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:396
int height
Definition: frame.h:376
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:406
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:465
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:562
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:573
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:391
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:401
AVOption.
Definition: opt.h:248
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
Rational number (pair of numerator and denominator).
Definition: rational.h:58
FFDrawContext draw
Definition: vsrc_testsrc.c:74
AVRational sar
sample aspect ratio
Definition: vsrc_testsrc.c:60
int64_t duration
duration expressed in microseconds
Definition: vsrc_testsrc.c:59
AVRational frame_rate
Definition: vsrc_testsrc.c:57
uint8_t color_rgba[4]
Definition: vsrc_testsrc.c:76
unsigned int nb_frame
Definition: vsrc_testsrc.c:56
int draw_once
draw only the first frame, always put out the same picture
Definition: vsrc_testsrc.c:61
int draw_once_reset
draw only the first frame or in case of reset
Definition: vsrc_testsrc.c:62
AVRational time_base
Definition: vsrc_testsrc.c:57
AVFrame * picref
cached reference containing the painted picture
Definition: vsrc_testsrc.c:63
uint8_t rgba_map[4]
Definition: vsrc_testsrc.c:79
void(* fill_picture_fn)(AVFilterContext *ctx, AVFrame *frame)
Definition: vsrc_testsrc.c:65
FFDrawColor color
Definition: vsrc_testsrc.c:75
Definition: graph2dot.c:48
uint8_t level
Definition: svq3.c:206
#define av_log(a,...)
static uint8_t tmp[11]
Definition: aes_ctr.c:27
AVFormatContext * ctx
Definition: movenc.c:48
#define height
#define width
int size
const char * b
Definition: vf_curves.c:119
const char * g
Definition: vf_curves.c:118
const char * r
Definition: vf_curves.c:117
static void draw_text(FFDrawContext *draw, AVFrame *frame, FFDrawColor *color, int x0, int y0, const uint8_t *text, int vertical)
Definition: vf_datascope.c:87
static const int factor[16]
Definition: vf_pp7.c:77
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104
static double c[64]
static int config_props(AVFilterLink *outlink)
Definition: vsrc_testsrc.c:134
#define FLAGSR
Definition: vsrc_testsrc.c:89
static const AVOption options[]
Definition: vsrc_testsrc.c:107
#define COMMON_OPTIONS
Definition: vsrc_testsrc.c:102
#define FLAGS
Definition: vsrc_testsrc.c:88
static void av_unused set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
Definition: vsrc_testsrc.c:697
static int activate(AVFilterContext *ctx)
Definition: vsrc_testsrc.c:147
static av_cold int init(AVFilterContext *ctx)
Definition: vsrc_testsrc.c:112
static av_cold void uninit(AVFilterContext *ctx)
Definition: vsrc_testsrc.c:127
#define OFFSET(x)
Definition: vsrc_testsrc.c:87
#define COMMON_OPTIONS_NOSIZE
Definition: vsrc_testsrc.c:95
static void draw_rectangle(AVFormatContext *s)
Definition: xcbgrab.c:647
const uint8_t avpriv_vga16_font[4096]
CGA/EGA/VGA ROM font data.