FFmpeg
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 "config_components.h"
37 
38 #include "libavutil/avassert.h"
39 #include "libavutil/common.h"
40 #include "libavutil/ffmath.h"
41 #include "libavutil/mem.h"
42 #include "libavutil/opt.h"
43 #include "libavutil/imgutils.h"
44 #include "libavutil/intreadwrite.h"
46 #include "avfilter.h"
47 #include "drawutils.h"
48 #include "filters.h"
49 #include "filters.h"
50 #include "formats.h"
51 #include "video.h"
52 
53 typedef struct TestSourceContext {
54  const AVClass *class;
55  int w, h;
56  int pw, ph;
57  unsigned int nb_frame;
60  int64_t duration; ///< duration expressed in microseconds
61  AVRational sar; ///< sample aspect ratio
62  int draw_once; ///< draw only the first frame, always put out the same picture
63  int draw_once_reset; ///< draw only the first frame or in case of reset
64  AVFrame *picref; ///< cached reference containing the painted picture
65 
67 
68  /* only used by testsrc */
70 
71  /* only used by testsrc2 */
72  int alpha;
73 
74  /* only used by colorspectrum */
75  int type;
76 
77  /* only used by color */
80  uint8_t color_rgba[4];
81 
82  /* only used by rgbtest */
83  uint8_t rgba_map[4];
85  int depth;
86 
87  /* only used by haldclut */
88  int level;
89 
90  /* only used by zoneplate */
91  int k0, kx, ky, kt;
92  int kxt, kyt, kxy;
93  int kx2, ky2, kt2;
94  int xo, yo, to, kU, kV;
96  uint8_t *lut;
97  int (*fill_slice_fn)(AVFilterContext *ctx, void *arg, int job, int nb_jobs);
99 
100 #define OFFSET(x) offsetof(TestSourceContext, x)
101 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
102 #define FLAGSR AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
103 
104 #define SIZE_OPTIONS \
105  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
106  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
107 
108 #define COMMON_OPTIONS_NOSIZE \
109  { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
110  { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
111  { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
112  { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
113  { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
114 
115 #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
116 
117 #define NOSIZE_OPTIONS_OFFSET 2
118 /* Filters using COMMON_OPTIONS_NOSIZE also use the following options
119  * via &options[NOSIZE_OPTIONS_OFFSET]. So don't break it. */
120 static const AVOption options[] = {
122  { NULL }
123 };
124 
126 {
127  TestSourceContext *test = ctx->priv;
128 
129  test->time_base = av_inv_q(test->frame_rate);
130  test->nb_frame = 0;
131  test->pts = 0;
132 
133  av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
134  test->w, test->h, test->frame_rate.num, test->frame_rate.den,
135  test->duration < 0 ? -1 : (double)test->duration/1000000,
136  test->sar.num, test->sar.den);
137  return 0;
138 }
139 
141 {
142  TestSourceContext *test = ctx->priv;
143 
144  av_frame_free(&test->picref);
145  av_freep(&test->lut);
146 }
147 
148 static int config_props(AVFilterLink *outlink)
149 {
150  TestSourceContext *test = outlink->src->priv;
151  FilterLink *l = ff_filter_link(outlink);
152 
153  outlink->w = test->w;
154  outlink->h = test->h;
155  outlink->sample_aspect_ratio = test->sar;
156  l->frame_rate = test->frame_rate;
157  outlink->time_base = test->time_base;
158 
159  return 0;
160 }
161 
162 static const AVFilterPad outputs[] = {
163  {
164  .name = "default",
165  .type = AVMEDIA_TYPE_VIDEO,
166  .config_props = config_props,
167  },
168 };
169 
171 {
172  AVFilterLink *outlink = ctx->outputs[0];
173  TestSourceContext *test = ctx->priv;
174  AVFrame *frame;
175 
176  if (!ff_outlink_frame_wanted(outlink))
177  return FFERROR_NOT_READY;
178  if (test->duration >= 0 &&
179  av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration) {
180  ff_outlink_set_status(outlink, AVERROR_EOF, test->pts);
181  return 0;
182  }
183 
184  if (test->draw_once) {
185  if (test->draw_once_reset) {
186  av_frame_free(&test->picref);
187  test->draw_once_reset = 0;
188  }
189  if (!test->picref) {
190  test->picref =
191  ff_get_video_buffer(outlink, test->w, test->h);
192  if (!test->picref)
193  return AVERROR(ENOMEM);
194  test->fill_picture_fn(outlink->src, test->picref);
195  }
196  frame = av_frame_clone(test->picref);
197  } else
198  frame = ff_get_video_buffer(outlink, test->w, test->h);
199 
200  if (!frame)
201  return AVERROR(ENOMEM);
202  frame->pts = test->pts;
203  frame->duration = 1;
204  frame->flags |= AV_FRAME_FLAG_KEY;
205 #if FF_API_INTERLACED_FRAME
207  frame->interlaced_frame = 0;
209 #endif
210  frame->flags &= ~AV_FRAME_FLAG_INTERLACED;
211  frame->pict_type = AV_PICTURE_TYPE_I;
212  frame->sample_aspect_ratio = test->sar;
213  if (!test->draw_once)
214  test->fill_picture_fn(outlink->src, frame);
215 
216  test->pts++;
217  test->nb_frame++;
218 
219  return ff_filter_frame(outlink, frame);
220 }
221 
222 #if CONFIG_COLOR_FILTER
223 
224 static const AVOption color_options[] = {
225  { "color", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGSR },
226  { "c", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGSR },
228  { NULL }
229 };
230 
232 
233 static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
234 {
235  TestSourceContext *test = ctx->priv;
236  ff_fill_rectangle(&test->draw, &test->color,
237  picref->data, picref->linesize,
238  0, 0, test->w, test->h);
239 }
240 
241 static av_cold int color_init(AVFilterContext *ctx)
242 {
243  TestSourceContext *test = ctx->priv;
244  test->fill_picture_fn = color_fill_picture;
245  test->draw_once = 1;
246  return init(ctx);
247 }
248 
249 static int color_query_formats(const AVFilterContext *ctx,
250  AVFilterFormatsConfig **cfg_in,
251  AVFilterFormatsConfig **cfg_out)
252 {
253  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_draw_supported_pixel_formats(0));
254 }
255 
256 static int color_config_props(AVFilterLink *inlink)
257 {
258  AVFilterContext *ctx = inlink->src;
259  TestSourceContext *test = ctx->priv;
260  int ret;
261 
262  ff_draw_init2(&test->draw, inlink->format, inlink->colorspace,
263  inlink->color_range, 0);
264  ff_draw_color(&test->draw, &test->color, test->color_rgba);
265 
266  if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
267  return AVERROR(EINVAL);
268 
269  if ((ret = config_props(inlink)) < 0)
270  return ret;
271 
272  return 0;
273 }
274 
275 static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
276  char *res, int res_len, int flags)
277 {
278  TestSourceContext *test = ctx->priv;
279  int ret;
280 
281  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
282  if (ret < 0)
283  return ret;
284 
285  ff_draw_color(&test->draw, &test->color, test->color_rgba);
286  test->draw_once_reset = 1;
287  return 0;
288 }
289 
290 static const AVFilterPad color_outputs[] = {
291  {
292  .name = "default",
293  .type = AVMEDIA_TYPE_VIDEO,
294  .config_props = color_config_props,
295  },
296 };
297 
298 const AVFilter ff_vsrc_color = {
299  .name = "color",
300  .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
301  .priv_class = &color_class,
302  .priv_size = sizeof(TestSourceContext),
303  .init = color_init,
304  .uninit = uninit,
305  .activate = activate,
306  .inputs = NULL,
307  FILTER_OUTPUTS(color_outputs),
308  FILTER_QUERY_FUNC2(color_query_formats),
309  .process_command = color_process_command,
310 };
311 
312 #endif /* CONFIG_COLOR_FILTER */
313 
314 #if CONFIG_HALDCLUTSRC_FILTER
315 
316 static const AVOption haldclutsrc_options[] = {
317  { "level", "set level", OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 6}, 2, 16, FLAGS },
319  { NULL }
320 };
321 
322 AVFILTER_DEFINE_CLASS(haldclutsrc);
323 
324 static void haldclutsrc_fill_picture(AVFilterContext *ctx, AVFrame *frame)
325 {
326  int i, j, k, x = 0, y = 0, is16bit = 0, step;
327  uint32_t alpha = 0;
328  const TestSourceContext *hc = ctx->priv;
329  int level = hc->level;
330  float scale;
331  const int w = frame->width;
332  const int h = frame->height;
333  uint8_t *data = frame->data[0];
334  const ptrdiff_t linesize = frame->linesize[0];
336  const int depth = desc->comp[0].depth;
337  const int planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
338  const int planes = av_pix_fmt_count_planes(frame->format);
339  uint8_t rgba_map[4];
340 
341  av_assert0(w == h && w == level*level*level);
342 
343  ff_fill_rgba_map(rgba_map, frame->format);
344 
345  alpha = (1 << depth) - 1;
346  is16bit = depth > 8;
347 
348  step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
349  scale = ((float)alpha) / (level*level - 1);
350 
351 #define LOAD_CLUT(nbits) do { \
352  uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step; \
353  dst[rgba_map[0]] = av_clip_uint##nbits(i * scale); \
354  dst[rgba_map[1]] = av_clip_uint##nbits(j * scale); \
355  dst[rgba_map[2]] = av_clip_uint##nbits(k * scale); \
356  if (step == 4) \
357  dst[rgba_map[3]] = alpha; \
358 } while (0)
359 
360 #define LOAD_CLUT_PLANAR(type, nbits) do { \
361  type *dst = ((type *)(frame->data[2] + y*frame->linesize[2])) + x; \
362  dst[0] = av_clip_uintp2(i * scale, nbits); \
363  dst = ((type *)(frame->data[0] + y*frame->linesize[0])) + x; \
364  dst[0] = av_clip_uintp2(j * scale, nbits); \
365  dst = ((type *)(frame->data[1] + y*frame->linesize[1])) + x; \
366  dst[0] = av_clip_uintp2(k * scale, nbits); \
367  if (planes == 4) { \
368  dst = ((type *)(frame->data[3] + y*linesize)) + x; \
369  dst[0] = alpha; \
370  } \
371 } while (0)
372 
373  level *= level;
374  for (k = 0; k < level; k++) {
375  for (j = 0; j < level; j++) {
376  for (i = 0; i < level; i++) {
377  if (!planar) {
378  if (!is16bit)
379  LOAD_CLUT(8);
380  else
381  LOAD_CLUT(16);
382  } else {
383  switch (depth) {
384  case 8: LOAD_CLUT_PLANAR(uint8_t, 8); break;
385  case 9: LOAD_CLUT_PLANAR(uint16_t, 9); break;
386  case 10: LOAD_CLUT_PLANAR(uint16_t,10); break;
387  case 12: LOAD_CLUT_PLANAR(uint16_t,12); break;
388  case 14: LOAD_CLUT_PLANAR(uint16_t,14); break;
389  case 16: LOAD_CLUT_PLANAR(uint16_t,16); break;
390  }
391  }
392  if (++x == w) {
393  x = 0;
394  y++;
395  }
396  }
397  }
398  }
399 }
400 
401 static av_cold int haldclutsrc_init(AVFilterContext *ctx)
402 {
403  TestSourceContext *hc = ctx->priv;
404  hc->fill_picture_fn = haldclutsrc_fill_picture;
405  hc->draw_once = 1;
406  return init(ctx);
407 }
408 
409 static const enum AVPixelFormat haldclutsrc_pix_fmts[] = {
424 };
425 
426 static int haldclutsrc_config_props(AVFilterLink *outlink)
427 {
428  AVFilterContext *ctx = outlink->src;
429  TestSourceContext *hc = ctx->priv;
430 
431  hc->w = hc->h = hc->level * hc->level * hc->level;
432  return config_props(outlink);
433 }
434 
435 static const AVFilterPad haldclutsrc_outputs[] = {
436  {
437  .name = "default",
438  .type = AVMEDIA_TYPE_VIDEO,
439  .config_props = haldclutsrc_config_props,
440  },
441 };
442 
444  .name = "haldclutsrc",
445  .description = NULL_IF_CONFIG_SMALL("Provide an identity Hald CLUT."),
446  .priv_class = &haldclutsrc_class,
447  .priv_size = sizeof(TestSourceContext),
448  .init = haldclutsrc_init,
449  .uninit = uninit,
450  .activate = activate,
451  .inputs = NULL,
452  FILTER_OUTPUTS(haldclutsrc_outputs),
453  FILTER_PIXFMTS_ARRAY(haldclutsrc_pix_fmts),
454 };
455 #endif /* CONFIG_HALDCLUTSRC_FILTER */
456 
457 AVFILTER_DEFINE_CLASS_EXT(nullsrc_yuvtestsrc, "nullsrc/yuvtestsrc", options);
458 
459 #if CONFIG_NULLSRC_FILTER
460 
461 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
462 
463 static av_cold int nullsrc_init(AVFilterContext *ctx)
464 {
465  TestSourceContext *test = ctx->priv;
466 
467  test->fill_picture_fn = nullsrc_fill_picture;
468  return init(ctx);
469 }
470 
471 const AVFilter ff_vsrc_nullsrc = {
472  .name = "nullsrc",
473  .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
474  .priv_class = &nullsrc_yuvtestsrc_class,
475  .init = nullsrc_init,
476  .uninit = uninit,
477  .activate = activate,
478  .priv_size = sizeof(TestSourceContext),
479  .inputs = NULL,
481 };
482 
483 #endif /* CONFIG_NULLSRC_FILTER */
484 
485 #if CONFIG_TESTSRC_FILTER
486 
487 static const AVOption testsrc_options[] = {
489  { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
490  { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
491  { NULL }
492 };
493 
494 AVFILTER_DEFINE_CLASS(testsrc);
495 
496 /**
497  * Fill a rectangle with value val.
498  *
499  * @param val the RGB value to set
500  * @param dst pointer to the destination buffer to fill
501  * @param dst_linesize linesize of destination
502  * @param segment_width width of the segment
503  * @param x horizontal coordinate where to draw the rectangle in the destination buffer
504  * @param y horizontal coordinate where to draw the rectangle in the destination buffer
505  * @param w width of the rectangle to draw, expressed as a number of segment_width units
506  * @param h height of the rectangle to draw, expressed as a number of segment_width units
507  */
508 static void draw_rectangle(unsigned val, uint8_t *dst, ptrdiff_t dst_linesize, int segment_width,
509  int x, int y, int w, int h)
510 {
511  int i;
512  int step = 3;
513 
514  dst += segment_width * (step * x + y * dst_linesize);
515  w *= segment_width * step;
516  h *= segment_width;
517  for (i = 0; i < h; i++) {
518  memset(dst, val, w);
519  dst += dst_linesize;
520  }
521 }
522 
523 static void draw_digit(int digit, uint8_t *dst, ptrdiff_t dst_linesize,
524  int segment_width)
525 {
526 #define TOP_HBAR 1
527 #define MID_HBAR 2
528 #define BOT_HBAR 4
529 #define LEFT_TOP_VBAR 8
530 #define LEFT_BOT_VBAR 16
531 #define RIGHT_TOP_VBAR 32
532 #define RIGHT_BOT_VBAR 64
533  struct segments {
534  int x, y, w, h;
535  } segments[] = {
536  { 1, 0, 5, 1 }, /* TOP_HBAR */
537  { 1, 6, 5, 1 }, /* MID_HBAR */
538  { 1, 12, 5, 1 }, /* BOT_HBAR */
539  { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
540  { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
541  { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
542  { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
543  };
544  static const unsigned char masks[10] = {
545  /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
546  /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
547  /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
548  /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
549  /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
550  /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
551  /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
552  /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
553  /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
554  /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
555  };
556  unsigned mask = masks[digit];
557  int i;
558 
559  draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
560  for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
561  if (mask & (1<<i))
562  draw_rectangle(255, dst, dst_linesize, segment_width,
563  segments[i].x, segments[i].y, segments[i].w, segments[i].h);
564 }
565 
566 #define GRADIENT_SIZE (6 * 256)
567 
568 static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
569 {
570  TestSourceContext *test = ctx->priv;
571  uint8_t *p, *p0;
572  int x, y;
573  int color, color_rest;
574  int icolor;
575  int radius;
576  int quad0, quad;
577  int dquad_x, dquad_y;
578  int grad, dgrad, rgrad, drgrad;
579  int seg_size;
580  int second;
581  int i;
582  uint8_t *data = frame->data[0];
583  int width = frame->width;
584  int height = frame->height;
585 
586  /* draw colored bars and circle */
587  radius = (width + height) / 4;
588  quad0 = width * width / 4 + height * height / 4 - radius * radius;
589  dquad_y = 1 - height;
590  p0 = data;
591  for (y = 0; y < height; y++) {
592  p = p0;
593  color = 0;
594  color_rest = 0;
595  quad = quad0;
596  dquad_x = 1 - width;
597  for (x = 0; x < width; x++) {
598  icolor = color;
599  if (quad < 0)
600  icolor ^= 7;
601  quad += dquad_x;
602  dquad_x += 2;
603  *(p++) = icolor & 1 ? 255 : 0;
604  *(p++) = icolor & 2 ? 255 : 0;
605  *(p++) = icolor & 4 ? 255 : 0;
606  color_rest += 8;
607  if (color_rest >= width) {
608  color_rest -= width;
609  color++;
610  }
611  }
612  quad0 += dquad_y;
613  dquad_y += 2;
614  p0 += frame->linesize[0];
615  }
616 
617  /* draw sliding color line */
618  p0 = p = data + frame->linesize[0] * (height * 3/4);
619  grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
620  GRADIENT_SIZE;
621  rgrad = 0;
622  dgrad = GRADIENT_SIZE / width;
623  drgrad = GRADIENT_SIZE % width;
624  for (x = 0; x < width; x++) {
625  *(p++) =
626  grad < 256 || grad >= 5 * 256 ? 255 :
627  grad >= 2 * 256 && grad < 4 * 256 ? 0 :
628  grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
629  *(p++) =
630  grad >= 4 * 256 ? 0 :
631  grad >= 1 * 256 && grad < 3 * 256 ? 255 :
632  grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
633  *(p++) =
634  grad < 2 * 256 ? 0 :
635  grad >= 3 * 256 && grad < 5 * 256 ? 255 :
636  grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
637  grad += dgrad;
638  rgrad += drgrad;
639  if (rgrad >= GRADIENT_SIZE) {
640  grad++;
641  rgrad -= GRADIENT_SIZE;
642  }
643  if (grad >= GRADIENT_SIZE)
644  grad -= GRADIENT_SIZE;
645  }
646  p = p0;
647  for (y = height / 8; y > 0; y--) {
648  memcpy(p+frame->linesize[0], p, 3 * width);
649  p += frame->linesize[0];
650  }
651 
652  /* draw digits */
653  seg_size = width / 80;
654  if (seg_size >= 1 && height >= 13 * seg_size) {
655  int64_t p10decimals = 1;
656  double time = av_q2d(test->time_base) * test->nb_frame *
657  ff_exp10(test->nb_decimals);
658  if (time >= INT_MAX)
659  return;
660 
661  for (x = 0; x < test->nb_decimals; x++)
662  p10decimals *= 10;
663 
664  second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
665  x = width - (width - seg_size * 64) / 2;
666  y = (height - seg_size * 13) / 2;
667  p = data + (x*3 + y * frame->linesize[0]);
668  for (i = 0; i < 8; i++) {
669  p -= 3 * 8 * seg_size;
670  draw_digit(second % 10, p, frame->linesize[0], seg_size);
671  second /= 10;
672  if (second == 0)
673  break;
674  }
675  }
676 }
677 
678 static av_cold int test_init(AVFilterContext *ctx)
679 {
680  TestSourceContext *test = ctx->priv;
681 
682  test->fill_picture_fn = test_fill_picture;
683  return init(ctx);
684 }
685 
686 const AVFilter ff_vsrc_testsrc = {
687  .name = "testsrc",
688  .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
689  .priv_size = sizeof(TestSourceContext),
690  .priv_class = &testsrc_class,
691  .init = test_init,
692  .uninit = uninit,
693  .activate = activate,
694  .inputs = NULL,
697 };
698 
699 #endif /* CONFIG_TESTSRC_FILTER */
700 
701 static void av_unused set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
702 {
703  uint8_t rgba[4] = { (argb >> 16) & 0xFF,
704  (argb >> 8) & 0xFF,
705  (argb >> 0) & 0xFF,
706  (argb >> 24) & 0xFF, };
707  ff_draw_color(&s->draw, color, rgba);
708 }
709 
710 #if CONFIG_TESTSRC2_FILTER
711 
712 static const AVOption testsrc2_options[] = {
714  { "alpha", "set global alpha (opacity)", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 255}, 0, 255, FLAGS },
715  { NULL }
716 };
717 
718 AVFILTER_DEFINE_CLASS(testsrc2);
719 
720 static uint32_t color_gradient(unsigned index)
721 {
722  unsigned si = index & 0xFF, sd = 0xFF - si;
723  switch (index >> 8) {
724  case 0: return 0xFF0000 + (si << 8);
725  case 1: return 0x00FF00 + (sd << 16);
726  case 2: return 0x00FF00 + (si << 0);
727  case 3: return 0x0000FF + (sd << 8);
728  case 4: return 0x0000FF + (si << 16);
729  case 5: return 0xFF0000 + (sd << 0);
730  default: av_assert0(0); return 0;
731  }
732 }
733 
735  int x0, int y0, const uint8_t *text)
736 {
737  int x = x0;
738 
739  for (; *text; text++) {
740  if (*text == '\n') {
741  x = x0;
742  y0 += 16;
743  continue;
744  }
745  ff_blend_mask(&s->draw, color, frame->data, frame->linesize,
746  frame->width, frame->height,
747  avpriv_vga16_font + *text * 16, 1, 8, 16, 0, 0, x, y0);
748  x += 8;
749  }
750 }
751 
752 static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame)
753 {
754  TestSourceContext *s = ctx->priv;
756  unsigned alpha = (uint32_t)s->alpha << 24;
757 
758  /* colored background */
759  {
760  unsigned i, x = 0, x2;
761 
762  x = 0;
763  for (i = 1; i < 7; i++) {
764  x2 = av_rescale(i, s->w, 6);
765  x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2);
766  set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) |
767  ((i & 2) ? 0x00FF00 : 0) |
768  ((i & 4) ? 0x0000FF : 0) |
769  alpha);
770  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
771  x, 0, x2 - x, frame->height);
772  x = x2;
773  }
774  }
775 
776  /* oblique gradient */
777  /* note: too slow if using blending */
778  if (s->h >= 64) {
779  unsigned x, dx, y0, y, g0, g;
780 
781  dx = ff_draw_round_to_sub(&s->draw, 0, +1, 1);
782  y0 = av_rescale_q(s->pts, s->time_base, av_make_q(2, s->h - 16));
783  g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128));
784  for (x = 0; x < s->w; x += dx) {
785  g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256);
786  set_color(s, &color, color_gradient(g) | alpha);
787  y = y0 + av_rescale(x, s->h / 2, s->w);
788  y %= 2 * (s->h - 16);
789  if (y > s->h - 16)
790  y = 2 * (s->h - 16) - y;
791  y = ff_draw_round_to_sub(&s->draw, 1, 0, y);
792  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
793  x, y, dx, 16);
794  }
795  }
796 
797  /* top right: draw clock hands */
798  if (s->w >= 64 && s->h >= 64) {
799  int l = (FFMIN(s->w, s->h) - 32) >> 1;
800  int steps = FFMAX(4, l >> 5);
801  int xc = (s->w >> 2) + (s->w >> 1);
802  int yc = (s->h >> 2);
803  int cycle = l << 2;
804  int pos, xh, yh;
805  int c, i;
806 
807  for (c = 0; c < 3; c++) {
808  set_color(s, &color, (0xBBBBBB ^ (0xFF << (c << 3))) | alpha);
809  pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle;
810  xh = pos < 1 * l ? pos :
811  pos < 2 * l ? l :
812  pos < 3 * l ? 3 * l - pos : 0;
813  yh = pos < 1 * l ? 0 :
814  pos < 2 * l ? pos - l :
815  pos < 3 * l ? l :
816  cycle - pos;
817  xh -= l >> 1;
818  yh -= l >> 1;
819  for (i = 1; i <= steps; i++) {
820  int x = av_rescale(xh, i, steps) + xc;
821  int y = av_rescale(yh, i, steps) + yc;
822  x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
823  y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
824  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
825  x, y, 8, 8);
826  }
827  }
828  }
829 
830  /* bottom left: beating rectangles */
831  if (s->w >= 64 && s->h >= 64) {
832  int l = (FFMIN(s->w, s->h) - 16) >> 2;
833  int cycle = l << 3;
834  int xc = (s->w >> 2);
835  int yc = (s->h >> 2) + (s->h >> 1);
836  int xm1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 8);
837  int xm2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 8);
838  int ym1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 8);
839  int ym2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 8);
840  int size, step, x1, x2, y1, y2;
841 
842  size = av_rescale_q(s->pts, s->time_base, av_make_q(4, cycle));
843  step = size / l;
844  size %= l;
845  if (step & 1)
846  size = l - size;
847  step = (step >> 1) & 3;
848  set_color(s, &color, 0xFF808080);
849  x1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 4 - size);
850  x2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 4 + size);
851  y1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 4 - size);
852  y2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 4 + size);
853  if (step == 0 || step == 2)
854  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
855  x1, ym1, x2 - x1, ym2 - ym1);
856  if (step == 1 || step == 2)
857  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
858  xm1, y1, xm2 - xm1, y2 - y1);
859  if (step == 3)
860  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
861  x1, y1, x2 - x1, y2 - y1);
862  }
863 
864  /* bottom right: checker with random noise */
865  {
866  unsigned xmin = av_rescale(5, s->w, 8);
867  unsigned xmax = av_rescale(7, s->w, 8);
868  unsigned ymin = av_rescale(5, s->h, 8);
869  unsigned ymax = av_rescale(7, s->h, 8);
870  unsigned x, y, i, r;
871  uint8_t alpha[256];
872 
873  r = s->pts;
874  for (y = ymin; y + 15 < ymax; y += 16) {
875  for (x = xmin; x + 15 < xmax; x += 16) {
876  if ((x ^ y) & 16)
877  continue;
878  for (i = 0; i < 256; i++) {
879  r = r * 1664525 + 1013904223;
880  alpha[i] = r >> 24;
881  }
882  set_color(s, &color, 0xFF00FF80);
883  ff_blend_mask(&s->draw, &color, frame->data, frame->linesize,
884  frame->width, frame->height,
885  alpha, 16, 16, 16, 3, 0, x, y);
886  }
887  }
888  }
889 
890  /* bouncing square */
891  if (s->w >= 16 && s->h >= 16) {
892  unsigned w = s->w - 8;
893  unsigned h = s->h - 8;
894  unsigned x = av_rescale_q(s->pts, s->time_base, av_make_q(233, 55 * w)) % (w << 1);
895  unsigned y = av_rescale_q(s->pts, s->time_base, av_make_q(233, 89 * h)) % (h << 1);
896  if (x > w)
897  x = (w << 1) - x;
898  if (y > h)
899  y = (h << 1) - y;
900  x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
901  y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
902  set_color(s, &color, 0xFF8000FF);
903  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
904  x, y, 8, 8);
905  }
906 
907  /* top right: draw frame time and frame number */
908  {
909  char buf[256];
910  unsigned time;
911 
912  time = av_rescale_q(s->pts, s->time_base, av_make_q(1, 1000)) % 86400000;
913  set_color(s, &color, 0xC0000000);
914  ff_blend_rectangle(&s->draw, &color, frame->data, frame->linesize,
915  frame->width, frame->height,
916  2, 2, 100, 36);
917  set_color(s, &color, 0xFFFF8000);
918  snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%03d\n%12"PRIi64,
919  time / 3600000, (time / 60000) % 60, (time / 1000) % 60,
920  time % 1000, s->pts);
921  draw_text(s, frame, &color, 4, 4, buf);
922  }
923 }
924 static av_cold int test2_init(AVFilterContext *ctx)
925 {
926  TestSourceContext *s = ctx->priv;
927 
928  s->fill_picture_fn = test2_fill_picture;
929  return init(ctx);
930 }
931 
932 static int test2_query_formats(const AVFilterContext *ctx,
933  AVFilterFormatsConfig **cfg_in,
934  AVFilterFormatsConfig **cfg_out)
935 {
936  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_draw_supported_pixel_formats(0));
937 }
938 
939 static int test2_config_props(AVFilterLink *inlink)
940 {
941  AVFilterContext *ctx = inlink->src;
942  TestSourceContext *s = ctx->priv;
943 
944  av_assert0(ff_draw_init2(&s->draw, inlink->format, inlink->colorspace,
945  inlink->color_range, 0) >= 0);
946  s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
947  s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
948  if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
949  return AVERROR(EINVAL);
950  return config_props(inlink);
951 }
952 
953 static const AVFilterPad avfilter_vsrc_testsrc2_outputs[] = {
954  {
955  .name = "default",
956  .type = AVMEDIA_TYPE_VIDEO,
957  .config_props = test2_config_props,
958  },
959 };
960 
961 const AVFilter ff_vsrc_testsrc2 = {
962  .name = "testsrc2",
963  .description = NULL_IF_CONFIG_SMALL("Generate another test pattern."),
964  .priv_size = sizeof(TestSourceContext),
965  .priv_class = &testsrc2_class,
966  .init = test2_init,
967  .uninit = uninit,
968  .activate = activate,
969  .inputs = NULL,
970  FILTER_OUTPUTS(avfilter_vsrc_testsrc2_outputs),
971  FILTER_QUERY_FUNC2(test2_query_formats),
972 };
973 
974 #endif /* CONFIG_TESTSRC2_FILTER */
975 
976 #if CONFIG_RGBTESTSRC_FILTER
977 
978 static const AVOption rgbtestsrc_options[] = {
980  { "complement", "set complement colors", OFFSET(complement), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
981  { "co", "set complement colors", OFFSET(complement), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
982  { NULL }
983 };
984 
985 AVFILTER_DEFINE_CLASS(rgbtestsrc);
986 
987 #define R 0
988 #define G 1
989 #define B 2
990 #define A 3
991 
992 static void rgbtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
993  int x, int y, unsigned r, unsigned g, unsigned b, enum AVPixelFormat fmt,
994  uint8_t rgba_map[4])
995 {
996  uint8_t *dst = dstp[0];
997  ptrdiff_t dst_linesize = dst_linesizep[0];
998  uint32_t v;
999  uint8_t *p;
1000  uint16_t *p16;
1001 
1002  switch (fmt) {
1003  case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
1004  case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
1005  case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
1006  case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
1007  case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
1008  case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
1009  case AV_PIX_FMT_RGB24:
1010  case AV_PIX_FMT_BGR24:
1011  v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
1012  p = dst + 3*x + y*dst_linesize;
1013  AV_WL24(p, v);
1014  break;
1015  case AV_PIX_FMT_RGBA:
1016  case AV_PIX_FMT_BGRA:
1017  case AV_PIX_FMT_ARGB:
1018  case AV_PIX_FMT_ABGR:
1019  v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255U << (rgba_map[A]*8));
1020  p = dst + 4*x + y*dst_linesize;
1021  AV_WL32(p, v);
1022  break;
1023  case AV_PIX_FMT_GBRP:
1024  p = dstp[0] + x + y * dst_linesize;
1025  p[0] = g;
1026  p = dstp[1] + x + y * dst_linesizep[1];
1027  p[0] = b;
1028  p = dstp[2] + x + y * dst_linesizep[2];
1029  p[0] = r;
1030  break;
1031  case AV_PIX_FMT_GBRP9:
1032  case AV_PIX_FMT_GBRP10:
1033  case AV_PIX_FMT_GBRP12:
1034  case AV_PIX_FMT_GBRP14:
1035  case AV_PIX_FMT_GBRP16:
1036  p16 = (uint16_t *)(dstp[0] + x*2 + y * dst_linesizep[0]);
1037  p16[0] = g;
1038  p16 = (uint16_t *)(dstp[1] + x*2 + y * dst_linesizep[1]);
1039  p16[0] = b;
1040  p16 = (uint16_t *)(dstp[2] + x*2 + y * dst_linesizep[2]);
1041  p16[0] = r;
1042  break;
1043  }
1044 }
1045 
1046 static void rgbtest_fill_picture_complement(AVFilterContext *ctx, AVFrame *frame)
1047 {
1048  TestSourceContext *test = ctx->priv;
1049  int x, y, w = frame->width, h = frame->height;
1050 
1051  for (y = 0; y < h; y++) {
1052  for (x = 0; x < w; x++) {
1053  int c = (1 << FFMAX(test->depth, 8))*x/w;
1054  int r = 0, g = 0, b = 0;
1055 
1056  if (6*y < h ) r = c;
1057  else if (6*y < 2*h) g = c, b = c;
1058  else if (6*y < 3*h) g = c;
1059  else if (6*y < 4*h) r = c, b = c;
1060  else if (6*y < 5*h) b = c;
1061  else r = c, g = c;
1062 
1063  rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
1064  ctx->outputs[0]->format, test->rgba_map);
1065  }
1066  }
1067 }
1068 
1069 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1070 {
1071  TestSourceContext *test = ctx->priv;
1072  int x, y, w = frame->width, h = frame->height;
1073 
1074  for (y = 0; y < h; y++) {
1075  for (x = 0; x < w; x++) {
1076  int c = (1 << FFMAX(test->depth, 8))*x/w;
1077  int r = 0, g = 0, b = 0;
1078 
1079  if (3*y < h ) r = c;
1080  else if (3*y < 2*h) g = c;
1081  else b = c;
1082 
1083  rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
1084  ctx->outputs[0]->format, test->rgba_map);
1085  }
1086  }
1087 }
1088 
1089 static av_cold int rgbtest_init(AVFilterContext *ctx)
1090 {
1091  TestSourceContext *test = ctx->priv;
1092 
1093  test->draw_once = 1;
1094  test->fill_picture_fn = test->complement ? rgbtest_fill_picture_complement : rgbtest_fill_picture;
1095  return init(ctx);
1096 }
1097 
1098 static const enum AVPixelFormat rgbtest_pix_fmts[] = {
1107  };
1108 
1109 static int rgbtest_config_props(AVFilterLink *outlink)
1110 {
1111  TestSourceContext *test = outlink->src->priv;
1113 
1114  test->depth = desc->comp[0].depth;
1115  ff_fill_rgba_map(test->rgba_map, outlink->format);
1116  return config_props(outlink);
1117 }
1118 
1119 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
1120  {
1121  .name = "default",
1122  .type = AVMEDIA_TYPE_VIDEO,
1123  .config_props = rgbtest_config_props,
1124  },
1125 };
1126 
1127 const AVFilter ff_vsrc_rgbtestsrc = {
1128  .name = "rgbtestsrc",
1129  .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
1130  .priv_size = sizeof(TestSourceContext),
1131  .priv_class = &rgbtestsrc_class,
1132  .init = rgbtest_init,
1133  .uninit = uninit,
1134  .activate = activate,
1135  .inputs = NULL,
1136  FILTER_OUTPUTS(avfilter_vsrc_rgbtestsrc_outputs),
1137  FILTER_PIXFMTS_ARRAY(rgbtest_pix_fmts),
1138 };
1139 
1140 #endif /* CONFIG_RGBTESTSRC_FILTER */
1141 
1142 #if CONFIG_YUVTESTSRC_FILTER
1143 
1144 static void yuvtest_fill_picture8(AVFilterContext *ctx, AVFrame *frame)
1145 {
1146  int x, y, w = frame->width, h = frame->height / 3;
1148  const int factor = 1 << desc->comp[0].depth;
1149  const int mid = 1 << (desc->comp[0].depth - 1);
1150  uint8_t *ydst = frame->data[0];
1151  uint8_t *udst = frame->data[1];
1152  uint8_t *vdst = frame->data[2];
1153  ptrdiff_t ylinesize = frame->linesize[0];
1154  ptrdiff_t ulinesize = frame->linesize[1];
1155  ptrdiff_t vlinesize = frame->linesize[2];
1156 
1157  for (y = 0; y < h; y++) {
1158  for (x = 0; x < w; x++) {
1159  int c = factor * x / w;
1160 
1161  ydst[x] = c;
1162  udst[x] = mid;
1163  vdst[x] = mid;
1164  }
1165 
1166  ydst += ylinesize;
1167  udst += ulinesize;
1168  vdst += vlinesize;
1169  }
1170 
1171  h += h;
1172  for (; y < h; y++) {
1173  for (x = 0; x < w; x++) {
1174  int c = factor * x / w;
1175 
1176  ydst[x] = mid;
1177  udst[x] = c;
1178  vdst[x] = mid;
1179  }
1180 
1181  ydst += ylinesize;
1182  udst += ulinesize;
1183  vdst += vlinesize;
1184  }
1185 
1186  for (; y < frame->height; y++) {
1187  for (x = 0; x < w; x++) {
1188  int c = factor * x / w;
1189 
1190  ydst[x] = mid;
1191  udst[x] = mid;
1192  vdst[x] = c;
1193  }
1194 
1195  ydst += ylinesize;
1196  udst += ulinesize;
1197  vdst += vlinesize;
1198  }
1199 }
1200 
1201 static void yuvtest_fill_picture16(AVFilterContext *ctx, AVFrame *frame)
1202 {
1203  int x, y, w = frame->width, h = frame->height / 3;
1205  const int factor = 1 << desc->comp[0].depth;
1206  const int mid = 1 << (desc->comp[0].depth - 1);
1207  uint16_t *ydst = (uint16_t *)frame->data[0];
1208  uint16_t *udst = (uint16_t *)frame->data[1];
1209  uint16_t *vdst = (uint16_t *)frame->data[2];
1210  ptrdiff_t ylinesize = frame->linesize[0] / 2;
1211  ptrdiff_t ulinesize = frame->linesize[1] / 2;
1212  ptrdiff_t vlinesize = frame->linesize[2] / 2;
1213 
1214  for (y = 0; y < h; y++) {
1215  for (x = 0; x < w; x++) {
1216  int c = factor * x / w;
1217 
1218  ydst[x] = c;
1219  udst[x] = mid;
1220  vdst[x] = mid;
1221  }
1222 
1223  ydst += ylinesize;
1224  udst += ulinesize;
1225  vdst += vlinesize;
1226  }
1227 
1228  h += h;
1229  for (; y < h; y++) {
1230  for (x = 0; x < w; x++) {
1231  int c = factor * x / w;
1232 
1233  ydst[x] = mid;
1234  udst[x] = c;
1235  vdst[x] = mid;
1236  }
1237 
1238  ydst += ylinesize;
1239  udst += ulinesize;
1240  vdst += vlinesize;
1241  }
1242 
1243  for (; y < frame->height; y++) {
1244  for (x = 0; x < w; x++) {
1245  int c = factor * x / w;
1246 
1247  ydst[x] = mid;
1248  udst[x] = mid;
1249  vdst[x] = c;
1250  }
1251 
1252  ydst += ylinesize;
1253  udst += ulinesize;
1254  vdst += vlinesize;
1255  }
1256 }
1257 
1258 static av_cold int yuvtest_init(AVFilterContext *ctx)
1259 {
1260  TestSourceContext *test = ctx->priv;
1261 
1262  test->draw_once = 1;
1263  return init(ctx);
1264 }
1265 
1266 static const enum AVPixelFormat yuvtest_pix_fmts[] = {
1272 };
1273 
1274 static int yuvtest_config_props(AVFilterLink *outlink)
1275 {
1276  TestSourceContext *test = outlink->src->priv;
1278 
1279  test->fill_picture_fn = desc->comp[0].depth > 8 ? yuvtest_fill_picture16 : yuvtest_fill_picture8;
1280  return config_props(outlink);
1281 }
1282 
1283 static const AVFilterPad avfilter_vsrc_yuvtestsrc_outputs[] = {
1284  {
1285  .name = "default",
1286  .type = AVMEDIA_TYPE_VIDEO,
1287  .config_props = yuvtest_config_props,
1288  },
1289 };
1290 
1291 const AVFilter ff_vsrc_yuvtestsrc = {
1292  .name = "yuvtestsrc",
1293  .description = NULL_IF_CONFIG_SMALL("Generate YUV test pattern."),
1294  .priv_size = sizeof(TestSourceContext),
1295  .priv_class = &nullsrc_yuvtestsrc_class,
1296  .init = yuvtest_init,
1297  .uninit = uninit,
1298  .activate = activate,
1299  .inputs = NULL,
1300  FILTER_OUTPUTS(avfilter_vsrc_yuvtestsrc_outputs),
1301  FILTER_PIXFMTS_ARRAY(yuvtest_pix_fmts),
1302 };
1303 
1304 #endif /* CONFIG_YUVTESTSRC_FILTER */
1305 
1306 #if CONFIG_PAL75BARS_FILTER || CONFIG_PAL100BARS_FILTER || CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
1307 
1308 static const uint8_t rainbow[7][4] = {
1309  { 180, 128, 128, 255 }, /* 75% white */
1310  { 162, 44, 142, 255 }, /* 75% yellow */
1311  { 131, 156, 44, 255 }, /* 75% cyan */
1312  { 112, 72, 58, 255 }, /* 75% green */
1313  { 84, 184, 198, 255 }, /* 75% magenta */
1314  { 65, 100, 212, 255 }, /* 75% red */
1315  { 35, 212, 114, 255 }, /* 75% blue */
1316 };
1317 
1318 static const uint8_t rainbow100[7][4] = {
1319  { 235, 128, 128, 255 }, /* 100% white */
1320  { 210, 16, 146, 255 }, /* 100% yellow */
1321  { 170, 166, 16, 255 }, /* 100% cyan */
1322  { 145, 54, 34, 255 }, /* 100% green */
1323  { 106, 202, 222, 255 }, /* 100% magenta */
1324  { 81, 90, 240, 255 }, /* 100% red */
1325  { 41, 240, 110, 255 }, /* 100% blue */
1326 };
1327 
1328 static const uint8_t rainbowhd[7][4] = {
1329  { 180, 128, 128, 255 }, /* 75% white */
1330  { 168, 44, 136, 255 }, /* 75% yellow */
1331  { 145, 147, 44, 255 }, /* 75% cyan */
1332  { 133, 63, 52, 255 }, /* 75% green */
1333  { 63, 193, 204, 255 }, /* 75% magenta */
1334  { 51, 109, 212, 255 }, /* 75% red */
1335  { 28, 212, 120, 255 }, /* 75% blue */
1336 };
1337 
1338 static const uint8_t wobnair[7][4] = {
1339  { 35, 212, 114, 255 }, /* 75% blue */
1340  { 19, 128, 128, 255 }, /* 7.5% intensity black */
1341  { 84, 184, 198, 255 }, /* 75% magenta */
1342  { 19, 128, 128, 255 }, /* 7.5% intensity black */
1343  { 131, 156, 44, 255 }, /* 75% cyan */
1344  { 19, 128, 128, 255 }, /* 7.5% intensity black */
1345  { 180, 128, 128, 255 }, /* 75% white */
1346 };
1347 
1348 static const uint8_t white[4] = { 235, 128, 128, 255 };
1349 
1350 /* pluge pulses */
1351 static const uint8_t neg4ire[4] = { 7, 128, 128, 255 };
1352 static const uint8_t pos4ire[4] = { 24, 128, 128, 255 };
1353 
1354 /* fudged Q/-I */
1355 static const uint8_t i_pixel[4] = { 57, 156, 97, 255 };
1356 static const uint8_t q_pixel[4] = { 44, 171, 147, 255 };
1357 
1358 static const uint8_t gray40[4] = { 104, 128, 128, 255 };
1359 static const uint8_t gray15[4] = { 49, 128, 128, 255 };
1360 static const uint8_t cyan[4] = { 188, 154, 16, 255 };
1361 static const uint8_t yellow[4] = { 219, 16, 138, 255 };
1362 static const uint8_t blue[4] = { 32, 240, 118, 255 };
1363 static const uint8_t red[4] = { 63, 102, 240, 255 };
1364 static const uint8_t black0[4] = { 16, 128, 128, 255 };
1365 static const uint8_t black2[4] = { 20, 128, 128, 255 };
1366 static const uint8_t black4[4] = { 25, 128, 128, 255 };
1367 static const uint8_t neg2[4] = { 12, 128, 128, 255 };
1368 
1369 static void draw_bar(TestSourceContext *test, const uint8_t color[4],
1370  int x, int y, int w, int h,
1371  AVFrame *frame)
1372 {
1374  uint8_t *p, *p0;
1375  int plane;
1376 
1377  x = FFMIN(x, test->w - 1);
1378  y = FFMIN(y, test->h - 1);
1379  w = FFMAX(FFMIN(w, test->w - x), 0);
1380  h = FFMAX(FFMIN(h, test->h - y), 0);
1381 
1382  av_assert0(x + w <= test->w);
1383  av_assert0(y + h <= test->h);
1384 
1385  for (plane = 0; frame->data[plane]; plane++) {
1386  const int c = color[plane];
1387  const ptrdiff_t linesize = frame->linesize[plane];
1388  int i, px, py, pw, ph;
1389 
1390  if (plane == 1 || plane == 2) {
1391  px = x >> desc->log2_chroma_w;
1392  pw = AV_CEIL_RSHIFT(w, desc->log2_chroma_w);
1393  py = y >> desc->log2_chroma_h;
1394  ph = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
1395  } else {
1396  px = x;
1397  pw = w;
1398  py = y;
1399  ph = h;
1400  }
1401 
1402  p0 = p = frame->data[plane] + py * linesize + px;
1403  memset(p, c, pw);
1404  p += linesize;
1405  for (i = 1; i < ph; i++, p += linesize)
1406  memcpy(p, p0, pw);
1407  }
1408 }
1409 
1410 static const enum AVPixelFormat smptebars_pix_fmts[] = {
1415 };
1416 
1417 static int smptebars_query_formats(const AVFilterContext *ctx,
1418  AVFilterFormatsConfig **cfg_in,
1419  AVFilterFormatsConfig **cfg_out)
1420 {
1421  enum AVColorSpace csp;
1422  int ret;
1423 
1424  if (!strcmp(ctx->name, "smptehdbars")) {
1425  csp = AVCOL_SPC_BT709;
1426  } else {
1427  csp = AVCOL_SPC_BT470BG;
1428  }
1429 
1430  if ((ret = ff_set_common_color_spaces2(ctx, cfg_in, cfg_out,
1432  return ret;
1433  if ((ret = ff_set_common_color_ranges2(ctx, cfg_in, cfg_out,
1435  return ret;
1436  return ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, smptebars_pix_fmts);
1437 }
1438 
1439 AVFILTER_DEFINE_CLASS_EXT(palbars, "pal(75|100)bars", options);
1440 
1441 #if CONFIG_PAL75BARS_FILTER
1442 
1443 static void pal75bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1444 {
1445  TestSourceContext *test = ctx->priv;
1446  int r_w, i, x = 0;
1447  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1448 
1449  r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1450 
1451  draw_bar(test, white, x, 0, r_w, test->h, picref);
1452  x += r_w;
1453  for (i = 1; i < 7; i++) {
1454  draw_bar(test, rainbow[i], x, 0, r_w, test->h, picref);
1455  x += r_w;
1456  }
1457  draw_bar(test, black0, x, 0, r_w, test->h, picref);
1458 }
1459 
1460 static av_cold int pal75bars_init(AVFilterContext *ctx)
1461 {
1462  TestSourceContext *test = ctx->priv;
1463 
1464  test->fill_picture_fn = pal75bars_fill_picture;
1465  test->draw_once = 1;
1466  return init(ctx);
1467 }
1468 
1469 const AVFilter ff_vsrc_pal75bars = {
1470  .name = "pal75bars",
1471  .description = NULL_IF_CONFIG_SMALL("Generate PAL 75% color bars."),
1472  .priv_class = &palbars_class,
1473  .priv_size = sizeof(TestSourceContext),
1474  .init = pal75bars_init,
1475  .uninit = uninit,
1476  .activate = activate,
1477  .inputs = NULL,
1479  FILTER_QUERY_FUNC2(smptebars_query_formats),
1480 };
1481 
1482 #endif /* CONFIG_PAL75BARS_FILTER */
1483 
1484 #if CONFIG_PAL100BARS_FILTER
1485 
1486 static void pal100bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1487 {
1488  TestSourceContext *test = ctx->priv;
1489  int r_w, i, x = 0;
1490  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1491 
1492  r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1493 
1494  for (i = 0; i < 7; i++) {
1495  draw_bar(test, rainbow100[i], x, 0, r_w, test->h, picref);
1496  x += r_w;
1497  }
1498  draw_bar(test, black0, x, 0, r_w, test->h, picref);
1499 }
1500 
1501 static av_cold int pal100bars_init(AVFilterContext *ctx)
1502 {
1503  TestSourceContext *test = ctx->priv;
1504 
1505  test->fill_picture_fn = pal100bars_fill_picture;
1506  test->draw_once = 1;
1507  return init(ctx);
1508 }
1509 
1510 const AVFilter ff_vsrc_pal100bars = {
1511  .name = "pal100bars",
1512  .description = NULL_IF_CONFIG_SMALL("Generate PAL 100% color bars."),
1513  .priv_class = &palbars_class,
1514  .priv_size = sizeof(TestSourceContext),
1515  .init = pal100bars_init,
1516  .uninit = uninit,
1517  .activate = activate,
1518  .inputs = NULL,
1520  FILTER_QUERY_FUNC2(smptebars_query_formats),
1521 };
1522 
1523 #endif /* CONFIG_PAL100BARS_FILTER */
1524 
1525 AVFILTER_DEFINE_CLASS_EXT(smptebars, "smpte(hd)bars", options);
1526 
1527 #if CONFIG_SMPTEBARS_FILTER
1528 
1529 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1530 {
1531  TestSourceContext *test = ctx->priv;
1532  int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
1533  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1534 
1535  r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
1536  r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
1537  w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
1538  p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
1539  p_h = test->h - w_h - r_h;
1540 
1541  for (i = 0; i < 7; i++) {
1542  draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
1543  draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
1544  x += r_w;
1545  }
1546  x = 0;
1547  draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
1548  x += p_w;
1549  draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
1550  x += p_w;
1551  draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
1552  x += p_w;
1553  tmp = FFALIGN(5 * r_w - x, 1 << pixdesc->log2_chroma_w);
1554  draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1555  x += tmp;
1556  tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1557  draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
1558  x += tmp;
1559  draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1560  x += tmp;
1561  draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
1562  x += tmp;
1563  draw_bar(test, black0, x, r_h + w_h, test->w - x, p_h, picref);
1564 }
1565 
1566 static av_cold int smptebars_init(AVFilterContext *ctx)
1567 {
1568  TestSourceContext *test = ctx->priv;
1569 
1570  test->fill_picture_fn = smptebars_fill_picture;
1571  test->draw_once = 1;
1572  return init(ctx);
1573 }
1574 
1575 const AVFilter ff_vsrc_smptebars = {
1576  .name = "smptebars",
1577  .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
1578  .priv_size = sizeof(TestSourceContext),
1579  .priv_class = &smptebars_class,
1580  .init = smptebars_init,
1581  .uninit = uninit,
1582  .activate = activate,
1583  .inputs = NULL,
1585  FILTER_QUERY_FUNC2(smptebars_query_formats),
1586 };
1587 
1588 #endif /* CONFIG_SMPTEBARS_FILTER */
1589 
1590 #if CONFIG_SMPTEHDBARS_FILTER
1591 
1592 static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1593 {
1594  TestSourceContext *test = ctx->priv;
1595  int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
1596  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1597 
1598  d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
1599  r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
1600  draw_bar(test, gray40, x, 0, d_w, r_h, picref);
1601  x += d_w;
1602 
1603  r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
1604  for (i = 0; i < 7; i++) {
1605  draw_bar(test, rainbowhd[i], x, 0, r_w, r_h, picref);
1606  x += r_w;
1607  }
1608  draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
1609  y = r_h;
1610  r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
1611  draw_bar(test, cyan, 0, y, d_w, r_h, picref);
1612  x = d_w;
1613  draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
1614  x += r_w;
1615  tmp = r_w * 6;
1616  draw_bar(test, rainbowhd[0], x, y, tmp, r_h, picref);
1617  x += tmp;
1618  l_w = x;
1619  draw_bar(test, blue, x, y, test->w - x, r_h, picref);
1620  y += r_h;
1621  draw_bar(test, yellow, 0, y, d_w, r_h, picref);
1622  x = d_w;
1623  draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
1624  x += r_w;
1625 
1626  for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
1627  uint8_t yramp[4] = {0};
1628 
1629  yramp[0] = i * 255 / tmp;
1630  yramp[1] = 128;
1631  yramp[2] = 128;
1632  yramp[3] = 255;
1633 
1634  draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
1635  x += 1 << pixdesc->log2_chroma_w;
1636  }
1637  draw_bar(test, red, x, y, test->w - x, r_h, picref);
1638  y += r_h;
1639  draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
1640  x = d_w;
1641  tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
1642  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1643  x += tmp;
1644  tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
1645  draw_bar(test, white, x, y, tmp, test->h - y, picref);
1646  x += tmp;
1647  tmp = FFALIGN(r_w * 5 / 6, 1 << pixdesc->log2_chroma_w);
1648  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1649  x += tmp;
1650  tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1651  draw_bar(test, neg2, x, y, tmp, test->h - y, picref);
1652  x += tmp;
1653  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1654  x += tmp;
1655  draw_bar(test, black2, x, y, tmp, test->h - y, picref);
1656  x += tmp;
1657  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1658  x += tmp;
1659  draw_bar(test, black4, x, y, tmp, test->h - y, picref);
1660  x += tmp;
1661  r_w = l_w - x;
1662  draw_bar(test, black0, x, y, r_w, test->h - y, picref);
1663  x += r_w;
1664  draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
1665 }
1666 
1667 static av_cold int smptehdbars_init(AVFilterContext *ctx)
1668 {
1669  TestSourceContext *test = ctx->priv;
1670 
1671  test->fill_picture_fn = smptehdbars_fill_picture;
1672  test->draw_once = 1;
1673  return init(ctx);
1674 }
1675 
1676 const AVFilter ff_vsrc_smptehdbars = {
1677  .name = "smptehdbars",
1678  .description = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
1679  .priv_class = &smptebars_class,
1680  .priv_size = sizeof(TestSourceContext),
1681  .init = smptehdbars_init,
1682  .uninit = uninit,
1683  .activate = activate,
1684  .inputs = NULL,
1686  FILTER_QUERY_FUNC2(smptebars_query_formats),
1687 };
1688 
1689 #endif /* CONFIG_SMPTEHDBARS_FILTER */
1690 #endif /* CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */
1691 
1692 AVFILTER_DEFINE_CLASS_EXT(allyuv_allrgb, "allyuv/allrgb",
1694 
1695 #if CONFIG_ALLYUV_FILTER
1696 
1697 static void allyuv_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1698 {
1699  const ptrdiff_t ys = frame->linesize[0];
1700  const ptrdiff_t us = frame->linesize[1];
1701  const ptrdiff_t vs = frame->linesize[2];
1702  int x, y, j;
1703 
1704  for (y = 0; y < 4096; y++) {
1705  for (x = 0; x < 2048; x++) {
1706  frame->data[0][y * ys + x] = ((x / 8) % 256);
1707  frame->data[0][y * ys + 4095 - x] = ((x / 8) % 256);
1708  }
1709 
1710  for (x = 0; x < 2048; x+=8) {
1711  for (j = 0; j < 8; j++) {
1712  frame->data[1][vs * y + x + j] = (y%16 + (j % 8) * 16);
1713  frame->data[1][vs * y + 4095 - x - j] = (128 + y%16 + (j % 8) * 16);
1714  }
1715  }
1716 
1717  for (x = 0; x < 4096; x++)
1718  frame->data[2][y * us + x] = 256 * y / 4096;
1719  }
1720 }
1721 
1722 static av_cold int allyuv_init(AVFilterContext *ctx)
1723 {
1724  TestSourceContext *test = ctx->priv;
1725 
1726  test->w = test->h = 4096;
1727  test->draw_once = 1;
1728  test->fill_picture_fn = allyuv_fill_picture;
1729  return init(ctx);
1730 }
1731 
1732 const AVFilter ff_vsrc_allyuv = {
1733  .name = "allyuv",
1734  .description = NULL_IF_CONFIG_SMALL("Generate all yuv colors."),
1735  .priv_size = sizeof(TestSourceContext),
1736  .priv_class = &allyuv_allrgb_class,
1737  .init = allyuv_init,
1738  .uninit = uninit,
1739  .activate = activate,
1740  .inputs = NULL,
1743 };
1744 
1745 #endif /* CONFIG_ALLYUV_FILTER */
1746 
1747 #if CONFIG_ALLRGB_FILTER
1748 
1749 static void allrgb_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1750 {
1751  unsigned x, y;
1752  const ptrdiff_t linesize = frame->linesize[0];
1753  uint8_t *line = frame->data[0];
1754 
1755  for (y = 0; y < 4096; y++) {
1756  uint8_t *dst = line;
1757 
1758  for (x = 0; x < 4096; x++) {
1759  *dst++ = x;
1760  *dst++ = y;
1761  *dst++ = (x >> 8) | ((y >> 8) << 4);
1762  }
1763  line += linesize;
1764  }
1765 }
1766 
1767 static av_cold int allrgb_init(AVFilterContext *ctx)
1768 {
1769  TestSourceContext *test = ctx->priv;
1770 
1771  test->w = test->h = 4096;
1772  test->draw_once = 1;
1773  test->fill_picture_fn = allrgb_fill_picture;
1774  return init(ctx);
1775 }
1776 
1777 static int allrgb_config_props(AVFilterLink *outlink)
1778 {
1779  TestSourceContext *test = outlink->src->priv;
1780 
1781  ff_fill_rgba_map(test->rgba_map, outlink->format);
1782  return config_props(outlink);
1783 }
1784 
1785 static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
1786  {
1787  .name = "default",
1788  .type = AVMEDIA_TYPE_VIDEO,
1789  .config_props = allrgb_config_props,
1790  },
1791 };
1792 
1793 const AVFilter ff_vsrc_allrgb = {
1794  .name = "allrgb",
1795  .description = NULL_IF_CONFIG_SMALL("Generate all RGB colors."),
1796  .priv_size = sizeof(TestSourceContext),
1797  .priv_class = &allyuv_allrgb_class,
1798  .init = allrgb_init,
1799  .uninit = uninit,
1800  .activate = activate,
1801  .inputs = NULL,
1802  FILTER_OUTPUTS(avfilter_vsrc_allrgb_outputs),
1804 };
1805 
1806 #endif /* CONFIG_ALLRGB_FILTER */
1807 
1808 #if CONFIG_COLORSPECTRUM_FILTER
1809 
1810 static const AVOption colorspectrum_options[] = {
1812  { "type", "set the color spectrum type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, .unit = "type" },
1813  { "black","fade to black", 0, AV_OPT_TYPE_CONST,{.i64=0},0, 0, FLAGS, .unit = "type" },
1814  { "white","fade to white", 0, AV_OPT_TYPE_CONST,{.i64=1},0, 0, FLAGS, .unit = "type" },
1815  { "all", "white to black", 0, AV_OPT_TYPE_CONST,{.i64=2},0, 0, FLAGS, .unit = "type" },
1816  { NULL }
1817 };
1818 
1819 AVFILTER_DEFINE_CLASS(colorspectrum);
1820 
1821 static inline float mix(float a, float b, float mix)
1822 {
1823  return a * mix + b * (1.f - mix);
1824 }
1825 
1826 static void hsb2rgb(const float *c, float *rgb)
1827 {
1828  rgb[0] = av_clipf(fabsf(fmodf(c[0] * 6.f + 0.f, 6.f) - 3.f) - 1.f, 0.f, 1.f);
1829  rgb[1] = av_clipf(fabsf(fmodf(c[0] * 6.f + 4.f, 6.f) - 3.f) - 1.f, 0.f, 1.f);
1830  rgb[2] = av_clipf(fabsf(fmodf(c[0] * 6.f + 2.f, 6.f) - 3.f) - 1.f, 0.f, 1.f);
1831  rgb[0] = mix(c[3], (rgb[0] * rgb[0] * (3.f - 2.f * rgb[0])), c[1]) * c[2];
1832  rgb[1] = mix(c[3], (rgb[1] * rgb[1] * (3.f - 2.f * rgb[1])), c[1]) * c[2];
1833  rgb[2] = mix(c[3], (rgb[2] * rgb[2] * (3.f - 2.f * rgb[2])), c[1]) * c[2];
1834 }
1835 
1836 static void colorspectrum_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1837 {
1838  TestSourceContext *test = ctx->priv;
1839  const float w = frame->width - 1.f;
1840  const float h = frame->height - 1.f;
1841  float c[4];
1842 
1843  for (int y = 0; y < frame->height; y++) {
1844  float *r = (float *)(frame->data[2] + y * frame->linesize[2]);
1845  float *g = (float *)(frame->data[0] + y * frame->linesize[0]);
1846  float *b = (float *)(frame->data[1] + y * frame->linesize[1]);
1847  const float yh = y / h;
1848 
1849  c[1] = test->type == 2 ? yh > 0.5f ? 2.f * (yh - 0.5f) : 1.f - 2.f * yh : test->type == 1 ? 1.f - yh : yh;
1850  c[2] = 1.f;
1851  c[3] = test->type == 1 ? 1.f : test->type == 2 ? (yh > 0.5f ? 0.f : 1.f): 0.f;
1852  for (int x = 0; x < frame->width; x++) {
1853  float rgb[3];
1854 
1855  c[0] = x / w;
1856  hsb2rgb(c, rgb);
1857 
1858  r[x] = rgb[0];
1859  g[x] = rgb[1];
1860  b[x] = rgb[2];
1861  }
1862  }
1863 }
1864 
1865 static av_cold int colorspectrum_init(AVFilterContext *ctx)
1866 {
1867  TestSourceContext *test = ctx->priv;
1868 
1869  test->draw_once = 1;
1870  test->fill_picture_fn = colorspectrum_fill_picture;
1871  return init(ctx);
1872 }
1873 
1875  .name = "colorspectrum",
1876  .description = NULL_IF_CONFIG_SMALL("Generate colors spectrum."),
1877  .priv_size = sizeof(TestSourceContext),
1878  .priv_class = &colorspectrum_class,
1879  .init = colorspectrum_init,
1880  .uninit = uninit,
1881  .activate = activate,
1882  .inputs = NULL,
1885 };
1886 
1887 #endif /* CONFIG_COLORSPECTRUM_FILTER */
1888 
1889 #if CONFIG_COLORCHART_FILTER
1890 
1891 static const AVOption colorchart_options[] = {
1893  { "patch_size", "set the single patch size", OFFSET(pw), AV_OPT_TYPE_IMAGE_SIZE, {.str="64x64"}, 0, 0, FLAGS },
1894  { "preset", "set the color checker chart preset", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, .unit = "preset" },
1895  { "reference", "reference", 0, AV_OPT_TYPE_CONST,{.i64=0}, 0, 0, FLAGS, .unit = "preset" },
1896  { "skintones", "skintones", 0, AV_OPT_TYPE_CONST,{.i64=1}, 0, 0, FLAGS, .unit = "preset" },
1897  { NULL }
1898 };
1899 
1900 AVFILTER_DEFINE_CLASS(colorchart);
1901 
1902 static const uint8_t reference_colors[][3] = {
1903  { 115, 82, 68 }, // dark skin
1904  { 194, 150, 130 }, // light skin
1905  { 98, 122, 157 }, // blue sky
1906  { 87, 108, 67 }, // foliage
1907  { 133, 128, 177 }, // blue flower
1908  { 103, 189, 170 }, // bluish green
1909 
1910  { 214, 126, 44 }, // orange
1911  { 80, 91, 166 }, // purple red
1912  { 193, 90, 99 }, // moderate red
1913  { 94, 60, 108 }, // purple
1914  { 157, 188, 64 }, // yellow green
1915  { 224, 163, 46 }, // orange yellow
1916 
1917  { 56, 61, 150 }, // blue
1918  { 70, 148, 73 }, // green
1919  { 175, 54, 60 }, // red
1920  { 231, 199, 31 }, // yellow
1921  { 187, 86, 149 }, // magenta
1922  { 8, 133, 161 }, // cyan
1923 
1924  { 243, 243, 242 }, // white
1925  { 200, 200, 200 }, // neutral 8
1926  { 160, 160, 160 }, // neutral 65
1927  { 122, 122, 121 }, // neutral 5
1928  { 85, 85, 85 }, // neutral 35
1929  { 52, 52, 52 }, // black
1930 };
1931 
1932 static const uint8_t skintones_colors[][3] = {
1933  { 54, 38, 43 },
1934  { 105, 43, 42 },
1935  { 147, 43, 43 },
1936  { 77, 41, 42 },
1937  { 134, 43, 41 },
1938  { 201, 134, 118 },
1939 
1940  { 59, 41, 41 },
1941  { 192, 103, 76 },
1942  { 208, 156, 141 },
1943  { 152, 82, 61 },
1944  { 162, 132, 118 },
1945  { 212, 171, 150 },
1946 
1947  { 205, 91, 31 },
1948  { 164, 100, 55 },
1949  { 204, 136, 95 },
1950  { 178, 142, 116 },
1951  { 210, 152, 108 },
1952  { 217, 167, 131 },
1953 
1954  { 206, 166, 126 },
1955  { 208, 163, 97 },
1956  { 245, 180, 0 },
1957  { 212, 184, 125 },
1958  { 179, 165, 150 },
1959  { 196, 184, 105 },
1960 };
1961 
1962 typedef struct ColorChartPreset {
1963  int w, h;
1964  const uint8_t (*colors)[3];
1965 } ColorChartPreset;
1966 
1967 static const ColorChartPreset colorchart_presets[] = {
1968  { 6, 4, reference_colors, },
1969  { 6, 4, skintones_colors, },
1970 };
1971 
1972 static int colorchart_config_props(AVFilterLink *inlink)
1973 {
1974  AVFilterContext *ctx = inlink->src;
1975  TestSourceContext *s = ctx->priv;
1976 
1977  av_assert0(ff_draw_init2(&s->draw, inlink->format, inlink->colorspace,
1978  inlink->color_range, 0) >= 0);
1979  if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
1980  return AVERROR(EINVAL);
1981  return config_props(inlink);
1982 }
1983 
1984 static void colorchart_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1985 {
1986  TestSourceContext *test = ctx->priv;
1987  const int preset = test->type;
1988  const int w = colorchart_presets[preset].w;
1989  const int h = colorchart_presets[preset].h;
1990  const int pw = test->pw;
1991  const int ph = test->ph;
1992 
1993  for (int y = 0; y < h; y++) {
1994  for (int x = 0; x < w; x++) {
1995  uint32_t pc = AV_RB24(colorchart_presets[preset].colors[y * w + x]);
1997 
1998  set_color(test, &color, pc);
1999  ff_fill_rectangle(&test->draw, &color, frame->data, frame->linesize,
2000  x * pw, y * ph, pw, ph);
2001  }
2002  }
2003 }
2004 
2005 static av_cold int colorchart_init(AVFilterContext *ctx)
2006 {
2007  TestSourceContext *test = ctx->priv;
2008  const int preset = test->type;
2009  const int w = colorchart_presets[preset].w;
2010  const int h = colorchart_presets[preset].h;
2011 
2012  test->w = w * test->pw;
2013  test->h = h * test->ph;
2014  test->draw_once = 1;
2015  test->fill_picture_fn = colorchart_fill_picture;
2016  return init(ctx);
2017 }
2018 
2019 static const AVFilterPad avfilter_vsrc_colorchart_outputs[] = {
2020  {
2021  .name = "default",
2022  .type = AVMEDIA_TYPE_VIDEO,
2023  .config_props = colorchart_config_props,
2024  },
2025 };
2026 
2027 const AVFilter ff_vsrc_colorchart = {
2028  .name = "colorchart",
2029  .description = NULL_IF_CONFIG_SMALL("Generate color checker chart."),
2030  .priv_size = sizeof(TestSourceContext),
2031  .priv_class = &colorchart_class,
2032  .init = colorchart_init,
2033  .uninit = uninit,
2034  .activate = activate,
2035  .inputs = NULL,
2036  FILTER_OUTPUTS(avfilter_vsrc_colorchart_outputs),
2038 };
2039 
2040 #endif /* CONFIG_COLORCHART_FILTER */
2041 
2042 #if CONFIG_ZONEPLATE_FILTER
2043 
2044 static const AVOption zoneplate_options[] = {
2046  { "precision", "set LUT precision", OFFSET(lut_precision), AV_OPT_TYPE_INT, {.i64=10}, 4, 16, FLAGS },
2047  { "xo", "set X-axis offset", OFFSET(xo), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2048  { "yo", "set Y-axis offset", OFFSET(yo), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2049  { "to", "set T-axis offset", OFFSET(to), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2050  { "k0", "set 0-order phase", OFFSET(k0), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2051  { "kx", "set 1-order X-axis phase", OFFSET(kx), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2052  { "ky", "set 1-order Y-axis phase", OFFSET(ky), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2053  { "kt", "set 1-order T-axis phase", OFFSET(kt), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2054  { "kxt", "set X-axis*T-axis product phase", OFFSET(kxt), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2055  { "kyt", "set Y-axis*T-axis product phase", OFFSET(kyt), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2056  { "kxy", "set X-axis*Y-axis product phase", OFFSET(kxy), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2057  { "kx2", "set 2-order X-axis phase", OFFSET(kx2), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2058  { "ky2", "set 2-order Y-axis phase", OFFSET(ky2), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2059  { "kt2", "set 2-order T-axis phase", OFFSET(kt2), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2060  { "ku", "set 0-order U-color phase", OFFSET(kU), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2061  { "kv", "set 0-order V-color phase", OFFSET(kV), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2062  { NULL }
2063 };
2064 
2065 AVFILTER_DEFINE_CLASS(zoneplate);
2066 
2067 #define ZONEPLATE_SLICE(name, type) \
2068 static int zoneplate_fill_slice_##name(AVFilterContext *ctx, \
2069  void *arg, int job, \
2070  int nb_jobs) \
2071 { \
2072  TestSourceContext *test = ctx->priv; \
2073  AVFrame *frame = arg; \
2074  const int w = frame->width; \
2075  const int h = frame->height; \
2076  const int kxt = test->kxt, kyt = test->kyt, kx2 = test->kx2; \
2077  const int t = test->pts + test->to, k0 = test->k0; \
2078  const int kt = test->kt, kt2 = test->kt2, ky2 = test->ky2; \
2079  const int ky = test->ky, kx = test->kx, kxy = test->kxy; \
2080  const int lut_mask = (1 << test->lut_precision) - 1; \
2081  const int nkt2t = kt2 * t * t, nktt = kt * t; \
2082  const int start = (h * job ) / nb_jobs; \
2083  const int end = (h * (job+1)) / nb_jobs; \
2084  const ptrdiff_t ylinesize = frame->linesize[0] / sizeof(type); \
2085  const ptrdiff_t ulinesize = frame->linesize[1] / sizeof(type); \
2086  const ptrdiff_t vlinesize = frame->linesize[2] / sizeof(type); \
2087  const int xreset = -(w / 2) - test->xo; \
2088  const int yreset = -(h / 2) - test->yo + start; \
2089  const int kU = test->kU, kV = test->kV; \
2090  const int skxy = 0xffff / (w / 2); \
2091  const int skx2 = 0xffff / w; \
2092  const int dkxt = kxt * t; \
2093  type *ydst = ((type *)frame->data[0]) + start * ylinesize; \
2094  type *udst = ((type *)frame->data[1]) + start * ulinesize; \
2095  type *vdst = ((type *)frame->data[2]) + start * vlinesize; \
2096  const type *lut = (const type *)test->lut; \
2097  int akx, akxt, aky, akyt; \
2098  \
2099  aky = start * ky; \
2100  akyt = start * kyt * t; \
2101  \
2102  for (int j = start, y = yreset; j < end; j++, y++) { \
2103  const int dkxy = kxy * y * skxy; \
2104  const int nky2kt2 = (ky2 * y * y) / h + (nkt2t >> 1); \
2105  int akxy = dkxy * xreset; \
2106  \
2107  akx = 0; \
2108  akxt = 0; \
2109  aky += ky; \
2110  akyt += kyt * t; \
2111  \
2112  for (int i = 0, x = xreset; i < w; i++, x++) { \
2113  int phase = k0, uphase = kU, vphase = kV; \
2114  \
2115  akx += kx; \
2116  phase += akx + aky + nktt; \
2117  \
2118  akxt += dkxt; \
2119  akxy += dkxy; \
2120  phase += akxt + akyt; \
2121  phase += akxy >> 16; \
2122  phase += ((kx2 * x * x * skx2) >> 16) + nky2kt2; \
2123  uphase += phase; \
2124  vphase += phase; \
2125  \
2126  ydst[i] = lut[phase & lut_mask]; \
2127  udst[i] = lut[uphase & lut_mask]; \
2128  vdst[i] = lut[vphase & lut_mask]; \
2129  } \
2130  \
2131  ydst += ylinesize; \
2132  udst += ulinesize; \
2133  vdst += vlinesize; \
2134  } \
2135  \
2136  return 0; \
2137 }
2138 
2139 ZONEPLATE_SLICE( 8, uint8_t)
2140 ZONEPLATE_SLICE( 9, uint16_t)
2141 ZONEPLATE_SLICE(10, uint16_t)
2142 ZONEPLATE_SLICE(12, uint16_t)
2143 ZONEPLATE_SLICE(14, uint16_t)
2144 ZONEPLATE_SLICE(16, uint16_t)
2145 
2146 static void zoneplate_fill_picture(AVFilterContext *ctx, AVFrame *frame)
2147 {
2148  TestSourceContext *test = ctx->priv;
2149  ff_filter_execute(ctx, test->fill_slice_fn, frame, NULL,
2151 }
2152 
2153 static int zoneplate_config_props(AVFilterLink *outlink)
2154 {
2155  AVFilterContext *ctx = outlink->src;
2156  TestSourceContext *test = ctx->priv;
2158  const int lut_size = 1 << test->lut_precision;
2159  const int depth = desc->comp[0].depth;
2160  uint16_t *lut16;
2161  uint8_t *lut8;
2162 
2163  if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
2164  return AVERROR(EINVAL);
2165 
2166  test->lut = av_calloc(lut_size, sizeof(*test->lut) * ((depth + 7) / 8));
2167  if (!test->lut)
2168  return AVERROR(ENOMEM);
2169 
2170  lut8 = test->lut;
2171  lut16 = (uint16_t *)test->lut;
2172  switch (depth) {
2173  case 8:
2174  for (int i = 0; i < lut_size; i++)
2175  lut8[i] = lrintf(255.f * (0.5f + 0.5f * sinf((2.f * M_PI * i) / lut_size)));
2176  break;
2177  default:
2178  for (int i = 0; i < lut_size; i++)
2179  lut16[i] = lrintf(((1 << depth) - 1) * (0.5f + 0.5f * sinf((2.f * M_PI * i) / lut_size)));
2180  break;
2181  }
2182 
2183  test->draw_once = 0;
2184  test->fill_picture_fn = zoneplate_fill_picture;
2185 
2186  switch (depth) {
2187  case 8: test->fill_slice_fn = zoneplate_fill_slice_8; break;
2188  case 9: test->fill_slice_fn = zoneplate_fill_slice_9; break;
2189  case 10: test->fill_slice_fn = zoneplate_fill_slice_10; break;
2190  case 12: test->fill_slice_fn = zoneplate_fill_slice_12; break;
2191  case 14: test->fill_slice_fn = zoneplate_fill_slice_14; break;
2192  case 16: test->fill_slice_fn = zoneplate_fill_slice_16; break;
2193  }
2194  return config_props(outlink);
2195 }
2196 
2197 static const enum AVPixelFormat zoneplate_pix_fmts[] = {
2202 };
2203 
2204 static int zoneplate_query_formats(const AVFilterContext *ctx,
2205  AVFilterFormatsConfig **cfg_in,
2206  AVFilterFormatsConfig **cfg_out)
2207 {
2208  int ret;
2209  if ((ret = ff_set_common_color_ranges2(ctx, cfg_in, cfg_out,
2211  return ret;
2212  return ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, zoneplate_pix_fmts);
2213 }
2214 
2215 static const AVFilterPad avfilter_vsrc_zoneplate_outputs[] = {
2216  {
2217  .name = "default",
2218  .type = AVMEDIA_TYPE_VIDEO,
2219  .config_props = zoneplate_config_props,
2220  },
2221 };
2222 
2223 const AVFilter ff_vsrc_zoneplate = {
2224  .name = "zoneplate",
2225  .description = NULL_IF_CONFIG_SMALL("Generate zone-plate."),
2226  .priv_size = sizeof(TestSourceContext),
2227  .priv_class = &zoneplate_class,
2228  .init = init,
2229  .uninit = uninit,
2230  .activate = activate,
2231  .inputs = NULL,
2232  FILTER_OUTPUTS(avfilter_vsrc_zoneplate_outputs),
2233  FILTER_QUERY_FUNC2(zoneplate_query_formats),
2234  .flags = AVFILTER_FLAG_SLICE_THREADS,
2235  .process_command = ff_filter_process_command,
2236 };
2237 
2238 #endif /* CONFIG_ZONEPLATE_FILTER */
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:116
A
#define A(x)
Definition: vpx_arith.h:28
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:510
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
FFDrawColor
Definition: drawutils.h:50
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ff_exp10
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
level
uint8_t level
Definition: svq3.c:205
mix
static int mix(int c0, int c1)
Definition: 4xm.c:716
r
const char * r
Definition: vf_curves.c:127
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:422
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:242
color
Definition: vf_paletteuse.c:511
TestSourceContext::kV
int kV
Definition: vsrc_testsrc.c:94
ff_set_common_color_ranges2
int ff_set_common_color_ranges2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *color_ranges)
Definition: formats.c:983
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3025
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vsrc_testsrc.c:140
ff_set_common_formats2
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition: formats.c:1007
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
TestSourceContext::kxt
int kxt
Definition: vsrc_testsrc.c:92
int64_t
long long int64_t
Definition: coverity.c:34
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
TestSourceContext::k0
int k0
Definition: vsrc_testsrc.c:91
av_unused
#define av_unused
Definition: attributes.h:131
mask
int mask
Definition: mediacodecdec_common.c:154
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
ph
static int FUNC() ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
Definition: cbs_h266_syntax_template.c:3034
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
ff_vsrc_color
const AVFilter ff_vsrc_color
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:696
AVOption
AVOption.
Definition: opt.h:429
b
#define b
Definition: input.c:41
AV_ROUND_ZERO
@ AV_ROUND_ZERO
Round toward zero.
Definition: mathematics.h:131
data
const char data[16]
Definition: mxf.c:149
R
#define R
Definition: huffyuv.h:44
test
Definition: idctdsp.c:35
ff_vsrc_pal75bars
const AVFilter ff_vsrc_pal75bars
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
init
static av_cold int init(AVFilterContext *ctx)
Definition: vsrc_testsrc.c:125
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
video.h
ff_make_formats_list_singleton
AVFilterFormats * ff_make_formats_list_singleton(int fmt)
Equivalent to ff_make_format_list({const int[]}{ fmt, -1 })
Definition: formats.c:529
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:410
formats.h
ff_vsrc_haldclutsrc
const AVFilter ff_vsrc_haldclutsrc
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3065
AVCOL_SPC_BT470BG
@ 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:625
rgb
Definition: rpzaenc.c:60
ff_vsrc_yuvtestsrc
const AVFilter ff_vsrc_yuvtestsrc
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:505
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:472
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:503
TestSourceContext::kyt
int kyt
Definition: vsrc_testsrc.c:92
draw_rectangle
static void draw_rectangle(AVFormatContext *s)
Definition: xcbgrab.c:649
val
static double val(void *priv, double ch)
Definition: aeval.c:77
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
TestSourceContext::kxy
int kxy
Definition: vsrc_testsrc.c:92
TestSourceContext::xo
int xo
Definition: vsrc_testsrc.c:94
us
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:263
ff_vsrc_allrgb
const AVFilter ff_vsrc_allrgb
ff_blend_mask
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
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
planar
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1<< 16)) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(UINT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out->ch+ch,(const uint8_t **) in->ch+ch, off *(out-> planar
Definition: audioconvert.c:56
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
TestSourceContext::rgba_map
uint8_t rgba_map[4]
Definition: vsrc_testsrc.c:83
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:490
preset
preset
Definition: vf_curves.c:47
avassert.h
ff_vsrc_pal100bars
const AVFilter ff_vsrc_pal100bars
TestSourceContext::duration
int64_t duration
duration expressed in microseconds
Definition: vsrc_testsrc.c:60
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:640
ff_set_common_color_spaces2
int ff_set_common_color_spaces2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *color_spaces)
Definition: formats.c:959
TestSourceContext::type
int type
Definition: vsrc_testsrc.c:75
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:507
float
float
Definition: af_crystalizer.c:122
ff_outlink_set_status
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:424
TestSourceContext::kt
int kt
Definition: vsrc_testsrc.c:91
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:508
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:500
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
g
const char * g
Definition: vf_curves.c:128
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
TestSourceContext::ph
int ph
Definition: vsrc_testsrc.c:56
TestSourceContext::time_base
AVRational time_base
Definition: vsrc_testsrc.c:58
to
const char * to
Definition: webvttdec.c:35
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
filters.h
B
#define B
Definition: huffyuv.h:42
ctx
AVFormatContext * ctx
Definition: movenc.c:49
FLAGSR
#define FLAGSR
Definition: vsrc_testsrc.c:102
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:597
av_rescale_q
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
TestSourceContext::color_rgba
uint8_t color_rgba[4]
Definition: vsrc_testsrc.c:80
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
ff_vsrc_testsrc2
const AVFilter ff_vsrc_testsrc2
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
AV_PIX_FMT_YUVJ444P
@ 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:87
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
arg
const char * arg
Definition: jacosubdec.c:67
TestSourceContext::kt2
int kt2
Definition: vsrc_testsrc.c:93
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:506
TestSourceContext::sar
AVRational sar
sample aspect ratio
Definition: vsrc_testsrc.c:61
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:477
FLAGS
#define FLAGS
Definition: vsrc_testsrc.c:101
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
AV_PIX_FMT_BGR48
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:478
NULL
#define NULL
Definition: coverity.c:32
ff_vsrc_colorspectrum
const AVFilter ff_vsrc_colorspectrum
TestSourceContext::lut_precision
int lut_precision
Definition: vsrc_testsrc.c:95
grad
static double grad(int hash, double x, double y, double z)
Definition: perlin.c:42
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
TestSourceContext::color
FFDrawColor color
Definition: vsrc_testsrc.c:79
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
Definition: opt.h:323
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition: opt.h:303
AV_WL24
#define AV_WL24(p, d)
Definition: intreadwrite.h:460
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
NOSIZE_OPTIONS_OFFSET
#define NOSIZE_OPTIONS_OFFSET
Definition: vsrc_testsrc.c:117
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:265
sinf
#define sinf(x)
Definition: libm.h:419
av_clipf
av_clipf
Definition: af_crystalizer.c:122
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:502
ff_vsrc_colorchart
const AVFilter ff_vsrc_colorchart
ff_vsrc_allyuv
const AVFilter ff_vsrc_allyuv
AVFILTER_DEFINE_CLASS
#define AVFILTER_DEFINE_CLASS(fname)
Definition: filters.h:273
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:101
index
int index
Definition: gxfenc.c:90
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:111
TestSourceContext::picref
AVFrame * picref
cached reference containing the painted picture
Definition: vsrc_testsrc.c:64
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
av_rescale_rnd
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
f
f
Definition: af_crystalizer.c:122
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
config_props
static int config_props(AVFilterLink *outlink)
Definition: vsrc_testsrc.c:148
height
#define height
Definition: dsp.h:85
ff_vsrc_smptehdbars
const AVFilter ff_vsrc_smptehdbars
av_get_padded_bits_per_pixel
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:2990
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
ff_blend_rectangle
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:354
ff_draw_init2
int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp, enum AVColorRange range, unsigned flags)
Init a draw context.
Definition: drawutils.c:81
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
TestSourceContext::frame_rate
AVRational frame_rate
Definition: vsrc_testsrc.c:58
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:517
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:473
size
int size
Definition: twinvq_data.h:10344
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:94
COMMON_OPTIONS
#define COMMON_OPTIONS
Definition: vsrc_testsrc.c:115
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
AV_PIX_FMT_BGR555
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:480
ff_fill_rectangle
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:232
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:494
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:476
ff_filter_process_command
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:901
TestSourceContext::level
int level
Definition: vsrc_testsrc.c:88
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
TestSourceContext::nb_decimals
int nb_decimals
Definition: vsrc_testsrc.c:69
TestSourceContext::lut
uint8_t * lut
Definition: vsrc_testsrc.c:96
draw_bar
static void draw_bar(ShowCWTContext *s, int y, float Y, float U, float V)
Definition: avf_showcwt.c:379
line
Definition: graph2dot.c:48
AV_PIX_FMT_RGB0
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:263
xga_font_data.h
M_PI
#define M_PI
Definition: mathematics.h:67
TestSourceContext
Definition: vsrc_testsrc.c:53
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
TestSourceContext::nb_frame
unsigned int nb_frame
Definition: vsrc_testsrc.c:57
TestSourceContext::draw_once
int draw_once
draw only the first frame, always put out the same picture
Definition: vsrc_testsrc.c:62
AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:482
TestSourceContext::h
int h
Definition: vsrc_testsrc.c:55
avpriv_vga16_font
const uint8_t avpriv_vga16_font[4096]
Definition: xga_font_data.c:160
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_vsrc_nullsrc
const AVFilter ff_vsrc_nullsrc
TestSourceContext::complement
int complement
Definition: vsrc_testsrc.c:84
ff_draw_supported_pixel_formats
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:648
ff_vsrc_zoneplate
const AVFilter ff_vsrc_zoneplate
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:504
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:619
AV_PIX_FMT_BGR444
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:481
common.h
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:841
AV_PIX_FMT_RGB555
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:475
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:239
ff_draw_round_to_sub
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:636
TestSourceContext::ky
int ky
Definition: vsrc_testsrc.c:91
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_vsrc_smptebars
const AVFilter ff_vsrc_smptebars
FFDrawContext
Definition: drawutils.h:35
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AV_PIX_FMT_BGR565
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:479
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
FILTER_PIXFMTS
#define FILTER_PIXFMTS(...)
Definition: filters.h:248
av_rescale
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
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:648
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:679
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:486
OFFSET
#define OFFSET(x)
Definition: vsrc_testsrc.c:100
AV_PIX_FMT_RGB565
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:474
ff_draw_color
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:157
AVFilter
Filter definition.
Definition: avfilter.h:201
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_0BGR
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:264
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
TestSourceContext::kU
int kU
Definition: vsrc_testsrc.c:94
pos
unsigned int pos
Definition: spdifenc.c:414
U
#define U(x)
Definition: vpx_arith.h:37
outputs
static const AVFilterPad outputs[]
Definition: vsrc_testsrc.c:162
draw_text
static void draw_text(FFDrawContext *draw, AVFrame *out, FFDrawColor *color, int x0, int y0, const uint8_t *text)
Definition: src_avsynctest.c:247
steps
static const int16_t steps[16]
Definition: misc4.c:30
ff_vsrc_rgbtestsrc
const AVFilter ff_vsrc_rgbtestsrc
TestSourceContext::to
int to
Definition: vsrc_testsrc.c:94
ff_set_common_formats_from_list2
int ff_set_common_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *fmts)
Definition: formats.c:1016
TestSourceContext::alpha
int alpha
Definition: vsrc_testsrc.c:72
ff_filter_execute
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: avfilter.c:1667
activate
static int activate(AVFilterContext *ctx)
Definition: vsrc_testsrc.c:170
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
TestSourceContext::yo
int yo
Definition: vsrc_testsrc.c:94
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
TestSourceContext::ky2
int ky2
Definition: vsrc_testsrc.c:93
AVFILTER_DEFINE_CLASS_EXT
AVFILTER_DEFINE_CLASS_EXT(nullsrc_yuvtestsrc, "nullsrc/yuvtestsrc", options)
AV_PIX_FMT_FLAG_PLANAR
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:132
ffmath.h
G
#define G
Definition: huffyuv.h:43
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
factor
static const int factor[16]
Definition: vf_pp7.c:80
TestSourceContext::pts
int64_t pts
Definition: vsrc_testsrc.c:59
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:152
desc
const char * desc
Definition: libsvtav1.c:79
TestSourceContext::fill_slice_fn
int(* fill_slice_fn)(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Definition: vsrc_testsrc.c:97
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
mem.h
ff_vsrc_testsrc
const AVFilter ff_vsrc_testsrc
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
TestSourceContext::kx
int kx
Definition: vsrc_testsrc.c:91
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:80
ff_fill_rgba_map
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:35
TestSourceContext::draw_once_reset
int draw_once_reset
draw only the first frame or in case of reset
Definition: vsrc_testsrc.c:63
TestSourceContext::kx2
int kx2
Definition: vsrc_testsrc.c:93
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:434
AV_PIX_FMT_0RGB
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:262
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:79
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
TestSourceContext::w
int w
Definition: vsrc_testsrc.c:55
h
h
Definition: vp9dsp_template.c:2070
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:497
av_image_check_size
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:318
TestSourceContext::draw
FFDrawContext draw
Definition: vsrc_testsrc.c:78
width
#define width
Definition: dsp.h:85
drawutils.h
AV_RB24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
Definition: bytestream.h:97
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:621
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:252
snprintf
#define snprintf
Definition: snprintf.h:34
TestSourceContext::fill_picture_fn
void(* fill_picture_fn)(AVFilterContext *ctx, AVFrame *frame)
Definition: vsrc_testsrc.c:66
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
line
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
Definition: swscale.txt:40
TestSourceContext::pw
int pw
Definition: vsrc_testsrc.c:56
TestSourceContext::depth
int depth
Definition: vsrc_testsrc.c:85
planes
static const struct @458 planes[]
set_color
static void av_unused set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
Definition: vsrc_testsrc.c:701
COMMON_OPTIONS_NOSIZE
#define COMMON_OPTIONS_NOSIZE
Definition: vsrc_testsrc.c:108
options
static const AVOption options[]
Definition: vsrc_testsrc.c:120
AV_PIX_FMT_RGB444
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:476