FFmpeg  4.4.8
vf_geq.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
3  * Copyright (C) 2012 Clément Bœsch <u pkh me>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Generic equation change filter
25  * Originally written by Michael Niedermayer for the MPlayer project, and
26  * ported by Clément Bœsch for FFmpeg.
27  */
28 
29 #include "libavutil/avassert.h"
30 #include "libavutil/avstring.h"
31 #include "libavutil/eval.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/pixdesc.h"
34 #include "internal.h"
35 #include "filters.h"
36 
37 #define MAX_NB_THREADS 32
38 #define NB_PLANES 4
39 
43  NB_INTERP
44 };
45 
46 static const char *const var_names[] = { "X", "Y", "W", "H", "N", "SW", "SH", "T", NULL };
48 
49 typedef struct GEQContext {
50  const AVClass *class;
51  AVExpr *e[NB_PLANES][MAX_NB_THREADS]; ///< expressions for each plane and thread
52  char *expr_str[4+3]; ///< expression strings for each plane
53  AVFrame *picref; ///< current input buffer
54  uint8_t *dst; ///< reference pointer to the 8bits output
55  uint16_t *dst16; ///< reference pointer to the 16bits output
56  double values[VAR_VARS_NB]; ///< expression values
57  int hsub, vsub; ///< chroma subsampling
58  int planes; ///< number of planes
60  int is_rgb;
61  int bps;
62 
65 } GEQContext;
66 
67 enum { Y = 0, U, V, A, G, B, R };
68 
69 #define OFFSET(x) offsetof(GEQContext, x)
70 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
71 
72 static const AVOption geq_options[] = {
73  { "lum_expr", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
74  { "lum", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
75  { "cb_expr", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
76  { "cb", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
77  { "cr_expr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
78  { "cr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
79  { "alpha_expr", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
80  { "a", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
81  { "red_expr", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
82  { "r", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
83  { "green_expr", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
84  { "g", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
85  { "blue_expr", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
86  { "b", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
87  { "interpolation","set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, "interp" },
88  { "i", "set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, "interp" },
89  { "nearest", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, "interp" },
90  { "n", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, "interp" },
91  { "bilinear", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, "interp" },
92  { "b", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, "interp" },
93  {NULL},
94 };
95 
97 
98 static inline double getpix(void *priv, double x, double y, int plane)
99 {
100  int xi, yi;
101  GEQContext *geq = priv;
102  AVFrame *picref = geq->picref;
103  const uint8_t *src = picref->data[plane];
104  int linesize = picref->linesize[plane];
105  const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width;
106  const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height;
107 
108  if (!src)
109  return 0;
110 
111  if (geq->interpolation == INTERP_BILINEAR) {
112  xi = x = av_clipd(x, 0, w - 2);
113  yi = y = av_clipd(y, 0, h - 2);
114 
115  x -= xi;
116  y -= yi;
117 
118  if (geq->bps > 8) {
119  const uint16_t *src16 = (const uint16_t*)src;
120  linesize /= 2;
121 
122  return (1-y)*((1-x)*src16[xi + yi * linesize] + x*src16[xi + 1 + yi * linesize])
123  + y *((1-x)*src16[xi + (yi+1) * linesize] + x*src16[xi + 1 + (yi+1) * linesize]);
124  } else {
125  return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xi + 1 + yi * linesize])
126  + y *((1-x)*src[xi + (yi+1) * linesize] + x*src[xi + 1 + (yi+1) * linesize]);
127  }
128  } else {
129  xi = av_clipd(x, 0, w - 1);
130  yi = av_clipd(y, 0, h - 1);
131 
132  if (geq->bps > 8) {
133  const uint16_t *src16 = (const uint16_t*)src;
134  linesize /= 2;
135 
136  return src16[xi + yi * linesize];
137  } else {
138  return src[xi + yi * linesize];
139  }
140  }
141 }
142 
143 static int calculate_sums(GEQContext *geq, int plane, int w, int h)
144 {
145  int xi, yi;
146  AVFrame *picref = geq->picref;
147  const uint8_t *src = picref->data[plane];
148  int linesize = picref->linesize[plane];
149 
150  if (!geq->pixel_sums[plane])
151  geq->pixel_sums[plane] = av_malloc_array(w, h * sizeof (*geq->pixel_sums[plane]));
152  if (!geq->pixel_sums[plane])
153  return AVERROR(ENOMEM);
154  if (geq->bps > 8)
155  linesize /= 2;
156  for (yi = 0; yi < h; yi ++) {
157  if (geq->bps > 8) {
158  const uint16_t *src16 = (const uint16_t*)src;
159  double linesum = 0;
160 
161  for (xi = 0; xi < w; xi ++) {
162  linesum += src16[xi + yi * linesize];
163  geq->pixel_sums[plane][xi + yi * w] = linesum;
164  }
165  } else {
166  double linesum = 0;
167 
168  for (xi = 0; xi < w; xi ++) {
169  linesum += src[xi + yi * linesize];
170  geq->pixel_sums[plane][xi + yi * w] = linesum;
171  }
172  }
173  if (yi)
174  for (xi = 0; xi < w; xi ++) {
175  geq->pixel_sums[plane][xi + yi * w] += geq->pixel_sums[plane][xi + yi * w - w];
176  }
177  }
178  return 0;
179 }
180 
181 static inline double getpix_integrate_internal(GEQContext *geq, int x, int y, int plane, int w, int h)
182 {
183  if (x > w - 1) {
184  double boundary = getpix_integrate_internal(geq, w - 1, y, plane, w, h);
185  return 2*boundary - getpix_integrate_internal(geq, 2*(w - 1) - x, y, plane, w, h);
186  } else if (y > h - 1) {
187  double boundary = getpix_integrate_internal(geq, x, h - 1, plane, w, h);
188  return 2*boundary - getpix_integrate_internal(geq, x, 2*(h - 1) - y, plane, w, h);
189  } else if (x < 0) {
190  if (x == -1) return 0;
191  return - getpix_integrate_internal(geq, -x-2, y, plane, w, h);
192  } else if (y < 0) {
193  if (y == -1) return 0;
194  return - getpix_integrate_internal(geq, x, -y-2, plane, w, h);
195  }
196 
197  return geq->pixel_sums[plane][x + y * w];
198 }
199 
200 static inline double getpix_integrate(void *priv, double x, double y, int plane) {
201  GEQContext *geq = priv;
202  AVFrame *picref = geq->picref;
203  const uint8_t *src = picref->data[plane];
204  const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width;
205  const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height;
206 
207  if (!src)
208  return 0;
209 
210  return getpix_integrate_internal(geq, lrint(av_clipd(x, -w, 2*w)), lrint(av_clipd(y, -h, 2*h)), plane, w, h);
211 }
212 
213 //TODO: cubic interpolate
214 //TODO: keep the last few frames
215 static double lum(void *priv, double x, double y) { return getpix(priv, x, y, 0); }
216 static double cb(void *priv, double x, double y) { return getpix(priv, x, y, 1); }
217 static double cr(void *priv, double x, double y) { return getpix(priv, x, y, 2); }
218 static double alpha(void *priv, double x, double y) { return getpix(priv, x, y, 3); }
219 
220 static double lumsum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 0); }
221 static double cbsum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 1); }
222 static double crsub(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 2); }
223 static double alphasum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 3); }
224 
226 {
227  GEQContext *geq = ctx->priv;
228  int plane, ret = 0;
229 
230  if (!geq->expr_str[Y] && !geq->expr_str[G] && !geq->expr_str[B] && !geq->expr_str[R]) {
231  av_log(ctx, AV_LOG_ERROR, "A luminance or RGB expression is mandatory\n");
232  ret = AVERROR(EINVAL);
233  goto end;
234  }
235  geq->is_rgb = !geq->expr_str[Y];
236 
237  if ((geq->expr_str[Y] || geq->expr_str[U] || geq->expr_str[V]) && (geq->expr_str[G] || geq->expr_str[B] || geq->expr_str[R])) {
238  av_log(ctx, AV_LOG_ERROR, "Either YCbCr or RGB but not both must be specified\n");
239  ret = AVERROR(EINVAL);
240  goto end;
241  }
242 
243  if (!geq->expr_str[U] && !geq->expr_str[V]) {
244  /* No chroma at all: fallback on luma */
245  geq->expr_str[U] = av_strdup(geq->expr_str[Y]);
246  geq->expr_str[V] = av_strdup(geq->expr_str[Y]);
247  } else {
248  /* One chroma unspecified, fallback on the other */
249  if (!geq->expr_str[U]) geq->expr_str[U] = av_strdup(geq->expr_str[V]);
250  if (!geq->expr_str[V]) geq->expr_str[V] = av_strdup(geq->expr_str[U]);
251  }
252 
253  if (!geq->expr_str[A]) {
254  char bps_string[8];
255  snprintf(bps_string, sizeof(bps_string), "%d", (1<<geq->bps) - 1);
256  geq->expr_str[A] = av_strdup(bps_string);
257  }
258  if (!geq->expr_str[G])
259  geq->expr_str[G] = av_strdup("g(X,Y)");
260  if (!geq->expr_str[B])
261  geq->expr_str[B] = av_strdup("b(X,Y)");
262  if (!geq->expr_str[R])
263  geq->expr_str[R] = av_strdup("r(X,Y)");
264 
265  if (geq->is_rgb ?
266  (!geq->expr_str[G] || !geq->expr_str[B] || !geq->expr_str[R])
267  :
268  (!geq->expr_str[U] || !geq->expr_str[V] || !geq->expr_str[A])) {
269  ret = AVERROR(ENOMEM);
270  goto end;
271  }
272 
273  for (plane = 0; plane < NB_PLANES; plane++) {
274  static double (*const p[])(void *, double, double) = {
275  lum , cb , cr , alpha ,
277  };
278  static const char *const func2_yuv_names[] = {
279  "lum" , "cb" , "cr" , "alpha" , "p",
280  "lumsum", "cbsum", "crsum", "alphasum", "psum",
281  NULL };
282  static const char *const func2_rgb_names[] = {
283  "g" , "b" , "r" , "alpha" , "p",
284  "gsum", "bsum", "rsum", "alphasum", "psum",
285  NULL };
286  const char *const *func2_names = geq->is_rgb ? func2_rgb_names : func2_yuv_names;
287  double (*const func2[])(void *, double, double) = {
288  lum , cb , cr , alpha , p[plane],
289  lumsum, cbsum, crsub, alphasum, p[plane + 4],
290  NULL };
291  int counter[10] = {0};
292 
293  for (int i = 0; i < MAX_NB_THREADS; i++) {
294  ret = av_expr_parse(&geq->e[plane][i], geq->expr_str[plane < 3 && geq->is_rgb ? plane+4 : plane], var_names,
295  NULL, NULL, func2_names, func2, 0, ctx);
296  if (ret < 0)
297  goto end;
298  }
299 
300  av_expr_count_func(geq->e[plane][0], counter, FF_ARRAY_ELEMS(counter), 2);
301  geq->needs_sum[plane] = counter[5] + counter[6] + counter[7] + counter[8] + counter[9];
302  }
303 
304 end:
305  return ret;
306 }
307 
309 {
310  GEQContext *geq = ctx->priv;
311  static const enum AVPixelFormat yuv_pix_fmts[] = {
329  };
330  static const enum AVPixelFormat rgb_pix_fmts[] = {
338  };
339  AVFilterFormats *fmts_list;
340 
341  if (geq->is_rgb) {
342  fmts_list = ff_make_format_list(rgb_pix_fmts);
343  } else
344  fmts_list = ff_make_format_list(yuv_pix_fmts);
345  if (!fmts_list)
346  return AVERROR(ENOMEM);
347  return ff_set_common_formats(ctx, fmts_list);
348 }
349 
350 static int geq_config_props(AVFilterLink *inlink)
351 {
352  GEQContext *geq = inlink->dst->priv;
354 
355  av_assert0(desc);
356 
357  geq->hsub = desc->log2_chroma_w;
358  geq->vsub = desc->log2_chroma_h;
359  geq->bps = desc->comp[0].depth;
360  geq->planes = desc->nb_components;
361  return 0;
362 }
363 
364 typedef struct ThreadData {
365  int height;
366  int width;
367  int plane;
368  int linesize;
369 } ThreadData;
370 
371 static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
372 {
373  GEQContext *geq = ctx->priv;
374  ThreadData *td = arg;
375  const int height = td->height;
376  const int width = td->width;
377  const int plane = td->plane;
378  const int linesize = td->linesize;
379  const int slice_start = ff_slice_pos(height, jobnr, nb_jobs);
380  const int slice_end = ff_slice_pos(height, jobnr + 1, nb_jobs);
381  int x, y;
382 
383  double values[VAR_VARS_NB];
384  values[VAR_W] = geq->values[VAR_W];
385  values[VAR_H] = geq->values[VAR_H];
386  values[VAR_N] = geq->values[VAR_N];
387  values[VAR_SW] = geq->values[VAR_SW];
388  values[VAR_SH] = geq->values[VAR_SH];
389  values[VAR_T] = geq->values[VAR_T];
390 
391  if (geq->bps == 8) {
392  uint8_t *ptr = geq->dst + linesize * slice_start;
393  for (y = slice_start; y < slice_end; y++) {
394  values[VAR_Y] = y;
395 
396  for (x = 0; x < width; x++) {
397  values[VAR_X] = x;
398  ptr[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
399  }
400  ptr += linesize;
401  }
402  } else {
403  uint16_t *ptr16 = geq->dst16 + (linesize/2) * slice_start;
404  for (y = slice_start; y < slice_end; y++) {
405  values[VAR_Y] = y;
406  for (x = 0; x < width; x++) {
407  values[VAR_X] = x;
408  ptr16[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
409  }
410  ptr16 += linesize/2;
411  }
412  }
413 
414  return 0;
415 }
416 
418 {
419  int plane;
420  AVFilterContext *ctx = inlink->dst;
421  const int nb_threads = FFMIN(MAX_NB_THREADS, ff_filter_get_nb_threads(ctx));
422  GEQContext *geq = ctx->priv;
423  AVFilterLink *outlink = inlink->dst->outputs[0];
424  AVFrame *out;
425 
426  geq->values[VAR_N] = inlink->frame_count_out,
427  geq->values[VAR_T] = in->pts == AV_NOPTS_VALUE ? NAN : in->pts * av_q2d(inlink->time_base),
428 
429  geq->picref = in;
430  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
431  if (!out) {
432  av_frame_free(&in);
433  return AVERROR(ENOMEM);
434  }
436 
437  for (plane = 0; plane < geq->planes && out->data[plane]; plane++) {
438  const int width = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->w, geq->hsub) : inlink->w;
439  const int height = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->h, geq->vsub) : inlink->h;
440  const int linesize = out->linesize[plane];
441  ThreadData td;
442 
443  geq->dst = out->data[plane];
444  geq->dst16 = (uint16_t*)out->data[plane];
445 
446  geq->values[VAR_W] = width;
447  geq->values[VAR_H] = height;
448  geq->values[VAR_SW] = width / (double)inlink->w;
449  geq->values[VAR_SH] = height / (double)inlink->h;
450 
451  td.width = width;
452  td.height = height;
453  td.plane = plane;
454  td.linesize = linesize;
455 
456  if (geq->needs_sum[plane])
457  calculate_sums(geq, plane, width, height);
458 
459  ctx->internal->execute(ctx, slice_geq_filter, &td, NULL, FFMIN(height, nb_threads));
460  }
461 
462  av_frame_free(&geq->picref);
463  return ff_filter_frame(outlink, out);
464 }
465 
467 {
468  int i;
469  GEQContext *geq = ctx->priv;
470 
471  for (i = 0; i < NB_PLANES; i++)
472  for (int j = 0; j < MAX_NB_THREADS; j++)
473  av_expr_free(geq->e[i][j]);
474  for (i = 0; i < NB_PLANES; i++)
475  av_freep(&geq->pixel_sums);
476 }
477 
478 static const AVFilterPad geq_inputs[] = {
479  {
480  .name = "default",
481  .type = AVMEDIA_TYPE_VIDEO,
482  .config_props = geq_config_props,
483  .filter_frame = geq_filter_frame,
484  },
485  { NULL }
486 };
487 
488 static const AVFilterPad geq_outputs[] = {
489  {
490  .name = "default",
491  .type = AVMEDIA_TYPE_VIDEO,
492  },
493  { NULL }
494 };
495 
497  .name = "geq",
498  .description = NULL_IF_CONFIG_SMALL("Apply generic equation to each pixel."),
499  .priv_size = sizeof(GEQContext),
500  .init = geq_init,
501  .uninit = geq_uninit,
503  .inputs = geq_inputs,
504  .outputs = geq_outputs,
505  .priv_class = &geq_class,
507 };
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:243
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static int interpolation(DeclickChannel *c, const double *src, int ar_order, double *acoefficients, int *index, int nb_errors, double *auxiliary, double *interpolated)
Definition: af_adeclick.c:365
static double(*const func2[])(void *, double, double)
Definition: af_afftfilt.c:121
static const char *const func2_names[]
Definition: af_afftfilt.c:120
#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:1096
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:802
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define xi(width, name, var, range_min, range_max, subs,...)
Definition: cbs_h2645.c:404
#define FFMIN(a, b)
Definition: common.h:105
#define av_clipd
Definition: common.h:173
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define NULL
Definition: coverity.c:32
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:339
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:781
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:700
int av_expr_count_func(AVExpr *e, unsigned *counter, int size, int arg)
Track the presence of user provided functions and their number of occurrences in a parsed expression.
Definition: eval.c:776
simple arithmetic expression evaluator
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:271
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 AVERROR(e)
Definition: error.h:43
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_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
int i
Definition: input.c:407
static enum AVPixelFormat rgb_pix_fmts[]
Definition: jpeg2000dec.c:260
static enum AVPixelFormat yuv_pix_fmts[]
Definition: jpeg2000dec.c:262
const char * arg
Definition: jacosubdec.c:66
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
const char * desc
Definition: libsvtav1.c:79
uint8_t w
Definition: llviddspenc.c:39
#define NAN
Definition: mathematics.h:64
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2033
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:420
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:410
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:379
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:421
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:414
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:438
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:441
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:436
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:434
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:415
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:381
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:416
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:433
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:437
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:407
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:408
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:380
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:382
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:401
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:383
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:419
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:443
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:442
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:418
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:409
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:435
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:417
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
#define td
Definition: regdef.h:70
#define FF_ARRAY_ELEMS(a)
#define snprintf
Definition: snprintf.h:34
Describe the class of an AVClass context structure.
Definition: log.h:67
Definition: eval.c:159
An instance of a filter.
Definition: avfilter.h:341
void * priv
private data for use by the filter
Definition: avfilter.h:356
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
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
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
int height
Definition: frame.h:376
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
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 is_rgb
Definition: vf_geq.c:60
AVFrame * picref
current input buffer
Definition: vf_geq.c:53
AVExpr * e[NB_PLANES][MAX_NB_THREADS]
expressions for each plane and thread
Definition: vf_geq.c:51
int vsub
chroma subsampling
Definition: vf_geq.c:57
int needs_sum[NB_PLANES]
Definition: vf_geq.c:64
double values[VAR_VARS_NB]
expression values
Definition: vf_geq.c:56
uint16_t * dst16
reference pointer to the 16bits output
Definition: vf_geq.c:55
uint8_t * dst
reference pointer to the 8bits output
Definition: vf_geq.c:54
int planes
number of planes
Definition: vf_geq.c:58
int interpolation
Definition: vf_geq.c:59
int bps
Definition: vf_geq.c:61
double * pixel_sums[NB_PLANES]
Definition: vf_geq.c:63
int hsub
Definition: vf_geq.c:57
char * expr_str[4+3]
expression strings for each plane
Definition: vf_geq.c:52
Used for passing data between threads.
Definition: dsddec.c:67
int height
Definition: vf_avgblur.c:62
int linesize
Definition: vf_avgblur.c:65
int plane
Definition: vf_blend.c:59
#define lrint
Definition: tablegen.h:53
#define av_malloc_array(a, b)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition: vp8dsp.c:255
FILE * out
Definition: movenc.c:54
AVFormatContext * ctx
Definition: movenc.c:48
#define height
#define width
static double crsub(void *priv, double x, double y)
Definition: vf_geq.c:222
@ VAR_H
Definition: vf_geq.c:47
@ VAR_SW
Definition: vf_geq.c:47
@ VAR_N
Definition: vf_geq.c:47
@ VAR_W
Definition: vf_geq.c:47
@ VAR_SH
Definition: vf_geq.c:47
@ VAR_VARS_NB
Definition: vf_geq.c:47
@ VAR_X
Definition: vf_geq.c:47
@ VAR_T
Definition: vf_geq.c:47
@ VAR_Y
Definition: vf_geq.c:47
static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_geq.c:371
AVFILTER_DEFINE_CLASS(geq)
static av_cold void geq_uninit(AVFilterContext *ctx)
Definition: vf_geq.c:466
AVFilter ff_vf_geq
Definition: vf_geq.c:496
static double getpix(void *priv, double x, double y, int plane)
Definition: vf_geq.c:98
static int calculate_sums(GEQContext *geq, int plane, int w, int h)
Definition: vf_geq.c:143
#define MAX_NB_THREADS
Definition: vf_geq.c:37
static double alphasum(void *priv, double x, double y)
Definition: vf_geq.c:223
static int geq_config_props(AVFilterLink *inlink)
Definition: vf_geq.c:350
static double cbsum(void *priv, double x, double y)
Definition: vf_geq.c:221
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:218
#define FLAGS
Definition: vf_geq.c:70
@ R
Definition: vf_geq.c:67
@ V
Definition: vf_geq.c:67
@ G
Definition: vf_geq.c:67
@ B
Definition: vf_geq.c:67
@ A
Definition: vf_geq.c:67
@ Y
Definition: vf_geq.c:67
@ U
Definition: vf_geq.c:67
static double getpix_integrate(void *priv, double x, double y, int plane)
Definition: vf_geq.c:200
static const AVFilterPad geq_inputs[]
Definition: vf_geq.c:478
InterpolationMethods
Definition: vf_geq.c:40
@ INTERP_NEAREST
Definition: vf_geq.c:41
@ INTERP_BILINEAR
Definition: vf_geq.c:42
@ NB_INTERP
Definition: vf_geq.c:43
static double getpix_integrate_internal(GEQContext *geq, int x, int y, int plane, int w, int h)
Definition: vf_geq.c:181
static double lum(void *priv, double x, double y)
Definition: vf_geq.c:215
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:217
static const char *const var_names[]
Definition: vf_geq.c:46
static double lumsum(void *priv, double x, double y)
Definition: vf_geq.c:220
static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_geq.c:417
#define NB_PLANES
Definition: vf_geq.c:38
#define OFFSET(x)
Definition: vf_geq.c:69
static int geq_query_formats(AVFilterContext *ctx)
Definition: vf_geq.c:308
static const AVFilterPad geq_outputs[]
Definition: vf_geq.c:488
static const AVOption geq_options[]
Definition: vf_geq.c:72
static av_cold int geq_init(AVFilterContext *ctx)
Definition: vf_geq.c:225
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:216
if(ret< 0)
Definition: vf_mcdeint.c:282
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