FFmpeg  2.1.1
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 {
62  const AVClass *class;
63  enum preset preset;
64  char *comp_points_str[NB_COMP + 1];
66  uint8_t graph[NB_COMP + 1][256];
67  char *psfile;
68  uint8_t rgba_map[4];
69  int step;
71 
72 #define OFFSET(x) offsetof(CurvesContext, x)
73 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
74 static const AVOption curves_options[] = {
75  { "preset", "select a color curves preset", OFFSET(preset), AV_OPT_TYPE_INT, {.i64=PRESET_NONE}, PRESET_NONE, NB_PRESETS-1, FLAGS, "preset_name" },
76  { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NONE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
77  { "color_negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_COLOR_NEGATIVE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
78  { "cross_process", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_CROSS_PROCESS}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
79  { "darker", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_DARKER}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
80  { "increase_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_INCREASE_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
81  { "lighter", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LIGHTER}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
82  { "linear_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LINEAR_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
83  { "medium_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_MEDIUM_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
84  { "negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NEGATIVE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
85  { "strong_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_STRONG_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
86  { "vintage", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_VINTAGE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
87  { "master","set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
88  { "m", "set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
89  { "red", "set red points coordinates", OFFSET(comp_points_str[0]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
90  { "r", "set red points coordinates", OFFSET(comp_points_str[0]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
91  { "green", "set green points coordinates", OFFSET(comp_points_str[1]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
92  { "g", "set green points coordinates", OFFSET(comp_points_str[1]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
93  { "blue", "set blue points coordinates", OFFSET(comp_points_str[2]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
94  { "b", "set blue points coordinates", OFFSET(comp_points_str[2]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
95  { "all", "set points coordinates for all components", OFFSET(comp_points_str_all), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
96  { "psfile", "set Photoshop curves file name", OFFSET(psfile), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
97  { NULL }
98 };
99 
100 AVFILTER_DEFINE_CLASS(curves);
101 
102 static const struct {
103  const char *r;
104  const char *g;
105  const char *b;
106  const char *master;
107 } curves_presets[] = {
109  "0/1 0.129/1 0.466/0.498 0.725/0 1/0",
110  "0/1 0.109/1 0.301/0.498 0.517/0 1/0",
111  "0/1 0.098/1 0.235/0.498 0.423/0 1/0",
112  },
114  "0.25/0.156 0.501/0.501 0.686/0.745",
115  "0.25/0.188 0.38/0.501 0.745/0.815 1/0.815",
116  "0.231/0.094 0.709/0.874",
117  },
118  [PRESET_DARKER] = { .master = "0.5/0.4" },
119  [PRESET_INCREASE_CONTRAST] = { .master = "0.149/0.066 0.831/0.905 0.905/0.98" },
120  [PRESET_LIGHTER] = { .master = "0.4/0.5" },
121  [PRESET_LINEAR_CONTRAST] = { .master = "0.305/0.286 0.694/0.713" },
122  [PRESET_MEDIUM_CONTRAST] = { .master = "0.286/0.219 0.639/0.643" },
123  [PRESET_NEGATIVE] = { .master = "0/1 1/0" },
124  [PRESET_STRONG_CONTRAST] = { .master = "0.301/0.196 0.592/0.6 0.686/0.737" },
125  [PRESET_VINTAGE] = {
126  "0/0.11 0.42/0.51 1/0.95",
127  "0.50/0.48",
128  "0/0.22 0.49/0.44 1/0.8",
129  }
130 };
131 
132 static struct keypoint *make_point(double x, double y, struct keypoint *next)
133 {
134  struct keypoint *point = av_mallocz(sizeof(*point));
135 
136  if (!point)
137  return NULL;
138  point->x = x;
139  point->y = y;
140  point->next = next;
141  return point;
142 }
143 
144 static int parse_points_str(AVFilterContext *ctx, struct keypoint **points, const char *s)
145 {
146  char *p = (char *)s; // strtod won't alter the string
147  struct keypoint *last = NULL;
148 
149  /* construct a linked list based on the key points string */
150  while (p && *p) {
151  struct keypoint *point = make_point(0, 0, NULL);
152  if (!point)
153  return AVERROR(ENOMEM);
154  point->x = av_strtod(p, &p); if (p && *p) p++;
155  point->y = av_strtod(p, &p); if (p && *p) p++;
156  if (point->x < 0 || point->x > 1 || point->y < 0 || point->y > 1) {
157  av_log(ctx, AV_LOG_ERROR, "Invalid key point coordinates (%f;%f), "
158  "x and y must be in the [0;1] range.\n", point->x, point->y);
159  return AVERROR(EINVAL);
160  }
161  if (!*points)
162  *points = point;
163  if (last) {
164  if ((int)(last->x * 255) >= (int)(point->x * 255)) {
165  av_log(ctx, AV_LOG_ERROR, "Key point coordinates (%f;%f) "
166  "and (%f;%f) are too close from each other or not "
167  "strictly increasing on the x-axis\n",
168  last->x, last->y, point->x, point->y);
169  return AVERROR(EINVAL);
170  }
171  last->next = point;
172  }
173  last = point;
174  }
175 
176  /* auto insert first key point if missing at x=0 */
177  if (!*points) {
178  last = make_point(0, 0, NULL);
179  if (!last)
180  return AVERROR(ENOMEM);
181  last->x = last->y = 0;
182  *points = last;
183  } else if ((*points)->x != 0.) {
184  struct keypoint *newfirst = make_point(0, 0, *points);
185  if (!newfirst)
186  return AVERROR(ENOMEM);
187  *points = newfirst;
188  }
189 
190  av_assert0(last);
191 
192  /* auto insert last key point if missing at x=1 */
193  if (last->x != 1.) {
194  struct keypoint *point = make_point(1, 1, NULL);
195  if (!point)
196  return AVERROR(ENOMEM);
197  last->next = point;
198  }
199 
200  return 0;
201 }
202 
203 static int get_nb_points(const struct keypoint *d)
204 {
205  int n = 0;
206  while (d) {
207  n++;
208  d = d->next;
209  }
210  return n;
211 }
212 
213 /**
214  * Natural cubic spline interpolation
215  * Finding curves using Cubic Splines notes by Steven Rauch and John Stockie.
216  * @see http://people.math.sfu.ca/~stockie/teaching/macm316/notes/splines.pdf
217  */
218 static int interpolate(AVFilterContext *ctx, uint8_t *y, const struct keypoint *points)
219 {
220  int i, ret = 0;
221  const struct keypoint *point;
222  double xprev = 0;
223 
224  int n = get_nb_points(points); // number of splines
225 
226  double (*matrix)[3] = av_calloc(n, sizeof(*matrix));
227  double *h = av_malloc((n - 1) * sizeof(*h));
228  double *r = av_calloc(n, sizeof(*r));
229 
230  if (!matrix || !h || !r) {
231  ret = AVERROR(ENOMEM);
232  goto end;
233  }
234 
235  /* h(i) = x(i+1) - x(i) */
236  i = -1;
237  for (point = points; point; point = point->next) {
238  if (i != -1)
239  h[i] = point->x - xprev;
240  xprev = point->x;
241  i++;
242  }
243 
244  /* right-side of the polynomials, will be modified to contains the solution */
245  point = points;
246  for (i = 1; i < n - 1; i++) {
247  double yp = point->y,
248  yc = point->next->y,
249  yn = point->next->next->y;
250  r[i] = 6 * ((yn-yc)/h[i] - (yc-yp)/h[i-1]);
251  point = point->next;
252  }
253 
254 #define BD 0 /* sub diagonal (below main) */
255 #define MD 1 /* main diagonal (center) */
256 #define AD 2 /* sup diagonal (above main) */
257 
258  /* left side of the polynomials into a tridiagonal matrix. */
259  matrix[0][MD] = matrix[n - 1][MD] = 1;
260  for (i = 1; i < n - 1; i++) {
261  matrix[i][BD] = h[i-1];
262  matrix[i][MD] = 2 * (h[i-1] + h[i]);
263  matrix[i][AD] = h[i];
264  }
265 
266  /* tridiagonal solving of the linear system */
267  for (i = 1; i < n; i++) {
268  double den = matrix[i][MD] - matrix[i][BD] * matrix[i-1][AD];
269  double k = den ? 1./den : 1.;
270  matrix[i][AD] *= k;
271  r[i] = (r[i] - matrix[i][BD] * r[i - 1]) * k;
272  }
273  for (i = n - 2; i >= 0; i--)
274  r[i] = r[i] - matrix[i][AD] * r[i + 1];
275 
276  /* compute the graph with x=[0..255] */
277  i = 0;
278  point = points;
279  av_assert0(point->next); // always at least 2 key points
280  while (point->next) {
281  double yc = point->y;
282  double yn = point->next->y;
283 
284  double a = yc;
285  double b = (yn-yc)/h[i] - h[i]*r[i]/2. - h[i]*(r[i+1]-r[i])/6.;
286  double c = r[i] / 2.;
287  double d = (r[i+1] - r[i]) / (6.*h[i]);
288 
289  int x;
290  int x_start = point->x * 255;
291  int x_end = point->next->x * 255;
292 
293  av_assert0(x_start >= 0 && x_start <= 255 &&
294  x_end >= 0 && x_end <= 255);
295 
296  for (x = x_start; x <= x_end; x++) {
297  double xx = (x - x_start) * 1/255.;
298  double yy = a + b*xx + c*xx*xx + d*xx*xx*xx;
299  y[x] = av_clipf(yy, 0, 1) * 255;
300  av_log(ctx, AV_LOG_DEBUG, "f(%f)=%f -> y[%d]=%d\n", xx, yy, x, y[x]);
301  }
302 
303  point = point->next;
304  i++;
305  }
306 
307 end:
308  av_free(matrix);
309  av_free(h);
310  av_free(r);
311  return ret;
312 }
313 
314 static int parse_psfile(AVFilterContext *ctx, const char *fname)
315 {
316  CurvesContext *curves = ctx->priv;
317  uint8_t *buf;
318  size_t size;
319  int i, ret, av_unused(version), nb_curves;
320  AVBPrint ptstr;
321  static const int comp_ids[] = {3, 0, 1, 2};
322 
324 
325  ret = av_file_map(fname, &buf, &size, 0, NULL);
326  if (ret < 0)
327  return ret;
328 
329 #define READ16(dst) do { \
330  if (size < 2) \
331  return AVERROR_INVALIDDATA; \
332  dst = AV_RB16(buf); \
333  buf += 2; \
334  size -= 2; \
335 } while (0)
336 
337  READ16(version);
338  READ16(nb_curves);
339  for (i = 0; i < FFMIN(nb_curves, FF_ARRAY_ELEMS(comp_ids)); i++) {
340  int nb_points, n;
341  av_bprint_clear(&ptstr);
342  READ16(nb_points);
343  for (n = 0; n < nb_points; n++) {
344  int y, x;
345  READ16(y);
346  READ16(x);
347  av_bprintf(&ptstr, "%f/%f ", x / 255., y / 255.);
348  }
349  if (*ptstr.str) {
350  char **pts = &curves->comp_points_str[comp_ids[i]];
351  if (!*pts) {
352  *pts = av_strdup(ptstr.str);
353  av_log(ctx, AV_LOG_DEBUG, "curves %d (intid=%d) [%d points]: [%s]\n",
354  i, comp_ids[i], nb_points, *pts);
355  if (!*pts) {
356  ret = AVERROR(ENOMEM);
357  goto end;
358  }
359  }
360  }
361  }
362 end:
363  av_bprint_finalize(&ptstr, NULL);
364  av_file_unmap(buf, size);
365  return ret;
366 }
367 
368 static av_cold int init(AVFilterContext *ctx)
369 {
370  int i, j, ret;
371  CurvesContext *curves = ctx->priv;
372  struct keypoint *comp_points[NB_COMP + 1] = {0};
373  char **pts = curves->comp_points_str;
374  const char *allp = curves->comp_points_str_all;
375 
376  //if (!allp && curves->preset != PRESET_NONE && curves_presets[curves->preset].all)
377  // allp = curves_presets[curves->preset].all;
378 
379  if (allp) {
380  for (i = 0; i < NB_COMP; i++) {
381  if (!pts[i])
382  pts[i] = av_strdup(allp);
383  if (!pts[i])
384  return AVERROR(ENOMEM);
385  }
386  }
387 
388  if (curves->psfile) {
389  ret = parse_psfile(ctx, curves->psfile);
390  if (ret < 0)
391  return ret;
392  }
393 
394  if (curves->preset != PRESET_NONE) {
395 #define SET_COMP_IF_NOT_SET(n, name) do { \
396  if (!pts[n] && curves_presets[curves->preset].name) { \
397  pts[n] = av_strdup(curves_presets[curves->preset].name); \
398  if (!pts[n]) \
399  return AVERROR(ENOMEM); \
400  } \
401 } while (0)
406  }
407 
408  for (i = 0; i < NB_COMP + 1; i++) {
409  ret = parse_points_str(ctx, comp_points + i, curves->comp_points_str[i]);
410  if (ret < 0)
411  return ret;
412  ret = interpolate(ctx, curves->graph[i], comp_points[i]);
413  if (ret < 0)
414  return ret;
415  }
416 
417  if (pts[NB_COMP]) {
418  for (i = 0; i < NB_COMP; i++)
419  for (j = 0; j < 256; j++)
420  curves->graph[i][j] = curves->graph[NB_COMP][curves->graph[i][j]];
421  }
422 
423  if (av_log_get_level() >= AV_LOG_VERBOSE) {
424  for (i = 0; i < NB_COMP; i++) {
425  struct keypoint *point = comp_points[i];
426  av_log(ctx, AV_LOG_VERBOSE, "#%d points:", i);
427  while (point) {
428  av_log(ctx, AV_LOG_VERBOSE, " (%f;%f)", point->x, point->y);
429  point = point->next;
430  }
431  av_log(ctx, AV_LOG_VERBOSE, "\n");
432  av_log(ctx, AV_LOG_VERBOSE, "#%d values:", i);
433  for (j = 0; j < 256; j++)
434  av_log(ctx, AV_LOG_VERBOSE, " %02X", curves->graph[i][j]);
435  av_log(ctx, AV_LOG_VERBOSE, "\n");
436  }
437  }
438 
439  for (i = 0; i < NB_COMP + 1; i++) {
440  struct keypoint *point = comp_points[i];
441  while (point) {
442  struct keypoint *next = point->next;
443  av_free(point);
444  point = next;
445  }
446  }
447 
448  return 0;
449 }
450 
452 {
453  static const enum AVPixelFormat pix_fmts[] = {
460  };
462  return 0;
463 }
464 
465 static int config_input(AVFilterLink *inlink)
466 {
467  CurvesContext *curves = inlink->dst->priv;
468  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
469 
470  ff_fill_rgba_map(curves->rgba_map, inlink->format);
471  curves->step = av_get_padded_bits_per_pixel(desc) >> 3;
472 
473  return 0;
474 }
475 
476 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
477 {
478  int x, y, direct = 0;
479  AVFilterContext *ctx = inlink->dst;
480  CurvesContext *curves = ctx->priv;
481  AVFilterLink *outlink = ctx->outputs[0];
482  AVFrame *out;
483  uint8_t *dst;
484  const uint8_t *src;
485  const int step = curves->step;
486  const uint8_t r = curves->rgba_map[R];
487  const uint8_t g = curves->rgba_map[G];
488  const uint8_t b = curves->rgba_map[B];
489  const uint8_t a = curves->rgba_map[A];
490 
491  if (av_frame_is_writable(in)) {
492  direct = 1;
493  out = in;
494  } else {
495  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
496  if (!out) {
497  av_frame_free(&in);
498  return AVERROR(ENOMEM);
499  }
500  av_frame_copy_props(out, in);
501  }
502 
503  dst = out->data[0];
504  src = in ->data[0];
505 
506  for (y = 0; y < inlink->h; y++) {
507  for (x = 0; x < inlink->w * step; x += step) {
508  dst[x + r] = curves->graph[R][src[x + r]];
509  dst[x + g] = curves->graph[G][src[x + g]];
510  dst[x + b] = curves->graph[B][src[x + b]];
511  if (!direct && step == 4)
512  dst[x + a] = src[x + a];
513  }
514  dst += out->linesize[0];
515  src += in ->linesize[0];
516  }
517 
518  if (!direct)
519  av_frame_free(&in);
520 
521  return ff_filter_frame(outlink, out);
522 }
523 
524 static const AVFilterPad curves_inputs[] = {
525  {
526  .name = "default",
527  .type = AVMEDIA_TYPE_VIDEO,
528  .filter_frame = filter_frame,
529  .config_props = config_input,
530  },
531  { NULL }
532 };
533 
534 static const AVFilterPad curves_outputs[] = {
535  {
536  .name = "default",
537  .type = AVMEDIA_TYPE_VIDEO,
538  },
539  { NULL }
540 };
541 
543  .name = "curves",
544  .description = NULL_IF_CONFIG_SMALL("Adjust components curves."),
545  .priv_size = sizeof(CurvesContext),
546  .init = init,
548  .inputs = curves_inputs,
549  .outputs = curves_outputs,
550  .priv_class = &curves_class,
552 };
#define MD
const char * s
Definition: avisynth_c.h:668
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
Definition: mem.c:249
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
AVOption.
Definition: opt.h:253
struct keypoint * next
Definition: vf_curves.c:41
const char * name
Filter name.
Definition: avfilter.h:468
#define B
Definition: dsputil.c:2028
void * priv
private data for use by the filter
Definition: avfilter.h:648
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:111
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
Definition: mem.c:256
const char * g
Definition: vf_curves.c:104
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: avcodec.h:4536
static int interpolate(AVFilterContext *ctx, uint8_t *y, const struct keypoint *points)
Natural cubic spline interpolation Finding curves using Cubic Splines notes by Steven Rauch and John ...
Definition: vf_curves.c:218
static struct keypoint * make_point(double x, double y, struct keypoint *next)
Definition: vf_curves.c:132
const char * b
Definition: vf_curves.c:105
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
#define AD
int version
Definition: avisynth_c.h:666
const char * master
Definition: vf_curves.c:106
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
Pixel format.
Definition: avcodec.h:4533
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:382
packed RGB 8:8:8, 32bpp, RGB0RGB0...
Definition: avcodec.h:4690
#define av_cold
Definition: avcodec.h:653
packed BGR 8:8:8, 32bpp, 0BGR0BGR...
Definition: avcodec.h:4691
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:294
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: avcodec.h:4562
char * psfile
Definition: vf_curves.c:67
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic &quot;enable&quot; expression option that can be used to enable or disable a fil...
Definition: avfilter.h:445
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: avcodec.h:4537
const char * name
Pad name.
Definition: internal.h:66
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1118
uint8_t
static const AVOption curves_options[]
Definition: vf_curves.c:74
#define NB_COMP
Definition: vf_curves.c:44
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only &quot;metadata&quot; fields from src to dst.
Definition: frame.c:446
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_curves.c:476
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: avcodec.h:4564
#define R
Definition: dsputil.c:2030
#define AV_LOG_VERBOSE
Detailed information.
Definition: avcodec.h:4163
void 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:531
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition: eval.c:90
#define A(x)
Definition: vp56_arith.h:28
char * comp_points_str_all
Definition: vf_curves.c:65
A filter pad used for either input or output.
Definition: internal.h:60
#define FLAGS
Definition: vf_curves.c:73
#define SET_COMP_IF_NOT_SET(n, name)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:219
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;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);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
AVFilter avfilter_vf_curves
Definition: vf_curves.c:542
packed BGR 8:8:8, 32bpp, BGR0BGR0...
Definition: avcodec.h:4692
#define READ16(dst)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
const char * r
Definition: vf_curves.c:103
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: avcodec.h:4168
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
int av_log_get_level(void)
Get the current log level.
Definition: log.c:288
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:123
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
#define av_unused
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
Definition: avcodec.h:697
static int config_input(AVFilterLink *inlink)
Definition: vf_curves.c:465
double x
Definition: vf_curves.c:40
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Init a print buffer.
Definition: bprint.c:69
#define FF_ARRAY_ELEMS(a)
Definition: avcodec.h:929
Buffer to print data progressively.
Definition: bprint.h:77
char * comp_points_str[NB_COMP+1]
Definition: vf_curves.c:64
float y
ret
Definition: avfilter.c:961
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
#define FFMIN(a, b)
Definition: avcodec.h:925
#define AV_BPRINT_SIZE_AUTOMATIC
Definition: bprint.h:92
int n
Definition: avisynth_c.h:588
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:33
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1938
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:642
enum preset preset
Definition: vf_curves.c:63
AVS_Value src
Definition: avisynth_c.h:523
static int parse_psfile(AVFilterContext *ctx, const char *fname)
Definition: vf_curves.c:314
misc drawing utilities
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:57
#define BD
double y
Definition: vf_curves.c:40
static int parse_points_str(AVFilterContext *ctx, struct keypoint **points, const char *s)
Definition: vf_curves.c:144
void * buf
Definition: avisynth_c.h:594
static av_cold int init(AVFilterContext *ctx)
Definition: vf_curves.c:368
static int get_nb_points(const struct keypoint *d)
Definition: vf_curves.c:203
#define OFFSET(x)
Definition: vf_curves.c:72
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:464
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:102
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
static const AVFilterPad curves_inputs[]
Definition: vf_curves.c:524
void av_bprint_clear(AVBPrint *buf)
Reset the string to &quot;&quot; but keep internal allocated data.
Definition: bprint.c:227
static int flags
Definition: cpu.c:45
static struct @124 curves_presets[]
preset
Definition: vf_curves.c:46
static double c[64]
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: avcodec.h:4565
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition: file.c:129
uint8_t graph[NB_COMP+1][256]
Definition: vf_curves.c:66
void av_bprintf(AVBPrint *buf, const char *fmt,...) av_printf_format(2
Append a formatted string to a print buffer.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;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);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:301
uint8_t rgba_map[4]
Definition: vf_curves.c:68
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: avcodec.h:4563
#define AVERROR(e)
#define G
Definition: dsputil.c:2029
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:1904
An instance of a filter.
Definition: avfilter.h:627
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:49
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static int query_formats(AVFilterContext *ctx)
Definition: vf_curves.c:451
internal API functions
packed RGB 8:8:8, 32bpp, 0RGB0RGB...
Definition: avcodec.h:4689
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:241
static const AVFilterPad curves_outputs[]
Definition: vf_curves.c:534