FFmpeg
Loading...
Searching...
No Matches
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
36#include "filters.h"
37#include "formats.h"
38#include "video.h"
39
40#define MAX_NB_THREADS 32
41#define NB_PLANES 4
42
48
49static const char *const var_names[] = { "X", "Y", "W", "H", "N", "SW", "SH", "T", NULL };
51
52typedef struct GEQContext {
53 const AVClass *class;
54 AVExpr *e[NB_PLANES][MAX_NB_THREADS]; ///< expressions for each plane and thread
55 char *expr_str[4+3]; ///< expression strings for each plane
56 AVFrame *picref; ///< current input buffer
57 uint8_t *dst; ///< reference pointer to the 8bits output
58 uint16_t *dst16; ///< reference pointer to the 16bits output
59 float *dst32; ///< reference pointer to the 32bits output
60 double values[VAR_VARS_NB]; ///< expression values
61 int hsub, vsub; ///< chroma subsampling
62 int planes; ///< number of planes
64 int is_rgb;
65 int bps;
66
70
71enum { Y = 0, U, V, A, G, B, R };
72
73#define OFFSET(x) offsetof(GEQContext, x)
74#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
75
76static const AVOption geq_options[] = {
77 { "lum_expr", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
78 { "lum", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
79 { "cb_expr", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
80 { "cb", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
81 { "cr_expr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
82 { "cr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
83 { "alpha_expr", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
84 { "a", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
85 { "red_expr", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
86 { "r", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
87 { "green_expr", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
88 { "g", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
89 { "blue_expr", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
90 { "b", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
91 { "interpolation","set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, .unit = "interp" },
92 { "i", "set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, .unit = "interp" },
93 { "nearest", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, .unit = "interp" },
94 { "n", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, .unit = "interp" },
95 { "bilinear", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, .unit = "interp" },
96 { "b", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, .unit = "interp" },
97 {NULL},
98};
99
101
102static inline double getpix(void *priv, double x, double y, int plane)
103{
104 int xi, yi;
105 GEQContext *geq = priv;
106 AVFrame *picref = geq->picref;
107 const uint8_t *src = picref->data[plane];
108 int linesize = picref->linesize[plane];
109 const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width;
110 const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height;
111
112 if (!src)
113 return 0;
114
115 if (geq->interpolation == INTERP_BILINEAR) {
116 int xn, yn;
117
118 xi = x = av_clipd(x, 0, w - 1);
119 yi = y = av_clipd(y, 0, h - 1);
120 xn = FFMIN(xi + 1, w - 1);
121 yn = FFMIN(yi + 1, h - 1);
122
123 x -= xi;
124 y -= yi;
125
126 if (geq->bps > 8 && geq->bps <= 16) {
127 const uint16_t *src16 = (const uint16_t*)src;
128 linesize /= 2;
129
130 return (1-y)*((1-x)*src16[xi + yi * linesize] + x*src16[xn + yi * linesize])
131 + y *((1-x)*src16[xi + yn * linesize] + x*src16[xn + yn * linesize]);
132 } else if (geq->bps == 32) {
133 const float *src32 = (const float*)src;
134 linesize /= 4;
135
136 return (1-y)*((1-x)*src32[xi + yi * linesize] + x*src32[xn + yi * linesize])
137 + y *((1-x)*src32[xi + yn * linesize] + x*src32[xn + yn * linesize]);
138 } else if (geq->bps == 8) {
139 return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xn + yi * linesize])
140 + y *((1-x)*src[xi + yn * linesize] + x*src[xn + yn * linesize]);
141 }
142 } else {
143 xi = av_clipd(x, 0, w - 1);
144 yi = av_clipd(y, 0, h - 1);
145
146 if (geq->bps > 8 && geq->bps <= 16) {
147 const uint16_t *src16 = (const uint16_t*)src;
148 linesize /= 2;
149
150 return src16[xi + yi * linesize];
151 } else if (geq->bps == 32) {
152 const float *src32 = (const float*)src;
153 linesize /= 4;
154
155 return src32[xi + yi * linesize];
156 } else if (geq->bps == 8) {
157 return src[xi + yi * linesize];
158 }
159 }
160
161 return 0;
162}
163
164static int calculate_sums(GEQContext *geq, int plane, int w, int h)
165{
166 int xi, yi;
167 AVFrame *picref = geq->picref;
168 const uint8_t *src = picref->data[plane];
169 int linesize = picref->linesize[plane];
170
171 if (!geq->pixel_sums[plane])
172 geq->pixel_sums[plane] = av_malloc_array(w, h * sizeof (*geq->pixel_sums[plane]));
173 if (!geq->pixel_sums[plane])
174 return AVERROR(ENOMEM);
175 if (geq->bps == 32)
176 linesize /= 4;
177 else if (geq->bps > 8 && geq->bps <= 16)
178 linesize /= 2;
179 for (yi = 0; yi < h; yi ++) {
180 if (geq->bps > 8 && geq->bps <= 16) {
181 const uint16_t *src16 = (const uint16_t*)src;
182 double linesum = 0;
183
184 for (xi = 0; xi < w; xi ++) {
185 linesum += src16[xi + yi * linesize];
186 geq->pixel_sums[plane][xi + yi * w] = linesum;
187 }
188 } else if (geq->bps == 8) {
189 double linesum = 0;
190
191 for (xi = 0; xi < w; xi ++) {
192 linesum += src[xi + yi * linesize];
193 geq->pixel_sums[plane][xi + yi * w] = linesum;
194 }
195 } else if (geq->bps == 32) {
196 const float *src32 = (const float*)src;
197 double linesum = 0;
198
199 for (xi = 0; xi < w; xi ++) {
200 linesum += src32[xi + yi * linesize];
201 geq->pixel_sums[plane][xi + yi * w] = linesum;
202 }
203 }
204 if (yi)
205 for (xi = 0; xi < w; xi ++) {
206 geq->pixel_sums[plane][xi + yi * w] += geq->pixel_sums[plane][xi + yi * w - w];
207 }
208 }
209 return 0;
210}
211
212static inline double getpix_integrate_internal(GEQContext *geq, int x, int y, int plane, int w, int h)
213{
214 if (x > w - 1) {
215 double boundary = getpix_integrate_internal(geq, w - 1, y, plane, w, h);
216 return 2*boundary - getpix_integrate_internal(geq, 2*(w - 1) - x, y, plane, w, h);
217 } else if (y > h - 1) {
218 double boundary = getpix_integrate_internal(geq, x, h - 1, plane, w, h);
219 return 2*boundary - getpix_integrate_internal(geq, x, 2*(h - 1) - y, plane, w, h);
220 } else if (x < 0) {
221 if (x == -1) return 0;
222 return - getpix_integrate_internal(geq, -x-2, y, plane, w, h);
223 } else if (y < 0) {
224 if (y == -1) return 0;
225 return - getpix_integrate_internal(geq, x, -y-2, plane, w, h);
226 }
227
228 return geq->pixel_sums[plane][x + y * w];
229}
230
231static inline double getpix_integrate(void *priv, double x, double y, int plane) {
232 GEQContext *geq = priv;
233 AVFrame *picref = geq->picref;
234 const uint8_t *src = picref->data[plane];
235 const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width;
236 const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height;
237
238 if (!src)
239 return 0;
240
241 return getpix_integrate_internal(geq, lrint(av_clipd(x, -w, 2*w)), lrint(av_clipd(y, -h, 2*h)), plane, w, h);
242}
243
244//TODO: cubic interpolate
245//TODO: keep the last few frames
246static double lum(void *priv, double x, double y) { return getpix(priv, x, y, 0); }
247static double cb(void *priv, double x, double y) { return getpix(priv, x, y, 1); }
248static double cr(void *priv, double x, double y) { return getpix(priv, x, y, 2); }
249static double alpha(void *priv, double x, double y) { return getpix(priv, x, y, 3); }
250
251static double lumsum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 0); }
252static double cbsum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 1); }
253static double crsub(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 2); }
254static double alphasum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 3); }
255
257{
258 GEQContext *geq = ctx->priv;
259 int plane, ret = 0;
260
261 if (!geq->expr_str[Y] && !geq->expr_str[G] && !geq->expr_str[B] && !geq->expr_str[R]) {
262 av_log(ctx, AV_LOG_ERROR, "A luminance or RGB expression is mandatory\n");
263 ret = AVERROR(EINVAL);
264 goto end;
265 }
266 geq->is_rgb = !geq->expr_str[Y];
267
268 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])) {
269 av_log(ctx, AV_LOG_ERROR, "Either YCbCr or RGB but not both must be specified\n");
270 ret = AVERROR(EINVAL);
271 goto end;
272 }
273
274 if (!geq->expr_str[U] && !geq->expr_str[V]) {
275 /* No chroma at all: fallback on luma */
276 geq->expr_str[U] = av_strdup(geq->expr_str[Y]);
277 geq->expr_str[V] = av_strdup(geq->expr_str[Y]);
278 } else {
279 /* One chroma unspecified, fallback on the other */
280 if (!geq->expr_str[U]) geq->expr_str[U] = av_strdup(geq->expr_str[V]);
281 if (!geq->expr_str[V]) geq->expr_str[V] = av_strdup(geq->expr_str[U]);
282 }
283
284 if (!geq->expr_str[A] && geq->bps != 32) {
285 geq->expr_str[A] = av_asprintf("%d", (1<<geq->bps) - 1);
286 } else if (!geq->expr_str[A]) {
287 geq->expr_str[A] = av_asprintf("%f", 1.f);
288 }
289 if (!geq->expr_str[G])
290 geq->expr_str[G] = av_strdup("g(X,Y)");
291 if (!geq->expr_str[B])
292 geq->expr_str[B] = av_strdup("b(X,Y)");
293 if (!geq->expr_str[R])
294 geq->expr_str[R] = av_strdup("r(X,Y)");
295
296 if (geq->is_rgb ?
297 (!geq->expr_str[G] || !geq->expr_str[B] || !geq->expr_str[R])
298 :
299 (!geq->expr_str[U] || !geq->expr_str[V] || !geq->expr_str[A])) {
300 ret = AVERROR(ENOMEM);
301 goto end;
302 }
303
304 for (plane = 0; plane < NB_PLANES; plane++) {
305 static double (*const p[])(void *, double, double) = {
306 lum , cb , cr , alpha ,
308 };
309 static const char *const func2_yuv_names[] = {
310 "lum" , "cb" , "cr" , "alpha" , "p",
311 "lumsum", "cbsum", "crsum", "alphasum", "psum",
312 NULL };
313 static const char *const func2_rgb_names[] = {
314 "g" , "b" , "r" , "alpha" , "p",
315 "gsum", "bsum", "rsum", "alphasum", "psum",
316 NULL };
317 const char *const *func2_names = geq->is_rgb ? func2_rgb_names : func2_yuv_names;
318 double (*const func2[])(void *, double, double) = {
319 lum , cb , cr , alpha , p[plane],
320 lumsum, cbsum, crsub, alphasum, p[plane + 4],
321 NULL };
322 int counter[10] = {0};
323
324 for (int i = 0; i < MAX_NB_THREADS; i++) {
325 ret = av_expr_parse(&geq->e[plane][i], geq->expr_str[plane < 3 && geq->is_rgb ? plane+4 : plane], var_names,
326 NULL, NULL, func2_names, func2, 0, ctx);
327 if (ret < 0)
328 goto end;
329 }
330
331 av_expr_count_func(geq->e[plane][0], counter, FF_ARRAY_ELEMS(counter), 2);
332 geq->needs_sum[plane] = counter[5] + counter[6] + counter[7] + counter[8] + counter[9];
333 }
334
335end:
336 return ret;
337}
338
340 AVFilterFormatsConfig **cfg_in,
341 AVFilterFormatsConfig **cfg_out)
342{
343 const GEQContext *geq = ctx->priv;
344 static const enum AVPixelFormat yuv_pix_fmts[] = {
363 };
364 static const enum AVPixelFormat rgb_pix_fmts[] = {
373 };
375
376 return ff_set_pixel_formats_from_list2(ctx, cfg_in, cfg_out, pix_fmts);
377}
378
380{
381 GEQContext *geq = inlink->dst->priv;
383
385
386 geq->hsub = desc->log2_chroma_w;
387 geq->vsub = desc->log2_chroma_h;
388 geq->bps = desc->comp[0].depth;
389 geq->planes = desc->nb_components;
390 return 0;
391}
392
393typedef struct ThreadData {
394 int height;
395 int width;
396 int plane;
397 int linesize;
398} ThreadData;
399
400static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
401{
402 GEQContext *geq = ctx->priv;
403 ThreadData *td = arg;
404 const int height = td->height;
405 const int width = td->width;
406 const int plane = td->plane;
407 const int linesize = td->linesize;
408 const int slice_start = ff_slice_pos(height, jobnr, nb_jobs);
409 const int slice_end = ff_slice_pos(height, jobnr + 1, nb_jobs);
410 int x, y;
411
412 double values[VAR_VARS_NB];
413 values[VAR_W] = geq->values[VAR_W];
414 values[VAR_H] = geq->values[VAR_H];
415 values[VAR_N] = geq->values[VAR_N];
416 values[VAR_SW] = geq->values[VAR_SW];
417 values[VAR_SH] = geq->values[VAR_SH];
418 values[VAR_T] = geq->values[VAR_T];
419
420 if (geq->bps == 8) {
421 uint8_t *ptr = geq->dst + linesize * slice_start;
422 for (y = slice_start; y < slice_end; y++) {
423 values[VAR_Y] = y;
424
425 for (x = 0; x < width; x++) {
426 values[VAR_X] = x;
427 ptr[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
428 }
429 ptr += linesize;
430 }
431 } else if (geq->bps <= 16) {
432 uint16_t *ptr16 = geq->dst16 + (linesize/2) * slice_start;
433 for (y = slice_start; y < slice_end; y++) {
434 values[VAR_Y] = y;
435 for (x = 0; x < width; x++) {
436 values[VAR_X] = x;
437 ptr16[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
438 }
439 ptr16 += linesize/2;
440 }
441 } else {
442 float *ptr32 = geq->dst32 + (linesize/4) * slice_start;
443 for (y = slice_start; y < slice_end; y++) {
444 values[VAR_Y] = y;
445 for (x = 0; x < width; x++) {
446 values[VAR_X] = x;
447 ptr32[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
448 }
449 ptr32 += linesize/4;
450 }
451 }
452
453 return 0;
454}
455
456static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
457{
458 int plane;
459 FilterLink *inl = ff_filter_link(inlink);
460 AVFilterContext *ctx = inlink->dst;
461 const int nb_threads = FFMIN(MAX_NB_THREADS, ff_filter_get_nb_threads(ctx));
462 GEQContext *geq = ctx->priv;
463 AVFilterLink *outlink = inlink->dst->outputs[0];
464 AVFrame *out;
465
466 geq->values[VAR_N] = inl->frame_count_out,
467 geq->values[VAR_T] = in->pts == AV_NOPTS_VALUE ? NAN : in->pts * av_q2d(inlink->time_base),
468
469 geq->picref = in;
470 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
471 if (!out) {
472 av_frame_free(&in);
473 return AVERROR(ENOMEM);
474 }
476
477 for (plane = 0; plane < geq->planes && out->data[plane]; plane++) {
478 const int width = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->w, geq->hsub) : inlink->w;
479 const int height = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->h, geq->vsub) : inlink->h;
480 const int linesize = out->linesize[plane];
481 ThreadData td;
482
483 geq->dst = out->data[plane];
484 geq->dst16 = (uint16_t*)out->data[plane];
485 geq->dst32 = (float*)out->data[plane];
486
487 geq->values[VAR_W] = width;
488 geq->values[VAR_H] = height;
489 geq->values[VAR_SW] = width / (double)inlink->w;
490 geq->values[VAR_SH] = height / (double)inlink->h;
491
492 td.width = width;
493 td.height = height;
494 td.plane = plane;
495 td.linesize = linesize;
496
497 if (geq->needs_sum[plane])
498 calculate_sums(geq, plane, width, height);
499
501 NULL, FFMIN(height, nb_threads));
502 }
503
504 av_frame_free(&geq->picref);
505 return ff_filter_frame(outlink, out);
506}
507
509{
510 int i;
511 GEQContext *geq = ctx->priv;
512
513 for (i = 0; i < NB_PLANES; i++)
514 for (int j = 0; j < MAX_NB_THREADS; j++)
515 av_expr_free(geq->e[i][j]);
516 for (i = 0; i < NB_PLANES; i++)
517 av_freep(&geq->pixel_sums);
518}
519
520static const AVFilterPad geq_inputs[] = {
521 {
522 .name = "default",
523 .type = AVMEDIA_TYPE_VIDEO,
524 .config_props = geq_config_props,
525 .filter_frame = geq_filter_frame,
526 },
527};
528
530 .p.name = "geq",
531 .p.description = NULL_IF_CONFIG_SMALL("Apply generic equation to each pixel."),
532 .p.priv_class = &geq_class,
534 .priv_size = sizeof(GEQContext),
535 .init = geq_init,
540};
@ VAR_T
Definition aeval.c:53
static int interpolation(DeclickChannel *c, const double *src, int ar_order, double *acoefficients, int *index, int nb_errors, double *auxiliary, double *interpolated)
static double(*const func2[])(void *, double, double)
Definition af_afftfilt.c:99
static const char *const func2_names[]
Definition af_afftfilt.c:98
const FFFilter ff_vf_geq
Definition vf_geq.c:529
#define U(x)
Definition vpx_arith.h:37
#define A(x)
Definition vpx_arith.h:28
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:42
#define V
Definition avdct.c:32
@ VAR_H
Definition avfilter.c:565
@ VAR_W
Definition avfilter.c:564
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition avfilter.c:1696
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition avfilter.c:846
char * av_asprintf(const char *fmt,...)
Definition avstring.c:115
#define Y
Definition boxblur.h:37
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define xi(width, name, var, range_min, range_max, subs,...)
Definition cbs_h264.c:115
#define FLAGS
Definition cmdutils.c:598
#define av_clipd
Definition common.h:148
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define NULL
Definition coverity.c:32
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition eval.c:368
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition eval.c:824
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:735
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:819
simple arithmetic expression evaluator
int ff_set_pixel_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const enum AVPixelFormat *fmts)
Definition formats.c:1162
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
#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:196
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition avfilter.h:166
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define B
Definition huffyuv.h:42
#define R
Definition huffyuv.h:44
#define G
Definition huffyuv.h:43
static const int16_t alpha[]
Definition ilbcdata.h:55
static enum AVPixelFormat rgb_pix_fmts[]
static enum AVPixelFormat yuv_pix_fmts[]
static av_cold void uninit(AVBitStreamFilterContext *ctx)
const char * arg
Definition jacosubdec.c:65
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
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:763
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
@ VAR_SW
Definition vf_blend.c:55
@ VAR_SH
Definition vf_blend.c:55
@ VAR_X
Definition vf_blend.c:55
@ VAR_Y
Definition vf_blend.c:55
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
const char * desc
Definition libsvtav1.c:83
uint8_t w
Definition llvidencdsp.c:39
#define FFMIN(a, b)
Definition macros.h:49
#define NAN
Memory handling functions.
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
Definition mpeg12dec.c:1697
@ VAR_N
Definition noise.c:47
@ VAR_VARS_NB
Definition noise.c:59
static const char *const var_names[]
Definition noise.c:30
#define av_strdup(s)
Definition ops_static.c:55
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_GBRAP12
Definition pixfmt.h:569
#define AV_PIX_FMT_YUV420P16
Definition pixfmt.h:556
#define AV_PIX_FMT_GBRPF32
Definition pixfmt.h:584
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:552
#define AV_PIX_FMT_YUV444P9
Definition pixfmt.h:544
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:545
#define AV_PIX_FMT_GRAY9
Definition pixfmt.h:524
#define AV_PIX_FMT_GBRAP16
Definition pixfmt.h:571
#define AV_PIX_FMT_GBRP9
Definition pixfmt.h:563
#define AV_PIX_FMT_YUV422P9
Definition pixfmt.h:543
#define AV_PIX_FMT_YUVA444P10
Definition pixfmt.h:598
#define AV_PIX_FMT_YUVA420P16
Definition pixfmt.h:601
#define AV_PIX_FMT_YUV420P12
Definition pixfmt.h:549
#define AV_PIX_FMT_YUVA420P10
Definition pixfmt.h:596
#define AV_PIX_FMT_YUVA422P9
Definition pixfmt.h:594
#define AV_PIX_FMT_YUV422P12
Definition pixfmt.h:550
#define AV_PIX_FMT_GBRP10
Definition pixfmt.h:564
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
#define AV_PIX_FMT_GRAY12
Definition pixfmt.h:526
#define AV_PIX_FMT_GBRP12
Definition pixfmt.h:565
#define AV_PIX_FMT_YUV420P9
Definition pixfmt.h:542
#define AV_PIX_FMT_YUVA420P9
Definition pixfmt.h:593
#define AV_PIX_FMT_YUVA422P10
Definition pixfmt.h:597
#define AV_PIX_FMT_GRAYF32
Definition pixfmt.h:588
#define AV_PIX_FMT_YUV420P14
Definition pixfmt.h:553
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ 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_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition pixfmt.h:106
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition pixfmt.h:108
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition pixfmt.h:79
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition pixfmt.h:80
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ 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_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition pixfmt.h:212
@ 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_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165
#define AV_PIX_FMT_YUV422P14
Definition pixfmt.h:554
#define AV_PIX_FMT_GRAY10
Definition pixfmt.h:525
#define AV_PIX_FMT_GRAY14
Definition pixfmt.h:527
#define AV_PIX_FMT_YUV422P16
Definition pixfmt.h:557
#define AV_PIX_FMT_YUV440P10
Definition pixfmt.h:547
#define AV_PIX_FMT_GRAY16
Definition pixfmt.h:528
#define AV_PIX_FMT_GBRAP10
Definition pixfmt.h:568
#define AV_PIX_FMT_YUVA444P16
Definition pixfmt.h:603
#define AV_PIX_FMT_YUVA422P16
Definition pixfmt.h:602
#define AV_PIX_FMT_GBRP16
Definition pixfmt.h:567
#define AV_PIX_FMT_YUV444P14
Definition pixfmt.h:555
#define AV_PIX_FMT_YUVA444P9
Definition pixfmt.h:595
#define AV_PIX_FMT_GBRP14
Definition pixfmt.h:566
#define AV_PIX_FMT_GBRAPF32
Definition pixfmt.h:585
#define AV_PIX_FMT_YUV444P16
Definition pixfmt.h:558
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:548
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
Definition log.h:76
Definition eval.c:171
An instance of a filter.
Definition avfilter.h:273
void * priv
private data for use by the filter
Definition avfilter.h:288
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:285
Lists of formats / etc.
Definition avfilter.h:120
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition frame.h:574
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int width
Definition frame.h:544
int height
Definition frame.h:544
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:517
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
int is_rgb
Definition vf_geq.c:64
AVFrame * picref
current input buffer
Definition vf_geq.c:56
AVExpr * e[NB_PLANES][MAX_NB_THREADS]
expressions for each plane and thread
Definition vf_geq.c:54
int vsub
chroma subsampling
Definition vf_geq.c:61
int needs_sum[NB_PLANES]
Definition vf_geq.c:68
double values[VAR_VARS_NB]
expression values
Definition vf_geq.c:60
uint16_t * dst16
reference pointer to the 16bits output
Definition vf_geq.c:58
uint8_t * dst
reference pointer to the 8bits output
Definition vf_geq.c:57
int planes
number of planes
Definition vf_geq.c:62
int interpolation
Definition vf_geq.c:63
float * dst32
reference pointer to the 32bits output
Definition vf_geq.c:59
int bps
Definition vf_geq.c:65
double * pixel_sums[NB_PLANES]
Definition vf_geq.c:67
int hsub
Definition vf_geq.c:61
char * expr_str[4+3]
expression strings for each plane
Definition vf_geq.c:55
Used for passing data between threads.
Definition dsddec.c:71
int plane
Definition vf_blend.c:61
#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:248
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
#define MAX_NB_THREADS
Definition vf_bm3d.c:45
static double lum(void *priv, double x, double y, int plane)
Definition vf_fftfilt.c:107
static double crsub(void *priv, double x, double y)
Definition vf_geq.c:253
static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition vf_geq.c:400
static av_cold void geq_uninit(AVFilterContext *ctx)
Definition vf_geq.c:508
static double getpix(void *priv, double x, double y, int plane)
Definition vf_geq.c:102
static int calculate_sums(GEQContext *geq, int plane, int w, int h)
Definition vf_geq.c:164
#define MAX_NB_THREADS
Definition vf_geq.c:40
static double alphasum(void *priv, double x, double y)
Definition vf_geq.c:254
static int geq_config_props(AVFilterLink *inlink)
Definition vf_geq.c:379
static double cbsum(void *priv, double x, double y)
Definition vf_geq.c:252
static double getpix_integrate(void *priv, double x, double y, int plane)
Definition vf_geq.c:231
static const AVFilterPad geq_inputs[]
Definition vf_geq.c:520
InterpolationMethods
Definition vf_geq.c:43
@ INTERP_NEAREST
Definition vf_geq.c:44
@ INTERP_BILINEAR
Definition vf_geq.c:45
@ NB_INTERP
Definition vf_geq.c:46
static double getpix_integrate_internal(GEQContext *geq, int x, int y, int plane, int w, int h)
Definition vf_geq.c:212
static double lum(void *priv, double x, double y)
Definition vf_geq.c:246
static double cr(void *priv, double x, double y)
Definition vf_geq.c:248
static int geq_query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition vf_geq.c:339
static double lumsum(void *priv, double x, double y)
Definition vf_geq.c:251
static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition vf_geq.c:456
#define NB_PLANES
Definition vf_geq.c:41
@ VAR_VARS_NB
Definition vf_geq.c:50
#define OFFSET(x)
Definition vf_geq.c:73
static const AVOption geq_options[]
Definition vf_geq.c:76
static av_cold int geq_init(AVFilterContext *ctx)
Definition vf_geq.c:256
static double cb(void *priv, double x, double y)
Definition vf_geq.c:247
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
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition video.c:89
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition dec.c:844