FFmpeg
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/mem.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/pixdesc.h"
35 #include "formats.h"
36 #include "internal.h"
37 #include "video.h"
38 
39 #define MAX_NB_THREADS 32
40 #define NB_PLANES 4
41 
46 };
47 
48 static const char *const var_names[] = { "X", "Y", "W", "H", "N", "SW", "SH", "T", NULL };
50 
51 typedef struct GEQContext {
52  const AVClass *class;
53  AVExpr *e[NB_PLANES][MAX_NB_THREADS]; ///< expressions for each plane and thread
54  char *expr_str[4+3]; ///< expression strings for each plane
55  AVFrame *picref; ///< current input buffer
56  uint8_t *dst; ///< reference pointer to the 8bits output
57  uint16_t *dst16; ///< reference pointer to the 16bits output
58  float *dst32; ///< reference pointer to the 32bits output
59  double values[VAR_VARS_NB]; ///< expression values
60  int hsub, vsub; ///< chroma subsampling
61  int planes; ///< number of planes
63  int is_rgb;
64  int bps;
65 
68 } GEQContext;
69 
70 enum { Y = 0, U, V, A, G, B, R };
71 
72 #define OFFSET(x) offsetof(GEQContext, x)
73 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
74 
75 static const AVOption geq_options[] = {
76  { "lum_expr", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
77  { "lum", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
78  { "cb_expr", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
79  { "cb", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
80  { "cr_expr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
81  { "cr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
82  { "alpha_expr", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
83  { "a", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
84  { "red_expr", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
85  { "r", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
86  { "green_expr", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
87  { "g", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
88  { "blue_expr", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
89  { "b", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
90  { "interpolation","set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, .unit = "interp" },
91  { "i", "set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, .unit = "interp" },
92  { "nearest", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, .unit = "interp" },
93  { "n", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, .unit = "interp" },
94  { "bilinear", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, .unit = "interp" },
95  { "b", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, .unit = "interp" },
96  {NULL},
97 };
98 
100 
101 static inline double getpix(void *priv, double x, double y, int plane)
102 {
103  int xi, yi;
104  GEQContext *geq = priv;
105  AVFrame *picref = geq->picref;
106  const uint8_t *src = picref->data[plane];
107  int linesize = picref->linesize[plane];
108  const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width;
109  const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height;
110 
111  if (!src)
112  return 0;
113 
114  if (geq->interpolation == INTERP_BILINEAR) {
115  xi = x = av_clipd(x, 0, w - 2);
116  yi = y = av_clipd(y, 0, h - 2);
117 
118  x -= xi;
119  y -= yi;
120 
121  if (geq->bps > 8 && geq->bps <= 16) {
122  const uint16_t *src16 = (const uint16_t*)src;
123  linesize /= 2;
124 
125  return (1-y)*((1-x)*src16[xi + yi * linesize] + x*src16[xi + 1 + yi * linesize])
126  + y *((1-x)*src16[xi + (yi+1) * linesize] + x*src16[xi + 1 + (yi+1) * linesize]);
127  } else if (geq->bps == 32) {
128  const float *src32 = (const float*)src;
129  linesize /= 4;
130 
131  return (1-y)*((1-x)*src32[xi + yi * linesize] + x*src32[xi + 1 + yi * linesize])
132  + y *((1-x)*src32[xi + (yi+1) * linesize] + x*src32[xi + 1 + (yi+1) * linesize]);
133  } else if (geq->bps == 8) {
134  return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xi + 1 + yi * linesize])
135  + y *((1-x)*src[xi + (yi+1) * linesize] + x*src[xi + 1 + (yi+1) * linesize]);
136  }
137  } else {
138  xi = av_clipd(x, 0, w - 1);
139  yi = av_clipd(y, 0, h - 1);
140 
141  if (geq->bps > 8 && geq->bps <= 16) {
142  const uint16_t *src16 = (const uint16_t*)src;
143  linesize /= 2;
144 
145  return src16[xi + yi * linesize];
146  } else if (geq->bps == 32) {
147  const float *src32 = (const float*)src;
148  linesize /= 4;
149 
150  return src32[xi + yi * linesize];
151  } else if (geq->bps == 8) {
152  return src[xi + yi * linesize];
153  }
154  }
155 
156  return 0;
157 }
158 
159 static int calculate_sums(GEQContext *geq, int plane, int w, int h)
160 {
161  int xi, yi;
162  AVFrame *picref = geq->picref;
163  const uint8_t *src = picref->data[plane];
164  int linesize = picref->linesize[plane];
165 
166  if (!geq->pixel_sums[plane])
167  geq->pixel_sums[plane] = av_malloc_array(w, h * sizeof (*geq->pixel_sums[plane]));
168  if (!geq->pixel_sums[plane])
169  return AVERROR(ENOMEM);
170  if (geq->bps == 32)
171  linesize /= 4;
172  else if (geq->bps > 8 && geq->bps <= 16)
173  linesize /= 2;
174  for (yi = 0; yi < h; yi ++) {
175  if (geq->bps > 8 && geq->bps <= 16) {
176  const uint16_t *src16 = (const uint16_t*)src;
177  double linesum = 0;
178 
179  for (xi = 0; xi < w; xi ++) {
180  linesum += src16[xi + yi * linesize];
181  geq->pixel_sums[plane][xi + yi * w] = linesum;
182  }
183  } else if (geq->bps == 8) {
184  double linesum = 0;
185 
186  for (xi = 0; xi < w; xi ++) {
187  linesum += src[xi + yi * linesize];
188  geq->pixel_sums[plane][xi + yi * w] = linesum;
189  }
190  } else if (geq->bps == 32) {
191  const float *src32 = (const float*)src;
192  double linesum = 0;
193 
194  for (xi = 0; xi < w; xi ++) {
195  linesum += src32[xi + yi * linesize];
196  geq->pixel_sums[plane][xi + yi * w] = linesum;
197  }
198  }
199  if (yi)
200  for (xi = 0; xi < w; xi ++) {
201  geq->pixel_sums[plane][xi + yi * w] += geq->pixel_sums[plane][xi + yi * w - w];
202  }
203  }
204  return 0;
205 }
206 
207 static inline double getpix_integrate_internal(GEQContext *geq, int x, int y, int plane, int w, int h)
208 {
209  if (x > w - 1) {
210  double boundary = getpix_integrate_internal(geq, w - 1, y, plane, w, h);
211  return 2*boundary - getpix_integrate_internal(geq, 2*(w - 1) - x, y, plane, w, h);
212  } else if (y > h - 1) {
213  double boundary = getpix_integrate_internal(geq, x, h - 1, plane, w, h);
214  return 2*boundary - getpix_integrate_internal(geq, x, 2*(h - 1) - y, plane, w, h);
215  } else if (x < 0) {
216  if (x == -1) return 0;
217  return - getpix_integrate_internal(geq, -x-2, y, plane, w, h);
218  } else if (y < 0) {
219  if (y == -1) return 0;
220  return - getpix_integrate_internal(geq, x, -y-2, plane, w, h);
221  }
222 
223  return geq->pixel_sums[plane][x + y * w];
224 }
225 
226 static inline double getpix_integrate(void *priv, double x, double y, int plane) {
227  GEQContext *geq = priv;
228  AVFrame *picref = geq->picref;
229  const uint8_t *src = picref->data[plane];
230  const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width;
231  const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height;
232 
233  if (!src)
234  return 0;
235 
236  return getpix_integrate_internal(geq, lrint(av_clipd(x, -w, 2*w)), lrint(av_clipd(y, -h, 2*h)), plane, w, h);
237 }
238 
239 //TODO: cubic interpolate
240 //TODO: keep the last few frames
241 static double lum(void *priv, double x, double y) { return getpix(priv, x, y, 0); }
242 static double cb(void *priv, double x, double y) { return getpix(priv, x, y, 1); }
243 static double cr(void *priv, double x, double y) { return getpix(priv, x, y, 2); }
244 static double alpha(void *priv, double x, double y) { return getpix(priv, x, y, 3); }
245 
246 static double lumsum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 0); }
247 static double cbsum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 1); }
248 static double crsub(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 2); }
249 static double alphasum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 3); }
250 
252 {
253  GEQContext *geq = ctx->priv;
254  int plane, ret = 0;
255 
256  if (!geq->expr_str[Y] && !geq->expr_str[G] && !geq->expr_str[B] && !geq->expr_str[R]) {
257  av_log(ctx, AV_LOG_ERROR, "A luminance or RGB expression is mandatory\n");
258  ret = AVERROR(EINVAL);
259  goto end;
260  }
261  geq->is_rgb = !geq->expr_str[Y];
262 
263  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])) {
264  av_log(ctx, AV_LOG_ERROR, "Either YCbCr or RGB but not both must be specified\n");
265  ret = AVERROR(EINVAL);
266  goto end;
267  }
268 
269  if (!geq->expr_str[U] && !geq->expr_str[V]) {
270  /* No chroma at all: fallback on luma */
271  geq->expr_str[U] = av_strdup(geq->expr_str[Y]);
272  geq->expr_str[V] = av_strdup(geq->expr_str[Y]);
273  } else {
274  /* One chroma unspecified, fallback on the other */
275  if (!geq->expr_str[U]) geq->expr_str[U] = av_strdup(geq->expr_str[V]);
276  if (!geq->expr_str[V]) geq->expr_str[V] = av_strdup(geq->expr_str[U]);
277  }
278 
279  if (!geq->expr_str[A] && geq->bps != 32) {
280  geq->expr_str[A] = av_asprintf("%d", (1<<geq->bps) - 1);
281  } else if (!geq->expr_str[A]) {
282  geq->expr_str[A] = av_asprintf("%f", 1.f);
283  }
284  if (!geq->expr_str[G])
285  geq->expr_str[G] = av_strdup("g(X,Y)");
286  if (!geq->expr_str[B])
287  geq->expr_str[B] = av_strdup("b(X,Y)");
288  if (!geq->expr_str[R])
289  geq->expr_str[R] = av_strdup("r(X,Y)");
290 
291  if (geq->is_rgb ?
292  (!geq->expr_str[G] || !geq->expr_str[B] || !geq->expr_str[R])
293  :
294  (!geq->expr_str[U] || !geq->expr_str[V] || !geq->expr_str[A])) {
295  ret = AVERROR(ENOMEM);
296  goto end;
297  }
298 
299  for (plane = 0; plane < NB_PLANES; plane++) {
300  static double (*const p[])(void *, double, double) = {
301  lum , cb , cr , alpha ,
303  };
304  static const char *const func2_yuv_names[] = {
305  "lum" , "cb" , "cr" , "alpha" , "p",
306  "lumsum", "cbsum", "crsum", "alphasum", "psum",
307  NULL };
308  static const char *const func2_rgb_names[] = {
309  "g" , "b" , "r" , "alpha" , "p",
310  "gsum", "bsum", "rsum", "alphasum", "psum",
311  NULL };
312  const char *const *func2_names = geq->is_rgb ? func2_rgb_names : func2_yuv_names;
313  double (*const func2[])(void *, double, double) = {
314  lum , cb , cr , alpha , p[plane],
315  lumsum, cbsum, crsub, alphasum, p[plane + 4],
316  NULL };
317  int counter[10] = {0};
318 
319  for (int i = 0; i < MAX_NB_THREADS; i++) {
320  ret = av_expr_parse(&geq->e[plane][i], geq->expr_str[plane < 3 && geq->is_rgb ? plane+4 : plane], var_names,
321  NULL, NULL, func2_names, func2, 0, ctx);
322  if (ret < 0)
323  goto end;
324  }
325 
326  av_expr_count_func(geq->e[plane][0], counter, FF_ARRAY_ELEMS(counter), 2);
327  geq->needs_sum[plane] = counter[5] + counter[6] + counter[7] + counter[8] + counter[9];
328  }
329 
330 end:
331  return ret;
332 }
333 
335 {
336  GEQContext *geq = ctx->priv;
337  static const enum AVPixelFormat yuv_pix_fmts[] = {
356  };
357  static const enum AVPixelFormat rgb_pix_fmts[] = {
366  };
367  const enum AVPixelFormat *pix_fmts = geq->is_rgb ? rgb_pix_fmts : yuv_pix_fmts;
368 
370 }
371 
373 {
374  GEQContext *geq = inlink->dst->priv;
376 
377  av_assert0(desc);
378 
379  geq->hsub = desc->log2_chroma_w;
380  geq->vsub = desc->log2_chroma_h;
381  geq->bps = desc->comp[0].depth;
382  geq->planes = desc->nb_components;
383  return 0;
384 }
385 
386 typedef struct ThreadData {
387  int height;
388  int width;
389  int plane;
390  int linesize;
391 } ThreadData;
392 
393 static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
394 {
395  GEQContext *geq = ctx->priv;
396  ThreadData *td = arg;
397  const int height = td->height;
398  const int width = td->width;
399  const int plane = td->plane;
400  const int linesize = td->linesize;
401  const int slice_start = (height * jobnr) / nb_jobs;
402  const int slice_end = (height * (jobnr+1)) / nb_jobs;
403  int x, y;
404 
405  double values[VAR_VARS_NB];
406  values[VAR_W] = geq->values[VAR_W];
407  values[VAR_H] = geq->values[VAR_H];
408  values[VAR_N] = geq->values[VAR_N];
409  values[VAR_SW] = geq->values[VAR_SW];
410  values[VAR_SH] = geq->values[VAR_SH];
411  values[VAR_T] = geq->values[VAR_T];
412 
413  if (geq->bps == 8) {
414  uint8_t *ptr = geq->dst + linesize * slice_start;
415  for (y = slice_start; y < slice_end; y++) {
416  values[VAR_Y] = y;
417 
418  for (x = 0; x < width; x++) {
419  values[VAR_X] = x;
420  ptr[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
421  }
422  ptr += linesize;
423  }
424  } else if (geq->bps <= 16) {
425  uint16_t *ptr16 = geq->dst16 + (linesize/2) * slice_start;
426  for (y = slice_start; y < slice_end; y++) {
427  values[VAR_Y] = y;
428  for (x = 0; x < width; x++) {
429  values[VAR_X] = x;
430  ptr16[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
431  }
432  ptr16 += linesize/2;
433  }
434  } else {
435  float *ptr32 = geq->dst32 + (linesize/4) * slice_start;
436  for (y = slice_start; y < slice_end; y++) {
437  values[VAR_Y] = y;
438  for (x = 0; x < width; x++) {
439  values[VAR_X] = x;
440  ptr32[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
441  }
442  ptr32 += linesize/4;
443  }
444  }
445 
446  return 0;
447 }
448 
450 {
451  int plane;
452  AVFilterContext *ctx = inlink->dst;
453  const int nb_threads = FFMIN(MAX_NB_THREADS, ff_filter_get_nb_threads(ctx));
454  GEQContext *geq = ctx->priv;
455  AVFilterLink *outlink = inlink->dst->outputs[0];
456  AVFrame *out;
457 
458  geq->values[VAR_N] = inlink->frame_count_out,
459  geq->values[VAR_T] = in->pts == AV_NOPTS_VALUE ? NAN : in->pts * av_q2d(inlink->time_base),
460 
461  geq->picref = in;
462  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
463  if (!out) {
464  av_frame_free(&in);
465  return AVERROR(ENOMEM);
466  }
468 
469  for (plane = 0; plane < geq->planes && out->data[plane]; plane++) {
470  const int width = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->w, geq->hsub) : inlink->w;
471  const int height = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->h, geq->vsub) : inlink->h;
472  const int linesize = out->linesize[plane];
473  ThreadData td;
474 
475  geq->dst = out->data[plane];
476  geq->dst16 = (uint16_t*)out->data[plane];
477  geq->dst32 = (float*)out->data[plane];
478 
479  geq->values[VAR_W] = width;
480  geq->values[VAR_H] = height;
481  geq->values[VAR_SW] = width / (double)inlink->w;
482  geq->values[VAR_SH] = height / (double)inlink->h;
483 
484  td.width = width;
485  td.height = height;
486  td.plane = plane;
487  td.linesize = linesize;
488 
489  if (geq->needs_sum[plane])
490  calculate_sums(geq, plane, width, height);
491 
493  NULL, FFMIN(height, nb_threads));
494  }
495 
496  av_frame_free(&geq->picref);
497  return ff_filter_frame(outlink, out);
498 }
499 
501 {
502  int i;
503  GEQContext *geq = ctx->priv;
504 
505  for (i = 0; i < NB_PLANES; i++)
506  for (int j = 0; j < MAX_NB_THREADS; j++)
507  av_expr_free(geq->e[i][j]);
508  for (i = 0; i < NB_PLANES; i++)
509  av_freep(&geq->pixel_sums);
510 }
511 
512 static const AVFilterPad geq_inputs[] = {
513  {
514  .name = "default",
515  .type = AVMEDIA_TYPE_VIDEO,
516  .config_props = geq_config_props,
517  .filter_frame = geq_filter_frame,
518  },
519 };
520 
522  .name = "geq",
523  .description = NULL_IF_CONFIG_SMALL("Apply generic equation to each pixel."),
524  .priv_size = sizeof(GEQContext),
525  .init = geq_init,
526  .uninit = geq_uninit,
530  .priv_class = &geq_class,
532 };
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:112
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:522
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:501
td
#define td
Definition: regdef.h:70
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
getpix
static double getpix(void *priv, double x, double y, int plane)
Definition: vf_geq.c:101
var_names
static const char *const var_names[]
Definition: vf_geq.c:48
out
FILE * out
Definition: movenc.c:55
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:242
geq_query_formats
static int geq_query_formats(AVFilterContext *ctx)
Definition: vf_geq.c:334
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1015
geq_uninit
static av_cold void geq_uninit(AVFilterContext *ctx)
Definition: vf_geq.c:500
B
@ B
Definition: vf_geq.c:70
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2965
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:115
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:160
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:514
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:375
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:487
AVFrame::width
int width
Definition: frame.h:447
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:521
w
uint8_t w
Definition: llviddspenc.c:38
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:516
AVOption
AVOption.
Definition: opt.h:346
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:159
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:478
av_expr_count_func
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:787
NB_INTERP
@ NB_INTERP
Definition: vf_geq.c:45
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
GEQContext::planes
int planes
number of planes
Definition: vf_geq.c:61
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:517
VAR_T
@ VAR_T
Definition: vf_geq.c:49
lumsum
static double lumsum(void *priv, double x, double y)
Definition: vf_geq.c:246
crsub
static double crsub(void *priv, double x, double y)
Definition: vf_geq.c:248
func2_names
static const char *const func2_names[]
Definition: af_afftfilt.c:99
ThreadData::width
int width
Definition: vf_avgblur.c:65
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:458
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:396
GEQContext::pixel_sums
double * pixel_sums[NB_PLANES]
Definition: vf_geq.c:66
formats.h
av_expr_parse
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:710
geq_config_props
static int geq_config_props(AVFilterLink *inlink)
Definition: vf_geq.c:372
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:513
GEQContext::interpolation
int interpolation
Definition: vf_geq.c:62
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:496
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:494
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:523
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:476
InterpolationMethods
InterpolationMethods
Definition: vf_geq.c:42
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:462
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:358
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:481
avassert.h
lrint
#define lrint
Definition: tablegen.h:53
func2
static double(*const func2[])(void *, double, double)
Definition: af_afftfilt.c:100
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:490
MAX_NB_THREADS
#define MAX_NB_THREADS
Definition: vf_geq.c:39
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:37
OFFSET
#define OFFSET(x)
Definition: vf_geq.c:72
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:498
ThreadData::plane
int plane
Definition: vf_blend.c:59
width
#define width
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:499
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
VAR_N
@ VAR_N
Definition: vf_geq.c:49
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:491
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:59
ThreadData::height
int height
Definition: vf_avgblur.c:64
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:1730
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
NB_PLANES
#define NB_PLANES
Definition: vf_geq.c:40
GEQContext::vsub
int vsub
chroma subsampling
Definition: vf_geq.c:60
ThreadData::linesize
int linesize
Definition: vf_avgblur.c:68
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:874
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:475
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:489
ctx
AVFormatContext * ctx
Definition: movenc.c:49
xi
#define xi(width, name, var, range_min, range_max, subs,...)
Definition: cbs_h2645.c:418
av_expr_eval
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:792
geq_options
static const AVOption geq_options[]
Definition: vf_geq.c:75
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:461
AVExpr
Definition: eval.c:158
G
@ G
Definition: vf_geq.c:70
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:511
NAN
#define NAN
Definition: mathematics.h:115
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
VAR_H
@ VAR_H
Definition: vf_geq.c:49
alpha
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:244
arg
const char * arg
Definition: jacosubdec.c:67
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:459
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:497
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
VAR_W
@ VAR_W
Definition: vf_geq.c:49
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:709
INTERP_NEAREST
@ INTERP_NEAREST
Definition: vf_geq.c:43
getpix_integrate
static double getpix_integrate(void *priv, double x, double y, int plane)
Definition: vf_geq.c:226
GEQContext::picref
AVFrame * picref
current input buffer
Definition: vf_geq.c:55
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:480
calculate_sums
static int calculate_sums(GEQContext *geq, int plane, int w, int h)
Definition: vf_geq.c:159
double
double
Definition: af_crystalizer.c:131
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:479
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:493
INTERP_BILINEAR
@ INTERP_BILINEAR
Definition: vf_geq.c:44
cbsum
static double cbsum(void *priv, double x, double y)
Definition: vf_geq.c:247
GEQContext::bps
int bps
Definition: vf_geq.c:64
GEQContext::e
AVExpr * e[NB_PLANES][MAX_NB_THREADS]
expressions for each plane and thread
Definition: vf_geq.c:53
eval.h
f
f
Definition: af_crystalizer.c:121
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:366
VAR_VARS_NB
@ VAR_VARS_NB
Definition: vf_geq.c:49
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
A
@ A
Definition: vf_geq.c:70
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:508
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:483
VAR_X
@ VAR_X
Definition: vf_geq.c:49
GEQContext::values
double values[VAR_VARS_NB]
expression values
Definition: vf_geq.c:59
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:485
geq_init
static av_cold int geq_init(AVFilterContext *ctx)
Definition: vf_geq.c:251
height
#define height
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:518
FLAGS
#define FLAGS
Definition: vf_geq.c:73
interpolation
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:390
internal.h
VAR_SW
@ VAR_SW
Definition: vf_geq.c:49
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:147
GEQContext
Definition: vf_geq.c:51
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
GEQContext::is_rgb
int is_rgb
Definition: vf_geq.c:63
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
lum
static double lum(void *priv, double x, double y)
Definition: vf_geq.c:241
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:495
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:827
ThreadData
Used for passing data between threads.
Definition: dsddec.c:71
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
VAR_Y
@ VAR_Y
Definition: vf_geq.c:49
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
GEQContext::expr_str
char * expr_str[4+3]
expression strings for each plane
Definition: vf_geq.c:54
GEQContext::dst
uint8_t * dst
reference pointer to the 8bits output
Definition: vf_geq.c:56
GEQContext::dst16
uint16_t * dst16
reference pointer to the 16bits output
Definition: vf_geq.c:57
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:477
AVFilter
Filter definition.
Definition: avfilter.h:166
ret
ret
Definition: filter_design.txt:187
GEQContext::needs_sum
int needs_sum[NB_PLANES]
Definition: vf_geq.c:67
U
@ U
Definition: vf_geq.c:70
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:515
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:482
GEQContext::hsub
int hsub
Definition: vf_geq.c:60
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:487
Y
@ Y
Definition: vf_geq.c:70
AVFrame::height
int height
Definition: frame.h:447
geq_filter_frame
static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_geq.c:449
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:509
values
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
Definition: filter_design.txt:263
slice_start
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition: dec.c:688
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(geq)
VAR_SH
@ VAR_SH
Definition: vf_geq.c:49
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
desc
const char * desc
Definition: libsvtav1.c:75
alphasum
static double alphasum(void *priv, double x, double y)
Definition: vf_geq.c:249
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
mem.h
R
@ R
Definition: vf_geq.c:70
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
yuv_pix_fmts
static enum AVPixelFormat yuv_pix_fmts[]
Definition: jpeg2000dec.c:178
cr
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:243
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
V
@ V
Definition: vf_geq.c:70
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:80
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:420
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:79
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2038
GEQContext::dst32
float * dst32
reference pointer to the 32bits output
Definition: vf_geq.c:58
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:488
rgb_pix_fmts
static enum AVPixelFormat rgb_pix_fmts[]
Definition: jpeg2000dec.c:176
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:239
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:460
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:134
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
slice_geq_filter
static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_geq.c:393
ff_vf_geq
const AVFilter ff_vf_geq
Definition: vf_geq.c:521
geq_inputs
static const AVFilterPad geq_inputs[]
Definition: vf_geq.c:512
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:173
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:486
getpix_integrate_internal
static double getpix_integrate_internal(GEQContext *geq, int x, int y, int plane, int w, int h)
Definition: vf_geq.c:207
av_clipd
av_clipd
Definition: af_crystalizer.c:131