FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_geq.c
Date: 2024-02-16 17:37:06
Exec Total Coverage
Lines: 0 245 0.0%
Functions: 0 18 0.0%
Branches: 0 194 0.0%

Line Branch Exec Source
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 "formats.h"
35 #include "internal.h"
36 #include "video.h"
37
38 #define MAX_NB_THREADS 32
39 #define NB_PLANES 4
40
41 enum InterpolationMethods {
42 INTERP_NEAREST,
43 INTERP_BILINEAR,
44 NB_INTERP
45 };
46
47 static const char *const var_names[] = { "X", "Y", "W", "H", "N", "SW", "SH", "T", NULL };
48 enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_N, VAR_SW, VAR_SH, VAR_T, VAR_VARS_NB };
49
50 typedef struct GEQContext {
51 const AVClass *class;
52 AVExpr *e[NB_PLANES][MAX_NB_THREADS]; ///< expressions for each plane and thread
53 char *expr_str[4+3]; ///< expression strings for each plane
54 AVFrame *picref; ///< current input buffer
55 uint8_t *dst; ///< reference pointer to the 8bits output
56 uint16_t *dst16; ///< reference pointer to the 16bits output
57 float *dst32; ///< reference pointer to the 32bits output
58 double values[VAR_VARS_NB]; ///< expression values
59 int hsub, vsub; ///< chroma subsampling
60 int planes; ///< number of planes
61 int interpolation;
62 int is_rgb;
63 int bps;
64
65 double *pixel_sums[NB_PLANES];
66 int needs_sum[NB_PLANES];
67 } GEQContext;
68
69 enum { Y = 0, U, V, A, G, B, R };
70
71 #define OFFSET(x) offsetof(GEQContext, x)
72 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
73
74 static const AVOption geq_options[] = {
75 { "lum_expr", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
76 { "lum", "set luminance expression", OFFSET(expr_str[Y]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
77 { "cb_expr", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
78 { "cb", "set chroma blue expression", OFFSET(expr_str[U]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
79 { "cr_expr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
80 { "cr", "set chroma red expression", OFFSET(expr_str[V]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
81 { "alpha_expr", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
82 { "a", "set alpha expression", OFFSET(expr_str[A]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
83 { "red_expr", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
84 { "r", "set red expression", OFFSET(expr_str[R]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
85 { "green_expr", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
86 { "g", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
87 { "blue_expr", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
88 { "b", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
89 { "interpolation","set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, .unit = "interp" },
90 { "i", "set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, .unit = "interp" },
91 { "nearest", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, .unit = "interp" },
92 { "n", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, .unit = "interp" },
93 { "bilinear", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, .unit = "interp" },
94 { "b", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, .unit = "interp" },
95 {NULL},
96 };
97
98 AVFILTER_DEFINE_CLASS(geq);
99
100 static inline double getpix(void *priv, double x, double y, int plane)
101 {
102 int xi, yi;
103 GEQContext *geq = priv;
104 AVFrame *picref = geq->picref;
105 const uint8_t *src = picref->data[plane];
106 int linesize = picref->linesize[plane];
107 const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width;
108 const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height;
109
110 if (!src)
111 return 0;
112
113 if (geq->interpolation == INTERP_BILINEAR) {
114 xi = x = av_clipd(x, 0, w - 2);
115 yi = y = av_clipd(y, 0, h - 2);
116
117 x -= xi;
118 y -= yi;
119
120 if (geq->bps > 8 && geq->bps <= 16) {
121 const uint16_t *src16 = (const uint16_t*)src;
122 linesize /= 2;
123
124 return (1-y)*((1-x)*src16[xi + yi * linesize] + x*src16[xi + 1 + yi * linesize])
125 + y *((1-x)*src16[xi + (yi+1) * linesize] + x*src16[xi + 1 + (yi+1) * linesize]);
126 } else if (geq->bps == 32) {
127 const float *src32 = (const float*)src;
128 linesize /= 4;
129
130 return (1-y)*((1-x)*src32[xi + yi * linesize] + x*src32[xi + 1 + yi * linesize])
131 + y *((1-x)*src32[xi + (yi+1) * linesize] + x*src32[xi + 1 + (yi+1) * linesize]);
132 } else if (geq->bps == 8) {
133 return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xi + 1 + yi * linesize])
134 + y *((1-x)*src[xi + (yi+1) * linesize] + x*src[xi + 1 + (yi+1) * linesize]);
135 }
136 } else {
137 xi = av_clipd(x, 0, w - 1);
138 yi = av_clipd(y, 0, h - 1);
139
140 if (geq->bps > 8 && geq->bps <= 16) {
141 const uint16_t *src16 = (const uint16_t*)src;
142 linesize /= 2;
143
144 return src16[xi + yi * linesize];
145 } else if (geq->bps == 32) {
146 const float *src32 = (const float*)src;
147 linesize /= 4;
148
149 return src32[xi + yi * linesize];
150 } else if (geq->bps == 8) {
151 return src[xi + yi * linesize];
152 }
153 }
154
155 return 0;
156 }
157
158 static int calculate_sums(GEQContext *geq, int plane, int w, int h)
159 {
160 int xi, yi;
161 AVFrame *picref = geq->picref;
162 const uint8_t *src = picref->data[plane];
163 int linesize = picref->linesize[plane];
164
165 if (!geq->pixel_sums[plane])
166 geq->pixel_sums[plane] = av_malloc_array(w, h * sizeof (*geq->pixel_sums[plane]));
167 if (!geq->pixel_sums[plane])
168 return AVERROR(ENOMEM);
169 if (geq->bps == 32)
170 linesize /= 4;
171 else if (geq->bps > 8 && geq->bps <= 16)
172 linesize /= 2;
173 for (yi = 0; yi < h; yi ++) {
174 if (geq->bps > 8 && geq->bps <= 16) {
175 const uint16_t *src16 = (const uint16_t*)src;
176 double linesum = 0;
177
178 for (xi = 0; xi < w; xi ++) {
179 linesum += src16[xi + yi * linesize];
180 geq->pixel_sums[plane][xi + yi * w] = linesum;
181 }
182 } else if (geq->bps == 8) {
183 double linesum = 0;
184
185 for (xi = 0; xi < w; xi ++) {
186 linesum += src[xi + yi * linesize];
187 geq->pixel_sums[plane][xi + yi * w] = linesum;
188 }
189 } else if (geq->bps == 32) {
190 const float *src32 = (const float*)src;
191 double linesum = 0;
192
193 for (xi = 0; xi < w; xi ++) {
194 linesum += src32[xi + yi * linesize];
195 geq->pixel_sums[plane][xi + yi * w] = linesum;
196 }
197 }
198 if (yi)
199 for (xi = 0; xi < w; xi ++) {
200 geq->pixel_sums[plane][xi + yi * w] += geq->pixel_sums[plane][xi + yi * w - w];
201 }
202 }
203 return 0;
204 }
205
206 static inline double getpix_integrate_internal(GEQContext *geq, int x, int y, int plane, int w, int h)
207 {
208 if (x > w - 1) {
209 double boundary = getpix_integrate_internal(geq, w - 1, y, plane, w, h);
210 return 2*boundary - getpix_integrate_internal(geq, 2*(w - 1) - x, y, plane, w, h);
211 } else if (y > h - 1) {
212 double boundary = getpix_integrate_internal(geq, x, h - 1, plane, w, h);
213 return 2*boundary - getpix_integrate_internal(geq, x, 2*(h - 1) - y, plane, w, h);
214 } else if (x < 0) {
215 if (x == -1) return 0;
216 return - getpix_integrate_internal(geq, -x-2, y, plane, w, h);
217 } else if (y < 0) {
218 if (y == -1) return 0;
219 return - getpix_integrate_internal(geq, x, -y-2, plane, w, h);
220 }
221
222 return geq->pixel_sums[plane][x + y * w];
223 }
224
225 static inline double getpix_integrate(void *priv, double x, double y, int plane) {
226 GEQContext *geq = priv;
227 AVFrame *picref = geq->picref;
228 const uint8_t *src = picref->data[plane];
229 const int w = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->width, geq->hsub) : picref->width;
230 const int h = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(picref->height, geq->vsub) : picref->height;
231
232 if (!src)
233 return 0;
234
235 return getpix_integrate_internal(geq, lrint(av_clipd(x, -w, 2*w)), lrint(av_clipd(y, -h, 2*h)), plane, w, h);
236 }
237
238 //TODO: cubic interpolate
239 //TODO: keep the last few frames
240 static double lum(void *priv, double x, double y) { return getpix(priv, x, y, 0); }
241 static double cb(void *priv, double x, double y) { return getpix(priv, x, y, 1); }
242 static double cr(void *priv, double x, double y) { return getpix(priv, x, y, 2); }
243 static double alpha(void *priv, double x, double y) { return getpix(priv, x, y, 3); }
244
245 static double lumsum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 0); }
246 static double cbsum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 1); }
247 static double crsub(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 2); }
248 static double alphasum(void *priv, double x, double y) { return getpix_integrate(priv, x, y, 3); }
249
250 static av_cold int geq_init(AVFilterContext *ctx)
251 {
252 GEQContext *geq = ctx->priv;
253 int plane, ret = 0;
254
255 if (!geq->expr_str[Y] && !geq->expr_str[G] && !geq->expr_str[B] && !geq->expr_str[R]) {
256 av_log(ctx, AV_LOG_ERROR, "A luminance or RGB expression is mandatory\n");
257 ret = AVERROR(EINVAL);
258 goto end;
259 }
260 geq->is_rgb = !geq->expr_str[Y];
261
262 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])) {
263 av_log(ctx, AV_LOG_ERROR, "Either YCbCr or RGB but not both must be specified\n");
264 ret = AVERROR(EINVAL);
265 goto end;
266 }
267
268 if (!geq->expr_str[U] && !geq->expr_str[V]) {
269 /* No chroma at all: fallback on luma */
270 geq->expr_str[U] = av_strdup(geq->expr_str[Y]);
271 geq->expr_str[V] = av_strdup(geq->expr_str[Y]);
272 } else {
273 /* One chroma unspecified, fallback on the other */
274 if (!geq->expr_str[U]) geq->expr_str[U] = av_strdup(geq->expr_str[V]);
275 if (!geq->expr_str[V]) geq->expr_str[V] = av_strdup(geq->expr_str[U]);
276 }
277
278 if (!geq->expr_str[A] && geq->bps != 32) {
279 geq->expr_str[A] = av_asprintf("%d", (1<<geq->bps) - 1);
280 } else if (!geq->expr_str[A]) {
281 geq->expr_str[A] = av_asprintf("%f", 1.f);
282 }
283 if (!geq->expr_str[G])
284 geq->expr_str[G] = av_strdup("g(X,Y)");
285 if (!geq->expr_str[B])
286 geq->expr_str[B] = av_strdup("b(X,Y)");
287 if (!geq->expr_str[R])
288 geq->expr_str[R] = av_strdup("r(X,Y)");
289
290 if (geq->is_rgb ?
291 (!geq->expr_str[G] || !geq->expr_str[B] || !geq->expr_str[R])
292 :
293 (!geq->expr_str[U] || !geq->expr_str[V] || !geq->expr_str[A])) {
294 ret = AVERROR(ENOMEM);
295 goto end;
296 }
297
298 for (plane = 0; plane < NB_PLANES; plane++) {
299 static double (*const p[])(void *, double, double) = {
300 lum , cb , cr , alpha ,
301 lumsum, cbsum, crsub, alphasum,
302 };
303 static const char *const func2_yuv_names[] = {
304 "lum" , "cb" , "cr" , "alpha" , "p",
305 "lumsum", "cbsum", "crsum", "alphasum", "psum",
306 NULL };
307 static const char *const func2_rgb_names[] = {
308 "g" , "b" , "r" , "alpha" , "p",
309 "gsum", "bsum", "rsum", "alphasum", "psum",
310 NULL };
311 const char *const *func2_names = geq->is_rgb ? func2_rgb_names : func2_yuv_names;
312 double (*const func2[])(void *, double, double) = {
313 lum , cb , cr , alpha , p[plane],
314 lumsum, cbsum, crsub, alphasum, p[plane + 4],
315 NULL };
316 int counter[10] = {0};
317
318 for (int i = 0; i < MAX_NB_THREADS; i++) {
319 ret = av_expr_parse(&geq->e[plane][i], geq->expr_str[plane < 3 && geq->is_rgb ? plane+4 : plane], var_names,
320 NULL, NULL, func2_names, func2, 0, ctx);
321 if (ret < 0)
322 goto end;
323 }
324
325 av_expr_count_func(geq->e[plane][0], counter, FF_ARRAY_ELEMS(counter), 2);
326 geq->needs_sum[plane] = counter[5] + counter[6] + counter[7] + counter[8] + counter[9];
327 }
328
329 end:
330 return ret;
331 }
332
333 static int geq_query_formats(AVFilterContext *ctx)
334 {
335 GEQContext *geq = ctx->priv;
336 static const enum AVPixelFormat yuv_pix_fmts[] = {
337 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
338 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P,
339 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
340 AV_PIX_FMT_GRAY8,
341 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV420P9,
342 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA420P9,
343 AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10,
344 AV_PIX_FMT_YUV440P10,
345 AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA420P10,
346 AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10,
347 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12,
348 AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14,
349 AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV420P14,
350 AV_PIX_FMT_YUV444P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV420P16,
351 AV_PIX_FMT_YUVA444P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA420P16,
352 AV_PIX_FMT_GRAY16,
353 AV_PIX_FMT_GRAYF32,
354 AV_PIX_FMT_NONE
355 };
356 static const enum AVPixelFormat rgb_pix_fmts[] = {
357 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
358 AV_PIX_FMT_GBRP9,
359 AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10,
360 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
361 AV_PIX_FMT_GBRP14,
362 AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16,
363 AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32,
364 AV_PIX_FMT_NONE
365 };
366 const enum AVPixelFormat *pix_fmts = geq->is_rgb ? rgb_pix_fmts : yuv_pix_fmts;
367
368 return ff_set_common_formats_from_list(ctx, pix_fmts);
369 }
370
371 static int geq_config_props(AVFilterLink *inlink)
372 {
373 GEQContext *geq = inlink->dst->priv;
374 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
375
376 av_assert0(desc);
377
378 geq->hsub = desc->log2_chroma_w;
379 geq->vsub = desc->log2_chroma_h;
380 geq->bps = desc->comp[0].depth;
381 geq->planes = desc->nb_components;
382 return 0;
383 }
384
385 typedef struct ThreadData {
386 int height;
387 int width;
388 int plane;
389 int linesize;
390 } ThreadData;
391
392 static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
393 {
394 GEQContext *geq = ctx->priv;
395 ThreadData *td = arg;
396 const int height = td->height;
397 const int width = td->width;
398 const int plane = td->plane;
399 const int linesize = td->linesize;
400 const int slice_start = (height * jobnr) / nb_jobs;
401 const int slice_end = (height * (jobnr+1)) / nb_jobs;
402 int x, y;
403
404 double values[VAR_VARS_NB];
405 values[VAR_W] = geq->values[VAR_W];
406 values[VAR_H] = geq->values[VAR_H];
407 values[VAR_N] = geq->values[VAR_N];
408 values[VAR_SW] = geq->values[VAR_SW];
409 values[VAR_SH] = geq->values[VAR_SH];
410 values[VAR_T] = geq->values[VAR_T];
411
412 if (geq->bps == 8) {
413 uint8_t *ptr = geq->dst + linesize * slice_start;
414 for (y = slice_start; y < slice_end; y++) {
415 values[VAR_Y] = y;
416
417 for (x = 0; x < width; x++) {
418 values[VAR_X] = x;
419 ptr[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
420 }
421 ptr += linesize;
422 }
423 } else if (geq->bps <= 16) {
424 uint16_t *ptr16 = geq->dst16 + (linesize/2) * slice_start;
425 for (y = slice_start; y < slice_end; y++) {
426 values[VAR_Y] = y;
427 for (x = 0; x < width; x++) {
428 values[VAR_X] = x;
429 ptr16[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
430 }
431 ptr16 += linesize/2;
432 }
433 } else {
434 float *ptr32 = geq->dst32 + (linesize/4) * slice_start;
435 for (y = slice_start; y < slice_end; y++) {
436 values[VAR_Y] = y;
437 for (x = 0; x < width; x++) {
438 values[VAR_X] = x;
439 ptr32[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
440 }
441 ptr32 += linesize/4;
442 }
443 }
444
445 return 0;
446 }
447
448 static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
449 {
450 int plane;
451 AVFilterContext *ctx = inlink->dst;
452 const int nb_threads = FFMIN(MAX_NB_THREADS, ff_filter_get_nb_threads(ctx));
453 GEQContext *geq = ctx->priv;
454 AVFilterLink *outlink = inlink->dst->outputs[0];
455 AVFrame *out;
456
457 geq->values[VAR_N] = inlink->frame_count_out,
458 geq->values[VAR_T] = in->pts == AV_NOPTS_VALUE ? NAN : in->pts * av_q2d(inlink->time_base),
459
460 geq->picref = in;
461 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
462 if (!out) {
463 av_frame_free(&in);
464 return AVERROR(ENOMEM);
465 }
466 av_frame_copy_props(out, in);
467
468 for (plane = 0; plane < geq->planes && out->data[plane]; plane++) {
469 const int width = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->w, geq->hsub) : inlink->w;
470 const int height = (plane == 1 || plane == 2) ? AV_CEIL_RSHIFT(inlink->h, geq->vsub) : inlink->h;
471 const int linesize = out->linesize[plane];
472 ThreadData td;
473
474 geq->dst = out->data[plane];
475 geq->dst16 = (uint16_t*)out->data[plane];
476 geq->dst32 = (float*)out->data[plane];
477
478 geq->values[VAR_W] = width;
479 geq->values[VAR_H] = height;
480 geq->values[VAR_SW] = width / (double)inlink->w;
481 geq->values[VAR_SH] = height / (double)inlink->h;
482
483 td.width = width;
484 td.height = height;
485 td.plane = plane;
486 td.linesize = linesize;
487
488 if (geq->needs_sum[plane])
489 calculate_sums(geq, plane, width, height);
490
491 ff_filter_execute(ctx, slice_geq_filter, &td,
492 NULL, FFMIN(height, nb_threads));
493 }
494
495 av_frame_free(&geq->picref);
496 return ff_filter_frame(outlink, out);
497 }
498
499 static av_cold void geq_uninit(AVFilterContext *ctx)
500 {
501 int i;
502 GEQContext *geq = ctx->priv;
503
504 for (i = 0; i < NB_PLANES; i++)
505 for (int j = 0; j < MAX_NB_THREADS; j++)
506 av_expr_free(geq->e[i][j]);
507 for (i = 0; i < NB_PLANES; i++)
508 av_freep(&geq->pixel_sums);
509 }
510
511 static const AVFilterPad geq_inputs[] = {
512 {
513 .name = "default",
514 .type = AVMEDIA_TYPE_VIDEO,
515 .config_props = geq_config_props,
516 .filter_frame = geq_filter_frame,
517 },
518 };
519
520 const AVFilter ff_vf_geq = {
521 .name = "geq",
522 .description = NULL_IF_CONFIG_SMALL("Apply generic equation to each pixel."),
523 .priv_size = sizeof(GEQContext),
524 .init = geq_init,
525 .uninit = geq_uninit,
526 FILTER_INPUTS(geq_inputs),
527 FILTER_OUTPUTS(ff_video_default_filterpad),
528 FILTER_QUERY_FUNC(geq_query_formats),
529 .priv_class = &geq_class,
530 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
531 };
532