FFmpeg
vf_curves.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Clément Bœsch
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/opt.h"
22 #include "libavutil/bprint.h"
23 #include "libavutil/eval.h"
24 #include "libavutil/file.h"
25 #include "libavutil/intreadwrite.h"
26 #include "libavutil/avassert.h"
27 #include "libavutil/pixdesc.h"
28 #include "avfilter.h"
29 #include "drawutils.h"
30 #include "formats.h"
31 #include "internal.h"
32 #include "video.h"
33 
34 #define R 0
35 #define G 1
36 #define B 2
37 #define A 3
38 
39 struct keypoint {
40  double x, y;
41  struct keypoint *next;
42 };
43 
44 #define NB_COMP 3
45 
46 enum preset {
59 };
60 
61 typedef struct CurvesContext {
62  const AVClass *class;
63  int preset;
66  uint16_t *graph[NB_COMP + 1];
67  int lut_size;
68  char *psfile;
69  uint8_t rgba_map[4];
70  int step;
73  int is_16bit;
74  int depth;
76 
77  int (*filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
79 
80 typedef struct ThreadData {
81  AVFrame *in, *out;
82 } ThreadData;
83 
84 #define OFFSET(x) offsetof(CurvesContext, x)
85 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
86 static const AVOption curves_options[] = {
87  { "preset", "select a color curves preset", OFFSET(preset), AV_OPT_TYPE_INT, {.i64=PRESET_NONE}, PRESET_NONE, NB_PRESETS-1, FLAGS, "preset_name" },
88  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NONE}, 0, 0, FLAGS, "preset_name" },
89  { "color_negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_COLOR_NEGATIVE}, 0, 0, FLAGS, "preset_name" },
90  { "cross_process", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_CROSS_PROCESS}, 0, 0, FLAGS, "preset_name" },
91  { "darker", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_DARKER}, 0, 0, FLAGS, "preset_name" },
92  { "increase_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_INCREASE_CONTRAST}, 0, 0, FLAGS, "preset_name" },
93  { "lighter", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LIGHTER}, 0, 0, FLAGS, "preset_name" },
94  { "linear_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LINEAR_CONTRAST}, 0, 0, FLAGS, "preset_name" },
95  { "medium_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_MEDIUM_CONTRAST}, 0, 0, FLAGS, "preset_name" },
96  { "negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NEGATIVE}, 0, 0, FLAGS, "preset_name" },
97  { "strong_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_STRONG_CONTRAST}, 0, 0, FLAGS, "preset_name" },
98  { "vintage", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_VINTAGE}, 0, 0, FLAGS, "preset_name" },
99  { "master","set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
100  { "m", "set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
101  { "red", "set red points coordinates", OFFSET(comp_points_str[0]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
102  { "r", "set red points coordinates", OFFSET(comp_points_str[0]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
103  { "green", "set green points coordinates", OFFSET(comp_points_str[1]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
104  { "g", "set green points coordinates", OFFSET(comp_points_str[1]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
105  { "blue", "set blue points coordinates", OFFSET(comp_points_str[2]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
106  { "b", "set blue points coordinates", OFFSET(comp_points_str[2]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
107  { "all", "set points coordinates for all components", OFFSET(comp_points_str_all), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
108  { "psfile", "set Photoshop curves file name", OFFSET(psfile), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
109  { "plot", "save Gnuplot script of the curves in specified file", OFFSET(plot_filename), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
110  { NULL }
111 };
112 
114 
115 static const struct {
116  const char *r;
117  const char *g;
118  const char *b;
119  const char *master;
120 } curves_presets[] = {
122  "0.129/1 0.466/0.498 0.725/0",
123  "0.109/1 0.301/0.498 0.517/0",
124  "0.098/1 0.235/0.498 0.423/0",
125  },
127  "0/0 0.25/0.156 0.501/0.501 0.686/0.745 1/1",
128  "0/0 0.25/0.188 0.38/0.501 0.745/0.815 1/0.815",
129  "0/0 0.231/0.094 0.709/0.874 1/1",
130  },
131  [PRESET_DARKER] = { .master = "0/0 0.5/0.4 1/1" },
132  [PRESET_INCREASE_CONTRAST] = { .master = "0/0 0.149/0.066 0.831/0.905 0.905/0.98 1/1" },
133  [PRESET_LIGHTER] = { .master = "0/0 0.4/0.5 1/1" },
134  [PRESET_LINEAR_CONTRAST] = { .master = "0/0 0.305/0.286 0.694/0.713 1/1" },
135  [PRESET_MEDIUM_CONTRAST] = { .master = "0/0 0.286/0.219 0.639/0.643 1/1" },
136  [PRESET_NEGATIVE] = { .master = "0/1 1/0" },
137  [PRESET_STRONG_CONTRAST] = { .master = "0/0 0.301/0.196 0.592/0.6 0.686/0.737 1/1" },
138  [PRESET_VINTAGE] = {
139  "0/0.11 0.42/0.51 1/0.95",
140  "0/0 0.50/0.48 1/1",
141  "0/0.22 0.49/0.44 1/0.8",
142  }
143 };
144 
145 static struct keypoint *make_point(double x, double y, struct keypoint *next)
146 {
147  struct keypoint *point = av_mallocz(sizeof(*point));
148 
149  if (!point)
150  return NULL;
151  point->x = x;
152  point->y = y;
153  point->next = next;
154  return point;
155 }
156 
157 static int parse_points_str(AVFilterContext *ctx, struct keypoint **points, const char *s,
158  int lut_size)
159 {
160  char *p = (char *)s; // strtod won't alter the string
161  struct keypoint *last = NULL;
162  const int scale = lut_size - 1;
163 
164  /* construct a linked list based on the key points string */
165  while (p && *p) {
166  struct keypoint *point = make_point(0, 0, NULL);
167  if (!point)
168  return AVERROR(ENOMEM);
169  point->x = av_strtod(p, &p); if (p && *p) p++;
170  point->y = av_strtod(p, &p); if (p && *p) p++;
171  if (point->x < 0 || point->x > 1 || point->y < 0 || point->y > 1) {
172  av_log(ctx, AV_LOG_ERROR, "Invalid key point coordinates (%f;%f), "
173  "x and y must be in the [0;1] range.\n", point->x, point->y);
174  return AVERROR(EINVAL);
175  }
176  if (!*points)
177  *points = point;
178  if (last) {
179  if ((int)(last->x * scale) >= (int)(point->x * scale)) {
180  av_log(ctx, AV_LOG_ERROR, "Key point coordinates (%f;%f) "
181  "and (%f;%f) are too close from each other or not "
182  "strictly increasing on the x-axis\n",
183  last->x, last->y, point->x, point->y);
184  return AVERROR(EINVAL);
185  }
186  last->next = point;
187  }
188  last = point;
189  }
190 
191  if (*points && !(*points)->next) {
192  av_log(ctx, AV_LOG_WARNING, "Only one point (at (%f;%f)) is defined, "
193  "this is unlikely to behave as you expect. You probably want"
194  "at least 2 points.",
195  (*points)->x, (*points)->y);
196  }
197 
198  return 0;
199 }
200 
201 static int get_nb_points(const struct keypoint *d)
202 {
203  int n = 0;
204  while (d) {
205  n++;
206  d = d->next;
207  }
208  return n;
209 }
210 
211 /**
212  * Natural cubic spline interpolation
213  * Finding curves using Cubic Splines notes by Steven Rauch and John Stockie.
214  * @see http://people.math.sfu.ca/~stockie/teaching/macm316/notes/splines.pdf
215  */
216 
217 #define CLIP(v) (nbits == 8 ? av_clip_uint8(v) : av_clip_uintp2_c(v, nbits))
218 
219 static inline int interpolate(void *log_ctx, uint16_t *y,
220  const struct keypoint *points, int nbits)
221 {
222  int i, ret = 0;
223  const struct keypoint *point = points;
224  double xprev = 0;
225  const int lut_size = 1<<nbits;
226  const int scale = lut_size - 1;
227 
228  double (*matrix)[3];
229  double *h, *r;
230  const int n = get_nb_points(points); // number of splines
231 
232  if (n == 0) {
233  for (i = 0; i < lut_size; i++)
234  y[i] = i;
235  return 0;
236  }
237 
238  if (n == 1) {
239  for (i = 0; i < lut_size; i++)
240  y[i] = CLIP(point->y * scale);
241  return 0;
242  }
243 
244  matrix = av_calloc(n, sizeof(*matrix));
245  h = av_malloc((n - 1) * sizeof(*h));
246  r = av_calloc(n, sizeof(*r));
247 
248  if (!matrix || !h || !r) {
249  ret = AVERROR(ENOMEM);
250  goto end;
251  }
252 
253  /* h(i) = x(i+1) - x(i) */
254  i = -1;
255  for (point = points; point; point = point->next) {
256  if (i != -1)
257  h[i] = point->x - xprev;
258  xprev = point->x;
259  i++;
260  }
261 
262  /* right-side of the polynomials, will be modified to contains the solution */
263  point = points;
264  for (i = 1; i < n - 1; i++) {
265  const double yp = point->y;
266  const double yc = point->next->y;
267  const double yn = point->next->next->y;
268  r[i] = 6 * ((yn-yc)/h[i] - (yc-yp)/h[i-1]);
269  point = point->next;
270  }
271 
272 #define BD 0 /* sub diagonal (below main) */
273 #define MD 1 /* main diagonal (center) */
274 #define AD 2 /* sup diagonal (above main) */
275 
276  /* left side of the polynomials into a tridiagonal matrix. */
277  matrix[0][MD] = matrix[n - 1][MD] = 1;
278  for (i = 1; i < n - 1; i++) {
279  matrix[i][BD] = h[i-1];
280  matrix[i][MD] = 2 * (h[i-1] + h[i]);
281  matrix[i][AD] = h[i];
282  }
283 
284  /* tridiagonal solving of the linear system */
285  for (i = 1; i < n; i++) {
286  const double den = matrix[i][MD] - matrix[i][BD] * matrix[i-1][AD];
287  const double k = den ? 1./den : 1.;
288  matrix[i][AD] *= k;
289  r[i] = (r[i] - matrix[i][BD] * r[i - 1]) * k;
290  }
291  for (i = n - 2; i >= 0; i--)
292  r[i] = r[i] - matrix[i][AD] * r[i + 1];
293 
294  point = points;
295 
296  /* left padding */
297  for (i = 0; i < (int)(point->x * scale); i++)
298  y[i] = CLIP(point->y * scale);
299 
300  /* compute the graph with x=[x0..xN] */
301  i = 0;
302  av_assert0(point->next); // always at least 2 key points
303  while (point->next) {
304  const double yc = point->y;
305  const double yn = point->next->y;
306 
307  const double a = yc;
308  const double b = (yn-yc)/h[i] - h[i]*r[i]/2. - h[i]*(r[i+1]-r[i])/6.;
309  const double c = r[i] / 2.;
310  const double d = (r[i+1] - r[i]) / (6.*h[i]);
311 
312  int x;
313  const int x_start = point->x * scale;
314  const int x_end = point->next->x * scale;
315 
316  av_assert0(x_start >= 0 && x_start < lut_size &&
317  x_end >= 0 && x_end < lut_size);
318 
319  for (x = x_start; x <= x_end; x++) {
320  const double xx = (x - x_start) * 1./scale;
321  const double yy = a + b*xx + c*xx*xx + d*xx*xx*xx;
322  y[x] = CLIP(yy * scale);
323  av_log(log_ctx, AV_LOG_DEBUG, "f(%f)=%f -> y[%d]=%d\n", xx, yy, x, y[x]);
324  }
325 
326  point = point->next;
327  i++;
328  }
329 
330  /* right padding */
331  for (i = (int)(point->x * scale); i < lut_size; i++)
332  y[i] = CLIP(point->y * scale);
333 
334 end:
335  av_free(matrix);
336  av_free(h);
337  av_free(r);
338  return ret;
339 }
340 
341 #define DECLARE_INTERPOLATE_FUNC(nbits) \
342 static int interpolate##nbits(void *log_ctx, uint16_t *y, \
343  const struct keypoint *points) \
344 { \
345  return interpolate(log_ctx, y, points, nbits); \
346 }
347 
354 
355 static int parse_psfile(AVFilterContext *ctx, const char *fname)
356 {
357  CurvesContext *curves = ctx->priv;
358  uint8_t *buf;
359  size_t size;
360  int i, ret, av_unused(version), nb_curves;
361  AVBPrint ptstr;
362  static const int comp_ids[] = {3, 0, 1, 2};
363 
365 
366  ret = av_file_map(fname, &buf, &size, 0, NULL);
367  if (ret < 0)
368  return ret;
369 
370 #define READ16(dst) do { \
371  if (size < 2) { \
372  ret = AVERROR_INVALIDDATA; \
373  goto end; \
374  } \
375  dst = AV_RB16(buf); \
376  buf += 2; \
377  size -= 2; \
378 } while (0)
379 
380  READ16(version);
381  READ16(nb_curves);
382  for (i = 0; i < FFMIN(nb_curves, FF_ARRAY_ELEMS(comp_ids)); i++) {
383  int nb_points, n;
384  av_bprint_clear(&ptstr);
385  READ16(nb_points);
386  for (n = 0; n < nb_points; n++) {
387  int y, x;
388  READ16(y);
389  READ16(x);
390  av_bprintf(&ptstr, "%f/%f ", x / 255., y / 255.);
391  }
392  if (*ptstr.str) {
393  char **pts = &curves->comp_points_str[comp_ids[i]];
394  if (!*pts) {
395  *pts = av_strdup(ptstr.str);
396  av_log(ctx, AV_LOG_DEBUG, "curves %d (intid=%d) [%d points]: [%s]\n",
397  i, comp_ids[i], nb_points, *pts);
398  if (!*pts) {
399  ret = AVERROR(ENOMEM);
400  goto end;
401  }
402  }
403  }
404  }
405 end:
406  av_bprint_finalize(&ptstr, NULL);
407  av_file_unmap(buf, size);
408  return ret;
409 }
410 
411 static int dump_curves(const char *fname, uint16_t *graph[NB_COMP + 1],
412  struct keypoint *comp_points[NB_COMP + 1],
413  int lut_size)
414 {
415  int i;
416  AVBPrint buf;
417  const double scale = 1. / (lut_size - 1);
418  static const char * const colors[] = { "red", "green", "blue", "#404040", };
419  FILE *f = av_fopen_utf8(fname, "w");
420 
421  av_assert0(FF_ARRAY_ELEMS(colors) == NB_COMP + 1);
422 
423  if (!f) {
424  int ret = AVERROR(errno);
425  av_log(NULL, AV_LOG_ERROR, "Cannot open file '%s' for writing: %s\n",
426  fname, av_err2str(ret));
427  return ret;
428  }
429 
431 
432  av_bprintf(&buf, "set xtics 0.1\n");
433  av_bprintf(&buf, "set ytics 0.1\n");
434  av_bprintf(&buf, "set size square\n");
435  av_bprintf(&buf, "set grid\n");
436 
437  for (i = 0; i < FF_ARRAY_ELEMS(colors); i++) {
438  av_bprintf(&buf, "%s'-' using 1:2 with lines lc '%s' title ''",
439  i ? ", " : "plot ", colors[i]);
440  if (comp_points[i])
441  av_bprintf(&buf, ", '-' using 1:2 with points pointtype 3 lc '%s' title ''",
442  colors[i]);
443  }
444  av_bprintf(&buf, "\n");
445 
446  for (i = 0; i < FF_ARRAY_ELEMS(colors); i++) {
447  int x;
448 
449  /* plot generated values */
450  for (x = 0; x < lut_size; x++)
451  av_bprintf(&buf, "%f %f\n", x * scale, graph[i][x] * scale);
452  av_bprintf(&buf, "e\n");
453 
454  /* plot user knots */
455  if (comp_points[i]) {
456  const struct keypoint *point = comp_points[i];
457 
458  while (point) {
459  av_bprintf(&buf, "%f %f\n", point->x, point->y);
460  point = point->next;
461  }
462  av_bprintf(&buf, "e\n");
463  }
464  }
465 
466  fwrite(buf.str, 1, buf.len, f);
467  fclose(f);
468  av_bprint_finalize(&buf, NULL);
469  return 0;
470 }
471 
473 {
474  int i, ret;
475  CurvesContext *curves = ctx->priv;
476  char **pts = curves->comp_points_str;
477  const char *allp = curves->comp_points_str_all;
478 
479  //if (!allp && curves->preset != PRESET_NONE && curves_presets[curves->preset].all)
480  // allp = curves_presets[curves->preset].all;
481 
482  if (allp) {
483  for (i = 0; i < NB_COMP; i++) {
484  if (!pts[i])
485  pts[i] = av_strdup(allp);
486  if (!pts[i])
487  return AVERROR(ENOMEM);
488  }
489  }
490 
491  if (curves->psfile && !curves->parsed_psfile) {
492  ret = parse_psfile(ctx, curves->psfile);
493  if (ret < 0)
494  return ret;
495  curves->parsed_psfile = 1;
496  }
497 
498  if (curves->preset != PRESET_NONE) {
499 #define SET_COMP_IF_NOT_SET(n, name) do { \
500  if (!pts[n] && curves_presets[curves->preset].name) { \
501  pts[n] = av_strdup(curves_presets[curves->preset].name); \
502  if (!pts[n]) \
503  return AVERROR(ENOMEM); \
504  } \
505 } while (0)
510  curves->preset = PRESET_NONE;
511  }
512 
513  return 0;
514 }
515 
516 static int filter_slice_packed(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
517 {
518  int x, y;
519  const CurvesContext *curves = ctx->priv;
520  const ThreadData *td = arg;
521  const AVFrame *in = td->in;
522  const AVFrame *out = td->out;
523  const int direct = out == in;
524  const int step = curves->step;
525  const uint8_t r = curves->rgba_map[R];
526  const uint8_t g = curves->rgba_map[G];
527  const uint8_t b = curves->rgba_map[B];
528  const uint8_t a = curves->rgba_map[A];
529  const int slice_start = (in->height * jobnr ) / nb_jobs;
530  const int slice_end = (in->height * (jobnr+1)) / nb_jobs;
531 
532  if (curves->is_16bit) {
533  for (y = slice_start; y < slice_end; y++) {
534  uint16_t *dstp = ( uint16_t *)(out->data[0] + y * out->linesize[0]);
535  const uint16_t *srcp = (const uint16_t *)(in ->data[0] + y * in->linesize[0]);
536 
537  for (x = 0; x < in->width * step; x += step) {
538  dstp[x + r] = curves->graph[R][srcp[x + r]];
539  dstp[x + g] = curves->graph[G][srcp[x + g]];
540  dstp[x + b] = curves->graph[B][srcp[x + b]];
541  if (!direct && step == 4)
542  dstp[x + a] = srcp[x + a];
543  }
544  }
545  } else {
546  uint8_t *dst = out->data[0] + slice_start * out->linesize[0];
547  const uint8_t *src = in->data[0] + slice_start * in->linesize[0];
548 
549  for (y = slice_start; y < slice_end; y++) {
550  for (x = 0; x < in->width * step; x += step) {
551  dst[x + r] = curves->graph[R][src[x + r]];
552  dst[x + g] = curves->graph[G][src[x + g]];
553  dst[x + b] = curves->graph[B][src[x + b]];
554  if (!direct && step == 4)
555  dst[x + a] = src[x + a];
556  }
557  dst += out->linesize[0];
558  src += in ->linesize[0];
559  }
560  }
561  return 0;
562 }
563 
564 static int filter_slice_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
565 {
566  int x, y;
567  const CurvesContext *curves = ctx->priv;
568  const ThreadData *td = arg;
569  const AVFrame *in = td->in;
570  const AVFrame *out = td->out;
571  const int direct = out == in;
572  const int step = curves->step;
573  const uint8_t r = curves->rgba_map[R];
574  const uint8_t g = curves->rgba_map[G];
575  const uint8_t b = curves->rgba_map[B];
576  const uint8_t a = curves->rgba_map[A];
577  const int slice_start = (in->height * jobnr ) / nb_jobs;
578  const int slice_end = (in->height * (jobnr+1)) / nb_jobs;
579 
580  if (curves->is_16bit) {
581  for (y = slice_start; y < slice_end; y++) {
582  uint16_t *dstrp = ( uint16_t *)(out->data[r] + y * out->linesize[r]);
583  uint16_t *dstgp = ( uint16_t *)(out->data[g] + y * out->linesize[g]);
584  uint16_t *dstbp = ( uint16_t *)(out->data[b] + y * out->linesize[b]);
585  uint16_t *dstap = ( uint16_t *)(out->data[a] + y * out->linesize[a]);
586  const uint16_t *srcrp = (const uint16_t *)(in ->data[r] + y * in->linesize[r]);
587  const uint16_t *srcgp = (const uint16_t *)(in ->data[g] + y * in->linesize[g]);
588  const uint16_t *srcbp = (const uint16_t *)(in ->data[b] + y * in->linesize[b]);
589  const uint16_t *srcap = (const uint16_t *)(in ->data[a] + y * in->linesize[a]);
590 
591  for (x = 0; x < in->width; x++) {
592  dstrp[x] = curves->graph[R][srcrp[x]];
593  dstgp[x] = curves->graph[G][srcgp[x]];
594  dstbp[x] = curves->graph[B][srcbp[x]];
595  if (!direct && step == 4)
596  dstap[x] = srcap[x];
597  }
598  }
599  } else {
600  uint8_t *dstr = out->data[r] + slice_start * out->linesize[r];
601  uint8_t *dstg = out->data[g] + slice_start * out->linesize[g];
602  uint8_t *dstb = out->data[b] + slice_start * out->linesize[b];
603  uint8_t *dsta = out->data[a] + slice_start * out->linesize[a];
604  const uint8_t *srcr = in->data[r] + slice_start * in->linesize[r];
605  const uint8_t *srcg = in->data[g] + slice_start * in->linesize[g];
606  const uint8_t *srcb = in->data[b] + slice_start * in->linesize[b];
607  const uint8_t *srca = in->data[a] + slice_start * in->linesize[a];
608 
609  for (y = slice_start; y < slice_end; y++) {
610  for (x = 0; x < in->width; x++) {
611  dstr[x] = curves->graph[R][srcr[x]];
612  dstg[x] = curves->graph[G][srcg[x]];
613  dstb[x] = curves->graph[B][srcb[x]];
614  if (!direct && step == 4)
615  dsta[x] = srca[x];
616  }
617  dstr += out->linesize[r];
618  dstg += out->linesize[g];
619  dstb += out->linesize[b];
620  dsta += out->linesize[a];
621  srcr += in ->linesize[r];
622  srcg += in ->linesize[g];
623  srcb += in ->linesize[b];
624  srca += in ->linesize[a];
625  }
626  }
627  return 0;
628 }
629 
631 {
632  int i, j, ret;
633  AVFilterContext *ctx = inlink->dst;
634  CurvesContext *curves = ctx->priv;
636  char **pts = curves->comp_points_str;
637  struct keypoint *comp_points[NB_COMP + 1] = {0};
638 
639  ff_fill_rgba_map(curves->rgba_map, inlink->format);
640  curves->is_16bit = desc->comp[0].depth > 8;
641  curves->depth = desc->comp[0].depth;
642  curves->lut_size = 1 << curves->depth;
643  curves->step = av_get_padded_bits_per_pixel(desc) >> (3 + curves->is_16bit);
645 
646  for (i = 0; i < NB_COMP + 1; i++) {
647  if (!curves->graph[i])
648  curves->graph[i] = av_calloc(curves->lut_size, sizeof(*curves->graph[0]));
649  if (!curves->graph[i])
650  return AVERROR(ENOMEM);
651  ret = parse_points_str(ctx, comp_points + i, curves->comp_points_str[i], curves->lut_size);
652  if (ret < 0)
653  return ret;
654  switch (curves->depth) {
655  case 8: ret = interpolate8 (ctx, curves->graph[i], comp_points[i]); break;
656  case 9: ret = interpolate9 (ctx, curves->graph[i], comp_points[i]); break;
657  case 10: ret = interpolate10(ctx, curves->graph[i], comp_points[i]); break;
658  case 12: ret = interpolate12(ctx, curves->graph[i], comp_points[i]); break;
659  case 14: ret = interpolate14(ctx, curves->graph[i], comp_points[i]); break;
660  case 16: ret = interpolate16(ctx, curves->graph[i], comp_points[i]); break;
661  }
662  if (ret < 0)
663  return ret;
664  }
665 
666  if (pts[NB_COMP]) {
667  for (i = 0; i < NB_COMP; i++)
668  for (j = 0; j < curves->lut_size; j++)
669  curves->graph[i][j] = curves->graph[NB_COMP][curves->graph[i][j]];
670  }
671 
672  if (av_log_get_level() >= AV_LOG_VERBOSE) {
673  for (i = 0; i < NB_COMP; i++) {
674  const struct keypoint *point = comp_points[i];
675  av_log(ctx, AV_LOG_VERBOSE, "#%d points:", i);
676  while (point) {
677  av_log(ctx, AV_LOG_VERBOSE, " (%f;%f)", point->x, point->y);
678  point = point->next;
679  }
680  }
681  }
682 
683  if (curves->plot_filename && !curves->saved_plot) {
684  dump_curves(curves->plot_filename, curves->graph, comp_points, curves->lut_size);
685  curves->saved_plot = 1;
686  }
687 
688  for (i = 0; i < NB_COMP + 1; i++) {
689  struct keypoint *point = comp_points[i];
690  while (point) {
691  struct keypoint *next = point->next;
692  av_free(point);
693  point = next;
694  }
695  }
696 
697  return 0;
698 }
699 
701 {
702  AVFilterContext *ctx = inlink->dst;
703  CurvesContext *curves = ctx->priv;
704  AVFilterLink *outlink = ctx->outputs[0];
705  AVFrame *out;
706  ThreadData td;
707 
708  if (av_frame_is_writable(in)) {
709  out = in;
710  } else {
711  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
712  if (!out) {
713  av_frame_free(&in);
714  return AVERROR(ENOMEM);
715  }
717  }
718 
719  td.in = in;
720  td.out = out;
721  ff_filter_execute(ctx, curves->filter_slice, &td, NULL,
722  FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
723 
724  if (out != in)
725  av_frame_free(&in);
726 
727  return ff_filter_frame(outlink, out);
728 }
729 
730 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
731  char *res, int res_len, int flags)
732 {
733  CurvesContext *curves = ctx->priv;
734  int ret;
735 
736  if (!strcmp(cmd, "plot")) {
737  curves->saved_plot = 0;
738  } else if (!strcmp(cmd, "all") || !strcmp(cmd, "preset") || !strcmp(cmd, "psfile")) {
739  if (!strcmp(cmd, "psfile"))
740  curves->parsed_psfile = 0;
741  av_freep(&curves->comp_points_str_all);
742  av_freep(&curves->comp_points_str[0]);
743  av_freep(&curves->comp_points_str[1]);
744  av_freep(&curves->comp_points_str[2]);
745  av_freep(&curves->comp_points_str[NB_COMP]);
746  } else if (!strcmp(cmd, "red") || !strcmp(cmd, "r")) {
747  av_freep(&curves->comp_points_str[0]);
748  } else if (!strcmp(cmd, "green") || !strcmp(cmd, "g")) {
749  av_freep(&curves->comp_points_str[1]);
750  } else if (!strcmp(cmd, "blue") || !strcmp(cmd, "b")) {
751  av_freep(&curves->comp_points_str[2]);
752  } else if (!strcmp(cmd, "master") || !strcmp(cmd, "m")) {
753  av_freep(&curves->comp_points_str[NB_COMP]);
754  }
755 
756  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
757  if (ret < 0)
758  return ret;
759 
760  ret = curves_init(ctx);
761  if (ret < 0)
762  return ret;
763  return config_input(ctx->inputs[0]);
764 }
765 
767 {
768  int i;
769  CurvesContext *curves = ctx->priv;
770 
771  for (i = 0; i < NB_COMP + 1; i++)
772  av_freep(&curves->graph[i]);
773 }
774 
775 static const AVFilterPad curves_inputs[] = {
776  {
777  .name = "default",
778  .type = AVMEDIA_TYPE_VIDEO,
779  .filter_frame = filter_frame,
780  .config_props = config_input,
781  },
782 };
783 
784 static const AVFilterPad curves_outputs[] = {
785  {
786  .name = "default",
787  .type = AVMEDIA_TYPE_VIDEO,
788  },
789 };
790 
792  .name = "curves",
793  .description = NULL_IF_CONFIG_SMALL("Adjust components curves."),
794  .priv_size = sizeof(CurvesContext),
795  .init = curves_init,
812  .priv_class = &curves_class,
814  .process_command = process_command,
815 };
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:98
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:413
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
direct
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
Definition: af_afir.c:61
CurvesContext::graph
uint16_t * graph[NB_COMP+1]
Definition: vf_curves.c:66
td
#define td
Definition: regdef.h:70
PRESET_CROSS_PROCESS
@ PRESET_CROSS_PROCESS
Definition: vf_curves.c:49
READ16
#define READ16(dst)
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
PRESET_LIGHTER
@ PRESET_LIGHTER
Definition: vf_curves.c:52
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
CurvesContext::psfile
char * psfile
Definition: vf_curves.c:68
dump_curves
static int dump_curves(const char *fname, uint16_t *graph[NB_COMP+1], struct keypoint *comp_points[NB_COMP+1], int lut_size)
Definition: vf_curves.c:411
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:234
out
FILE * out
Definition: movenc.c:54
curves
static const Curve curves[]
Definition: vf_pseudocolor.c:138
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:68
keypoint::next
struct keypoint * next
Definition: vf_curves.c:41
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2564
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
FLAGS
#define FLAGS
Definition: vf_curves.c:85
CurvesContext::saved_plot
int saved_plot
Definition: vf_curves.c:72
PRESET_MEDIUM_CONTRAST
@ PRESET_MEDIUM_CONTRAST
Definition: vf_curves.c:54
av_unused
#define av_unused
Definition: attributes.h:131
graph
fg outputs[0] graph
Definition: ffmpeg_filter.c:174
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:112
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
pixdesc.h
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
AVFrame::width
int width
Definition: frame.h:361
DECLARE_INTERPOLATE_FUNC
#define DECLARE_INTERPOLATE_FUNC(nbits)
Definition: vf_curves.c:341
AVOption
AVOption.
Definition: opt.h:247
data
const char data[16]
Definition: mxf.c:143
CurvesContext
Definition: vf_curves.c:61
curves_inputs
static const AVFilterPad curves_inputs[]
Definition: vf_curves.c:775
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
BD
#define BD
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:473
get_nb_points
static int get_nb_points(const struct keypoint *d)
Definition: vf_curves.c:201
CurvesContext::rgba_map
uint8_t rgba_map[4]
Definition: vf_curves.c:69
video.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:317
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
CurvesContext::filter_slice
int(* filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_curves.c:77
formats.h
A
#define A
Definition: vf_curves.c:37
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:409
av_file_map
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
Definition: file.c:53
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:407
NB_PRESETS
@ NB_PRESETS
Definition: vf_curves.c:58
CurvesContext::preset
int preset
Definition: vf_curves.c:63
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1377
pts
static int64_t pts
Definition: transcode_aac.c:653
curves_presets
static const struct @217 curves_presets[]
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
preset
preset
Definition: vf_curves.c:46
avassert.h
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_fopen_utf8
FILE * av_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
Definition: file_open.c:158
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:411
keypoint::x
double x
Definition: vf_curves.c:40
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:412
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_curves.c:730
g
const char * g
Definition: vf_curves.c:117
curves_outputs
static const AVFilterPad curves_outputs[]
Definition: vf_curves.c:784
keypoint
Definition: vf_curves.c:39
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2041
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
CLIP
#define CLIP(v)
Natural cubic spline interpolation Finding curves using Cubic Splines notes by Steven Rauch and John ...
Definition: vf_curves.c:217
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(curves)
ctx
AVFormatContext * ctx
Definition: movenc.c:48
CurvesContext::lut_size
int lut_size
Definition: vf_curves.c:67
CurvesContext::is_16bit
int is_16bit
Definition: vf_curves.c:73
f
#define f(width, name)
Definition: cbs_vp9.c:255
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
av_file_unmap
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition: file.c:144
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
arg
const char * arg
Definition: jacosubdec.c:67
av_log_get_level
int av_log_get_level(void)
Get the current log level.
Definition: log.c:435
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:410
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:381
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
interpolate
static int interpolate(void *log_ctx, uint16_t *y, const struct keypoint *points, int nbits)
Definition: vf_curves.c:219
AV_PIX_FMT_BGR48
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:382
NULL
#define NULL
Definition: coverity.c:32
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:537
G
#define G
Definition: vf_curves.c:35
src
#define src
Definition: vp8dsp.c:255
CurvesContext::parsed_psfile
int parsed_psfile
Definition: vf_curves.c:75
AV_PIX_FMT_BGR0
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:230
CurvesContext::depth
int depth
Definition: vf_curves.c:74
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:406
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
MD
#define MD
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
b
const char * b
Definition: vf_curves.c:118
PRESET_DARKER
@ PRESET_DARKER
Definition: vf_curves.c:50
eval.h
AD
#define AD
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
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
master
const char * master
Definition: vf_curves.c:119
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:2529
FILTER_PIXFMTS
#define FILTER_PIXFMTS(...)
Definition: internal.h:177
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
ff_vf_curves
const AVFilter ff_vf_curves
Definition: vf_curves.c:791
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:377
size
int size
Definition: twinvq_data.h:10344
curves_uninit
static av_cold void curves_uninit(AVFilterContext *ctx)
Definition: vf_curves.c:766
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:473
filter_slice_planar
static int filter_slice_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_curves.c:564
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:882
curves_options
static const AVOption curves_options[]
Definition: vf_curves.c:86
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
AV_PIX_FMT_RGB0
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:228
version
version
Definition: libkvazaar.c:307
filter_slice_packed
static int filter_slice_packed(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_curves.c:516
CurvesContext::plot_filename
char * plot_filename
Definition: vf_curves.c:71
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:130
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
CurvesContext::comp_points_str
char * comp_points_str[NB_COMP+1]
Definition: vf_curves.c:64
PRESET_INCREASE_CONTRAST
@ PRESET_INCREASE_CONTRAST
Definition: vf_curves.c:51
AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:386
bprint.h
PRESET_NONE
@ PRESET_NONE
Definition: vf_curves.c:47
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
B
#define B
Definition: vf_curves.c:36
CurvesContext::step
int step
Definition: vf_curves.c:70
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:408
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:803
ThreadData
Used for passing data between threads.
Definition: dsddec.c:67
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:263
PRESET_VINTAGE
@ PRESET_VINTAGE
Definition: vf_curves.c:57
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
PRESET_COLOR_NEGATIVE
@ PRESET_COLOR_NEGATIVE
Definition: vf_curves.c:48
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
AVFilter
Filter definition.
Definition: avfilter.h:149
NB_COMP
#define NB_COMP
Definition: vf_curves.c:44
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:229
av_strtod
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition: eval.c:106
R
#define R
Definition: vf_curves.c:34
CurvesContext::comp_points_str_all
char * comp_points_str_all
Definition: vf_curves.c:65
PRESET_NEGATIVE
@ PRESET_NEGATIVE
Definition: vf_curves.c:55
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:93
AVFrame::height
int height
Definition: frame.h:361
av_bprint_clear
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:226
PRESET_LINEAR_CONTRAST
@ PRESET_LINEAR_CONTRAST
Definition: vf_curves.c:53
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
make_point
static struct keypoint * make_point(double x, double y, struct keypoint *next)
Definition: vf_curves.c:145
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
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_curves.c:630
file.h
AVFilterContext
An instance of a filter.
Definition: avfilter.h:386
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:121
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:279
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ThreadData::in
AVFrame * in
Definition: af_adecorrelate.c:154
SET_COMP_IF_NOT_SET
#define SET_COMP_IF_NOT_SET(n, name)
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
curves_init
static av_cold int curves_init(AVFilterContext *ctx)
Definition: vf_curves.c:472
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
keypoint::y
double y
Definition: vf_curves.c:40
parse_psfile
static int parse_psfile(AVFilterContext *ctx, const char *fname)
Definition: vf_curves.c:355
parse_points_str
static int parse_points_str(AVFilterContext *ctx, struct keypoint **points, const char *s, int lut_size)
Definition: vf_curves.c:157
ff_fill_rgba_map
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:33
d
d
Definition: ffmpeg_filter.c:156
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:334
AV_PIX_FMT_0RGB
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:227
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
h
h
Definition: vp9dsp_template.c:2038
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:228
drawutils.h
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:143
PRESET_STRONG_CONTRAST
@ PRESET_STRONG_CONTRAST
Definition: vf_curves.c:56
int
int
Definition: ffmpeg_filter.c:156
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
OFFSET
#define OFFSET(x)
Definition: vf_curves.c:84
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_curves.c:700