FFmpeg
vf_pseudocolor.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/attributes.h"
22 #include "libavutil/common.h"
23 #include "libavutil/eval.h"
24 #include "libavutil/imgutils.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 static const char *const var_names[] = {
33  "w", ///< width of the input video
34  "h", ///< height of the input video
35  "val", ///< input value for the pixel
36  "ymin",
37  "umin",
38  "vmin",
39  "amin",
40  "ymax",
41  "umax",
42  "vmax",
43  "amax",
44  NULL
45 };
46 
47 enum var_name {
60 };
61 
62 typedef struct PseudoColorContext {
63  const AVClass *class;
64  int max;
65  int index;
66  int nb_planes;
67  int color;
68  int linesize[4];
69  int width[4], height[4];
71  char *comp_expr_str[4];
73  float lut[4][256*256];
74 
75  void (*filter[4])(int max, int width, int height,
76  const uint8_t *index, const uint8_t *src,
77  uint8_t *dst,
78  ptrdiff_t ilinesize,
79  ptrdiff_t slinesize,
80  ptrdiff_t dlinesize,
81  float *lut);
83 
84 #define OFFSET(x) offsetof(PseudoColorContext, x)
85 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
86 
87 static const AVOption pseudocolor_options[] = {
88  { "c0", "set component #0 expression", OFFSET(comp_expr_str[0]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS },
89  { "c1", "set component #1 expression", OFFSET(comp_expr_str[1]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS },
90  { "c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS },
91  { "c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS },
92  { "i", "set component as base", OFFSET(index), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, .flags = FLAGS },
93  { NULL }
94 };
95 
96 static const enum AVPixelFormat pix_fmts[] = {
123 };
124 
126 {
128  if (!fmts_list)
129  return AVERROR(ENOMEM);
130  return ff_set_common_formats(ctx, fmts_list);
131 }
132 
133 static void pseudocolor_filter(int max, int width, int height,
134  const uint8_t *index,
135  const uint8_t *src,
136  uint8_t *dst,
137  ptrdiff_t ilinesize,
138  ptrdiff_t slinesize,
139  ptrdiff_t dlinesize,
140  float *lut)
141 {
142  int x, y;
143 
144  for (y = 0; y < height; y++) {
145  for (x = 0; x < width; x++) {
146  int v = lut[index[x]];
147 
148  if (v >= 0 && v <= max) {
149  dst[x] = v;
150  } else {
151  dst[x] = src[x];
152  }
153  }
154  index += ilinesize;
155  src += slinesize;
156  dst += dlinesize;
157  }
158 }
159 
160 static void pseudocolor_filter_11(int max, int width, int height,
161  const uint8_t *index,
162  const uint8_t *src,
163  uint8_t *dst,
164  ptrdiff_t ilinesize,
165  ptrdiff_t slinesize,
166  ptrdiff_t dlinesize,
167  float *lut)
168 {
169  int x, y;
170 
171  for (y = 0; y < height; y++) {
172  for (x = 0; x < width; x++) {
173  int v = lut[index[(y << 1) * ilinesize + (x << 1)]];
174 
175  if (v >= 0 && v <= max) {
176  dst[x] = v;
177  } else {
178  dst[x] = src[x];
179  }
180  }
181  src += slinesize;
182  dst += dlinesize;
183  }
184 }
185 
186 static void pseudocolor_filter_11d(int max, int width, int height,
187  const uint8_t *index,
188  const uint8_t *src,
189  uint8_t *dst,
190  ptrdiff_t ilinesize,
191  ptrdiff_t slinesize,
192  ptrdiff_t dlinesize,
193  float *lut)
194 {
195  int x, y;
196 
197  for (y = 0; y < height; y++) {
198  for (x = 0; x < width; x++) {
199  int v = lut[index[(y >> 1) * ilinesize + (x >> 1)]];
200 
201  if (v >= 0 && v <= max) {
202  dst[x] = v;
203  } else {
204  dst[x] = src[x];
205  }
206  }
207  src += slinesize;
208  dst += dlinesize;
209  }
210 }
211 
212 static void pseudocolor_filter_10(int max, int width, int height,
213  const uint8_t *index,
214  const uint8_t *src,
215  uint8_t *dst,
216  ptrdiff_t ilinesize,
217  ptrdiff_t slinesize,
218  ptrdiff_t dlinesize,
219  float *lut)
220 {
221  int x, y;
222 
223  for (y = 0; y < height; y++) {
224  for (x = 0; x < width; x++) {
225  int v = lut[index[x << 1]];
226 
227  if (v >= 0 && v <= max) {
228  dst[x] = v;
229  } else {
230  dst[x] = src[x];
231  }
232  }
233  index += ilinesize;
234  src += slinesize;
235  dst += dlinesize;
236  }
237 }
238 
239 static void pseudocolor_filter_10d(int max, int width, int height,
240  const uint8_t *index,
241  const uint8_t *src,
242  uint8_t *dst,
243  ptrdiff_t ilinesize,
244  ptrdiff_t slinesize,
245  ptrdiff_t dlinesize,
246  float *lut)
247 {
248  int x, y;
249 
250  for (y = 0; y < height; y++) {
251  for (x = 0; x < width; x++) {
252  int v = lut[index[x >> 1]];
253 
254  if (v >= 0 && v <= max) {
255  dst[x] = v;
256  } else {
257  dst[x] = src[x];
258  }
259  }
260  index += ilinesize;
261  src += slinesize;
262  dst += dlinesize;
263  }
264 }
265 
266 static void pseudocolor_filter_16(int max, int width, int height,
267  const uint8_t *iindex,
268  const uint8_t *ssrc,
269  uint8_t *ddst,
270  ptrdiff_t ilinesize,
271  ptrdiff_t slinesize,
272  ptrdiff_t dlinesize,
273  float *lut)
274 {
275  const uint16_t *index = (const uint16_t *)iindex;
276  const uint16_t *src = (const uint16_t *)ssrc;
277  uint16_t *dst = (uint16_t *)ddst;
278  int x, y;
279 
280  for (y = 0; y < height; y++) {
281  for (x = 0; x < width; x++) {
282  int v = lut[index[x]];
283 
284  if (v >= 0 && v <= max) {
285  dst[x] = v;
286  } else {
287  dst[x] = src[x];
288  }
289  }
290  index += ilinesize / 2;
291  src += slinesize / 2;
292  dst += dlinesize / 2;
293  }
294 }
295 
296 static void pseudocolor_filter_16_10(int max, int width, int height,
297  const uint8_t *iindex,
298  const uint8_t *ssrc,
299  uint8_t *ddst,
300  ptrdiff_t ilinesize,
301  ptrdiff_t slinesize,
302  ptrdiff_t dlinesize,
303  float *lut)
304 {
305  const uint16_t *index = (const uint16_t *)iindex;
306  const uint16_t *src = (const uint16_t *)ssrc;
307  uint16_t *dst = (uint16_t *)ddst;
308  int x, y;
309 
310  for (y = 0; y < height; y++) {
311  for (x = 0; x < width; x++) {
312  int v = lut[index[x << 1]];
313 
314  if (v >= 0 && v <= max) {
315  dst[x] = v;
316  } else {
317  dst[x] = src[x];
318  }
319  }
320  index += ilinesize / 2;
321  src += slinesize / 2;
322  dst += dlinesize / 2;
323  }
324 }
325 
326 static void pseudocolor_filter_16_10d(int max, int width, int height,
327  const uint8_t *iindex,
328  const uint8_t *ssrc,
329  uint8_t *ddst,
330  ptrdiff_t ilinesize,
331  ptrdiff_t slinesize,
332  ptrdiff_t dlinesize,
333  float *lut)
334 {
335  const uint16_t *index = (const uint16_t *)iindex;
336  const uint16_t *src = (const uint16_t *)ssrc;
337  uint16_t *dst = (uint16_t *)ddst;
338  int x, y;
339 
340  for (y = 0; y < height; y++) {
341  for (x = 0; x < width; x++) {
342  int v = lut[index[x >> 1]];
343 
344  if (v >= 0 && v <= max) {
345  dst[x] = v;
346  } else {
347  dst[x] = src[x];
348  }
349  }
350  index += ilinesize / 2;
351  src += slinesize / 2;
352  dst += dlinesize / 2;
353  }
354 }
355 
356 static void pseudocolor_filter_16_11(int max, int width, int height,
357  const uint8_t *iindex,
358  const uint8_t *ssrc,
359  uint8_t *ddst,
360  ptrdiff_t ilinesize,
361  ptrdiff_t slinesize,
362  ptrdiff_t dlinesize,
363  float *lut)
364 {
365  const uint16_t *index = (const uint16_t *)iindex;
366  const uint16_t *src = (const uint16_t *)ssrc;
367  uint16_t *dst = (uint16_t *)ddst;
368  int x, y;
369 
370  ilinesize /= 2;
371  dlinesize /= 2;
372  slinesize /= 2;
373 
374  for (y = 0; y < height; y++) {
375  for (x = 0; x < width; x++) {
376  int v = lut[index[(y << 1) * ilinesize + (x << 1)]];
377 
378  if (v >= 0 && v <= max) {
379  dst[x] = v;
380  } else {
381  dst[x] = src[x];
382  }
383  }
384  src += slinesize;
385  dst += dlinesize;
386  }
387 }
388 
389 static void pseudocolor_filter_16_11d(int max, int width, int height,
390  const uint8_t *iindex,
391  const uint8_t *ssrc,
392  uint8_t *ddst,
393  ptrdiff_t ilinesize,
394  ptrdiff_t slinesize,
395  ptrdiff_t dlinesize,
396  float *lut)
397 {
398  const uint16_t *index = (const uint16_t *)iindex;
399  const uint16_t *src = (const uint16_t *)ssrc;
400  uint16_t *dst = (uint16_t *)ddst;
401  int x, y;
402 
403  ilinesize /= 2;
404  dlinesize /= 2;
405  slinesize /= 2;
406 
407  for (y = 0; y < height; y++) {
408  for (x = 0; x < width; x++) {
409  int v = lut[index[(y >> 1) * ilinesize + (x >> 1)]];
410 
411  if (v >= 0 && v <= max) {
412  dst[x] = v;
413  } else {
414  dst[x] = src[x];
415  }
416  }
417  src += slinesize;
418  dst += dlinesize;
419  }
420 }
421 
423 {
424  AVFilterContext *ctx = inlink->dst;
425  PseudoColorContext *s = ctx->priv;
427  int depth, ret, hsub, vsub, color;
428 
429  depth = desc->comp[0].depth;
430  s->max = (1 << depth) - 1;
431  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
432 
433  if (s->index >= s->nb_planes) {
434  av_log(ctx, AV_LOG_ERROR, "index out of allowed range\n");
435  return AVERROR(EINVAL);
436  }
437 
438  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
439  return ret;
440 
441  hsub = desc->log2_chroma_w;
442  vsub = desc->log2_chroma_h;
443  s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
444  s->height[0] = s->height[3] = inlink->h;
445  s->width[1] = s->width[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
446  s->width[0] = s->width[3] = inlink->w;
447 
448  s->var_values[VAR_W] = inlink->w;
449  s->var_values[VAR_H] = inlink->h;
450 
451  s->var_values[VAR_YMIN] = 16 * (1 << (depth - 8));
452  s->var_values[VAR_UMIN] = 16 * (1 << (depth - 8));
453  s->var_values[VAR_VMIN] = 16 * (1 << (depth - 8));
454  s->var_values[VAR_AMIN] = 0;
455  s->var_values[VAR_YMAX] = 235 * (1 << (depth - 8));
456  s->var_values[VAR_UMAX] = 240 * (1 << (depth - 8));
457  s->var_values[VAR_VMAX] = 240 * (1 << (depth - 8));
458  s->var_values[VAR_AMAX] = s->max;
459 
460  for (color = 0; color < s->nb_planes; color++) {
461  double res;
462  int val;
463 
464  /* create the parsed expression */
465  av_expr_free(s->comp_expr[color]);
466  s->comp_expr[color] = NULL;
467  ret = av_expr_parse(&s->comp_expr[color], s->comp_expr_str[color],
468  var_names, NULL, NULL, NULL, NULL, 0, ctx);
469  if (ret < 0) {
471  "Error when parsing the expression '%s' for the component %d and color %d.\n",
472  s->comp_expr_str[color], color, color);
473  return AVERROR(EINVAL);
474  }
475 
476  /* compute the lut */
477  for (val = 0; val < FF_ARRAY_ELEMS(s->lut[color]); val++) {
478  s->var_values[VAR_VAL] = val;
479 
480  res = av_expr_eval(s->comp_expr[color], s->var_values, s);
481  if (isnan(res)) {
483  "Error when evaluating the expression '%s' for the value %d for the component %d.\n",
484  s->comp_expr_str[color], val, color);
485  return AVERROR(EINVAL);
486  }
487  s->lut[color][val] = res;
488  }
489  }
490 
491  switch (inlink->format) {
492  case AV_PIX_FMT_YUV444P:
493  case AV_PIX_FMT_YUVA444P:
494  case AV_PIX_FMT_GBRP:
495  case AV_PIX_FMT_GBRAP:
496  case AV_PIX_FMT_GRAY8:
497  s->filter[0] = s->filter[1] = s->filter[2] = s->filter[3] = pseudocolor_filter;
498  break;
499  case AV_PIX_FMT_YUV420P:
500  case AV_PIX_FMT_YUVA420P:
501  switch (s->index) {
502  case 0:
503  case 3:
504  s->filter[0] = s->filter[3] = pseudocolor_filter;
505  s->filter[1] = s->filter[2] = pseudocolor_filter_11;
506  break;
507  case 1:
508  case 2:
509  s->filter[0] = s->filter[3] = pseudocolor_filter_11d;
510  s->filter[1] = s->filter[2] = pseudocolor_filter;
511  break;
512  }
513  break;
514  case AV_PIX_FMT_YUV422P:
515  case AV_PIX_FMT_YUVA422P:
516  switch (s->index) {
517  case 0:
518  case 3:
519  s->filter[0] = s->filter[3] = pseudocolor_filter;
520  s->filter[1] = s->filter[2] = pseudocolor_filter_10;
521  break;
522  case 1:
523  case 2:
524  s->filter[0] = s->filter[3] = pseudocolor_filter_10d;
525  s->filter[1] = s->filter[2] = pseudocolor_filter;
526  break;
527  }
528  break;
529  case AV_PIX_FMT_YUV444P9:
537  case AV_PIX_FMT_GBRP9:
538  case AV_PIX_FMT_GBRP10:
539  case AV_PIX_FMT_GBRP12:
540  case AV_PIX_FMT_GBRP14:
541  case AV_PIX_FMT_GBRP16:
542  case AV_PIX_FMT_GBRAP10:
543  case AV_PIX_FMT_GBRAP12:
544  case AV_PIX_FMT_GBRAP16:
545  case AV_PIX_FMT_GRAY9:
546  case AV_PIX_FMT_GRAY10:
547  case AV_PIX_FMT_GRAY12:
548  case AV_PIX_FMT_GRAY14:
549  case AV_PIX_FMT_GRAY16:
550  s->filter[0] = s->filter[1] = s->filter[2] = s->filter[3] = pseudocolor_filter_16;
551  break;
552  case AV_PIX_FMT_YUV422P9:
560  switch (s->index) {
561  case 0:
562  case 3:
563  s->filter[0] = s->filter[3] = pseudocolor_filter_16;
564  s->filter[1] = s->filter[2] = pseudocolor_filter_16_10;
565  break;
566  case 1:
567  case 2:
568  s->filter[0] = s->filter[3] = pseudocolor_filter_16_10d;
569  s->filter[1] = s->filter[2] = pseudocolor_filter_16;
570  break;
571  }
572  break;
573  case AV_PIX_FMT_YUV420P9:
581  switch (s->index) {
582  case 0:
583  case 3:
584  s->filter[0] = s->filter[3] = pseudocolor_filter_16;
585  s->filter[1] = s->filter[2] = pseudocolor_filter_16_11;
586  break;
587  case 1:
588  case 2:
589  s->filter[0] = s->filter[3] = pseudocolor_filter_16_11d;
590  s->filter[1] = s->filter[2] = pseudocolor_filter_16;
591  break;
592  }
593  break;
594  }
595 
596  return 0;
597 }
598 
600 {
601  AVFilterContext *ctx = inlink->dst;
602  PseudoColorContext *s = ctx->priv;
603  AVFilterLink *outlink = ctx->outputs[0];
604  AVFrame *out;
605  int plane;
606 
607  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
608  if (!out) {
609  av_frame_free(&in);
610  return AVERROR(ENOMEM);
611  }
613 
614  for (plane = 0; plane < s->nb_planes; plane++) {
615  const uint8_t *index = in->data[s->index];
616  const uint8_t *src = in->data[plane];
617  uint8_t *dst = out->data[plane];
618  ptrdiff_t ilinesize = in->linesize[s->index];
619  ptrdiff_t slinesize = in->linesize[plane];
620  ptrdiff_t dlinesize = out->linesize[plane];
621 
622  s->filter[plane](s->max, s->width[plane], s->height[plane],
623  index, src, dst, ilinesize, slinesize,
624  dlinesize, s->lut[plane]);
625  }
626 
627  av_frame_free(&in);
628  return ff_filter_frame(outlink, out);
629 }
630 
631 static const AVFilterPad inputs[] = {
632  {
633  .name = "default",
634  .type = AVMEDIA_TYPE_VIDEO,
635  .filter_frame = filter_frame,
636  .config_props = config_input,
637  },
638  { NULL }
639 };
640 
641 static const AVFilterPad outputs[] = {
642  {
643  .name = "default",
644  .type = AVMEDIA_TYPE_VIDEO,
645  },
646  { NULL }
647 };
648 
650 {
651  PseudoColorContext *s = ctx->priv;
652  int i;
653 
654  for (i = 0; i < 4; i++) {
655  av_expr_free(s->comp_expr[i]);
656  s->comp_expr[i] = NULL;
657  }
658 }
659 
660 AVFILTER_DEFINE_CLASS(pseudocolor);
661 
663  .name = "pseudocolor",
664  .description = NULL_IF_CONFIG_SMALL("Make pseudocolored video frames."),
665  .priv_size = sizeof(PseudoColorContext),
666  .priv_class = &pseudocolor_class,
667  .uninit = uninit,
669  .inputs = inputs,
670  .outputs = outputs,
672 };
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:99
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:430
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:409
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
PseudoColorContext::width
int width[4]
Definition: vf_pseudocolor.c:69
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
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
out
FILE * out
Definition: movenc.c:54
color
Definition: vf_paletteuse.c:588
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2522
PseudoColorContext::linesize
int linesize[4]
Definition: vf_pseudocolor.c:68
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_pseudocolor.c:125
PseudoColorContext::filter
void(* filter[4])(int max, int width, int height, const uint8_t *index, const uint8_t *src, uint8_t *dst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:75
PseudoColorContext::color
int color
Definition: vf_pseudocolor.c:67
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
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
VAR_AMAX
@ VAR_AMAX
Definition: vf_pseudocolor.c:58
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:422
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
pixdesc.h
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:429
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:424
AVOption
AVOption.
Definition: opt.h:246
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:387
VAR_UMAX
@ VAR_UMAX
Definition: vf_pseudocolor.c:56
max
#define max(a, b)
Definition: cuda_runtime.h:33
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
pseudocolor_filter_10d
static void pseudocolor_filter_10d(int max, int width, int height, const uint8_t *index, const uint8_t *src, uint8_t *dst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:239
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:425
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:367
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
av_expr_parse
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:679
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2562
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:421
PseudoColorContext::comp_expr
AVExpr * comp_expr[4]
Definition: vf_pseudocolor.c:72
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:405
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:403
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:431
plane
int plane
Definition: avisynth_c.h:384
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:385
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:371
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:334
src
#define src
Definition: vp8dsp.c:254
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:390
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold
#define av_cold
Definition: attributes.h:84
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:399
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:407
width
#define width
av_image_fill_linesizes
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:89
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:408
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:400
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
pseudocolor_filter_11d
static void pseudocolor_filter_11d(int max, int width, int height, const uint8_t *index, const uint8_t *src, uint8_t *dst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:186
VAR_VMIN
@ VAR_VMIN
Definition: vf_pseudocolor.c:53
pseudocolor_filter_16_10d
static void pseudocolor_filter_16_10d(int max, int width, int height, const uint8_t *iindex, const uint8_t *ssrc, uint8_t *ddst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:326
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:384
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:398
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_expr_eval
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:734
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:370
AVExpr
Definition: eval.c:157
VAR_YMAX
@ VAR_YMAX
Definition: vf_pseudocolor.c:55
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:66
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:368
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:406
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
pseudocolor_filter
static void pseudocolor_filter(int max, int width, int height, const uint8_t *index, const uint8_t *src, uint8_t *dst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:133
NULL
#define NULL
Definition: coverity.c:32
outputs
static const AVFilterPad outputs[]
Definition: vf_pseudocolor.c:641
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
VAR_VARS_NB
@ VAR_VARS_NB
Definition: vf_pseudocolor.c:59
isnan
#define isnan(x)
Definition: libm.h:340
OFFSET
#define OFFSET(x)
Definition: vf_pseudocolor.c:84
var_names
static const char *const var_names[]
Definition: vf_pseudocolor.c:32
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:388
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
VAR_UMIN
@ VAR_UMIN
Definition: vf_pseudocolor.c:52
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:402
FLAGS
#define FLAGS
Definition: vf_pseudocolor.c:85
index
int index
Definition: gxfenc.c:89
VAR_VMAX
@ VAR_VMAX
Definition: vf_pseudocolor.c:57
eval.h
pseudocolor_filter_16
static void pseudocolor_filter_16(int max, int width, int height, const uint8_t *iindex, const uint8_t *ssrc, uint8_t *ddst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:266
desc
const char * desc
Definition: nvenc.c:68
pseudocolor_options
static const AVOption pseudocolor_options[]
Definition: vf_pseudocolor.c:87
PseudoColorContext::height
int height[4]
Definition: vf_pseudocolor.c:69
PseudoColorContext::comp_expr_str
char * comp_expr_str[4]
Definition: vf_pseudocolor.c:71
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:188
PseudoColorContext::nb_planes
int nb_planes
Definition: vf_pseudocolor.c:66
var_name
var_name
Definition: aeval.c:46
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:392
PseudoColorContext::index
int index
Definition: vf_pseudocolor.c:65
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:92
pseudocolor_filter_16_11
static void pseudocolor_filter_16_11(int max, int width, int height, const uint8_t *iindex, const uint8_t *ssrc, uint8_t *ddst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:356
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:394
val
const char const char void * val
Definition: avisynth_c.h:863
height
#define height
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
VAR_W
@ VAR_W
Definition: vf_pseudocolor.c:48
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:426
pseudocolor_filter_16_11d
static void pseudocolor_filter_16_11d(int max, int width, int height, const uint8_t *iindex, const uint8_t *ssrc, uint8_t *ddst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:389
attributes.h
PseudoColorContext
Definition: vf_pseudocolor.c:62
VAR_H
@ VAR_H
Definition: vf_pseudocolor.c:49
internal.h
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:125
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
pseudocolor_filter_16_10
static void pseudocolor_filter_16_10(int max, int width, int height, const uint8_t *iindex, const uint8_t *ssrc, uint8_t *ddst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:296
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_pseudocolor.c:649
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:404
common.h
uint8_t
uint8_t
Definition: audio_convert.c:194
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_pseudocolor.c:96
inputs
static const AVFilterPad inputs[]
Definition: vf_pseudocolor.c:631
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:386
AVFilter
Filter definition.
Definition: avfilter.h:144
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_pseudocolor.c:422
ret
ret
Definition: filter_design.txt:187
PseudoColorContext::var_values
double var_values[VAR_VARS_NB]
Definition: vf_pseudocolor.c:70
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:423
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:391
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:396
VAR_YMIN
@ VAR_YMIN
Definition: vf_pseudocolor.c:51
pseudocolor_filter_11
static void pseudocolor_filter_11(int max, int width, int height, const uint8_t *index, const uint8_t *src, uint8_t *dst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:160
VAR_VAL
@ VAR_VAL
Definition: vf_pseudocolor.c:50
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
pseudocolor_filter_10
static void pseudocolor_filter_10(int max, int width, int height, const uint8_t *index, const uint8_t *src, uint8_t *dst, ptrdiff_t ilinesize, ptrdiff_t slinesize, ptrdiff_t dlinesize, float *lut)
Definition: vf_pseudocolor.c:212
VAR_AMIN
@ VAR_AMIN
Definition: vf_pseudocolor.c:54
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:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(pseudocolor)
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
ff_vf_pseudocolor
AVFilter ff_vf_pseudocolor
Definition: vf_pseudocolor.c:662
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_pseudocolor.c:599
PseudoColorContext::lut
float lut[4][256 *256]
Definition: vf_pseudocolor.c:73
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:397
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:369
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:395
PseudoColorContext::max
int max
Definition: vf_pseudocolor.c:64