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