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 yuvtest */
75  uint8_t ayuv_map[4];
76 
77  /* only used by colorspectrum */
78  int type;
79 
80  /* only used by color */
83  uint8_t color_rgba[4];
84 
85  /* only used by rgbtest */
86  uint8_t rgba_map[4];
88  int depth;
89 
90  /* only used by haldclut */
91  int level;
92 
93  /* only used by zoneplate */
94  int k0, kx, ky, kt;
95  int kxt, kyt, kxy;
96  int kx2, ky2, kt2;
97  int xo, yo, to, kU, kV;
99  uint8_t *lut;
100  int (*fill_slice_fn)(AVFilterContext *ctx, void *arg, int job, int nb_jobs);
102 
103 #define OFFSET(x) offsetof(TestSourceContext, x)
104 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
105 #define FLAGSR AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
106 
107 #define SIZE_OPTIONS \
108  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
109  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "320x240"}, 0, 0, FLAGS },\
110 
111 #define COMMON_OPTIONS_NOSIZE \
112  { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
113  { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },\
114  { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
115  { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },\
116  { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX, FLAGS },
117 
118 #define COMMON_OPTIONS SIZE_OPTIONS COMMON_OPTIONS_NOSIZE
119 
120 #define NOSIZE_OPTIONS_OFFSET 2
121 /* Filters using COMMON_OPTIONS_NOSIZE also use the following options
122  * via &options[NOSIZE_OPTIONS_OFFSET]. So don't break it. */
123 static const AVOption options[] = {
125  { NULL }
126 };
127 
129 {
130  TestSourceContext *test = ctx->priv;
131 
132  test->time_base = av_inv_q(test->frame_rate);
133  test->nb_frame = 0;
134  test->pts = 0;
135 
136  av_log(ctx, AV_LOG_VERBOSE, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n",
137  test->w, test->h, test->frame_rate.num, test->frame_rate.den,
138  test->duration < 0 ? -1 : (double)test->duration/1000000,
139  test->sar.num, test->sar.den);
140  return 0;
141 }
142 
144 {
145  TestSourceContext *test = ctx->priv;
146 
147  av_frame_free(&test->picref);
148  av_freep(&test->lut);
149 }
150 
151 static int config_props(AVFilterLink *outlink)
152 {
153  TestSourceContext *test = outlink->src->priv;
154  FilterLink *l = ff_filter_link(outlink);
155 
156  outlink->w = test->w;
157  outlink->h = test->h;
158  outlink->sample_aspect_ratio = test->sar;
159  l->frame_rate = test->frame_rate;
160  outlink->time_base = test->time_base;
161 
162  return 0;
163 }
164 
165 static const AVFilterPad outputs[] = {
166  {
167  .name = "default",
168  .type = AVMEDIA_TYPE_VIDEO,
169  .config_props = config_props,
170  },
171 };
172 
174 {
175  AVFilterLink *outlink = ctx->outputs[0];
176  TestSourceContext *test = ctx->priv;
177  AVFrame *frame;
178 
179  if (!ff_outlink_frame_wanted(outlink))
180  return FFERROR_NOT_READY;
181  if (test->duration >= 0 &&
182  av_rescale_q(test->pts, test->time_base, AV_TIME_BASE_Q) >= test->duration) {
183  ff_outlink_set_status(outlink, AVERROR_EOF, test->pts);
184  return 0;
185  }
186 
187  if (test->draw_once) {
188  if (test->draw_once_reset) {
189  av_frame_free(&test->picref);
190  test->draw_once_reset = 0;
191  }
192  if (!test->picref) {
193  test->picref =
194  ff_get_video_buffer(outlink, test->w, test->h);
195  if (!test->picref)
196  return AVERROR(ENOMEM);
197  test->fill_picture_fn(outlink->src, test->picref);
198  }
199  frame = av_frame_clone(test->picref);
200  } else
201  frame = ff_get_video_buffer(outlink, test->w, test->h);
202 
203  if (!frame)
204  return AVERROR(ENOMEM);
205  frame->pts = test->pts;
206  frame->duration = 1;
207  frame->flags |= AV_FRAME_FLAG_KEY;
208 #if FF_API_INTERLACED_FRAME
210  frame->interlaced_frame = 0;
212 #endif
213  frame->flags &= ~AV_FRAME_FLAG_INTERLACED;
214  frame->pict_type = AV_PICTURE_TYPE_I;
215  frame->sample_aspect_ratio = test->sar;
216  if (!test->draw_once)
217  test->fill_picture_fn(outlink->src, frame);
218 
219  test->pts++;
220  test->nb_frame++;
221 
222  return ff_filter_frame(outlink, frame);
223 }
224 
225 #if CONFIG_COLOR_FILTER
226 
227 static const AVOption color_options[] = {
228  { "color", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGSR },
229  { "c", "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGSR },
231  { NULL }
232 };
233 
235 
236 static void color_fill_picture(AVFilterContext *ctx, AVFrame *picref)
237 {
238  TestSourceContext *test = ctx->priv;
239  ff_fill_rectangle(&test->draw, &test->color,
240  picref->data, picref->linesize,
241  0, 0, test->w, test->h);
242 }
243 
244 static av_cold int color_init(AVFilterContext *ctx)
245 {
246  TestSourceContext *test = ctx->priv;
247  test->fill_picture_fn = color_fill_picture;
248  test->draw_once = 1;
249  return init(ctx);
250 }
251 
252 static int color_query_formats(const AVFilterContext *ctx,
253  AVFilterFormatsConfig **cfg_in,
254  AVFilterFormatsConfig **cfg_out)
255 {
256  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_draw_supported_pixel_formats(0));
257 }
258 
259 static int color_config_props(AVFilterLink *inlink)
260 {
261  AVFilterContext *ctx = inlink->src;
262  TestSourceContext *test = ctx->priv;
263  int ret;
264 
265  ff_draw_init2(&test->draw, inlink->format, inlink->colorspace,
266  inlink->color_range, 0);
267  ff_draw_color(&test->draw, &test->color, test->color_rgba);
268 
269  if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
270  return AVERROR(EINVAL);
271 
272  if ((ret = config_props(inlink)) < 0)
273  return ret;
274 
275  return 0;
276 }
277 
278 static int color_process_command(AVFilterContext *ctx, const char *cmd, const char *args,
279  char *res, int res_len, int flags)
280 {
281  TestSourceContext *test = ctx->priv;
282  int ret;
283 
284  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
285  if (ret < 0)
286  return ret;
287 
288  ff_draw_color(&test->draw, &test->color, test->color_rgba);
289  test->draw_once_reset = 1;
290  return 0;
291 }
292 
293 static const AVFilterPad color_outputs[] = {
294  {
295  .name = "default",
296  .type = AVMEDIA_TYPE_VIDEO,
297  .config_props = color_config_props,
298  },
299 };
300 
301 const AVFilter ff_vsrc_color = {
302  .name = "color",
303  .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
304  .priv_class = &color_class,
305  .priv_size = sizeof(TestSourceContext),
306  .init = color_init,
307  .uninit = uninit,
308  .activate = activate,
309  .inputs = NULL,
310  FILTER_OUTPUTS(color_outputs),
311  FILTER_QUERY_FUNC2(color_query_formats),
312  .process_command = color_process_command,
313 };
314 
315 #endif /* CONFIG_COLOR_FILTER */
316 
317 #if CONFIG_HALDCLUTSRC_FILTER
318 
319 static const AVOption haldclutsrc_options[] = {
320  { "level", "set level", OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 6}, 2, 16, FLAGS },
322  { NULL }
323 };
324 
325 AVFILTER_DEFINE_CLASS(haldclutsrc);
326 
327 static void haldclutsrc_fill_picture(AVFilterContext *ctx, AVFrame *frame)
328 {
329  int i, j, k, x = 0, y = 0, is16bit = 0, step;
330  uint32_t alpha = 0;
331  const TestSourceContext *hc = ctx->priv;
332  int level = hc->level;
333  float scale;
334  const int w = frame->width;
335  const int h = frame->height;
336  uint8_t *data = frame->data[0];
337  const ptrdiff_t linesize = frame->linesize[0];
339  const int depth = desc->comp[0].depth;
340  const int planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
341  const int planes = av_pix_fmt_count_planes(frame->format);
342  uint8_t rgba_map[4];
343 
344  av_assert0(w == h && w == level*level*level);
345 
346  ff_fill_rgba_map(rgba_map, frame->format);
347 
348  alpha = (1 << depth) - 1;
349  is16bit = depth > 8;
350 
351  step = av_get_padded_bits_per_pixel(desc) >> (3 + is16bit);
352  scale = ((float)alpha) / (level*level - 1);
353 
354 #define LOAD_CLUT(nbits) do { \
355  uint##nbits##_t *dst = ((uint##nbits##_t *)(data + y*linesize)) + x*step; \
356  dst[rgba_map[0]] = av_clip_uint##nbits(i * scale); \
357  dst[rgba_map[1]] = av_clip_uint##nbits(j * scale); \
358  dst[rgba_map[2]] = av_clip_uint##nbits(k * scale); \
359  if (step == 4) \
360  dst[rgba_map[3]] = alpha; \
361 } while (0)
362 
363 #define LOAD_CLUT_PLANAR(type, nbits) do { \
364  type *dst = ((type *)(frame->data[2] + y*frame->linesize[2])) + x; \
365  dst[0] = av_clip_uintp2(i * scale, nbits); \
366  dst = ((type *)(frame->data[0] + y*frame->linesize[0])) + x; \
367  dst[0] = av_clip_uintp2(j * scale, nbits); \
368  dst = ((type *)(frame->data[1] + y*frame->linesize[1])) + x; \
369  dst[0] = av_clip_uintp2(k * scale, nbits); \
370  if (planes == 4) { \
371  dst = ((type *)(frame->data[3] + y*linesize)) + x; \
372  dst[0] = alpha; \
373  } \
374 } while (0)
375 
376  level *= level;
377  for (k = 0; k < level; k++) {
378  for (j = 0; j < level; j++) {
379  for (i = 0; i < level; i++) {
380  if (!planar) {
381  if (!is16bit)
382  LOAD_CLUT(8);
383  else
384  LOAD_CLUT(16);
385  } else {
386  switch (depth) {
387  case 8: LOAD_CLUT_PLANAR(uint8_t, 8); break;
388  case 9: LOAD_CLUT_PLANAR(uint16_t, 9); break;
389  case 10: LOAD_CLUT_PLANAR(uint16_t,10); break;
390  case 12: LOAD_CLUT_PLANAR(uint16_t,12); break;
391  case 14: LOAD_CLUT_PLANAR(uint16_t,14); break;
392  case 16: LOAD_CLUT_PLANAR(uint16_t,16); break;
393  }
394  }
395  if (++x == w) {
396  x = 0;
397  y++;
398  }
399  }
400  }
401  }
402 }
403 
404 static av_cold int haldclutsrc_init(AVFilterContext *ctx)
405 {
406  TestSourceContext *hc = ctx->priv;
407  hc->fill_picture_fn = haldclutsrc_fill_picture;
408  hc->draw_once = 1;
409  return init(ctx);
410 }
411 
412 static const enum AVPixelFormat haldclutsrc_pix_fmts[] = {
427 };
428 
429 static int haldclutsrc_config_props(AVFilterLink *outlink)
430 {
431  AVFilterContext *ctx = outlink->src;
432  TestSourceContext *hc = ctx->priv;
433 
434  hc->w = hc->h = hc->level * hc->level * hc->level;
435  return config_props(outlink);
436 }
437 
438 static const AVFilterPad haldclutsrc_outputs[] = {
439  {
440  .name = "default",
441  .type = AVMEDIA_TYPE_VIDEO,
442  .config_props = haldclutsrc_config_props,
443  },
444 };
445 
447  .name = "haldclutsrc",
448  .description = NULL_IF_CONFIG_SMALL("Provide an identity Hald CLUT."),
449  .priv_class = &haldclutsrc_class,
450  .priv_size = sizeof(TestSourceContext),
451  .init = haldclutsrc_init,
452  .uninit = uninit,
453  .activate = activate,
454  .inputs = NULL,
455  FILTER_OUTPUTS(haldclutsrc_outputs),
456  FILTER_PIXFMTS_ARRAY(haldclutsrc_pix_fmts),
457 };
458 #endif /* CONFIG_HALDCLUTSRC_FILTER */
459 
460 AVFILTER_DEFINE_CLASS_EXT(nullsrc_yuvtestsrc, "nullsrc/yuvtestsrc", options);
461 
462 #if CONFIG_NULLSRC_FILTER
463 
464 static void nullsrc_fill_picture(AVFilterContext *ctx, AVFrame *picref) { }
465 
466 static av_cold int nullsrc_init(AVFilterContext *ctx)
467 {
468  TestSourceContext *test = ctx->priv;
469 
470  test->fill_picture_fn = nullsrc_fill_picture;
471  return init(ctx);
472 }
473 
474 const AVFilter ff_vsrc_nullsrc = {
475  .name = "nullsrc",
476  .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."),
477  .priv_class = &nullsrc_yuvtestsrc_class,
478  .init = nullsrc_init,
479  .uninit = uninit,
480  .activate = activate,
481  .priv_size = sizeof(TestSourceContext),
482  .inputs = NULL,
484 };
485 
486 #endif /* CONFIG_NULLSRC_FILTER */
487 
488 #if CONFIG_TESTSRC_FILTER
489 
490 static const AVOption testsrc_options[] = {
492  { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
493  { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.i64=0}, 0, 17, FLAGS },
494  { NULL }
495 };
496 
497 AVFILTER_DEFINE_CLASS(testsrc);
498 
499 /**
500  * Fill a rectangle with value val.
501  *
502  * @param val the RGB value to set
503  * @param dst pointer to the destination buffer to fill
504  * @param dst_linesize linesize of destination
505  * @param segment_width width of the segment
506  * @param x horizontal coordinate where to draw the rectangle in the destination buffer
507  * @param y horizontal coordinate where to draw the rectangle in the destination buffer
508  * @param w width of the rectangle to draw, expressed as a number of segment_width units
509  * @param h height of the rectangle to draw, expressed as a number of segment_width units
510  */
511 static void draw_rectangle(unsigned val, uint8_t *dst, ptrdiff_t dst_linesize, int segment_width,
512  int x, int y, int w, int h)
513 {
514  int i;
515  int step = 3;
516 
517  dst += segment_width * (step * x + y * dst_linesize);
518  w *= segment_width * step;
519  h *= segment_width;
520  for (i = 0; i < h; i++) {
521  memset(dst, val, w);
522  dst += dst_linesize;
523  }
524 }
525 
526 static void draw_digit(int digit, uint8_t *dst, ptrdiff_t dst_linesize,
527  int segment_width)
528 {
529 #define TOP_HBAR 1
530 #define MID_HBAR 2
531 #define BOT_HBAR 4
532 #define LEFT_TOP_VBAR 8
533 #define LEFT_BOT_VBAR 16
534 #define RIGHT_TOP_VBAR 32
535 #define RIGHT_BOT_VBAR 64
536  struct segments {
537  int x, y, w, h;
538  } segments[] = {
539  { 1, 0, 5, 1 }, /* TOP_HBAR */
540  { 1, 6, 5, 1 }, /* MID_HBAR */
541  { 1, 12, 5, 1 }, /* BOT_HBAR */
542  { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */
543  { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */
544  { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */
545  { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */
546  };
547  static const unsigned char masks[10] = {
548  /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
549  /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
550  /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR,
551  /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
552  /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
553  /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR,
554  /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR,
555  /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
556  /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
557  /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR,
558  };
559  unsigned mask = masks[digit];
560  int i;
561 
562  draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13);
563  for (i = 0; i < FF_ARRAY_ELEMS(segments); i++)
564  if (mask & (1<<i))
565  draw_rectangle(255, dst, dst_linesize, segment_width,
566  segments[i].x, segments[i].y, segments[i].w, segments[i].h);
567 }
568 
569 #define GRADIENT_SIZE (6 * 256)
570 
571 static void test_fill_picture(AVFilterContext *ctx, AVFrame *frame)
572 {
573  TestSourceContext *test = ctx->priv;
574  uint8_t *p, *p0;
575  int x, y;
576  int color, color_rest;
577  int icolor;
578  int radius;
579  int quad0, quad;
580  int dquad_x, dquad_y;
581  int grad, dgrad, rgrad, drgrad;
582  int seg_size;
583  int second;
584  int i;
585  uint8_t *data = frame->data[0];
586  int width = frame->width;
587  int height = frame->height;
588 
589  /* draw colored bars and circle */
590  radius = (width + height) / 4;
591  quad0 = width * width / 4 + height * height / 4 - radius * radius;
592  dquad_y = 1 - height;
593  p0 = data;
594  for (y = 0; y < height; y++) {
595  p = p0;
596  color = 0;
597  color_rest = 0;
598  quad = quad0;
599  dquad_x = 1 - width;
600  for (x = 0; x < width; x++) {
601  icolor = color;
602  if (quad < 0)
603  icolor ^= 7;
604  quad += dquad_x;
605  dquad_x += 2;
606  *(p++) = icolor & 1 ? 255 : 0;
607  *(p++) = icolor & 2 ? 255 : 0;
608  *(p++) = icolor & 4 ? 255 : 0;
609  color_rest += 8;
610  if (color_rest >= width) {
611  color_rest -= width;
612  color++;
613  }
614  }
615  quad0 += dquad_y;
616  dquad_y += 2;
617  p0 += frame->linesize[0];
618  }
619 
620  /* draw sliding color line */
621  p0 = p = data + frame->linesize[0] * (height * 3/4);
622  grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) %
623  GRADIENT_SIZE;
624  rgrad = 0;
625  dgrad = GRADIENT_SIZE / width;
626  drgrad = GRADIENT_SIZE % width;
627  for (x = 0; x < width; x++) {
628  *(p++) =
629  grad < 256 || grad >= 5 * 256 ? 255 :
630  grad >= 2 * 256 && grad < 4 * 256 ? 0 :
631  grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256;
632  *(p++) =
633  grad >= 4 * 256 ? 0 :
634  grad >= 1 * 256 && grad < 3 * 256 ? 255 :
635  grad < 1 * 256 ? grad : 4 * 256 - 1 - grad;
636  *(p++) =
637  grad < 2 * 256 ? 0 :
638  grad >= 3 * 256 && grad < 5 * 256 ? 255 :
639  grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad;
640  grad += dgrad;
641  rgrad += drgrad;
642  if (rgrad >= GRADIENT_SIZE) {
643  grad++;
644  rgrad -= GRADIENT_SIZE;
645  }
646  if (grad >= GRADIENT_SIZE)
647  grad -= GRADIENT_SIZE;
648  }
649  p = p0;
650  for (y = height / 8; y > 0; y--) {
651  memcpy(p+frame->linesize[0], p, 3 * width);
652  p += frame->linesize[0];
653  }
654 
655  /* draw digits */
656  seg_size = width / 80;
657  if (seg_size >= 1 && height >= 13 * seg_size) {
658  int64_t p10decimals = 1;
659  double time = av_q2d(test->time_base) * test->nb_frame *
660  ff_exp10(test->nb_decimals);
661  if (time >= INT_MAX)
662  return;
663 
664  for (x = 0; x < test->nb_decimals; x++)
665  p10decimals *= 10;
666 
667  second = av_rescale_rnd(test->nb_frame * test->time_base.num, p10decimals, test->time_base.den, AV_ROUND_ZERO);
668  x = width - (width - seg_size * 64) / 2;
669  y = (height - seg_size * 13) / 2;
670  p = data + (x*3 + y * frame->linesize[0]);
671  for (i = 0; i < 8; i++) {
672  p -= 3 * 8 * seg_size;
673  draw_digit(second % 10, p, frame->linesize[0], seg_size);
674  second /= 10;
675  if (second == 0)
676  break;
677  }
678  }
679 }
680 
681 static av_cold int test_init(AVFilterContext *ctx)
682 {
683  TestSourceContext *test = ctx->priv;
684 
685  test->fill_picture_fn = test_fill_picture;
686  return init(ctx);
687 }
688 
689 const AVFilter ff_vsrc_testsrc = {
690  .name = "testsrc",
691  .description = NULL_IF_CONFIG_SMALL("Generate test pattern."),
692  .priv_size = sizeof(TestSourceContext),
693  .priv_class = &testsrc_class,
694  .init = test_init,
695  .uninit = uninit,
696  .activate = activate,
697  .inputs = NULL,
700 };
701 
702 #endif /* CONFIG_TESTSRC_FILTER */
703 
704 static void av_unused set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
705 {
706  uint8_t rgba[4] = { (argb >> 16) & 0xFF,
707  (argb >> 8) & 0xFF,
708  (argb >> 0) & 0xFF,
709  (argb >> 24) & 0xFF, };
710  ff_draw_color(&s->draw, color, rgba);
711 }
712 
713 #if CONFIG_TESTSRC2_FILTER
714 
715 static const AVOption testsrc2_options[] = {
717  { "alpha", "set global alpha (opacity)", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 255}, 0, 255, FLAGS },
718  { NULL }
719 };
720 
721 AVFILTER_DEFINE_CLASS(testsrc2);
722 
723 static uint32_t color_gradient(unsigned index)
724 {
725  unsigned si = index & 0xFF, sd = 0xFF - si;
726  switch (index >> 8) {
727  case 0: return 0xFF0000 + (si << 8);
728  case 1: return 0x00FF00 + (sd << 16);
729  case 2: return 0x00FF00 + (si << 0);
730  case 3: return 0x0000FF + (sd << 8);
731  case 4: return 0x0000FF + (si << 16);
732  case 5: return 0xFF0000 + (sd << 0);
733  default: av_assert0(0); return 0;
734  }
735 }
736 
738  int x0, int y0, const uint8_t *text)
739 {
740  int x = x0;
741 
742  for (; *text; text++) {
743  if (*text == '\n') {
744  x = x0;
745  y0 += 16;
746  continue;
747  }
748  ff_blend_mask(&s->draw, color, frame->data, frame->linesize,
749  frame->width, frame->height,
750  avpriv_vga16_font + *text * 16, 1, 8, 16, 0, 0, x, y0);
751  x += 8;
752  }
753 }
754 
755 static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame)
756 {
757  TestSourceContext *s = ctx->priv;
759  unsigned alpha = (uint32_t)s->alpha << 24;
760 
761  /* colored background */
762  {
763  unsigned i, x = 0, x2;
764 
765  x = 0;
766  for (i = 1; i < 7; i++) {
767  x2 = av_rescale(i, s->w, 6);
768  x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2);
769  set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) |
770  ((i & 2) ? 0x00FF00 : 0) |
771  ((i & 4) ? 0x0000FF : 0) |
772  alpha);
773  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
774  x, 0, x2 - x, frame->height);
775  x = x2;
776  }
777  }
778 
779  /* oblique gradient */
780  /* note: too slow if using blending */
781  if (s->h >= 64) {
782  unsigned x, dx, y0, y, g0, g;
783 
784  dx = ff_draw_round_to_sub(&s->draw, 0, +1, 1);
785  y0 = av_rescale_q(s->pts, s->time_base, av_make_q(2, s->h - 16));
786  g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128));
787  for (x = 0; x < s->w; x += dx) {
788  g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256);
789  set_color(s, &color, color_gradient(g) | alpha);
790  y = y0 + av_rescale(x, s->h / 2, s->w);
791  y %= 2 * (s->h - 16);
792  if (y > s->h - 16)
793  y = 2 * (s->h - 16) - y;
794  y = ff_draw_round_to_sub(&s->draw, 1, 0, y);
795  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
796  x, y, dx, 16);
797  }
798  }
799 
800  /* top right: draw clock hands */
801  if (s->w >= 64 && s->h >= 64) {
802  int l = (FFMIN(s->w, s->h) - 32) >> 1;
803  int steps = FFMAX(4, l >> 5);
804  int xc = (s->w >> 2) + (s->w >> 1);
805  int yc = (s->h >> 2);
806  int cycle = l << 2;
807  int pos, xh, yh;
808  int c, i;
809 
810  for (c = 0; c < 3; c++) {
811  set_color(s, &color, (0xBBBBBB ^ (0xFF << (c << 3))) | alpha);
812  pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle;
813  xh = pos < 1 * l ? pos :
814  pos < 2 * l ? l :
815  pos < 3 * l ? 3 * l - pos : 0;
816  yh = pos < 1 * l ? 0 :
817  pos < 2 * l ? pos - l :
818  pos < 3 * l ? l :
819  cycle - pos;
820  xh -= l >> 1;
821  yh -= l >> 1;
822  for (i = 1; i <= steps; i++) {
823  int x = av_rescale(xh, i, steps) + xc;
824  int y = av_rescale(yh, i, steps) + yc;
825  x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
826  y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
827  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
828  x, y, 8, 8);
829  }
830  }
831  }
832 
833  /* bottom left: beating rectangles */
834  if (s->w >= 64 && s->h >= 64) {
835  int l = (FFMIN(s->w, s->h) - 16) >> 2;
836  int cycle = l << 3;
837  int xc = (s->w >> 2);
838  int yc = (s->h >> 2) + (s->h >> 1);
839  int xm1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 8);
840  int xm2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 8);
841  int ym1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 8);
842  int ym2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 8);
843  int size, step, x1, x2, y1, y2;
844 
845  size = av_rescale_q(s->pts, s->time_base, av_make_q(4, cycle));
846  step = size / l;
847  size %= l;
848  if (step & 1)
849  size = l - size;
850  step = (step >> 1) & 3;
851  set_color(s, &color, 0xFF808080);
852  x1 = ff_draw_round_to_sub(&s->draw, 0, -1, xc - 4 - size);
853  x2 = ff_draw_round_to_sub(&s->draw, 0, +1, xc + 4 + size);
854  y1 = ff_draw_round_to_sub(&s->draw, 1, -1, yc - 4 - size);
855  y2 = ff_draw_round_to_sub(&s->draw, 1, +1, yc + 4 + size);
856  if (step == 0 || step == 2)
857  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
858  x1, ym1, x2 - x1, ym2 - ym1);
859  if (step == 1 || step == 2)
860  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
861  xm1, y1, xm2 - xm1, y2 - y1);
862  if (step == 3)
863  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
864  x1, y1, x2 - x1, y2 - y1);
865  }
866 
867  /* bottom right: checker with random noise */
868  {
869  unsigned xmin = av_rescale(5, s->w, 8);
870  unsigned xmax = av_rescale(7, s->w, 8);
871  unsigned ymin = av_rescale(5, s->h, 8);
872  unsigned ymax = av_rescale(7, s->h, 8);
873  unsigned x, y, i, r;
874  uint8_t alpha[256];
875 
876  r = s->pts;
877  for (y = ymin; y + 15 < ymax; y += 16) {
878  for (x = xmin; x + 15 < xmax; x += 16) {
879  if ((x ^ y) & 16)
880  continue;
881  for (i = 0; i < 256; i++) {
882  r = r * 1664525 + 1013904223;
883  alpha[i] = r >> 24;
884  }
885  set_color(s, &color, 0xFF00FF80);
886  ff_blend_mask(&s->draw, &color, frame->data, frame->linesize,
887  frame->width, frame->height,
888  alpha, 16, 16, 16, 3, 0, x, y);
889  }
890  }
891  }
892 
893  /* bouncing square */
894  if (s->w >= 16 && s->h >= 16) {
895  unsigned w = s->w - 8;
896  unsigned h = s->h - 8;
897  unsigned x = av_rescale_q(s->pts, s->time_base, av_make_q(233, 55 * w)) % (w << 1);
898  unsigned y = av_rescale_q(s->pts, s->time_base, av_make_q(233, 89 * h)) % (h << 1);
899  if (x > w)
900  x = (w << 1) - x;
901  if (y > h)
902  y = (h << 1) - y;
903  x = ff_draw_round_to_sub(&s->draw, 0, -1, x);
904  y = ff_draw_round_to_sub(&s->draw, 1, -1, y);
905  set_color(s, &color, 0xFF8000FF);
906  ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize,
907  x, y, 8, 8);
908  }
909 
910  /* top right: draw frame time and frame number */
911  {
912  char buf[256];
913  unsigned time;
914 
915  time = av_rescale_q(s->pts, s->time_base, av_make_q(1, 1000)) % 86400000;
916  set_color(s, &color, 0xC0000000);
917  ff_blend_rectangle(&s->draw, &color, frame->data, frame->linesize,
918  frame->width, frame->height,
919  2, 2, 100, 36);
920  set_color(s, &color, 0xFFFF8000);
921  snprintf(buf, sizeof(buf), "%02d:%02d:%02d.%03d\n%12"PRIi64,
922  time / 3600000, (time / 60000) % 60, (time / 1000) % 60,
923  time % 1000, s->pts);
924  draw_text(s, frame, &color, 4, 4, buf);
925  }
926 }
927 static av_cold int test2_init(AVFilterContext *ctx)
928 {
929  TestSourceContext *s = ctx->priv;
930 
931  s->fill_picture_fn = test2_fill_picture;
932  return init(ctx);
933 }
934 
935 static int test2_query_formats(const AVFilterContext *ctx,
936  AVFilterFormatsConfig **cfg_in,
937  AVFilterFormatsConfig **cfg_out)
938 {
939  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_draw_supported_pixel_formats(0));
940 }
941 
942 static int test2_config_props(AVFilterLink *inlink)
943 {
944  AVFilterContext *ctx = inlink->src;
945  TestSourceContext *s = ctx->priv;
946 
947  av_assert0(ff_draw_init2(&s->draw, inlink->format, inlink->colorspace,
948  inlink->color_range, 0) >= 0);
949  s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w);
950  s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h);
951  if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
952  return AVERROR(EINVAL);
953  return config_props(inlink);
954 }
955 
956 static const AVFilterPad avfilter_vsrc_testsrc2_outputs[] = {
957  {
958  .name = "default",
959  .type = AVMEDIA_TYPE_VIDEO,
960  .config_props = test2_config_props,
961  },
962 };
963 
964 const AVFilter ff_vsrc_testsrc2 = {
965  .name = "testsrc2",
966  .description = NULL_IF_CONFIG_SMALL("Generate another test pattern."),
967  .priv_size = sizeof(TestSourceContext),
968  .priv_class = &testsrc2_class,
969  .init = test2_init,
970  .uninit = uninit,
971  .activate = activate,
972  .inputs = NULL,
973  FILTER_OUTPUTS(avfilter_vsrc_testsrc2_outputs),
974  FILTER_QUERY_FUNC2(test2_query_formats),
975 };
976 
977 #endif /* CONFIG_TESTSRC2_FILTER */
978 
979 #if CONFIG_RGBTESTSRC_FILTER
980 
981 static const AVOption rgbtestsrc_options[] = {
983  { "complement", "set complement colors", OFFSET(complement), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
984  { "co", "set complement colors", OFFSET(complement), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
985  { NULL }
986 };
987 
988 AVFILTER_DEFINE_CLASS(rgbtestsrc);
989 
990 #define R 0
991 #define G 1
992 #define B 2
993 #define A 3
994 
995 static void rgbtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
996  int x, int y, unsigned r, unsigned g, unsigned b, enum AVPixelFormat fmt,
997  uint8_t rgba_map[4])
998 {
1000  uint8_t *dst = dstp[0];
1001  ptrdiff_t dst_linesize = dst_linesizep[0];
1002  uint32_t v;
1003  uint8_t *p;
1004  uint16_t *p16;
1005 
1006  switch (fmt) {
1007  case AV_PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break;
1008  case AV_PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break;
1009  case AV_PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break;
1010  case AV_PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break;
1011  case AV_PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break;
1012  case AV_PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break;
1013  case AV_PIX_FMT_RGB24:
1014  case AV_PIX_FMT_BGR24:
1015  v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8));
1016  p = dst + 3*x + y*dst_linesize;
1017  AV_WL24(p, v);
1018  break;
1019  case AV_PIX_FMT_RGBA:
1020  case AV_PIX_FMT_BGRA:
1021  case AV_PIX_FMT_ARGB:
1022  case AV_PIX_FMT_ABGR:
1023  v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255U << (rgba_map[A]*8));
1024  p = dst + 4*x + y*dst_linesize;
1025  AV_WL32(p, v);
1026  break;
1027  case AV_PIX_FMT_X2RGB10LE:
1028  case AV_PIX_FMT_X2BGR10LE:
1029  v = (r << ((desc->comp[0].offset*8) + desc->comp[0].shift)) +
1030  (g << ((desc->comp[1].offset*8) + desc->comp[1].shift)) +
1031  (b << ((desc->comp[2].offset*8) + desc->comp[2].shift)) +
1032  (3U << ((desc->comp[3].offset*8) + desc->comp[3].shift));
1033  p = dst + 4*x + y*dst_linesize;
1034  AV_WL32(p, v);
1035  break;
1036  case AV_PIX_FMT_GBRP:
1037  p = dstp[0] + x + y * dst_linesize;
1038  p[0] = g;
1039  p = dstp[1] + x + y * dst_linesizep[1];
1040  p[0] = b;
1041  p = dstp[2] + x + y * dst_linesizep[2];
1042  p[0] = r;
1043  break;
1044  case AV_PIX_FMT_GBRP9:
1045  case AV_PIX_FMT_GBRP10:
1046  case AV_PIX_FMT_GBRP12:
1047  case AV_PIX_FMT_GBRP14:
1048  case AV_PIX_FMT_GBRP16:
1049  p16 = (uint16_t *)(dstp[0] + x*2 + y * dst_linesizep[0]);
1050  p16[0] = g;
1051  p16 = (uint16_t *)(dstp[1] + x*2 + y * dst_linesizep[1]);
1052  p16[0] = b;
1053  p16 = (uint16_t *)(dstp[2] + x*2 + y * dst_linesizep[2]);
1054  p16[0] = r;
1055  break;
1056  }
1057 }
1058 
1059 static void rgbtest_fill_picture_complement(AVFilterContext *ctx, AVFrame *frame)
1060 {
1061  TestSourceContext *test = ctx->priv;
1062  int x, y, w = frame->width, h = frame->height;
1063 
1064  for (y = 0; y < h; y++) {
1065  for (x = 0; x < w; x++) {
1066  int c = (1 << FFMAX(test->depth, 8))*x/w;
1067  int r = 0, g = 0, b = 0;
1068 
1069  if (6*y < h ) r = c;
1070  else if (6*y < 2*h) g = c, b = c;
1071  else if (6*y < 3*h) g = c;
1072  else if (6*y < 4*h) r = c, b = c;
1073  else if (6*y < 5*h) b = c;
1074  else r = c, g = c;
1075 
1076  rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
1077  ctx->outputs[0]->format, test->rgba_map);
1078  }
1079  }
1080 }
1081 
1082 static void rgbtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1083 {
1084  TestSourceContext *test = ctx->priv;
1085  int x, y, w = frame->width, h = frame->height;
1086 
1087  for (y = 0; y < h; y++) {
1088  for (x = 0; x < w; x++) {
1089  int c = (1 << FFMAX(test->depth, 8))*x/w;
1090  int r = 0, g = 0, b = 0;
1091 
1092  if (3*y < h ) r = c;
1093  else if (3*y < 2*h) g = c;
1094  else b = c;
1095 
1096  rgbtest_put_pixel(frame->data, frame->linesize, x, y, r, g, b,
1097  ctx->outputs[0]->format, test->rgba_map);
1098  }
1099  }
1100 }
1101 
1102 static av_cold int rgbtest_init(AVFilterContext *ctx)
1103 {
1104  TestSourceContext *test = ctx->priv;
1105 
1106  test->draw_once = 1;
1107  test->fill_picture_fn = test->complement ? rgbtest_fill_picture_complement : rgbtest_fill_picture;
1108  return init(ctx);
1109 }
1110 
1111 static const enum AVPixelFormat rgbtest_pix_fmts[] = {
1121  };
1122 
1123 static int rgbtest_config_props(AVFilterLink *outlink)
1124 {
1125  TestSourceContext *test = outlink->src->priv;
1127 
1128  test->depth = desc->comp[0].depth;
1129  ff_fill_rgba_map(test->rgba_map, outlink->format);
1130  return config_props(outlink);
1131 }
1132 
1133 static const AVFilterPad avfilter_vsrc_rgbtestsrc_outputs[] = {
1134  {
1135  .name = "default",
1136  .type = AVMEDIA_TYPE_VIDEO,
1137  .config_props = rgbtest_config_props,
1138  },
1139 };
1140 
1141 const AVFilter ff_vsrc_rgbtestsrc = {
1142  .name = "rgbtestsrc",
1143  .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."),
1144  .priv_size = sizeof(TestSourceContext),
1145  .priv_class = &rgbtestsrc_class,
1146  .init = rgbtest_init,
1147  .uninit = uninit,
1148  .activate = activate,
1149  .inputs = NULL,
1150  FILTER_OUTPUTS(avfilter_vsrc_rgbtestsrc_outputs),
1151  FILTER_PIXFMTS_ARRAY(rgbtest_pix_fmts),
1152 };
1153 
1154 #undef R
1155 #undef G
1156 #undef B
1157 #undef A
1158 
1159 #endif /* CONFIG_RGBTESTSRC_FILTER */
1160 
1161 #if CONFIG_YUVTESTSRC_FILTER
1162 
1163 #define Y 0
1164 #define U 1
1165 #define V 2
1166 #define A 3
1167 
1168 static void yuvtest_put_pixel(uint8_t *dstp[4], int dst_linesizep[4],
1169  int i, int j, unsigned y, unsigned u, unsigned v, enum AVPixelFormat fmt,
1170  uint8_t ayuv_map[4])
1171 {
1173  uint32_t n;
1174 
1175  switch (fmt) {
1176  case AV_PIX_FMT_VYU444:
1177  n = (y << (ayuv_map[Y]*8)) + (u << (ayuv_map[U]*8)) + (v << (ayuv_map[V]*8));
1178  AV_WL24(&dstp[0][i*3 + j*dst_linesizep[0]], n);
1179  break;
1180  case AV_PIX_FMT_V30XLE:
1181  case AV_PIX_FMT_XV30LE:
1182  n = (y << ((desc->comp[0].offset*8) + desc->comp[0].shift)) +
1183  (u << ((desc->comp[1].offset*8) + desc->comp[1].shift)) +
1184  (v << ((desc->comp[2].offset*8) + desc->comp[2].shift)) +
1185  (3U << ((desc->comp[3].offset*8) + desc->comp[3].shift));
1186  AV_WL32(&dstp[0][i*4 + j*dst_linesizep[0]], n);
1187  break;
1188  case AV_PIX_FMT_XV36:
1189  case AV_PIX_FMT_XV48:
1190  case AV_PIX_FMT_AYUV64:
1191  AV_WN16(&dstp[0][i*8 + ayuv_map[Y]*2 + j*dst_linesizep[0]], y << desc->comp[0].shift);
1192  AV_WN16(&dstp[0][i*8 + ayuv_map[U]*2 + j*dst_linesizep[0]], u << desc->comp[1].shift);
1193  AV_WN16(&dstp[0][i*8 + ayuv_map[V]*2 + j*dst_linesizep[0]], v << desc->comp[2].shift);
1194  AV_WN16(&dstp[0][i*8 + ayuv_map[A]*2 + j*dst_linesizep[0]], UINT16_MAX << desc->comp[3].shift);
1195  break;
1196  case AV_PIX_FMT_UYVA:
1197  case AV_PIX_FMT_VUYA:
1198  case AV_PIX_FMT_VUYX:
1199  case AV_PIX_FMT_AYUV:
1200  n = (y << (ayuv_map[Y]*8)) + (u << (ayuv_map[U]*8)) + (v << (ayuv_map[V]*8)) + (255U << (ayuv_map[A]*8));
1201  AV_WL32(&dstp[0][i*4 + j*dst_linesizep[0]], n);
1202  break;
1203  case AV_PIX_FMT_YUV444P:
1204  case AV_PIX_FMT_YUVJ444P:
1205  dstp[0][i + j*dst_linesizep[0]] = y;
1206  dstp[1][i + j*dst_linesizep[1]] = u;
1207  dstp[2][i + j*dst_linesizep[2]] = v;
1208  break;
1209  case AV_PIX_FMT_YUV444P9:
1210  case AV_PIX_FMT_YUV444P10:
1211  case AV_PIX_FMT_YUV444P12:
1212  case AV_PIX_FMT_YUV444P14:
1213  case AV_PIX_FMT_YUV444P16:
1214  AV_WN16(&dstp[0][i*2 + j*dst_linesizep[0]], y);
1215  AV_WN16(&dstp[1][i*2 + j*dst_linesizep[1]], u);
1216  AV_WN16(&dstp[2][i*2 + j*dst_linesizep[2]], v);
1217  break;
1218  }
1219 }
1220 
1221 static void yuvtest_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1222 {
1223  TestSourceContext *test = ctx->priv;
1224  int i, j, w = frame->width, h = frame->height;
1225  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(ctx->outputs[0]->format);
1226  const int factor = 1 << desc->comp[0].depth;
1227  const int mid = 1 << (desc->comp[0].depth - 1);
1228 
1229  for (j = 0; j < h; j++) {
1230  for (i = 0; i < w; i++) {
1231  int c = factor * i / w;
1232  int y = mid, u = mid, v = mid;
1233 
1234  if (3*j < h ) y = c;
1235  else if (3*j < 2*h) u = c;
1236  else v = c;
1237 
1238  yuvtest_put_pixel(frame->data, frame->linesize, i, j, y, u, v,
1239  ctx->outputs[0]->format, test->ayuv_map);
1240  }
1241  }
1242 }
1243 
1244 static av_cold int yuvtest_init(AVFilterContext *ctx)
1245 {
1246  TestSourceContext *test = ctx->priv;
1247 
1248  test->draw_once = 1;
1249  test->fill_picture_fn = yuvtest_fill_picture;
1250  return init(ctx);
1251 }
1252 
1253 static const enum AVPixelFormat yuvtest_pix_fmts[] = {
1262 };
1263 
1264 static int yuvtest_config_props(AVFilterLink *outlink)
1265 {
1266  TestSourceContext *test = outlink->src->priv;
1267 
1268  ff_fill_ayuv_map(test->ayuv_map, outlink->format);
1269  return config_props(outlink);
1270 }
1271 
1272 static const AVFilterPad avfilter_vsrc_yuvtestsrc_outputs[] = {
1273  {
1274  .name = "default",
1275  .type = AVMEDIA_TYPE_VIDEO,
1276  .config_props = yuvtest_config_props,
1277  },
1278 };
1279 
1280 const AVFilter ff_vsrc_yuvtestsrc = {
1281  .name = "yuvtestsrc",
1282  .description = NULL_IF_CONFIG_SMALL("Generate YUV test pattern."),
1283  .priv_size = sizeof(TestSourceContext),
1284  .priv_class = &nullsrc_yuvtestsrc_class,
1285  .init = yuvtest_init,
1286  .uninit = uninit,
1287  .activate = activate,
1288  .inputs = NULL,
1289  FILTER_OUTPUTS(avfilter_vsrc_yuvtestsrc_outputs),
1290  FILTER_PIXFMTS_ARRAY(yuvtest_pix_fmts),
1291 };
1292 
1293 #undef Y
1294 #undef U
1295 #undef V
1296 #undef A
1297 
1298 #endif /* CONFIG_YUVTESTSRC_FILTER */
1299 
1300 #if CONFIG_PAL75BARS_FILTER || CONFIG_PAL100BARS_FILTER || CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER
1301 
1302 static const uint8_t rainbow[7][4] = {
1303  { 180, 128, 128, 255 }, /* 75% white */
1304  { 162, 44, 142, 255 }, /* 75% yellow */
1305  { 131, 156, 44, 255 }, /* 75% cyan */
1306  { 112, 72, 58, 255 }, /* 75% green */
1307  { 84, 184, 198, 255 }, /* 75% magenta */
1308  { 65, 100, 212, 255 }, /* 75% red */
1309  { 35, 212, 114, 255 }, /* 75% blue */
1310 };
1311 
1312 static const uint8_t rainbow100[7][4] = {
1313  { 235, 128, 128, 255 }, /* 100% white */
1314  { 210, 16, 146, 255 }, /* 100% yellow */
1315  { 170, 166, 16, 255 }, /* 100% cyan */
1316  { 145, 54, 34, 255 }, /* 100% green */
1317  { 106, 202, 222, 255 }, /* 100% magenta */
1318  { 81, 90, 240, 255 }, /* 100% red */
1319  { 41, 240, 110, 255 }, /* 100% blue */
1320 };
1321 
1322 static const uint8_t rainbowhd[7][4] = {
1323  { 180, 128, 128, 255 }, /* 75% white */
1324  { 168, 44, 136, 255 }, /* 75% yellow */
1325  { 145, 147, 44, 255 }, /* 75% cyan */
1326  { 133, 63, 52, 255 }, /* 75% green */
1327  { 63, 193, 204, 255 }, /* 75% magenta */
1328  { 51, 109, 212, 255 }, /* 75% red */
1329  { 28, 212, 120, 255 }, /* 75% blue */
1330 };
1331 
1332 static const uint8_t wobnair[7][4] = {
1333  { 35, 212, 114, 255 }, /* 75% blue */
1334  { 19, 128, 128, 255 }, /* 7.5% intensity black */
1335  { 84, 184, 198, 255 }, /* 75% magenta */
1336  { 19, 128, 128, 255 }, /* 7.5% intensity black */
1337  { 131, 156, 44, 255 }, /* 75% cyan */
1338  { 19, 128, 128, 255 }, /* 7.5% intensity black */
1339  { 180, 128, 128, 255 }, /* 75% white */
1340 };
1341 
1342 static const uint8_t white[4] = { 235, 128, 128, 255 };
1343 
1344 /* pluge pulses */
1345 static const uint8_t neg4ire[4] = { 7, 128, 128, 255 };
1346 static const uint8_t pos4ire[4] = { 24, 128, 128, 255 };
1347 
1348 /* fudged Q/-I */
1349 static const uint8_t i_pixel[4] = { 57, 156, 97, 255 };
1350 static const uint8_t q_pixel[4] = { 44, 171, 147, 255 };
1351 
1352 static const uint8_t gray40[4] = { 104, 128, 128, 255 };
1353 static const uint8_t gray15[4] = { 49, 128, 128, 255 };
1354 static const uint8_t cyan[4] = { 188, 154, 16, 255 };
1355 static const uint8_t yellow[4] = { 219, 16, 138, 255 };
1356 static const uint8_t blue[4] = { 32, 240, 118, 255 };
1357 static const uint8_t red[4] = { 63, 102, 240, 255 };
1358 static const uint8_t black0[4] = { 16, 128, 128, 255 };
1359 static const uint8_t black2[4] = { 20, 128, 128, 255 };
1360 static const uint8_t black4[4] = { 25, 128, 128, 255 };
1361 static const uint8_t neg2[4] = { 12, 128, 128, 255 };
1362 
1363 static void draw_bar(TestSourceContext *test, const uint8_t color[4],
1364  int x, int y, int w, int h,
1365  AVFrame *frame)
1366 {
1368  uint8_t *p, *p0;
1369  int plane;
1370 
1371  x = FFMIN(x, test->w - 1);
1372  y = FFMIN(y, test->h - 1);
1373  w = FFMAX(FFMIN(w, test->w - x), 0);
1374  h = FFMAX(FFMIN(h, test->h - y), 0);
1375 
1376  av_assert0(x + w <= test->w);
1377  av_assert0(y + h <= test->h);
1378 
1379  for (plane = 0; frame->data[plane]; plane++) {
1380  const int c = color[plane];
1381  const ptrdiff_t linesize = frame->linesize[plane];
1382  int i, px, py, pw, ph;
1383 
1384  if (plane == 1 || plane == 2) {
1385  px = x >> desc->log2_chroma_w;
1386  pw = AV_CEIL_RSHIFT(w, desc->log2_chroma_w);
1387  py = y >> desc->log2_chroma_h;
1388  ph = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
1389  } else {
1390  px = x;
1391  pw = w;
1392  py = y;
1393  ph = h;
1394  }
1395 
1396  p0 = p = frame->data[plane] + py * linesize + px;
1397  memset(p, c, pw);
1398  p += linesize;
1399  for (i = 1; i < ph; i++, p += linesize)
1400  memcpy(p, p0, pw);
1401  }
1402 }
1403 
1404 static const enum AVPixelFormat smptebars_pix_fmts[] = {
1409 };
1410 
1411 static int smptebars_query_formats(const AVFilterContext *ctx,
1412  AVFilterFormatsConfig **cfg_in,
1413  AVFilterFormatsConfig **cfg_out)
1414 {
1415  enum AVColorSpace csp;
1416  int ret;
1417 
1418  if (!strcmp(ctx->name, "smptehdbars")) {
1419  csp = AVCOL_SPC_BT709;
1420  } else {
1421  csp = AVCOL_SPC_BT470BG;
1422  }
1423 
1424  if ((ret = ff_set_common_color_spaces2(ctx, cfg_in, cfg_out,
1426  return ret;
1427  if ((ret = ff_set_common_color_ranges2(ctx, cfg_in, cfg_out,
1429  return ret;
1430  return ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, smptebars_pix_fmts);
1431 }
1432 
1433 AVFILTER_DEFINE_CLASS_EXT(palbars, "pal(75|100)bars", options);
1434 
1435 #if CONFIG_PAL75BARS_FILTER
1436 
1437 static void pal75bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1438 {
1439  TestSourceContext *test = ctx->priv;
1440  int r_w, i, x = 0;
1441  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1442 
1443  r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1444 
1445  draw_bar(test, white, x, 0, r_w, test->h, picref);
1446  x += r_w;
1447  for (i = 1; i < 7; i++) {
1448  draw_bar(test, rainbow[i], x, 0, r_w, test->h, picref);
1449  x += r_w;
1450  }
1451  draw_bar(test, black0, x, 0, r_w, test->h, picref);
1452 }
1453 
1454 static av_cold int pal75bars_init(AVFilterContext *ctx)
1455 {
1456  TestSourceContext *test = ctx->priv;
1457 
1458  test->fill_picture_fn = pal75bars_fill_picture;
1459  test->draw_once = 1;
1460  return init(ctx);
1461 }
1462 
1463 const AVFilter ff_vsrc_pal75bars = {
1464  .name = "pal75bars",
1465  .description = NULL_IF_CONFIG_SMALL("Generate PAL 75% color bars."),
1466  .priv_class = &palbars_class,
1467  .priv_size = sizeof(TestSourceContext),
1468  .init = pal75bars_init,
1469  .uninit = uninit,
1470  .activate = activate,
1471  .inputs = NULL,
1473  FILTER_QUERY_FUNC2(smptebars_query_formats),
1474 };
1475 
1476 #endif /* CONFIG_PAL75BARS_FILTER */
1477 
1478 #if CONFIG_PAL100BARS_FILTER
1479 
1480 static void pal100bars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1481 {
1482  TestSourceContext *test = ctx->priv;
1483  int r_w, i, x = 0;
1484  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1485 
1486  r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w);
1487 
1488  for (i = 0; i < 7; i++) {
1489  draw_bar(test, rainbow100[i], x, 0, r_w, test->h, picref);
1490  x += r_w;
1491  }
1492  draw_bar(test, black0, x, 0, r_w, test->h, picref);
1493 }
1494 
1495 static av_cold int pal100bars_init(AVFilterContext *ctx)
1496 {
1497  TestSourceContext *test = ctx->priv;
1498 
1499  test->fill_picture_fn = pal100bars_fill_picture;
1500  test->draw_once = 1;
1501  return init(ctx);
1502 }
1503 
1504 const AVFilter ff_vsrc_pal100bars = {
1505  .name = "pal100bars",
1506  .description = NULL_IF_CONFIG_SMALL("Generate PAL 100% color bars."),
1507  .priv_class = &palbars_class,
1508  .priv_size = sizeof(TestSourceContext),
1509  .init = pal100bars_init,
1510  .uninit = uninit,
1511  .activate = activate,
1512  .inputs = NULL,
1514  FILTER_QUERY_FUNC2(smptebars_query_formats),
1515 };
1516 
1517 #endif /* CONFIG_PAL100BARS_FILTER */
1518 
1519 AVFILTER_DEFINE_CLASS_EXT(smptebars, "smpte(hd)bars", options);
1520 
1521 #if CONFIG_SMPTEBARS_FILTER
1522 
1523 static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1524 {
1525  TestSourceContext *test = ctx->priv;
1526  int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0;
1527  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1528 
1529  r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w);
1530  r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h);
1531  w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h);
1532  p_w = FFALIGN(r_w * 5 / 4, 1 << pixdesc->log2_chroma_w);
1533  p_h = test->h - w_h - r_h;
1534 
1535  for (i = 0; i < 7; i++) {
1536  draw_bar(test, rainbow[i], x, 0, r_w, r_h, picref);
1537  draw_bar(test, wobnair[i], x, r_h, r_w, w_h, picref);
1538  x += r_w;
1539  }
1540  x = 0;
1541  draw_bar(test, i_pixel, x, r_h + w_h, p_w, p_h, picref);
1542  x += p_w;
1543  draw_bar(test, white, x, r_h + w_h, p_w, p_h, picref);
1544  x += p_w;
1545  draw_bar(test, q_pixel, x, r_h + w_h, p_w, p_h, picref);
1546  x += p_w;
1547  tmp = FFALIGN(5 * r_w - x, 1 << pixdesc->log2_chroma_w);
1548  draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1549  x += tmp;
1550  tmp = FFALIGN(r_w / 3, 1 << pixdesc->log2_chroma_w);
1551  draw_bar(test, neg4ire, x, r_h + w_h, tmp, p_h, picref);
1552  x += tmp;
1553  draw_bar(test, black0, x, r_h + w_h, tmp, p_h, picref);
1554  x += tmp;
1555  draw_bar(test, pos4ire, x, r_h + w_h, tmp, p_h, picref);
1556  x += tmp;
1557  draw_bar(test, black0, x, r_h + w_h, test->w - x, p_h, picref);
1558 }
1559 
1560 static av_cold int smptebars_init(AVFilterContext *ctx)
1561 {
1562  TestSourceContext *test = ctx->priv;
1563 
1564  test->fill_picture_fn = smptebars_fill_picture;
1565  test->draw_once = 1;
1566  return init(ctx);
1567 }
1568 
1569 const AVFilter ff_vsrc_smptebars = {
1570  .name = "smptebars",
1571  .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
1572  .priv_size = sizeof(TestSourceContext),
1573  .priv_class = &smptebars_class,
1574  .init = smptebars_init,
1575  .uninit = uninit,
1576  .activate = activate,
1577  .inputs = NULL,
1579  FILTER_QUERY_FUNC2(smptebars_query_formats),
1580 };
1581 
1582 #endif /* CONFIG_SMPTEBARS_FILTER */
1583 
1584 #if CONFIG_SMPTEHDBARS_FILTER
1585 
1586 static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref)
1587 {
1588  TestSourceContext *test = ctx->priv;
1589  int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0;
1590  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format);
1591 
1592  d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w);
1593  r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h);
1594  draw_bar(test, gray40, x, 0, d_w, r_h, picref);
1595  x += d_w;
1596 
1597  r_w = FFALIGN((((test->w + 3) / 4) * 3) / 7, 1 << pixdesc->log2_chroma_w);
1598  for (i = 0; i < 7; i++) {
1599  draw_bar(test, rainbowhd[i], x, 0, r_w, r_h, picref);
1600  x += r_w;
1601  }
1602  draw_bar(test, gray40, x, 0, test->w - x, r_h, picref);
1603  y = r_h;
1604  r_h = FFALIGN(test->h / 12, 1 << pixdesc->log2_chroma_h);
1605  draw_bar(test, cyan, 0, y, d_w, r_h, picref);
1606  x = d_w;
1607  draw_bar(test, i_pixel, x, y, r_w, r_h, picref);
1608  x += r_w;
1609  tmp = r_w * 6;
1610  draw_bar(test, rainbowhd[0], x, y, tmp, r_h, picref);
1611  x += tmp;
1612  l_w = x;
1613  draw_bar(test, blue, x, y, test->w - x, r_h, picref);
1614  y += r_h;
1615  draw_bar(test, yellow, 0, y, d_w, r_h, picref);
1616  x = d_w;
1617  draw_bar(test, q_pixel, x, y, r_w, r_h, picref);
1618  x += r_w;
1619 
1620  for (i = 0; i < tmp; i += 1 << pixdesc->log2_chroma_w) {
1621  uint8_t yramp[4] = {0};
1622 
1623  yramp[0] = i * 255 / tmp;
1624  yramp[1] = 128;
1625  yramp[2] = 128;
1626  yramp[3] = 255;
1627 
1628  draw_bar(test, yramp, x, y, 1 << pixdesc->log2_chroma_w, r_h, picref);
1629  x += 1 << pixdesc->log2_chroma_w;
1630  }
1631  draw_bar(test, red, x, y, test->w - x, r_h, picref);
1632  y += r_h;
1633  draw_bar(test, gray15, 0, y, d_w, test->h - y, picref);
1634  x = d_w;
1635  tmp = FFALIGN(r_w * 3 / 2, 1 << pixdesc->log2_chroma_w);
1636  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1637  x += tmp;
1638  tmp = FFALIGN(r_w * 2, 1 << pixdesc->log2_chroma_w);
1639  draw_bar(test, white, x, y, tmp, test->h - y, picref);
1640  x += tmp;
1641  tmp = FFALIGN(r_w * 5 / 6, 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 / 3, 1 << pixdesc->log2_chroma_w);
1645  draw_bar(test, neg2, x, y, tmp, test->h - y, picref);
1646  x += tmp;
1647  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1648  x += tmp;
1649  draw_bar(test, black2, x, y, tmp, test->h - y, picref);
1650  x += tmp;
1651  draw_bar(test, black0, x, y, tmp, test->h - y, picref);
1652  x += tmp;
1653  draw_bar(test, black4, x, y, tmp, test->h - y, picref);
1654  x += tmp;
1655  r_w = l_w - x;
1656  draw_bar(test, black0, x, y, r_w, test->h - y, picref);
1657  x += r_w;
1658  draw_bar(test, gray15, x, y, test->w - x, test->h - y, picref);
1659 }
1660 
1661 static av_cold int smptehdbars_init(AVFilterContext *ctx)
1662 {
1663  TestSourceContext *test = ctx->priv;
1664 
1665  test->fill_picture_fn = smptehdbars_fill_picture;
1666  test->draw_once = 1;
1667  return init(ctx);
1668 }
1669 
1670 const AVFilter ff_vsrc_smptehdbars = {
1671  .name = "smptehdbars",
1672  .description = NULL_IF_CONFIG_SMALL("Generate SMPTE HD color bars."),
1673  .priv_class = &smptebars_class,
1674  .priv_size = sizeof(TestSourceContext),
1675  .init = smptehdbars_init,
1676  .uninit = uninit,
1677  .activate = activate,
1678  .inputs = NULL,
1680  FILTER_QUERY_FUNC2(smptebars_query_formats),
1681 };
1682 
1683 #endif /* CONFIG_SMPTEHDBARS_FILTER */
1684 #endif /* CONFIG_SMPTEBARS_FILTER || CONFIG_SMPTEHDBARS_FILTER */
1685 
1686 AVFILTER_DEFINE_CLASS_EXT(allyuv_allrgb, "allyuv/allrgb",
1688 
1689 #if CONFIG_ALLYUV_FILTER
1690 
1691 static void allyuv_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1692 {
1693  const ptrdiff_t ys = frame->linesize[0];
1694  const ptrdiff_t us = frame->linesize[1];
1695  const ptrdiff_t vs = frame->linesize[2];
1696  int x, y, j;
1697 
1698  for (y = 0; y < 4096; y++) {
1699  for (x = 0; x < 2048; x++) {
1700  frame->data[0][y * ys + x] = ((x / 8) % 256);
1701  frame->data[0][y * ys + 4095 - x] = ((x / 8) % 256);
1702  }
1703 
1704  for (x = 0; x < 2048; x+=8) {
1705  for (j = 0; j < 8; j++) {
1706  frame->data[1][vs * y + x + j] = (y%16 + (j % 8) * 16);
1707  frame->data[1][vs * y + 4095 - x - j] = (128 + y%16 + (j % 8) * 16);
1708  }
1709  }
1710 
1711  for (x = 0; x < 4096; x++)
1712  frame->data[2][y * us + x] = 256 * y / 4096;
1713  }
1714 }
1715 
1716 static av_cold int allyuv_init(AVFilterContext *ctx)
1717 {
1718  TestSourceContext *test = ctx->priv;
1719 
1720  test->w = test->h = 4096;
1721  test->draw_once = 1;
1722  test->fill_picture_fn = allyuv_fill_picture;
1723  return init(ctx);
1724 }
1725 
1726 const AVFilter ff_vsrc_allyuv = {
1727  .name = "allyuv",
1728  .description = NULL_IF_CONFIG_SMALL("Generate all yuv colors."),
1729  .priv_size = sizeof(TestSourceContext),
1730  .priv_class = &allyuv_allrgb_class,
1731  .init = allyuv_init,
1732  .uninit = uninit,
1733  .activate = activate,
1734  .inputs = NULL,
1737 };
1738 
1739 #endif /* CONFIG_ALLYUV_FILTER */
1740 
1741 #if CONFIG_ALLRGB_FILTER
1742 
1743 static void allrgb_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1744 {
1745  unsigned x, y;
1746  const ptrdiff_t linesize = frame->linesize[0];
1747  uint8_t *line = frame->data[0];
1748 
1749  for (y = 0; y < 4096; y++) {
1750  uint8_t *dst = line;
1751 
1752  for (x = 0; x < 4096; x++) {
1753  *dst++ = x;
1754  *dst++ = y;
1755  *dst++ = (x >> 8) | ((y >> 8) << 4);
1756  }
1757  line += linesize;
1758  }
1759 }
1760 
1761 static av_cold int allrgb_init(AVFilterContext *ctx)
1762 {
1763  TestSourceContext *test = ctx->priv;
1764 
1765  test->w = test->h = 4096;
1766  test->draw_once = 1;
1767  test->fill_picture_fn = allrgb_fill_picture;
1768  return init(ctx);
1769 }
1770 
1771 static int allrgb_config_props(AVFilterLink *outlink)
1772 {
1773  TestSourceContext *test = outlink->src->priv;
1774 
1775  ff_fill_rgba_map(test->rgba_map, outlink->format);
1776  return config_props(outlink);
1777 }
1778 
1779 static const AVFilterPad avfilter_vsrc_allrgb_outputs[] = {
1780  {
1781  .name = "default",
1782  .type = AVMEDIA_TYPE_VIDEO,
1783  .config_props = allrgb_config_props,
1784  },
1785 };
1786 
1787 const AVFilter ff_vsrc_allrgb = {
1788  .name = "allrgb",
1789  .description = NULL_IF_CONFIG_SMALL("Generate all RGB colors."),
1790  .priv_size = sizeof(TestSourceContext),
1791  .priv_class = &allyuv_allrgb_class,
1792  .init = allrgb_init,
1793  .uninit = uninit,
1794  .activate = activate,
1795  .inputs = NULL,
1796  FILTER_OUTPUTS(avfilter_vsrc_allrgb_outputs),
1798 };
1799 
1800 #endif /* CONFIG_ALLRGB_FILTER */
1801 
1802 #if CONFIG_COLORSPECTRUM_FILTER
1803 
1804 static const AVOption colorspectrum_options[] = {
1806  { "type", "set the color spectrum type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, FLAGS, .unit = "type" },
1807  { "black","fade to black", 0, AV_OPT_TYPE_CONST,{.i64=0},0, 0, FLAGS, .unit = "type" },
1808  { "white","fade to white", 0, AV_OPT_TYPE_CONST,{.i64=1},0, 0, FLAGS, .unit = "type" },
1809  { "all", "white to black", 0, AV_OPT_TYPE_CONST,{.i64=2},0, 0, FLAGS, .unit = "type" },
1810  { NULL }
1811 };
1812 
1813 AVFILTER_DEFINE_CLASS(colorspectrum);
1814 
1815 static inline float mix(float a, float b, float mix)
1816 {
1817  return a * mix + b * (1.f - mix);
1818 }
1819 
1820 static void hsb2rgb(const float *c, float *rgb)
1821 {
1822  rgb[0] = av_clipf(fabsf(fmodf(c[0] * 6.f + 0.f, 6.f) - 3.f) - 1.f, 0.f, 1.f);
1823  rgb[1] = av_clipf(fabsf(fmodf(c[0] * 6.f + 4.f, 6.f) - 3.f) - 1.f, 0.f, 1.f);
1824  rgb[2] = av_clipf(fabsf(fmodf(c[0] * 6.f + 2.f, 6.f) - 3.f) - 1.f, 0.f, 1.f);
1825  rgb[0] = mix(c[3], (rgb[0] * rgb[0] * (3.f - 2.f * rgb[0])), c[1]) * c[2];
1826  rgb[1] = mix(c[3], (rgb[1] * rgb[1] * (3.f - 2.f * rgb[1])), c[1]) * c[2];
1827  rgb[2] = mix(c[3], (rgb[2] * rgb[2] * (3.f - 2.f * rgb[2])), c[1]) * c[2];
1828 }
1829 
1830 static void colorspectrum_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1831 {
1832  TestSourceContext *test = ctx->priv;
1833  const float w = frame->width - 1.f;
1834  const float h = frame->height - 1.f;
1835  float c[4];
1836 
1837  for (int y = 0; y < frame->height; y++) {
1838  float *r = (float *)(frame->data[2] + y * frame->linesize[2]);
1839  float *g = (float *)(frame->data[0] + y * frame->linesize[0]);
1840  float *b = (float *)(frame->data[1] + y * frame->linesize[1]);
1841  const float yh = y / h;
1842 
1843  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;
1844  c[2] = 1.f;
1845  c[3] = test->type == 1 ? 1.f : test->type == 2 ? (yh > 0.5f ? 0.f : 1.f): 0.f;
1846  for (int x = 0; x < frame->width; x++) {
1847  float rgb[3];
1848 
1849  c[0] = x / w;
1850  hsb2rgb(c, rgb);
1851 
1852  r[x] = rgb[0];
1853  g[x] = rgb[1];
1854  b[x] = rgb[2];
1855  }
1856  }
1857 }
1858 
1859 static av_cold int colorspectrum_init(AVFilterContext *ctx)
1860 {
1861  TestSourceContext *test = ctx->priv;
1862 
1863  test->draw_once = 1;
1864  test->fill_picture_fn = colorspectrum_fill_picture;
1865  return init(ctx);
1866 }
1867 
1869  .name = "colorspectrum",
1870  .description = NULL_IF_CONFIG_SMALL("Generate colors spectrum."),
1871  .priv_size = sizeof(TestSourceContext),
1872  .priv_class = &colorspectrum_class,
1873  .init = colorspectrum_init,
1874  .uninit = uninit,
1875  .activate = activate,
1876  .inputs = NULL,
1879 };
1880 
1881 #endif /* CONFIG_COLORSPECTRUM_FILTER */
1882 
1883 #if CONFIG_COLORCHART_FILTER
1884 
1885 static const AVOption colorchart_options[] = {
1887  { "patch_size", "set the single patch size", OFFSET(pw), AV_OPT_TYPE_IMAGE_SIZE, {.str="64x64"}, 0, 0, FLAGS },
1888  { "preset", "set the color checker chart preset", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, .unit = "preset" },
1889  { "reference", "reference", 0, AV_OPT_TYPE_CONST,{.i64=0}, 0, 0, FLAGS, .unit = "preset" },
1890  { "skintones", "skintones", 0, AV_OPT_TYPE_CONST,{.i64=1}, 0, 0, FLAGS, .unit = "preset" },
1891  { NULL }
1892 };
1893 
1894 AVFILTER_DEFINE_CLASS(colorchart);
1895 
1896 static const uint8_t reference_colors[][3] = {
1897  { 115, 82, 68 }, // dark skin
1898  { 194, 150, 130 }, // light skin
1899  { 98, 122, 157 }, // blue sky
1900  { 87, 108, 67 }, // foliage
1901  { 133, 128, 177 }, // blue flower
1902  { 103, 189, 170 }, // bluish green
1903 
1904  { 214, 126, 44 }, // orange
1905  { 80, 91, 166 }, // purple red
1906  { 193, 90, 99 }, // moderate red
1907  { 94, 60, 108 }, // purple
1908  { 157, 188, 64 }, // yellow green
1909  { 224, 163, 46 }, // orange yellow
1910 
1911  { 56, 61, 150 }, // blue
1912  { 70, 148, 73 }, // green
1913  { 175, 54, 60 }, // red
1914  { 231, 199, 31 }, // yellow
1915  { 187, 86, 149 }, // magenta
1916  { 8, 133, 161 }, // cyan
1917 
1918  { 243, 243, 242 }, // white
1919  { 200, 200, 200 }, // neutral 8
1920  { 160, 160, 160 }, // neutral 65
1921  { 122, 122, 121 }, // neutral 5
1922  { 85, 85, 85 }, // neutral 35
1923  { 52, 52, 52 }, // black
1924 };
1925 
1926 static const uint8_t skintones_colors[][3] = {
1927  { 54, 38, 43 },
1928  { 105, 43, 42 },
1929  { 147, 43, 43 },
1930  { 77, 41, 42 },
1931  { 134, 43, 41 },
1932  { 201, 134, 118 },
1933 
1934  { 59, 41, 41 },
1935  { 192, 103, 76 },
1936  { 208, 156, 141 },
1937  { 152, 82, 61 },
1938  { 162, 132, 118 },
1939  { 212, 171, 150 },
1940 
1941  { 205, 91, 31 },
1942  { 164, 100, 55 },
1943  { 204, 136, 95 },
1944  { 178, 142, 116 },
1945  { 210, 152, 108 },
1946  { 217, 167, 131 },
1947 
1948  { 206, 166, 126 },
1949  { 208, 163, 97 },
1950  { 245, 180, 0 },
1951  { 212, 184, 125 },
1952  { 179, 165, 150 },
1953  { 196, 184, 105 },
1954 };
1955 
1956 typedef struct ColorChartPreset {
1957  int w, h;
1958  const uint8_t (*colors)[3];
1959 } ColorChartPreset;
1960 
1961 static const ColorChartPreset colorchart_presets[] = {
1962  { 6, 4, reference_colors, },
1963  { 6, 4, skintones_colors, },
1964 };
1965 
1966 static int colorchart_config_props(AVFilterLink *inlink)
1967 {
1968  AVFilterContext *ctx = inlink->src;
1969  TestSourceContext *s = ctx->priv;
1970 
1971  av_assert0(ff_draw_init2(&s->draw, inlink->format, inlink->colorspace,
1972  inlink->color_range, 0) >= 0);
1973  if (av_image_check_size(s->w, s->h, 0, ctx) < 0)
1974  return AVERROR(EINVAL);
1975  return config_props(inlink);
1976 }
1977 
1978 static void colorchart_fill_picture(AVFilterContext *ctx, AVFrame *frame)
1979 {
1980  TestSourceContext *test = ctx->priv;
1981  const int preset = test->type;
1982  const int w = colorchart_presets[preset].w;
1983  const int h = colorchart_presets[preset].h;
1984  const int pw = test->pw;
1985  const int ph = test->ph;
1986 
1987  for (int y = 0; y < h; y++) {
1988  for (int x = 0; x < w; x++) {
1989  uint32_t pc = AV_RB24(colorchart_presets[preset].colors[y * w + x]);
1991 
1992  set_color(test, &color, pc);
1993  ff_fill_rectangle(&test->draw, &color, frame->data, frame->linesize,
1994  x * pw, y * ph, pw, ph);
1995  }
1996  }
1997 }
1998 
1999 static av_cold int colorchart_init(AVFilterContext *ctx)
2000 {
2001  TestSourceContext *test = ctx->priv;
2002  const int preset = test->type;
2003  const int w = colorchart_presets[preset].w;
2004  const int h = colorchart_presets[preset].h;
2005 
2006  test->w = w * test->pw;
2007  test->h = h * test->ph;
2008  test->draw_once = 1;
2009  test->fill_picture_fn = colorchart_fill_picture;
2010  return init(ctx);
2011 }
2012 
2013 static const AVFilterPad avfilter_vsrc_colorchart_outputs[] = {
2014  {
2015  .name = "default",
2016  .type = AVMEDIA_TYPE_VIDEO,
2017  .config_props = colorchart_config_props,
2018  },
2019 };
2020 
2021 const AVFilter ff_vsrc_colorchart = {
2022  .name = "colorchart",
2023  .description = NULL_IF_CONFIG_SMALL("Generate color checker chart."),
2024  .priv_size = sizeof(TestSourceContext),
2025  .priv_class = &colorchart_class,
2026  .init = colorchart_init,
2027  .uninit = uninit,
2028  .activate = activate,
2029  .inputs = NULL,
2030  FILTER_OUTPUTS(avfilter_vsrc_colorchart_outputs),
2032 };
2033 
2034 #endif /* CONFIG_COLORCHART_FILTER */
2035 
2036 #if CONFIG_ZONEPLATE_FILTER
2037 
2038 static const AVOption zoneplate_options[] = {
2040  { "precision", "set LUT precision", OFFSET(lut_precision), AV_OPT_TYPE_INT, {.i64=10}, 4, 16, FLAGS },
2041  { "xo", "set X-axis offset", OFFSET(xo), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2042  { "yo", "set Y-axis offset", OFFSET(yo), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2043  { "to", "set T-axis offset", OFFSET(to), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2044  { "k0", "set 0-order phase", OFFSET(k0), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2045  { "kx", "set 1-order X-axis phase", OFFSET(kx), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2046  { "ky", "set 1-order Y-axis phase", OFFSET(ky), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2047  { "kt", "set 1-order T-axis phase", OFFSET(kt), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2048  { "kxt", "set X-axis*T-axis product phase", OFFSET(kxt), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2049  { "kyt", "set Y-axis*T-axis product phase", OFFSET(kyt), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2050  { "kxy", "set X-axis*Y-axis product phase", OFFSET(kxy), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2051  { "kx2", "set 2-order X-axis phase", OFFSET(kx2), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2052  { "ky2", "set 2-order Y-axis phase", OFFSET(ky2), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2053  { "kt2", "set 2-order T-axis phase", OFFSET(kt2), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2054  { "ku", "set 0-order U-color phase", OFFSET(kU), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2055  { "kv", "set 0-order V-color phase", OFFSET(kV), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGSR },
2056  { NULL }
2057 };
2058 
2059 AVFILTER_DEFINE_CLASS(zoneplate);
2060 
2061 #define ZONEPLATE_SLICE(name, type) \
2062 static int zoneplate_fill_slice_##name(AVFilterContext *ctx, \
2063  void *arg, int job, \
2064  int nb_jobs) \
2065 { \
2066  TestSourceContext *test = ctx->priv; \
2067  AVFrame *frame = arg; \
2068  const int w = frame->width; \
2069  const int h = frame->height; \
2070  const int kxt = test->kxt, kyt = test->kyt, kx2 = test->kx2; \
2071  const int t = test->pts + test->to, k0 = test->k0; \
2072  const int kt = test->kt, kt2 = test->kt2, ky2 = test->ky2; \
2073  const int ky = test->ky, kx = test->kx, kxy = test->kxy; \
2074  const int lut_mask = (1 << test->lut_precision) - 1; \
2075  const int nkt2t = kt2 * t * t, nktt = kt * t; \
2076  const int start = (h * job ) / nb_jobs; \
2077  const int end = (h * (job+1)) / nb_jobs; \
2078  const ptrdiff_t ylinesize = frame->linesize[0] / sizeof(type); \
2079  const ptrdiff_t ulinesize = frame->linesize[1] / sizeof(type); \
2080  const ptrdiff_t vlinesize = frame->linesize[2] / sizeof(type); \
2081  const int xreset = -(w / 2) - test->xo; \
2082  const int yreset = -(h / 2) - test->yo + start; \
2083  const int kU = test->kU, kV = test->kV; \
2084  const int skxy = 0xffff / (w / 2); \
2085  const int skx2 = 0xffff / w; \
2086  const int dkxt = kxt * t; \
2087  type *ydst = ((type *)frame->data[0]) + start * ylinesize; \
2088  type *udst = ((type *)frame->data[1]) + start * ulinesize; \
2089  type *vdst = ((type *)frame->data[2]) + start * vlinesize; \
2090  const type *lut = (const type *)test->lut; \
2091  int akx, akxt, aky, akyt; \
2092  \
2093  aky = start * ky; \
2094  akyt = start * kyt * t; \
2095  \
2096  for (int j = start, y = yreset; j < end; j++, y++) { \
2097  const int dkxy = kxy * y * skxy; \
2098  const int nky2kt2 = (ky2 * y * y) / h + (nkt2t >> 1); \
2099  int akxy = dkxy * xreset; \
2100  \
2101  akx = 0; \
2102  akxt = 0; \
2103  aky += ky; \
2104  akyt += kyt * t; \
2105  \
2106  for (int i = 0, x = xreset; i < w; i++, x++) { \
2107  int phase = k0, uphase = kU, vphase = kV; \
2108  \
2109  akx += kx; \
2110  phase += akx + aky + nktt; \
2111  \
2112  akxt += dkxt; \
2113  akxy += dkxy; \
2114  phase += akxt + akyt; \
2115  phase += akxy >> 16; \
2116  phase += ((kx2 * x * x * skx2) >> 16) + nky2kt2; \
2117  uphase += phase; \
2118  vphase += phase; \
2119  \
2120  ydst[i] = lut[phase & lut_mask]; \
2121  udst[i] = lut[uphase & lut_mask]; \
2122  vdst[i] = lut[vphase & lut_mask]; \
2123  } \
2124  \
2125  ydst += ylinesize; \
2126  udst += ulinesize; \
2127  vdst += vlinesize; \
2128  } \
2129  \
2130  return 0; \
2131 }
2132 
2133 ZONEPLATE_SLICE( 8, uint8_t)
2134 ZONEPLATE_SLICE( 9, uint16_t)
2135 ZONEPLATE_SLICE(10, uint16_t)
2136 ZONEPLATE_SLICE(12, uint16_t)
2137 ZONEPLATE_SLICE(14, uint16_t)
2138 ZONEPLATE_SLICE(16, uint16_t)
2139 
2140 static void zoneplate_fill_picture(AVFilterContext *ctx, AVFrame *frame)
2141 {
2142  TestSourceContext *test = ctx->priv;
2143  ff_filter_execute(ctx, test->fill_slice_fn, frame, NULL,
2145 }
2146 
2147 static int zoneplate_config_props(AVFilterLink *outlink)
2148 {
2149  AVFilterContext *ctx = outlink->src;
2150  TestSourceContext *test = ctx->priv;
2152  const int lut_size = 1 << test->lut_precision;
2153  const int depth = desc->comp[0].depth;
2154  uint16_t *lut16;
2155  uint8_t *lut8;
2156 
2157  if (av_image_check_size(test->w, test->h, 0, ctx) < 0)
2158  return AVERROR(EINVAL);
2159 
2160  test->lut = av_calloc(lut_size, sizeof(*test->lut) * ((depth + 7) / 8));
2161  if (!test->lut)
2162  return AVERROR(ENOMEM);
2163 
2164  lut8 = test->lut;
2165  lut16 = (uint16_t *)test->lut;
2166  switch (depth) {
2167  case 8:
2168  for (int i = 0; i < lut_size; i++)
2169  lut8[i] = lrintf(255.f * (0.5f + 0.5f * sinf((2.f * M_PI * i) / lut_size)));
2170  break;
2171  default:
2172  for (int i = 0; i < lut_size; i++)
2173  lut16[i] = lrintf(((1 << depth) - 1) * (0.5f + 0.5f * sinf((2.f * M_PI * i) / lut_size)));
2174  break;
2175  }
2176 
2177  test->draw_once = 0;
2178  test->fill_picture_fn = zoneplate_fill_picture;
2179 
2180  switch (depth) {
2181  case 8: test->fill_slice_fn = zoneplate_fill_slice_8; break;
2182  case 9: test->fill_slice_fn = zoneplate_fill_slice_9; break;
2183  case 10: test->fill_slice_fn = zoneplate_fill_slice_10; break;
2184  case 12: test->fill_slice_fn = zoneplate_fill_slice_12; break;
2185  case 14: test->fill_slice_fn = zoneplate_fill_slice_14; break;
2186  case 16: test->fill_slice_fn = zoneplate_fill_slice_16; break;
2187  }
2188  return config_props(outlink);
2189 }
2190 
2191 static const enum AVPixelFormat zoneplate_pix_fmts[] = {
2196 };
2197 
2198 static int zoneplate_query_formats(const AVFilterContext *ctx,
2199  AVFilterFormatsConfig **cfg_in,
2200  AVFilterFormatsConfig **cfg_out)
2201 {
2202  int ret;
2203  if ((ret = ff_set_common_color_ranges2(ctx, cfg_in, cfg_out,
2205  return ret;
2206  return ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, zoneplate_pix_fmts);
2207 }
2208 
2209 static const AVFilterPad avfilter_vsrc_zoneplate_outputs[] = {
2210  {
2211  .name = "default",
2212  .type = AVMEDIA_TYPE_VIDEO,
2213  .config_props = zoneplate_config_props,
2214  },
2215 };
2216 
2217 const AVFilter ff_vsrc_zoneplate = {
2218  .name = "zoneplate",
2219  .description = NULL_IF_CONFIG_SMALL("Generate zone-plate."),
2220  .priv_size = sizeof(TestSourceContext),
2221  .priv_class = &zoneplate_class,
2222  .init = init,
2223  .uninit = uninit,
2224  .activate = activate,
2225  .inputs = NULL,
2226  FILTER_OUTPUTS(avfilter_vsrc_zoneplate_outputs),
2227  FILTER_QUERY_FUNC2(zoneplate_query_formats),
2228  .flags = AVFILTER_FLAG_SLICE_THREADS,
2229  .process_command = ff_filter_process_command,
2230 };
2231 
2232 #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:525
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
AV_PIX_FMT_XV30LE
@ AV_PIX_FMT_XV30LE
packed XVYU 4:4:4, 32bpp, (msb)2X 10V 10Y 10U(lsb), little-endian, variant of Y410 where alpha channe...
Definition: pixfmt.h:415
FFDrawColor
Definition: drawutils.h:51
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:513
TestSourceContext::kV
int kV
Definition: vsrc_testsrc.c:97
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
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:251
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:3170
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:143
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:95
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:94
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:3042
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:717
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:128
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:3210
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:646
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:520
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:518
TestSourceContext::kyt
int kyt
Definition: vsrc_testsrc.c:95
draw_rectangle
static void draw_rectangle(AVFormatContext *s)
Definition: xcbgrab.c:649
val
static double val(void *priv, double ch)
Definition: aeval.c:77
AV_PIX_FMT_XV48
#define AV_PIX_FMT_XV48
Definition: pixfmt.h:561
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:95
TestSourceContext::xo
int xo
Definition: vsrc_testsrc.c:97
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:549
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:86
AV_PIX_FMT_VUYA
@ AV_PIX_FMT_VUYA
packed VUYA 4:4:4:4, 32bpp (1 Cr & Cb sample per 1x1 Y & A samples), VUYAVUYA...
Definition: pixfmt.h:401
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:505
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:78
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:522
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:94
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:523
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:515
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:105
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:83
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:96
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:521
planes
static const struct @465 planes[]
TestSourceContext::sar
AVRational sar
sample aspect ratio
Definition: vsrc_testsrc.c:61
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:492
FLAGS
#define FLAGS
Definition: vsrc_testsrc.c:104
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:493
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:98
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:82
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
V
#define V
Definition: avdct.c:31
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
NOSIZE_OPTIONS_OFFSET
#define NOSIZE_OPTIONS_OFFSET
Definition: vsrc_testsrc.c:120
ff_fill_ayuv_map
int ff_fill_ayuv_map(uint8_t *ayuv_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:87
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:517
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_PIX_FMT_X2RGB10LE
@ AV_PIX_FMT_X2RGB10LE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:384
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:151
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:3135
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:368
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:95
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:532
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:488
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:118
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:495
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:246
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:509
AV_PIX_FMT_AYUV64
#define AV_PIX_FMT_AYUV64
Definition: pixfmt.h:551
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:91
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:99
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
Y
#define Y
Definition: boxblur.h:37
TestSourceContext
Definition: vsrc_testsrc.c:53
AV_PIX_FMT_AYUV
@ AV_PIX_FMT_AYUV
packed AYUV 4:4:4:4, 32bpp (1 Cr & Cb sample per 1x1 Y & A samples), AYUVAYUV...
Definition: pixfmt.h:442
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
AV_PIX_FMT_UYVA
@ AV_PIX_FMT_UYVA
packed UYVA 4:4:4:4, 32bpp (1 Cr & Cb sample per 1x1 Y & A samples), UYVAUYVA...
Definition: pixfmt.h:444
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:497
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:87
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:662
ff_vsrc_zoneplate
const AVFilter ff_vsrc_zoneplate
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:519
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:640
AV_PIX_FMT_BGR444
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:496
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:490
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:650
TestSourceContext::ky
int ky
Definition: vsrc_testsrc.c:94
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_vsrc_smptebars
const AVFilter ff_vsrc_smptebars
FFDrawContext
Definition: drawutils.h:36
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:494
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:700
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:501
OFFSET
#define OFFSET(x)
Definition: vsrc_testsrc.c:103
AV_PIX_FMT_RGB565
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:489
ff_draw_color
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:171
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:97
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:165
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:97
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:173
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
TestSourceContext::yo
int yo
Definition: vsrc_testsrc.c:97
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:96
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:100
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_X2BGR10LE
@ AV_PIX_FMT_X2BGR10LE
packed BGR 10:10:10, 30bpp, (msb)2X 10B 10G 10R(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:386
AV_PIX_FMT_V30XLE
@ AV_PIX_FMT_V30XLE
packed VYUX 4:4:4 like XV30, 32bpp, (msb)10V 10Y 10U 2X(lsb), little-endian
Definition: pixfmt.h:449
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:94
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:79
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:96
imgutils.h
AV_PIX_FMT_XV36
#define AV_PIX_FMT_XV36
Definition: pixfmt.h:560
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:512
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:81
width
#define width
Definition: dsp.h:85
drawutils.h
AV_PIX_FMT_VUYX
@ AV_PIX_FMT_VUYX
packed VUYX 4:4:4:4, 32bpp, Variant of VUYA where alpha channel is left undefined
Definition: pixfmt.h:406
TestSourceContext::ayuv_map
uint8_t ayuv_map[4]
Definition: vsrc_testsrc.c:75
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
AV_PIX_FMT_VYU444
@ AV_PIX_FMT_VYU444
packed VYU 4:4:4, 24bpp (1 Cr & Cb sample per 1x1 Y), VYUVYU...
Definition: pixfmt.h:446
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:642
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:88
set_color
static void av_unused set_color(TestSourceContext *s, FFDrawColor *color, uint32_t argb)
Definition: vsrc_testsrc.c:704
COMMON_OPTIONS_NOSIZE
#define COMMON_OPTIONS_NOSIZE
Definition: vsrc_testsrc.c:111
options
static const AVOption options[]
Definition: vsrc_testsrc.c:123
AV_PIX_FMT_RGB444
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:491
AV_WN16
#define AV_WN16(p, v)
Definition: intreadwrite.h:368