FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_fftfilt.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 0 290 0.0%
Branches: 0 132 0.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2015 Arwa Arif <arwaarif1994@gmail.com>
3 * Copyright (c) 2017 Paul B Mahol
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; either version 2.1 of the License,
10 * 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 * FFT domain filtering.
25 */
26
27 #include "libavfilter/internal.h"
28 #include "libavutil/common.h"
29 #include "libavutil/cpu.h"
30 #include "libavutil/imgutils.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/pixdesc.h"
33 #include "libavutil/tx.h"
34 #include "libavutil/eval.h"
35
36 #define MAX_THREADS 32
37 #define MAX_PLANES 4
38
39 enum EvalMode {
40 EVAL_MODE_INIT,
41 EVAL_MODE_FRAME,
42 EVAL_MODE_NB
43 };
44
45 typedef struct FFTFILTContext {
46 const AVClass *class;
47
48 int eval_mode;
49 int depth;
50 int nb_planes;
51 int nb_threads;
52 int planewidth[MAX_PLANES];
53 int planeheight[MAX_PLANES];
54
55 AVTXContext *hrdft[MAX_THREADS][MAX_PLANES];
56 AVTXContext *vrdft[MAX_THREADS][MAX_PLANES];
57 AVTXContext *ihrdft[MAX_THREADS][MAX_PLANES];
58 AVTXContext *ivrdft[MAX_THREADS][MAX_PLANES];
59
60 av_tx_fn htx_fn, ihtx_fn;
61 av_tx_fn vtx_fn, ivtx_fn;
62
63 int rdft_hbits[MAX_PLANES];
64 int rdft_vbits[MAX_PLANES];
65 size_t rdft_hstride[MAX_PLANES];
66 size_t rdft_vstride[MAX_PLANES];
67 size_t rdft_hlen[MAX_PLANES];
68 size_t rdft_vlen[MAX_PLANES];
69 float *rdft_hdata_in[MAX_PLANES];
70 float *rdft_vdata_in[MAX_PLANES];
71 float *rdft_hdata_out[MAX_PLANES];
72 float *rdft_vdata_out[MAX_PLANES];
73
74 int dc[MAX_PLANES];
75 char *weight_str[MAX_PLANES];
76 AVExpr *weight_expr[MAX_PLANES];
77 double *weight[MAX_PLANES];
78
79 int (*rdft_horizontal)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
80 int (*irdft_horizontal)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
81 } FFTFILTContext;
82
83 static const char *const var_names[] = { "X", "Y", "W", "H", "N", "WS", "HS", NULL };
84 enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_N, VAR_WS, VAR_HS, VAR_VARS_NB };
85
86 enum { Y = 0, U, V };
87
88 #define OFFSET(x) offsetof(FFTFILTContext, x)
89 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
90
91 static const AVOption fftfilt_options[] = {
92 { "dc_Y", "adjust gain in Y plane", OFFSET(dc[Y]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
93 { "dc_U", "adjust gain in U plane", OFFSET(dc[U]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
94 { "dc_V", "adjust gain in V plane", OFFSET(dc[V]), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1000, FLAGS },
95 { "weight_Y", "set luminance expression in Y plane", OFFSET(weight_str[Y]), AV_OPT_TYPE_STRING, {.str = "1"}, 0, 0, FLAGS },
96 { "weight_U", "set chrominance expression in U plane", OFFSET(weight_str[U]), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
97 { "weight_V", "set chrominance expression in V plane", OFFSET(weight_str[V]), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
98 { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_INIT}, 0, EVAL_MODE_NB-1, FLAGS, "eval" },
99 { "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags = FLAGS, .unit = "eval" },
100 { "frame", "eval expressions per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" },
101 {NULL},
102 };
103
104 AVFILTER_DEFINE_CLASS(fftfilt);
105
106 static inline double lum(void *priv, double x, double y, int plane)
107 {
108 FFTFILTContext *s = priv;
109 return s->rdft_vdata_out[plane][(int)x * s->rdft_vstride[plane] + (int)y];
110 }
111
112 static double weight_Y(void *priv, double x, double y) { return lum(priv, x, y, Y); }
113 static double weight_U(void *priv, double x, double y) { return lum(priv, x, y, U); }
114 static double weight_V(void *priv, double x, double y) { return lum(priv, x, y, V); }
115
116 static void copy_rev(float *dest, int w, int w2)
117 {
118 int i;
119
120 for (i = w; i < w + (w2-w)/2; i++)
121 dest[i] = dest[2*w - i - 1];
122
123 for (; i < w2; i++)
124 dest[i] = dest[w2 - i];
125 }
126
127 static int rdft_horizontal8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
128 {
129 FFTFILTContext *s = ctx->priv;
130 AVFrame *in = arg;
131
132 for (int plane = 0; plane < s->nb_planes; plane++) {
133 const int w = s->planewidth[plane];
134 const int h = s->planeheight[plane];
135 const int slice_start = (h * jobnr) / nb_jobs;
136 const int slice_end = (h * (jobnr+1)) / nb_jobs;
137
138 for (int i = slice_start; i < slice_end; i++) {
139 const uint8_t *src = in->data[plane] + i * in->linesize[plane];
140 float *hdata_in = s->rdft_hdata_in[plane] + i * s->rdft_hstride[plane];
141
142 for (int j = 0; j < w; j++)
143 hdata_in[j] = src[j];
144
145 copy_rev(s->rdft_hdata_in[plane] + i * s->rdft_hstride[plane], w, s->rdft_hlen[plane]);
146 }
147
148 for (int i = slice_start; i < slice_end; i++)
149 s->htx_fn(s->hrdft[jobnr][plane],
150 s->rdft_hdata_out[plane] + i * s->rdft_hstride[plane],
151 s->rdft_hdata_in[plane] + i * s->rdft_hstride[plane],
152 sizeof(float));
153 }
154
155 return 0;
156 }
157
158 static int rdft_horizontal16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
159 {
160 FFTFILTContext *s = ctx->priv;
161 AVFrame *in = arg;
162
163 for (int plane = 0; plane < s->nb_planes; plane++) {
164 const int w = s->planewidth[plane];
165 const int h = s->planeheight[plane];
166 const int slice_start = (h * jobnr) / nb_jobs;
167 const int slice_end = (h * (jobnr+1)) / nb_jobs;
168
169 for (int i = slice_start; i < slice_end; i++) {
170 const uint16_t *src = (const uint16_t *)(in->data[plane] + i * in->linesize[plane]);
171 float *hdata_in = s->rdft_hdata_in[plane] + i * s->rdft_hstride[plane];
172
173 for (int j = 0; j < w; j++)
174 hdata_in[j] = src[j];
175
176 copy_rev(s->rdft_hdata_in[plane] + i * s->rdft_hstride[plane], w, s->rdft_hlen[plane]);
177 }
178
179 for (int i = slice_start; i < slice_end; i++)
180 s->htx_fn(s->hrdft[jobnr][plane],
181 s->rdft_hdata_out[plane] + i * s->rdft_hstride[plane],
182 s->rdft_hdata_in[plane] + i * s->rdft_hstride[plane],
183 sizeof(float));
184 }
185
186 return 0;
187 }
188
189 static int irdft_horizontal8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
190 {
191 FFTFILTContext *s = ctx->priv;
192 AVFrame *out = arg;
193
194 for (int plane = 0; plane < s->nb_planes; plane++) {
195 const int w = s->planewidth[plane];
196 const int h = s->planeheight[plane];
197 const int slice_start = (h * jobnr) / nb_jobs;
198 const int slice_end = (h * (jobnr+1)) / nb_jobs;
199
200 for (int i = slice_start; i < slice_end; i++)
201 s->ihtx_fn(s->ihrdft[jobnr][plane],
202 s->rdft_hdata_out[plane] + i * s->rdft_hstride[plane],
203 s->rdft_hdata_in[plane] + i * s->rdft_hstride[plane],
204 sizeof(AVComplexFloat));
205
206 for (int i = slice_start; i < slice_end; i++) {
207 const float scale = 1.f / (s->rdft_hlen[plane] * s->rdft_vlen[plane]);
208 const float *src = s->rdft_hdata_out[plane] + i * s->rdft_hstride[plane];
209 uint8_t *dst = out->data[plane] + i * out->linesize[plane];
210
211 for (int j = 0; j < w; j++)
212 dst[j] = av_clip_uint8(lrintf(src[j] * scale));
213 }
214 }
215
216 return 0;
217 }
218
219 static int irdft_horizontal16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
220 {
221 FFTFILTContext *s = ctx->priv;
222 AVFrame *out = arg;
223
224 for (int plane = 0; plane < s->nb_planes; plane++) {
225 int max = (1 << s->depth) - 1;
226 const int w = s->planewidth[plane];
227 const int h = s->planeheight[plane];
228 const int slice_start = (h * jobnr) / nb_jobs;
229 const int slice_end = (h * (jobnr+1)) / nb_jobs;
230
231 for (int i = slice_start; i < slice_end; i++)
232 s->ihtx_fn(s->ihrdft[jobnr][plane],
233 s->rdft_hdata_out[plane] + i * s->rdft_hstride[plane],
234 s->rdft_hdata_in[plane] + i * s->rdft_hstride[plane],
235 sizeof(AVComplexFloat));
236
237 for (int i = slice_start; i < slice_end; i++) {
238 const float scale = 1.f / (s->rdft_hlen[plane] * s->rdft_vlen[plane]);
239 const float *src = s->rdft_hdata_out[plane] + i * s->rdft_hstride[plane];
240 uint16_t *dst = (uint16_t *)(out->data[plane] + i * out->linesize[plane]);
241
242 for (int j = 0; j < w; j++)
243 dst[j] = av_clip(lrintf(src[j] * scale), 0, max);
244 }
245 }
246
247 return 0;
248 }
249
250 static av_cold int initialize(AVFilterContext *ctx)
251 {
252 FFTFILTContext *s = ctx->priv;
253 int ret = 0, plane;
254
255 if (!s->dc[U] && !s->dc[V]) {
256 s->dc[U] = s->dc[Y];
257 s->dc[V] = s->dc[Y];
258 } else {
259 if (!s->dc[U]) s->dc[U] = s->dc[V];
260 if (!s->dc[V]) s->dc[V] = s->dc[U];
261 }
262
263 if (!s->weight_str[U] && !s->weight_str[V]) {
264 s->weight_str[U] = av_strdup(s->weight_str[Y]);
265 s->weight_str[V] = av_strdup(s->weight_str[Y]);
266 } else {
267 if (!s->weight_str[U]) s->weight_str[U] = av_strdup(s->weight_str[V]);
268 if (!s->weight_str[V]) s->weight_str[V] = av_strdup(s->weight_str[U]);
269 }
270
271 for (plane = 0; plane < 3; plane++) {
272 static double (*p[])(void *, double, double) = { weight_Y, weight_U, weight_V };
273 const char *const func2_names[] = {"weight_Y", "weight_U", "weight_V", NULL };
274 double (*func2[])(void *, double, double) = { weight_Y, weight_U, weight_V, p[plane], NULL };
275
276 ret = av_expr_parse(&s->weight_expr[plane], s->weight_str[plane], var_names,
277 NULL, NULL, func2_names, func2, 0, ctx);
278 if (ret < 0)
279 break;
280 }
281 return ret;
282 }
283
284 static void do_eval(FFTFILTContext *s, AVFilterLink *inlink, int plane)
285 {
286 double values[VAR_VARS_NB];
287 int i, j;
288
289 values[VAR_N] = inlink->frame_count_out;
290 values[VAR_W] = s->planewidth[plane];
291 values[VAR_H] = s->planeheight[plane];
292 values[VAR_WS] = s->rdft_hlen[plane];
293 values[VAR_HS] = s->rdft_vlen[plane];
294
295 for (i = 0; i < s->rdft_hlen[plane]; i++) {
296 values[VAR_X] = i;
297 for (j = 0; j < s->rdft_vlen[plane]; j++) {
298 values[VAR_Y] = j;
299 s->weight[plane][i * s->rdft_vlen[plane] + j] =
300 av_expr_eval(s->weight_expr[plane], values, s);
301 }
302 }
303 }
304
305 static int config_props(AVFilterLink *inlink)
306 {
307 FFTFILTContext *s = inlink->dst->priv;
308 const AVPixFmtDescriptor *desc;
309 int ret, i, plane;
310
311 desc = av_pix_fmt_desc_get(inlink->format);
312 s->depth = desc->comp[0].depth;
313 s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
314 s->planewidth[0] = s->planewidth[3] = inlink->w;
315 s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
316 s->planeheight[0] = s->planeheight[3] = inlink->h;
317
318 s->nb_planes = av_pix_fmt_count_planes(inlink->format);
319 s->nb_threads = FFMIN(32, ff_filter_get_nb_threads(inlink->dst));
320
321 for (i = 0; i < desc->nb_components; i++) {
322 int w = s->planewidth[i];
323 int h = s->planeheight[i];
324
325 /* RDFT - Array initialization for Horizontal pass*/
326 s->rdft_hlen[i] = 1 << (32 - ff_clz(w));
327 s->rdft_hstride[i] = FFALIGN(s->rdft_hlen[i] + 2, av_cpu_max_align());
328 s->rdft_hbits[i] = av_log2(s->rdft_hlen[i]);
329 if (!(s->rdft_hdata_in[i] = av_calloc(h, s->rdft_hstride[i] * sizeof(float))))
330 return AVERROR(ENOMEM);
331
332 if (!(s->rdft_hdata_out[i] = av_calloc(h, s->rdft_hstride[i] * sizeof(float))))
333 return AVERROR(ENOMEM);
334
335 for (int j = 0; j < s->nb_threads; j++) {
336 float scale = 1.f, iscale = 1.f;
337
338 ret = av_tx_init(&s->hrdft[j][i], &s->htx_fn, AV_TX_FLOAT_RDFT,
339 0, 1 << s->rdft_hbits[i], &scale, 0);
340 if (ret < 0)
341 return ret;
342 ret = av_tx_init(&s->ihrdft[j][i], &s->ihtx_fn, AV_TX_FLOAT_RDFT,
343 1, 1 << s->rdft_hbits[i], &iscale, 0);
344 if (ret < 0)
345 return ret;
346 }
347
348 /* RDFT - Array initialization for Vertical pass*/
349 s->rdft_vlen[i] = 1 << (32 - ff_clz(h));
350 s->rdft_vstride[i] = FFALIGN(s->rdft_vlen[i] + 2, av_cpu_max_align());
351 s->rdft_vbits[i] = av_log2(s->rdft_vlen[i]);
352 if (!(s->rdft_vdata_in[i] = av_calloc(s->rdft_hstride[i], s->rdft_vstride[i] * sizeof(float))))
353 return AVERROR(ENOMEM);
354
355 if (!(s->rdft_vdata_out[i] = av_calloc(s->rdft_hstride[i], s->rdft_vstride[i] * sizeof(float))))
356 return AVERROR(ENOMEM);
357
358 for (int j = 0; j < s->nb_threads; j++) {
359 float scale = 1.f, iscale = 1.f;
360
361 ret = av_tx_init(&s->vrdft[j][i], &s->vtx_fn, AV_TX_FLOAT_RDFT,
362 0, 1 << s->rdft_vbits[i], &scale, 0);
363 if (ret < 0)
364 return ret;
365 ret = av_tx_init(&s->ivrdft[j][i], &s->ivtx_fn, AV_TX_FLOAT_RDFT,
366 1, 1 << s->rdft_vbits[i], &iscale, 0);
367 if (ret < 0)
368 return ret;
369 }
370 }
371
372 /*Luminance value - Array initialization*/
373 for (plane = 0; plane < 3; plane++) {
374 if(!(s->weight[plane] = av_calloc(s->rdft_hlen[plane], s->rdft_vlen[plane] * sizeof(double))))
375 return AVERROR(ENOMEM);
376
377 if (s->eval_mode == EVAL_MODE_INIT)
378 do_eval(s, inlink, plane);
379 }
380
381 if (s->depth <= 8) {
382 s->rdft_horizontal = rdft_horizontal8;
383 s->irdft_horizontal = irdft_horizontal8;
384 } else if (s->depth > 8) {
385 s->rdft_horizontal = rdft_horizontal16;
386 s->irdft_horizontal = irdft_horizontal16;
387 } else {
388 return AVERROR_BUG;
389 }
390 return 0;
391 }
392
393 static int multiply_data(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
394 {
395 FFTFILTContext *s = ctx->priv;
396
397 for (int plane = 0; plane < s->nb_planes; plane++) {
398 const int height = s->rdft_hlen[plane];
399 const int slice_start = (height * jobnr) / nb_jobs;
400 const int slice_end = (height * (jobnr+1)) / nb_jobs;
401 /*Change user defined parameters*/
402 for (int i = slice_start; i < slice_end; i++) {
403 const double *weight = s->weight[plane] + i * s->rdft_vlen[plane];
404 float *vdata = s->rdft_vdata_out[plane] + i * s->rdft_vstride[plane];
405
406 for (int j = 0; j < s->rdft_vlen[plane]; j++)
407 vdata[j] *= weight[j];
408 }
409 }
410
411 return 0;
412 }
413
414 static int copy_vertical(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
415 {
416 FFTFILTContext *s = ctx->priv;
417
418 for (int plane = 0; plane < s->nb_planes; plane++) {
419 const int hlen = s->rdft_hlen[plane];
420 const int vlen = s->rdft_vlen[plane];
421 const int hstride = s->rdft_hstride[plane];
422 const int vstride = s->rdft_vstride[plane];
423 const int slice_start = (hlen * jobnr) / nb_jobs;
424 const int slice_end = (hlen * (jobnr+1)) / nb_jobs;
425 const int h = s->planeheight[plane];
426 float *hdata = s->rdft_hdata_out[plane];
427 float *vdata = s->rdft_vdata_in[plane];
428
429 for (int i = slice_start; i < slice_end; i++) {
430 for (int j = 0; j < h; j++)
431 vdata[i * vstride + j] = hdata[j * hstride + i];
432 copy_rev(vdata + i * vstride, h, vlen);
433 }
434 }
435
436 return 0;
437 }
438
439 static int rdft_vertical(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
440 {
441 FFTFILTContext *s = ctx->priv;
442
443 for (int plane = 0; plane < s->nb_planes; plane++) {
444 const int height = s->rdft_hlen[plane];
445 const int slice_start = (height * jobnr) / nb_jobs;
446 const int slice_end = (height * (jobnr+1)) / nb_jobs;
447
448 for (int i = slice_start; i < slice_end; i++)
449 s->vtx_fn(s->vrdft[jobnr][plane],
450 s->rdft_vdata_out[plane] + i * s->rdft_vstride[plane],
451 s->rdft_vdata_in[plane] + i * s->rdft_vstride[plane],
452 sizeof(float));
453 }
454
455 return 0;
456 }
457
458 static int irdft_vertical(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
459 {
460 FFTFILTContext *s = ctx->priv;
461
462 for (int plane = 0; plane < s->nb_planes; plane++) {
463 const int height = s->rdft_hlen[plane];
464 const int slice_start = (height * jobnr) / nb_jobs;
465 const int slice_end = (height * (jobnr+1)) / nb_jobs;
466
467 for (int i = slice_start; i < slice_end; i++)
468 s->ivtx_fn(s->ivrdft[jobnr][plane],
469 s->rdft_vdata_in[plane] + i * s->rdft_vstride[plane],
470 s->rdft_vdata_out[plane] + i * s->rdft_vstride[plane],
471 sizeof(AVComplexFloat));
472 }
473
474 return 0;
475 }
476
477 static int copy_horizontal(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
478 {
479 FFTFILTContext *s = ctx->priv;
480
481 for (int plane = 0; plane < s->nb_planes; plane++) {
482 const int hlen = s->rdft_hlen[plane];
483 const int hstride = s->rdft_hstride[plane];
484 const int vstride = s->rdft_vstride[plane];
485 const int slice_start = (hlen * jobnr) / nb_jobs;
486 const int slice_end = (hlen * (jobnr+1)) / nb_jobs;
487 const int h = s->planeheight[plane];
488 float *hdata = s->rdft_hdata_in[plane];
489 float *vdata = s->rdft_vdata_in[plane];
490
491 for (int i = slice_start; i < slice_end; i++)
492 for (int j = 0; j < h; j++)
493 hdata[j * hstride + i] = vdata[i * vstride + j];
494 }
495
496 return 0;
497 }
498
499 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
500 {
501 AVFilterContext *ctx = inlink->dst;
502 AVFilterLink *outlink = inlink->dst->outputs[0];
503 FFTFILTContext *s = ctx->priv;
504 AVFrame *out;
505
506 out = ff_get_video_buffer(outlink, inlink->w, inlink->h);
507 if (!out) {
508 av_frame_free(&in);
509 return AVERROR(ENOMEM);
510 }
511
512 av_frame_copy_props(out, in);
513
514 ff_filter_execute(ctx, s->rdft_horizontal, in, NULL,
515 FFMIN(s->planeheight[1], s->nb_threads));
516
517 ff_filter_execute(ctx, copy_vertical, NULL, NULL,
518 FFMIN(s->planeheight[1], s->nb_threads));
519
520 ff_filter_execute(ctx, rdft_vertical, NULL, NULL,
521 FFMIN(s->planeheight[1], s->nb_threads));
522
523 for (int plane = 0; plane < s->nb_planes; plane++) {
524 if (s->eval_mode == EVAL_MODE_FRAME)
525 do_eval(s, inlink, plane);
526 }
527
528 ff_filter_execute(ctx, multiply_data, NULL, NULL,
529 FFMIN(s->planeheight[1], s->nb_threads));
530
531 for (int plane = 0; plane < s->nb_planes; plane++)
532 s->rdft_vdata_out[plane][0] += s->rdft_hlen[plane] * s->rdft_vlen[plane] * s->dc[plane] * (1 << (s->depth - 8));
533
534 ff_filter_execute(ctx, irdft_vertical, NULL, NULL,
535 FFMIN(s->planeheight[1], s->nb_threads));
536
537 ff_filter_execute(ctx, copy_horizontal, NULL, NULL,
538 FFMIN(s->planeheight[1], s->nb_threads));
539
540 ff_filter_execute(ctx, s->irdft_horizontal, out, NULL,
541 FFMIN(s->planeheight[1], s->nb_threads));
542
543 av_frame_free(&in);
544 return ff_filter_frame(outlink, out);
545 }
546
547 static av_cold void uninit(AVFilterContext *ctx)
548 {
549 FFTFILTContext *s = ctx->priv;
550
551 for (int i = 0; i < MAX_PLANES; i++) {
552 av_freep(&s->rdft_hdata_in[i]);
553 av_freep(&s->rdft_vdata_in[i]);
554 av_freep(&s->rdft_hdata_out[i]);
555 av_freep(&s->rdft_vdata_out[i]);
556 av_expr_free(s->weight_expr[i]);
557 av_freep(&s->weight[i]);
558 for (int j = 0; j < s->nb_threads; j++) {
559 av_tx_uninit(&s->hrdft[j][i]);
560 av_tx_uninit(&s->ihrdft[j][i]);
561 av_tx_uninit(&s->vrdft[j][i]);
562 av_tx_uninit(&s->ivrdft[j][i]);
563 }
564 }
565 }
566
567 static const enum AVPixelFormat pixel_fmts_fftfilt[] = {
568 AV_PIX_FMT_GRAY8,
569 AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12,
570 AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16,
571 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P,
572 AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P,
573 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVJ422P,
574 AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV420P10,
575 AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV420P14,
576 AV_PIX_FMT_YUV420P16,
577 AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV422P10,
578 AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV422P14,
579 AV_PIX_FMT_YUV422P16,
580 AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10,
581 AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P14,
582 AV_PIX_FMT_YUV444P16,
583 AV_PIX_FMT_NONE
584 };
585
586 static const AVFilterPad fftfilt_inputs[] = {
587 {
588 .name = "default",
589 .type = AVMEDIA_TYPE_VIDEO,
590 .config_props = config_props,
591 .filter_frame = filter_frame,
592 },
593 };
594
595 static const AVFilterPad fftfilt_outputs[] = {
596 {
597 .name = "default",
598 .type = AVMEDIA_TYPE_VIDEO,
599 },
600 };
601
602 const AVFilter ff_vf_fftfilt = {
603 .name = "fftfilt",
604 .description = NULL_IF_CONFIG_SMALL("Apply arbitrary expressions to pixels in frequency domain."),
605 .priv_size = sizeof(FFTFILTContext),
606 .priv_class = &fftfilt_class,
607 FILTER_INPUTS(fftfilt_inputs),
608 FILTER_OUTPUTS(fftfilt_outputs),
609 FILTER_PIXFMTS_ARRAY(pixel_fmts_fftfilt),
610 .init = initialize,
611 .uninit = uninit,
612 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
613 };
614