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 enum Curves {
71 };
72 
73 enum Presets {
89 };
90 
91 typedef double (*curve_fun)(double x);
92 
93 typedef struct Curve {
94  double coef[3][8];
95  double offset[3];
97 } Curve;
98 
99 typedef struct Fill {
100  float fill[4];
101 } Fill;
102 
103 typedef struct Range {
105 } Range;
106 
107 typedef struct Preset {
109  const Range *ranges;
110  const Curve *curves;
111  const Fill *fills;
112 } Preset;
113 
114 static const Range full_range = {{0, 1}, {1, 1}};
115 static const Range nominal_range[] = {{{0, 1}, {4096, 65536}}, {{4096, 65536}, {60161, 65536}}, {{60161, 65536}, {1, 1}}};
116 static const Range preferred_range[] = {{{0, 1}, {1280, 65536}}, {{1280, 65536}, {62977, 65536}}, {{62977, 65536}, {1, 1}}};
117 static const Range total_range[] = {{{0, 1}, {256, 65536}}, {{256, 65536}, {65280, 65536}}, {{65280, 65536}, {1, 1}}};
118 static const Range spec1_range[] = {{{0, 1}, {16, 256}}, {{16, 256}, {236, 256}}, {{236, 256}, {256, 256}}};
119 static const Range spec2_range[] = {{{0, 1}, {16, 256}}, {{16, 256}, {22, 256}}, {{22, 256}, {226, 256}}, {{226, 256}, {236, 256}}, {{236, 256}, {256, 256}}};
120 static const Range shadows_range[] = {{{0, 1}, {32, 256}}, {{32, 256}, {256, 256}}};
121 static const Range highlights_range[] = {{{0,1}, {214,256}}, {{214, 256}, {224, 256}}, {{224, 256}, {256, 256}}};
122 
123 static const Fill spec1_fills[] = {{{0.5f, 0.f, .5f, 1.f}}, {{-1.f, -1.f, -1.f, 1.f}}, {{1.f, 0.f, 0.f, 1.f}}};
124 static const Fill spec2_fills[] = {{{0.5f, 0.f, .5f, 1.f}}, {{0.f, 1.f, 1.f, 1.f}}, {{-1.f, -1.f, -1.f, 1.f}}, {{1.f, 1.f, 0.f, 1.f}}, {{1.f, 0.f, 0.f, 1.f}}};
125 static const Fill shadows_fills[] = {{{0.8f, 0.4f, .8f, 1.f}}, {{-1.f, -1.f, -1.f, 1.f}}};
126 static const Fill highlights_fills[] = {{{-1.f, -1.f, -1.f, 1.f}}, {{1.f, 0.3f, 0.6f, 1.f}}, {{1.f, 0.2f, .5f, 1.f}}};
127 
128 static double limit(double x)
129 {
130  return av_clipd(x, 0., 1.);
131 }
132 
133 static double solarfun(double x)
134 {
135  return 0.5 * sin(x) + 0.5;
136 }
137 
138 static const Curve curves[] =
139 {
140  [MAGMA] = {{
141  {-7.5631093e-16, 7.4289183e-13, -2.8525484e-10, 5.4446085e-08, -5.5596238e-06, 3.0569325e-04, -2.3137421e-03, 1.2152095e-02 },
142  { 1.3217636e-15, -1.2214648e-12, 4.4319712e-10, -8.0197993e-08, 7.6598370e-06, -3.6523704e-04, 8.4836670e-03, -2.5536888e-02 },
143  {-1.1446568e-15, 1.0013446e-12, -3.5651575e-10, 6.6775016e-08, -6.7120346e-06, 2.7346619e-04, 4.7969657e-03, 1.1971441e-02 },
144  }, .fun = { limit, limit, limit }, },
145  [INFERNO] = {{
146  {-3.9848859e-18, 9.4821649e-14, -6.7371977e-11, 1.8469937e-08, -2.5359307e-06, 1.7959053e-04, 3.9782564e-04, 2.8845935e-04 },
147  { 6.8408539e-16, -6.5499979e-13, 2.4562526e-10, -4.5989298e-08, 4.5723324e-06, -2.2111913e-04, 5.2023164e-03, -1.1226064e-02 },
148  {-2.9921470e-15, 2.5864165e-12, -8.7403799e-10, 1.4713388e-07, -1.2701505e-05, 4.5159935e-04, 3.1087989e-03, 1.9122831e-02 },
149  }, .fun = { limit, limit, limit }, },
150  [PLASMA] = {{
151  { 3.6196089e-16, -3.3623041e-13, 1.2324010e-10, -2.2769060e-08, 2.2297792e-06, -1.2567829e-04, 9.9791629e-03, 5.7247918e-02 },
152  { 5.0262888e-16, -5.3193896e-13, 2.2451715e-10, -4.7529623e-08, 5.1374873e-06, -2.3260136e-04, 3.1502825e-03, 1.5362491e-02 },
153  {-1.7782261e-16, 2.2487839e-13, -1.0610236e-10, 2.4112644e-08, -2.6331623e-06, 8.9499751e-05, 2.1386328e-03, 5.3824268e-01 },
154  }, .fun = { limit, limit, limit }, },
155  [VIRIDIS] = {{
156  { 9.4850045e-16, -8.6629383e-13, 3.0310944e-10, -5.1340396e-08, 4.6024275e-06, -2.2744239e-04, 4.5559993e-03, 2.5662350e-01 },
157  { 9.6461041e-17, -6.9209477e-14, 1.7625397e-11, -2.0229773e-09, 1.4900110e-07, -1.9315187e-05, 5.8967339e-03, 3.9544827e-03 },
158  { 5.1785449e-16, -3.6663004e-13, 1.0249990e-10, -1.5431998e-08, 1.5007941e-06, -1.2001502e-04, 7.6951526e-03, 3.2292815e-01 },
159  }, .fun = { limit, limit, limit }, },
160  [TURBO] = {{
161  {-4.3683890e-15, 3.7020347e-12, -1.1712592e-09, 1.6401790e-07, -8.6842919e-06, -1.8542465e-06, 8.4485325e-03, 1.6267077e-01 },
162  {-4.0011069e-16, 2.7861423e-13, -6.3388921e-11, 5.8872238e-09, -5.4466522e-07, 1.8037114e-05, 1.0599869e-02, 7.6914696e-02 },
163  {-2.8242609e-15, 2.9234108e-12, -1.1726546e-09, 2.2552115e-07, -2.0059387e-05, 5.0595552e-04, 1.7714932e-02, 2.7271836e-01 },
164  }, .fun = { limit, limit, limit }, },
165  [CIVIDIS] = {{
166  {-9.5484131e-16, 9.6988184e-13, -4.0058766e-10, 8.5743924e-08, -9.9644797e-06, 5.9197908e-04, -1.0361579e-02, 3.3164429e-02 },
167  { 1.2731941e-17, -9.4238449e-15, 2.2808841e-12, -1.1548296e-10, -2.3888913e-08, 3.8986680e-06, 2.5879330e-03, 1.2769733e-01 },
168  { 4.6004608e-16, -5.0686849e-13, 2.2753449e-10, -5.3074099e-08, 6.7196096e-06, -4.4120020e-04, 1.3435551e-02, 2.8293355e-01 },
169  }, .fun = { limit, limit, limit }, },
170  [SOLAR] = {{
171  { 0, 0, 0, 0, 0.000001983938313, -0.0007618323, 0.2, -M_PI_2 },
172  { 0, 0, 0, 0, 0.000001983938313, -0.0007618323, 0.2, -M_PI_2 },
173  { 0, 0, 0, 0, 0.000001983938313, -0.0007618323, 0.2, -M_PI_2 },
174  },
175  .offset = { 0., -9., 9. },
176  .fun = { solarfun, solarfun, solarfun }, },
177 };
178 
179 static const Preset presets[] =
180 {
181  [PRESET_MAGMA] = { 1, &full_range, &curves[MAGMA], NULL },
182  [PRESET_INFERNO] = { 1, &full_range, &curves[INFERNO], NULL },
183  [PRESET_PLASMA] = { 1, &full_range, &curves[PLASMA], NULL },
184  [PRESET_VIRIDIS] = { 1, &full_range, &curves[VIRIDIS], NULL },
185  [PRESET_TURBO] = { 1, &full_range, &curves[TURBO], NULL },
186  [PRESET_CIVIDIS] = { 1, &full_range, &curves[CIVIDIS], NULL },
194  [PRESET_SOLAR] = { 1, &full_range, &curves[SOLAR], NULL },
195 };
196 
197 typedef struct PseudoColorContext {
198  const AVClass *class;
199  int preset;
200  float opacity;
201  int max;
202  int index;
204  int color;
205  int linesize[4];
206  int width[4], height[4];
208  char *comp_expr_str[4];
210  float lut[4][256*256];
211 
212  void (*filter[4])(int max, int width, int height,
213  const uint8_t *index, const uint8_t *src,
214  uint8_t *dst,
215  ptrdiff_t ilinesize,
216  ptrdiff_t slinesize,
217  ptrdiff_t dlinesize,
218  float *lut,
219  float opacity);
221 
222 #define OFFSET(x) offsetof(PseudoColorContext, x)
223 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
224 
225 static const AVOption pseudocolor_options[] = {
226  { "c0", "set component #0 expression", OFFSET(comp_expr_str[0]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS },
227  { "c1", "set component #1 expression", OFFSET(comp_expr_str[1]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS },
228  { "c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS },
229  { "c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS },
230  { "index", "set component as base", OFFSET(index), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, .flags = FLAGS },
231  { "i", "set component as base", OFFSET(index), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, .flags = FLAGS },
232  { "preset", "set preset", OFFSET(preset), AV_OPT_TYPE_INT, {.i64=-1},-1, NB_PRESETS-1, .flags = FLAGS, "preset" },
233  { "p", "set preset", OFFSET(preset), AV_OPT_TYPE_INT, {.i64=-1},-1, NB_PRESETS-1, .flags = FLAGS, "preset" },
234  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=-1}, .flags = FLAGS, "preset" },
235  { "magma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_MAGMA}, .flags = FLAGS, "preset" },
236  { "inferno", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_INFERNO}, .flags = FLAGS, "preset" },
237  { "plasma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_PLASMA}, .flags = FLAGS, "preset" },
238  { "viridis", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_VIRIDIS}, .flags = FLAGS, "preset" },
239  { "turbo", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_TURBO}, .flags = FLAGS, "preset" },
240  { "cividis", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_CIVIDIS}, .flags = FLAGS, "preset" },
241  { "range1", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_RANGE1}, .flags = FLAGS, "preset" },
242  { "range2", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_RANGE2}, .flags = FLAGS, "preset" },
243  { "shadows", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_SHADOWS}, .flags = FLAGS, "preset" },
244  { "highlights", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_HIGHLIGHTS},.flags=FLAGS, "preset" },
245  { "solar", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_SOLAR}, .flags=FLAGS, "preset" },
246  { "nominal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NOMINAL}, .flags=FLAGS, "preset" },
247  { "preferred", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_PREFERRED},.flags=FLAGS,"preset" },
248  { "total", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_TOTAL}, .flags=FLAGS, "preset" },
249  { "opacity", "set pseudocolor opacity",OFFSET(opacity), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, .flags = FLAGS },
250  { NULL }
251 };
252 
253 static const enum AVPixelFormat pix_fmts[] = {
280 };
281 
282 static inline float lerpf(float v0, float v1, float f)
283 {
284  return v0 + (v1 - v0) * f;
285 }
286 
287 #define PCLIP(v, max, dst, src, x) \
288  if (v >= 0 && v <= max) { \
289  dst[x] = lerpf(src[x], v, opacity);\
290  } else { \
291  dst[x] = src[x]; \
292  }
293 
294 static void pseudocolor_filter(int max, int width, int height,
295  const uint8_t *index,
296  const uint8_t *src,
297  uint8_t *dst,
298  ptrdiff_t ilinesize,
299  ptrdiff_t slinesize,
300  ptrdiff_t dlinesize,
301  float *lut,
302  float opacity)
303 {
304  int x, y;
305 
306  for (y = 0; y < height; y++) {
307  for (x = 0; x < width; x++) {
308  int v = lut[index[x]];
309 
310  PCLIP(v, max, dst, src, x);
311  }
312  index += ilinesize;
313  src += slinesize;
314  dst += dlinesize;
315  }
316 }
317 
318 static void pseudocolor_filter_11(int max, int width, int height,
319  const uint8_t *index,
320  const uint8_t *src,
321  uint8_t *dst,
322  ptrdiff_t ilinesize,
323  ptrdiff_t slinesize,
324  ptrdiff_t dlinesize,
325  float *lut,
326  float opacity)
327 {
328  int x, y;
329 
330  for (y = 0; y < height; y++) {
331  for (x = 0; x < width; x++) {
332  int v = lut[index[(y << 1) * ilinesize + (x << 1)]];
333 
334  PCLIP(v, max, dst, src, x);
335  }
336  src += slinesize;
337  dst += dlinesize;
338  }
339 }
340 
341 static void pseudocolor_filter_11d(int max, int width, int height,
342  const uint8_t *index,
343  const uint8_t *src,
344  uint8_t *dst,
345  ptrdiff_t ilinesize,
346  ptrdiff_t slinesize,
347  ptrdiff_t dlinesize,
348  float *lut,
349  float opacity)
350 {
351  int x, y;
352 
353  for (y = 0; y < height; y++) {
354  for (x = 0; x < width; x++) {
355  int v = lut[index[(y >> 1) * ilinesize + (x >> 1)]];
356 
357  PCLIP(v, max, dst, src, x);
358  }
359  src += slinesize;
360  dst += dlinesize;
361  }
362 }
363 
364 static void pseudocolor_filter_10(int max, int width, int height,
365  const uint8_t *index,
366  const uint8_t *src,
367  uint8_t *dst,
368  ptrdiff_t ilinesize,
369  ptrdiff_t slinesize,
370  ptrdiff_t dlinesize,
371  float *lut,
372  float opacity)
373 {
374  int x, y;
375 
376  for (y = 0; y < height; y++) {
377  for (x = 0; x < width; x++) {
378  int v = lut[index[x << 1]];
379 
380  PCLIP(v, max, dst, src, x);
381  }
382  index += ilinesize;
383  src += slinesize;
384  dst += dlinesize;
385  }
386 }
387 
388 static void pseudocolor_filter_10d(int max, int width, int height,
389  const uint8_t *index,
390  const uint8_t *src,
391  uint8_t *dst,
392  ptrdiff_t ilinesize,
393  ptrdiff_t slinesize,
394  ptrdiff_t dlinesize,
395  float *lut,
396  float opacity)
397 {
398  int x, y;
399 
400  for (y = 0; y < height; y++) {
401  for (x = 0; x < width; x++) {
402  int v = lut[index[x >> 1]];
403 
404  PCLIP(v, max, dst, src, x);
405  }
406  index += ilinesize;
407  src += slinesize;
408  dst += dlinesize;
409  }
410 }
411 
412 static void pseudocolor_filter_16(int max, int width, int height,
413  const uint8_t *iindex,
414  const uint8_t *ssrc,
415  uint8_t *ddst,
416  ptrdiff_t ilinesize,
417  ptrdiff_t slinesize,
418  ptrdiff_t dlinesize,
419  float *lut,
420  float opacity)
421 {
422  const uint16_t *index = (const uint16_t *)iindex;
423  const uint16_t *src = (const uint16_t *)ssrc;
424  uint16_t *dst = (uint16_t *)ddst;
425  int x, y;
426 
427  for (y = 0; y < height; y++) {
428  for (x = 0; x < width; x++) {
429  int v = lut[index[x]];
430 
431  PCLIP(v, max, dst, src, x);
432  }
433  index += ilinesize / 2;
434  src += slinesize / 2;
435  dst += dlinesize / 2;
436  }
437 }
438 
439 static void pseudocolor_filter_16_10(int max, int width, int height,
440  const uint8_t *iindex,
441  const uint8_t *ssrc,
442  uint8_t *ddst,
443  ptrdiff_t ilinesize,
444  ptrdiff_t slinesize,
445  ptrdiff_t dlinesize,
446  float *lut,
447  float opacity)
448 {
449  const uint16_t *index = (const uint16_t *)iindex;
450  const uint16_t *src = (const uint16_t *)ssrc;
451  uint16_t *dst = (uint16_t *)ddst;
452  int x, y;
453 
454  for (y = 0; y < height; y++) {
455  for (x = 0; x < width; x++) {
456  int v = lut[index[x << 1]];
457 
458  PCLIP(v, max, dst, src, x);
459  }
460  index += ilinesize / 2;
461  src += slinesize / 2;
462  dst += dlinesize / 2;
463  }
464 }
465 
466 static void pseudocolor_filter_16_10d(int max, int width, int height,
467  const uint8_t *iindex,
468  const uint8_t *ssrc,
469  uint8_t *ddst,
470  ptrdiff_t ilinesize,
471  ptrdiff_t slinesize,
472  ptrdiff_t dlinesize,
473  float *lut,
474  float opacity)
475 {
476  const uint16_t *index = (const uint16_t *)iindex;
477  const uint16_t *src = (const uint16_t *)ssrc;
478  uint16_t *dst = (uint16_t *)ddst;
479  int x, y;
480 
481  for (y = 0; y < height; y++) {
482  for (x = 0; x < width; x++) {
483  int v = lut[index[x >> 1]];
484 
485  PCLIP(v, max, dst, src, x);
486  }
487  index += ilinesize / 2;
488  src += slinesize / 2;
489  dst += dlinesize / 2;
490  }
491 }
492 
493 static void pseudocolor_filter_16_11(int max, int width, int height,
494  const uint8_t *iindex,
495  const uint8_t *ssrc,
496  uint8_t *ddst,
497  ptrdiff_t ilinesize,
498  ptrdiff_t slinesize,
499  ptrdiff_t dlinesize,
500  float *lut,
501  float opacity)
502 {
503  const uint16_t *index = (const uint16_t *)iindex;
504  const uint16_t *src = (const uint16_t *)ssrc;
505  uint16_t *dst = (uint16_t *)ddst;
506  int x, y;
507 
508  ilinesize /= 2;
509  dlinesize /= 2;
510  slinesize /= 2;
511 
512  for (y = 0; y < height; y++) {
513  for (x = 0; x < width; x++) {
514  int v = lut[index[(y << 1) * ilinesize + (x << 1)]];
515 
516  PCLIP(v, max, dst, src, x);
517  }
518  src += slinesize;
519  dst += dlinesize;
520  }
521 }
522 
523 static void pseudocolor_filter_16_11d(int max, int width, int height,
524  const uint8_t *iindex,
525  const uint8_t *ssrc,
526  uint8_t *ddst,
527  ptrdiff_t ilinesize,
528  ptrdiff_t slinesize,
529  ptrdiff_t dlinesize,
530  float *lut,
531  float opacity)
532 {
533  const uint16_t *index = (const uint16_t *)iindex;
534  const uint16_t *src = (const uint16_t *)ssrc;
535  uint16_t *dst = (uint16_t *)ddst;
536  int x, y;
537 
538  ilinesize /= 2;
539  dlinesize /= 2;
540  slinesize /= 2;
541 
542  for (y = 0; y < height; y++) {
543  for (x = 0; x < width; x++) {
544  int v = lut[index[(y >> 1) * ilinesize + (x >> 1)]];
545 
546  PCLIP(v, max, dst, src, x);
547  }
548  src += slinesize;
549  dst += dlinesize;
550  }
551 }
552 
553 #define RGB_TO_Y_BT709(r, g, b) \
554 ((0.21260*219.0/255.0) * (r) + (0.71520*219.0/255.0) * (g) + \
555  (0.07220*219.0/255.0) * (b))
556 
557 #define RGB_TO_U_BT709(r1, g1, b1, max) \
558 (-(0.11457*224.0/255.0) * r1 - (0.38543*224.0/255.0) * g1 + \
559  (0.50000*224.0/255.0) * b1 + max * 0.5)
560 
561 #define RGB_TO_V_BT709(r1, g1, b1, max) \
562 ((0.50000*224.0/255.0) * r1 - (0.45415*224.0/255.0) * g1 - \
563  (0.04585*224.0/255.0) * b1 + max * 0.5)
564 
565 static double poly_eval(const double *const poly, double x, curve_fun fun)
566 {
567  double res = 0.;
568 
569  for (int i = 0; i < 8; i++) {
570  res += pow(x, i) * poly[7-i];
571  }
572 
573  return fun(res);
574 }
575 
577 {
578  AVFilterContext *ctx = inlink->dst;
579  PseudoColorContext *s = ctx->priv;
581  int depth, ret, hsub, vsub, color, rgb;
582 
583  rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
584  depth = desc->comp[0].depth;
585  s->max = (1 << depth) - 1;
586  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
587 
588  if (s->index >= s->nb_planes) {
589  av_log(ctx, AV_LOG_ERROR, "index out of allowed range\n");
590  return AVERROR(EINVAL);
591  }
592 
593  if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
594  return ret;
595 
596  hsub = desc->log2_chroma_w;
597  vsub = desc->log2_chroma_h;
598  s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
599  s->height[0] = s->height[3] = inlink->h;
600  s->width[1] = s->width[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
601  s->width[0] = s->width[3] = inlink->w;
602 
603  s->var_values[VAR_W] = inlink->w;
604  s->var_values[VAR_H] = inlink->h;
605 
606  s->var_values[VAR_YMIN] = 16 * (1 << (depth - 8));
607  s->var_values[VAR_UMIN] = 16 * (1 << (depth - 8));
608  s->var_values[VAR_VMIN] = 16 * (1 << (depth - 8));
609  s->var_values[VAR_AMIN] = 0;
610  s->var_values[VAR_YMAX] = 235 * (1 << (depth - 8));
611  s->var_values[VAR_UMAX] = 240 * (1 << (depth - 8));
612  s->var_values[VAR_VMAX] = 240 * (1 << (depth - 8));
613  s->var_values[VAR_AMAX] = s->max;
614 
615  for (color = 0; color < s->nb_planes && s->preset < 0; color++) {
616  double res;
617  int val;
618 
619  /* create the parsed expression */
620  av_expr_free(s->comp_expr[color]);
621  s->comp_expr[color] = NULL;
622  ret = av_expr_parse(&s->comp_expr[color], s->comp_expr_str[color],
623  var_names, NULL, NULL, NULL, NULL, 0, ctx);
624  if (ret < 0) {
626  "Error when parsing the expression '%s' for the component %d and color %d.\n",
627  s->comp_expr_str[color], color, color);
628  return AVERROR(EINVAL);
629  }
630 
631  /* compute the lut */
632  for (val = 0; val < FF_ARRAY_ELEMS(s->lut[color]); val++) {
633  s->var_values[VAR_VAL] = val;
634 
635  res = av_expr_eval(s->comp_expr[color], s->var_values, s);
636  if (isnan(res)) {
638  "Error when evaluating the expression '%s' for the value %d for the component %d.\n",
639  s->comp_expr_str[color], val, color);
640  return AVERROR(EINVAL);
641  }
642  s->lut[color][val] = res;
643  }
644  }
645 
646  if (s->preset >= 0) {
647  int nb_segments = presets[s->preset].nb_segments;
648 
649  for (int seg = 0; seg < nb_segments; seg++) {
650  AVRational rstart = presets[s->preset].ranges[seg].start;
651  AVRational rend = presets[s->preset].ranges[seg].end;
652  int start = av_rescale_rnd(s->max + 1, rstart.num, rstart.den, AV_ROUND_UP);
653  int end = av_rescale_rnd(s->max + 1, rend.num, rend.den, AV_ROUND_UP);
654 
655  for (int i = start; i < end; i++) {
656  if (!presets[s->preset].curves) {
657  const Fill fill = presets[s->preset].fills[seg];
658  double r, g, b, a;
659 
660  g = fill.fill[1];
661  b = fill.fill[2];
662  r = fill.fill[0];
663  a = fill.fill[3];
664 
665  if (g >= 0.f && b >= 0.f && r >= 0.f) {
666  g *= s->max;
667  b *= s->max;
668  r *= s->max;
669 
670  if (!rgb) {
671  double y = RGB_TO_Y_BT709(r, g, b);
672  double u = RGB_TO_U_BT709(r, g, b, s->max);
673  double v = RGB_TO_V_BT709(r, g, b, s->max);
674 
675  r = v;
676  g = y;
677  b = u;
678  }
679  }
680 
681  s->lut[0][i] = g;
682  s->lut[1][i] = b;
683  s->lut[2][i] = r;
684  s->lut[3][i] = a * s->max;
685  } else {
686  const Curve curve = presets[s->preset].curves[seg];
687  const double lf = i / (double)s->max * 256.;
688  double r, g, b;
689 
690  g = poly_eval(curve.coef[1], lf + curve.offset[1], curve.fun[1]) * s->max;
691  b = poly_eval(curve.coef[2], lf + curve.offset[2], curve.fun[2]) * s->max;
692  r = poly_eval(curve.coef[0], lf + curve.offset[0], curve.fun[0]) * s->max;
693 
694  if (!rgb) {
695  double y = RGB_TO_Y_BT709(r, g, b);
696  double u = RGB_TO_U_BT709(r, g, b, s->max);
697  double v = RGB_TO_V_BT709(r, g, b, s->max);
698 
699  r = v;
700  g = y;
701  b = u;
702  }
703 
704  s->lut[0][i] = g;
705  s->lut[1][i] = b;
706  s->lut[2][i] = r;
707  s->lut[3][i] = 1.f * s->max;
708  }
709  }
710  }
711  }
712 
713  switch (inlink->format) {
714  case AV_PIX_FMT_YUV444P:
715  case AV_PIX_FMT_YUVA444P:
716  case AV_PIX_FMT_GBRP:
717  case AV_PIX_FMT_GBRAP:
718  case AV_PIX_FMT_GRAY8:
719  s->filter[0] = s->filter[1] = s->filter[2] = s->filter[3] = pseudocolor_filter;
720  break;
721  case AV_PIX_FMT_YUV420P:
722  case AV_PIX_FMT_YUVA420P:
723  switch (s->index) {
724  case 0:
725  case 3:
726  s->filter[0] = s->filter[3] = pseudocolor_filter;
727  s->filter[1] = s->filter[2] = pseudocolor_filter_11;
728  break;
729  case 1:
730  case 2:
731  s->filter[0] = s->filter[3] = pseudocolor_filter_11d;
732  s->filter[1] = s->filter[2] = pseudocolor_filter;
733  break;
734  }
735  break;
736  case AV_PIX_FMT_YUV422P:
737  case AV_PIX_FMT_YUVA422P:
738  switch (s->index) {
739  case 0:
740  case 3:
741  s->filter[0] = s->filter[3] = pseudocolor_filter;
742  s->filter[1] = s->filter[2] = pseudocolor_filter_10;
743  break;
744  case 1:
745  case 2:
746  s->filter[0] = s->filter[3] = pseudocolor_filter_10d;
747  s->filter[1] = s->filter[2] = pseudocolor_filter;
748  break;
749  }
750  break;
751  case AV_PIX_FMT_YUV444P9:
759  case AV_PIX_FMT_GBRP9:
760  case AV_PIX_FMT_GBRP10:
761  case AV_PIX_FMT_GBRP12:
762  case AV_PIX_FMT_GBRP14:
763  case AV_PIX_FMT_GBRP16:
764  case AV_PIX_FMT_GBRAP10:
765  case AV_PIX_FMT_GBRAP12:
766  case AV_PIX_FMT_GBRAP16:
767  case AV_PIX_FMT_GRAY9:
768  case AV_PIX_FMT_GRAY10:
769  case AV_PIX_FMT_GRAY12:
770  case AV_PIX_FMT_GRAY14:
771  case AV_PIX_FMT_GRAY16:
772  s->filter[0] = s->filter[1] = s->filter[2] = s->filter[3] = pseudocolor_filter_16;
773  break;
774  case AV_PIX_FMT_YUV422P9:
782  switch (s->index) {
783  case 0:
784  case 3:
785  s->filter[0] = s->filter[3] = pseudocolor_filter_16;
786  s->filter[1] = s->filter[2] = pseudocolor_filter_16_10;
787  break;
788  case 1:
789  case 2:
790  s->filter[0] = s->filter[3] = pseudocolor_filter_16_10d;
791  s->filter[1] = s->filter[2] = pseudocolor_filter_16;
792  break;
793  }
794  break;
795  case AV_PIX_FMT_YUV420P9:
803  switch (s->index) {
804  case 0:
805  case 3:
806  s->filter[0] = s->filter[3] = pseudocolor_filter_16;
807  s->filter[1] = s->filter[2] = pseudocolor_filter_16_11;
808  break;
809  case 1:
810  case 2:
811  s->filter[0] = s->filter[3] = pseudocolor_filter_16_11d;
812  s->filter[1] = s->filter[2] = pseudocolor_filter_16;
813  break;
814  }
815  break;
816  }
817 
818  return 0;
819 }
820 
821 typedef struct ThreadData {
822  AVFrame *in, *out;
823 } ThreadData;
824 
825 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
826 {
827  PseudoColorContext *s = ctx->priv;
828  ThreadData *td = arg;
829  AVFrame *in = td->in;
830  AVFrame *out = td->out;
831 
832  for (int plane = 0; plane < s->nb_planes; plane++) {
833  const int slice_start = (s->height[plane] * jobnr) / nb_jobs;
834  const int slice_end = (s->height[plane] * (jobnr+1)) / nb_jobs;
835  const int islice_start = (s->height[s->index] * jobnr) / nb_jobs;
836  ptrdiff_t ilinesize = in->linesize[s->index];
837  ptrdiff_t slinesize = in->linesize[plane];
838  ptrdiff_t dlinesize = out->linesize[plane];
839  const uint8_t *index = in->data[s->index] + islice_start * ilinesize;
840  const uint8_t *src = in->data[plane] + slice_start * slinesize;
841  uint8_t *dst = out->data[plane] + slice_start * dlinesize;
842 
843  s->filter[plane](s->max, s->width[plane], slice_end - slice_start,
844  index, src, dst, ilinesize, slinesize,
845  dlinesize, s->lut[plane], s->opacity);
846  }
847 
848  return 0;
849 }
850 
852 {
853  AVFilterContext *ctx = inlink->dst;
854  PseudoColorContext *s = ctx->priv;
855  AVFilterLink *outlink = ctx->outputs[0];
856  ThreadData td;
857  AVFrame *out;
858 
859  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
860  if (!out) {
861  av_frame_free(&in);
862  return AVERROR(ENOMEM);
863  }
865 
866  td.out = out, td.in = in;
868  FFMIN(s->height[1], ff_filter_get_nb_threads(ctx)));
869 
870  av_frame_free(&in);
871  return ff_filter_frame(outlink, out);
872 }
873 
874 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
875  char *res, int res_len, int flags)
876 {
877  int ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
878 
879  if (ret < 0)
880  return ret;
881 
882  return config_input(ctx->inputs[0]);
883 }
884 
885 static const AVFilterPad inputs[] = {
886  {
887  .name = "default",
888  .type = AVMEDIA_TYPE_VIDEO,
889  .filter_frame = filter_frame,
890  .config_props = config_input,
891  },
892 };
893 
894 static const AVFilterPad outputs[] = {
895  {
896  .name = "default",
897  .type = AVMEDIA_TYPE_VIDEO,
898  },
899 };
900 
902 {
903  PseudoColorContext *s = ctx->priv;
904  int i;
905 
906  for (i = 0; i < 4; i++) {
907  av_expr_free(s->comp_expr[i]);
908  s->comp_expr[i] = NULL;
909  }
910 }
911 
912 AVFILTER_DEFINE_CLASS(pseudocolor);
913 
915  .name = "pseudocolor",
916  .description = NULL_IF_CONFIG_SMALL("Make pseudocolored video frames."),
917  .priv_size = sizeof(PseudoColorContext),
918  .priv_class = &pseudocolor_class,
919  .uninit = uninit,
924  .process_command = process_command,
925 };
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_pseudocolor.c:874
PRESET_VIRIDIS
@ PRESET_VIRIDIS
Definition: vf_pseudocolor.c:77
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:101
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:449
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:428
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, float opacity)
Definition: vf_pseudocolor.c:364
td
#define td
Definition: regdef.h:70
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
PseudoColorContext::width
int width[4]
Definition: vf_pseudocolor.c:206
Preset::nb_segments
int nb_segments
Definition: vf_pseudocolor.c:108
r
const char * r
Definition: vf_curves.c:116
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
out
FILE * out
Definition: movenc.c:54
curves
static const Curve curves[]
Definition: vf_pseudocolor.c:138
color
Definition: vf_paletteuse.c:600
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
filter_slice
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_pseudocolor.c:825
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:999
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2662
PseudoColorContext::linesize
int linesize[4]
Definition: vf_pseudocolor.c:205
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:170
PseudoColorContext::color
int color
Definition: vf_pseudocolor.c:204
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
spec2_fills
static const Fill spec2_fills[]
Definition: vf_pseudocolor.c:124
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:111
VAR_AMAX
@ VAR_AMAX
Definition: vf_pseudocolor.c:58
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:441
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
pixdesc.h
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:448
spec1_range
static const Range spec1_range[]
Definition: vf_pseudocolor.c:118
M_PI_2
#define M_PI_2
Definition: mathematics.h:55
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:443
AVOption
AVOption.
Definition: opt.h:251
PRESET_NOMINAL
@ PRESET_NOMINAL
Definition: vf_pseudocolor.c:85
b
#define b
Definition: input.c:34
solarfun
static double solarfun(double x)
Definition: vf_pseudocolor.c:133
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:406
VAR_UMAX
@ VAR_UMAX
Definition: vf_pseudocolor.c:56
TURBO
@ TURBO
Definition: vf_pseudocolor.c:67
lerpf
static float lerpf(float v0, float v1, float f)
Definition: vf_pseudocolor.c:282
max
#define max(a, b)
Definition: cuda_runtime.h:33
PRESET_RANGE1
@ PRESET_RANGE1
Definition: vf_pseudocolor.c:80
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:175
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:473
video.h
ThreadData::in
AVFrame * in
Definition: af_adecorrelate.c:154
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:444
Preset::curves
const Curve * curves
Definition: vf_pseudocolor.c:110
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:386
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:346
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, float opacity)
Definition: vf_pseudocolor.c:439
hsub
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:74
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:685
PRESET_RANGE2
@ PRESET_RANGE2
Definition: vf_pseudocolor.c:81
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2702
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:440
rgb
Definition: rpzaenc.c:59
PseudoColorContext::comp_expr
AVExpr * comp_expr[4]
Definition: vf_pseudocolor.c:209
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:424
VIRIDIS
@ VIRIDIS
Definition: vf_pseudocolor.c:66
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
highlights_fills
static const Fill highlights_fills[]
Definition: vf_pseudocolor.c:126
v0
#define v0
Definition: regdef.h:26
presets
static const Preset presets[]
Definition: vf_pseudocolor.c:179
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:422
PRESET_TOTAL
@ PRESET_TOTAL
Definition: vf_pseudocolor.c:87
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:450
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, float opacity)
Definition: vf_pseudocolor.c:412
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, float opacity)
Definition: vf_pseudocolor.c:523
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:404
PRESET_SHADOWS
@ PRESET_SHADOWS
Definition: vf_pseudocolor.c:82
val
static double val(void *priv, double ch)
Definition: aeval.c:77
AV_ROUND_UP
@ AV_ROUND_UP
Round toward +infinity.
Definition: mathematics.h:83
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:390
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:336
AVRational::num
int num
Numerator.
Definition: rational.h:59
Curve::offset
double offset[3]
Definition: vf_pseudocolor.c:95
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:409
preset
preset
Definition: vf_curves.c:46
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:418
PRESET_HIGHLIGHTS
@ PRESET_HIGHLIGHTS
Definition: vf_pseudocolor.c:83
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:426
PLASMA
@ PLASMA
Definition: vf_pseudocolor.c:65
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
RGB_TO_Y_BT709
#define RGB_TO_Y_BT709(r, g, b)
Definition: vf_pseudocolor.c:553
s
#define s(width, name)
Definition: cbs_vp9.c:256
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:427
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:419
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:50
g
const char * g
Definition: vf_curves.c:117
RGB_TO_U_BT709
#define RGB_TO_U_BT709(r1, g1, b1, max)
Definition: vf_pseudocolor.c:557
SOLAR
@ SOLAR
Definition: vf_pseudocolor.c:69
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2013
nominal_range
static const Range nominal_range[]
Definition: vf_pseudocolor.c:115
VAR_VMIN
@ VAR_VMIN
Definition: vf_pseudocolor.c:53
shadows_fills
static const Fill shadows_fills[]
Definition: vf_pseudocolor.c:125
var_name
var_name
Definition: noise_bsf.c:46
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:403
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:417
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:766
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:389
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
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
arg
const char * arg
Definition: jacosubdec.c:67
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:387
Presets
Presets
Definition: vf_pseudocolor.c:73
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, float opacity)
Definition: vf_pseudocolor.c:388
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:425
shadows_range
static const Range shadows_range[]
Definition: vf_pseudocolor.c:120
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
CIVIDIS
@ CIVIDIS
Definition: vf_pseudocolor.c:68
NULL
#define NULL
Definition: coverity.c:32
outputs
static const AVFilterPad outputs[]
Definition: vf_pseudocolor.c:894
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:596
MAGMA
@ MAGMA
Definition: vf_pseudocolor.c:63
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, float opacity)
Definition: vf_pseudocolor.c:466
VAR_VARS_NB
@ VAR_VARS_NB
Definition: vf_pseudocolor.c:59
spec2_range
static const Range spec2_range[]
Definition: vf_pseudocolor.c:119
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
isnan
#define isnan(x)
Definition: libm.h:340
NB_PRESETS
@ NB_PRESETS
Definition: vf_pseudocolor.c:88
OFFSET
#define OFFSET(x)
Definition: vf_pseudocolor.c:222
var_names
static const char *const var_names[]
Definition: vf_pseudocolor.c:32
double
double
Definition: af_crystalizer.c:132
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:407
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:421
FLAGS
#define FLAGS
Definition: vf_pseudocolor.c:223
Range
Definition: vf_colorbalance.c:38
index
int index
Definition: gxfenc.c:89
VAR_VMAX
@ VAR_VMAX
Definition: vf_pseudocolor.c:57
total_range
static const Range total_range[]
Definition: vf_pseudocolor.c:117
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
eval.h
Preset::ranges
const Range * ranges
Definition: vf_pseudocolor.c:109
f
f
Definition: af_crystalizer.c:122
RGB_TO_V_BT709
#define RGB_TO_V_BT709(r1, g1, b1, max)
Definition: vf_pseudocolor.c:561
pseudocolor_options
static const AVOption pseudocolor_options[]
Definition: vf_pseudocolor.c:225
PseudoColorContext::height
int height[4]
Definition: vf_pseudocolor.c:206
PseudoColorContext::comp_expr_str
char * comp_expr_str[4]
Definition: vf_pseudocolor.c:208
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:117
PseudoColorContext::nb_planes
int nb_planes
Definition: vf_pseudocolor.c:203
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
Curve
Definition: vf_pseudocolor.c:93
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:411
PCLIP
#define PCLIP(v, max, dst, src, x)
Definition: vf_pseudocolor.c:287
poly_eval
static double poly_eval(const double *const poly, double x, curve_fun fun)
Definition: vf_pseudocolor.c:565
PseudoColorContext::index
int index
Definition: vf_pseudocolor.c:202
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:94
PRESET_MAGMA
@ PRESET_MAGMA
Definition: vf_pseudocolor.c:74
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:413
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:863
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, float opacity)
Definition: vf_pseudocolor.c:294
height
#define height
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
curve_fun
double(* curve_fun)(double x)
Definition: vf_pseudocolor.c:91
Fill
Definition: vf_pseudocolor.c:99
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:167
VAR_W
@ VAR_W
Definition: vf_pseudocolor.c:48
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:445
attributes.h
PseudoColorContext
Definition: vf_pseudocolor.c:197
full_range
static const Range full_range
Definition: vf_pseudocolor.c:114
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:152
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
Fill::fill
float fill[4]
Definition: vf_pseudocolor.c:100
PRESET_PLASMA
@ PRESET_PLASMA
Definition: vf_pseudocolor.c:76
Curve::coef
double coef[3][8]
Definition: vf_pseudocolor.c:94
PRESET_CIVIDIS
@ PRESET_CIVIDIS
Definition: vf_pseudocolor.c:79
Curve::fun
curve_fun fun[3]
Definition: vf_pseudocolor.c:96
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_pseudocolor.c:901
Preset::fills
const Fill * fills
Definition: vf_pseudocolor.c:111
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:423
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:783
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, float opacity)
Definition: vf_pseudocolor.c:493
ThreadData
Used for passing data between threads.
Definition: dsddec.c:68
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, float opacity)
Definition: vf_pseudocolor.c:318
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_pseudocolor.c:253
inputs
static const AVFilterPad inputs[]
Definition: vf_pseudocolor.c:885
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:405
limit
static double limit(double x)
Definition: vf_pseudocolor.c:128
AVFilter
Filter definition.
Definition: avfilter.h:171
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_pseudocolor.c:576
ret
ret
Definition: filter_design.txt:187
PseudoColorContext::var_values
double var_values[VAR_VARS_NB]
Definition: vf_pseudocolor.c:207
PRESET_TURBO
@ PRESET_TURBO
Definition: vf_pseudocolor.c:78
Preset
Definition: vf_pseudocolor.c:107
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:442
PRESET_SOLAR
@ PRESET_SOLAR
Definition: vf_pseudocolor.c:84
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:410
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:415
VAR_YMIN
@ VAR_YMIN
Definition: vf_pseudocolor.c:51
spec1_fills
static const Fill spec1_fills[]
Definition: vf_pseudocolor.c:123
Range::end
AVRational end
Definition: vf_pseudocolor.c:104
VAR_VAL
@ VAR_VAL
Definition: vf_pseudocolor.c:50
ff_vf_pseudocolor
const AVFilter ff_vf_pseudocolor
Definition: vf_pseudocolor.c:914
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
NB_CURVES
@ NB_CURVES
Definition: vf_pseudocolor.c:70
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
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
Range::start
AVRational start
Definition: vf_pseudocolor.c:104
AVFilterContext
An instance of a filter.
Definition: avfilter.h:408
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(pseudocolor)
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
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:127
desc
const char * desc
Definition: libsvtav1.c:83
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
INFERNO
@ INFERNO
Definition: vf_pseudocolor.c:64
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
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, float opacity)
Definition: vf_pseudocolor.c:212
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
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, float opacity)
Definition: vf_pseudocolor.c:341
PRESET_INFERNO
@ PRESET_INFERNO
Definition: vf_pseudocolor.c:75
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
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:370
rgb
static const SheerTable rgb[2]
Definition: sheervideodata.h:32
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
Curves
Curves
Definition: vf_pseudocolor.c:62
PseudoColorContext::opacity
float opacity
Definition: vf_pseudocolor.c:200
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_pseudocolor.c:851
PseudoColorContext::lut
float lut[4][256 *256]
Definition: vf_pseudocolor.c:210
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:416
preferred_range
static const Range preferred_range[]
Definition: vf_pseudocolor.c:116
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:388
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:142
highlights_range
static const Range highlights_range[]
Definition: vf_pseudocolor.c:121
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
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:166
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:414
av_clipd
av_clipd
Definition: af_crystalizer.c:132
PseudoColorContext::preset
int preset
Definition: vf_pseudocolor.c:199
PseudoColorContext::max
int max
Definition: vf_pseudocolor.c:201
PRESET_PREFERRED
@ PRESET_PREFERRED
Definition: vf_pseudocolor.c:86