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.

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