You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

505 lines
19KB

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