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.

592 lines
20KB

  1. /*
  2. * Copyright (c) 2011 Stefano Sabatini
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * Compute a look-up table for binding the input value to the output
  23. * value, and apply it to input video.
  24. */
  25. #include "libavutil/attributes.h"
  26. #include "libavutil/bswap.h"
  27. #include "libavutil/common.h"
  28. #include "libavutil/eval.h"
  29. #include "libavutil/opt.h"
  30. #include "libavutil/pixdesc.h"
  31. #include "avfilter.h"
  32. #include "drawutils.h"
  33. #include "formats.h"
  34. #include "internal.h"
  35. #include "video.h"
  36. static const char *const var_names[] = {
  37. "w", ///< width of the input video
  38. "h", ///< height of the input video
  39. "val", ///< input value for the pixel
  40. "maxval", ///< max value for the pixel
  41. "minval", ///< min value for the pixel
  42. "negval", ///< negated value
  43. "clipval",
  44. NULL
  45. };
  46. enum var_name {
  47. VAR_W,
  48. VAR_H,
  49. VAR_VAL,
  50. VAR_MAXVAL,
  51. VAR_MINVAL,
  52. VAR_NEGVAL,
  53. VAR_CLIPVAL,
  54. VAR_VARS_NB
  55. };
  56. typedef struct LutContext {
  57. const AVClass *class;
  58. uint16_t lut[4][256 * 256]; ///< lookup table for each component
  59. char *comp_expr_str[4];
  60. AVExpr *comp_expr[4];
  61. int hsub, vsub;
  62. double var_values[VAR_VARS_NB];
  63. int is_rgb, is_yuv;
  64. int is_planar;
  65. int is_16bit;
  66. int step;
  67. int negate_alpha; /* only used by negate */
  68. } LutContext;
  69. #define Y 0
  70. #define U 1
  71. #define V 2
  72. #define R 0
  73. #define G 1
  74. #define B 2
  75. #define A 3
  76. #define OFFSET(x) offsetof(LutContext, x)
  77. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  78. static const AVOption options[] = {
  79. { "c0", "set component #0 expression", OFFSET(comp_expr_str[0]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  80. { "c1", "set component #1 expression", OFFSET(comp_expr_str[1]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  81. { "c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  82. { "c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  83. { "y", "set Y expression", OFFSET(comp_expr_str[Y]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  84. { "u", "set U expression", OFFSET(comp_expr_str[U]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  85. { "v", "set V expression", OFFSET(comp_expr_str[V]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  86. { "r", "set R expression", OFFSET(comp_expr_str[R]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  87. { "g", "set G expression", OFFSET(comp_expr_str[G]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  88. { "b", "set B expression", OFFSET(comp_expr_str[B]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  89. { "a", "set A expression", OFFSET(comp_expr_str[A]), AV_OPT_TYPE_STRING, { .str = "clipval" }, .flags = FLAGS },
  90. { NULL }
  91. };
  92. static av_cold void uninit(AVFilterContext *ctx)
  93. {
  94. LutContext *s = ctx->priv;
  95. int i;
  96. for (i = 0; i < 4; i++) {
  97. av_expr_free(s->comp_expr[i]);
  98. s->comp_expr[i] = NULL;
  99. av_freep(&s->comp_expr_str[i]);
  100. }
  101. }
  102. #define YUV_FORMATS \
  103. AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, \
  104. AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P, \
  105. AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, \
  106. AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P, \
  107. AV_PIX_FMT_YUVJ440P, \
  108. AV_PIX_FMT_YUV444P9LE, AV_PIX_FMT_YUV422P9LE, AV_PIX_FMT_YUV420P9LE, \
  109. AV_PIX_FMT_YUV444P10LE, AV_PIX_FMT_YUV422P10LE, AV_PIX_FMT_YUV420P10LE, AV_PIX_FMT_YUV440P10LE, \
  110. AV_PIX_FMT_YUV444P12LE, AV_PIX_FMT_YUV422P12LE, AV_PIX_FMT_YUV420P12LE, AV_PIX_FMT_YUV440P12LE, \
  111. AV_PIX_FMT_YUV444P14LE, AV_PIX_FMT_YUV422P14LE, AV_PIX_FMT_YUV420P14LE, \
  112. AV_PIX_FMT_YUV444P16LE, AV_PIX_FMT_YUV422P16LE, AV_PIX_FMT_YUV420P16LE, \
  113. AV_PIX_FMT_YUVA444P16LE, AV_PIX_FMT_YUVA422P16LE, AV_PIX_FMT_YUVA420P16LE
  114. #define RGB_FORMATS \
  115. AV_PIX_FMT_ARGB, AV_PIX_FMT_RGBA, \
  116. AV_PIX_FMT_ABGR, AV_PIX_FMT_BGRA, \
  117. AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, \
  118. AV_PIX_FMT_RGB48LE, AV_PIX_FMT_RGBA64LE, \
  119. AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, \
  120. AV_PIX_FMT_GBRP9LE, AV_PIX_FMT_GBRP10LE, \
  121. AV_PIX_FMT_GBRAP10LE, \
  122. AV_PIX_FMT_GBRP12LE, AV_PIX_FMT_GBRP14LE, \
  123. AV_PIX_FMT_GBRP16LE, AV_PIX_FMT_GBRAP12LE, \
  124. AV_PIX_FMT_GBRAP16LE
  125. #define GRAY_FORMATS \
  126. AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9LE, AV_PIX_FMT_GRAY10LE, \
  127. AV_PIX_FMT_GRAY12LE, AV_PIX_FMT_GRAY16LE
  128. static const enum AVPixelFormat yuv_pix_fmts[] = { YUV_FORMATS, AV_PIX_FMT_NONE };
  129. static const enum AVPixelFormat rgb_pix_fmts[] = { RGB_FORMATS, AV_PIX_FMT_NONE };
  130. static const enum AVPixelFormat all_pix_fmts[] = { RGB_FORMATS, YUV_FORMATS, GRAY_FORMATS, AV_PIX_FMT_NONE };
  131. static int query_formats(AVFilterContext *ctx)
  132. {
  133. LutContext *s = ctx->priv;
  134. const enum AVPixelFormat *pix_fmts = s->is_rgb ? rgb_pix_fmts :
  135. s->is_yuv ? yuv_pix_fmts :
  136. all_pix_fmts;
  137. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  138. if (!fmts_list)
  139. return AVERROR(ENOMEM);
  140. return ff_set_common_formats(ctx, fmts_list);
  141. }
  142. /**
  143. * Clip value val in the minval - maxval range.
  144. */
  145. static double clip(void *opaque, double val)
  146. {
  147. LutContext *s = opaque;
  148. double minval = s->var_values[VAR_MINVAL];
  149. double maxval = s->var_values[VAR_MAXVAL];
  150. return av_clip(val, minval, maxval);
  151. }
  152. /**
  153. * Compute gamma correction for value val, assuming the minval-maxval
  154. * range, val is clipped to a value contained in the same interval.
  155. */
  156. static double compute_gammaval(void *opaque, double gamma)
  157. {
  158. LutContext *s = opaque;
  159. double val = s->var_values[VAR_CLIPVAL];
  160. double minval = s->var_values[VAR_MINVAL];
  161. double maxval = s->var_values[VAR_MAXVAL];
  162. return pow((val-minval)/(maxval-minval), gamma) * (maxval-minval)+minval;
  163. }
  164. /**
  165. * Compute ITU Rec.709 gamma correction of value val.
  166. */
  167. static double compute_gammaval709(void *opaque, double gamma)
  168. {
  169. LutContext *s = opaque;
  170. double val = s->var_values[VAR_CLIPVAL];
  171. double minval = s->var_values[VAR_MINVAL];
  172. double maxval = s->var_values[VAR_MAXVAL];
  173. double level = (val - minval) / (maxval - minval);
  174. level = level < 0.018 ? 4.5 * level
  175. : 1.099 * pow(level, 1.0 / gamma) - 0.099;
  176. return level * (maxval - minval) + minval;
  177. }
  178. static double (* const funcs1[])(void *, double) = {
  179. clip,
  180. compute_gammaval,
  181. compute_gammaval709,
  182. NULL
  183. };
  184. static const char * const funcs1_names[] = {
  185. "clip",
  186. "gammaval",
  187. "gammaval709",
  188. NULL
  189. };
  190. static int config_props(AVFilterLink *inlink)
  191. {
  192. AVFilterContext *ctx = inlink->dst;
  193. LutContext *s = ctx->priv;
  194. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  195. uint8_t rgba_map[4]; /* component index -> RGBA color index map */
  196. int min[4], max[4];
  197. int val, color, ret;
  198. s->hsub = desc->log2_chroma_w;
  199. s->vsub = desc->log2_chroma_h;
  200. s->var_values[VAR_W] = inlink->w;
  201. s->var_values[VAR_H] = inlink->h;
  202. s->is_16bit = desc->comp[0].depth > 8;
  203. switch (inlink->format) {
  204. case AV_PIX_FMT_YUV410P:
  205. case AV_PIX_FMT_YUV411P:
  206. case AV_PIX_FMT_YUV420P:
  207. case AV_PIX_FMT_YUV422P:
  208. case AV_PIX_FMT_YUV440P:
  209. case AV_PIX_FMT_YUV444P:
  210. case AV_PIX_FMT_YUVA420P:
  211. case AV_PIX_FMT_YUVA422P:
  212. case AV_PIX_FMT_YUVA444P:
  213. case AV_PIX_FMT_YUV420P9LE:
  214. case AV_PIX_FMT_YUV422P9LE:
  215. case AV_PIX_FMT_YUV444P9LE:
  216. case AV_PIX_FMT_YUVA420P9LE:
  217. case AV_PIX_FMT_YUVA422P9LE:
  218. case AV_PIX_FMT_YUVA444P9LE:
  219. case AV_PIX_FMT_YUV420P10LE:
  220. case AV_PIX_FMT_YUV422P10LE:
  221. case AV_PIX_FMT_YUV440P10LE:
  222. case AV_PIX_FMT_YUV444P10LE:
  223. case AV_PIX_FMT_YUVA420P10LE:
  224. case AV_PIX_FMT_YUVA422P10LE:
  225. case AV_PIX_FMT_YUVA444P10LE:
  226. case AV_PIX_FMT_YUV420P12LE:
  227. case AV_PIX_FMT_YUV422P12LE:
  228. case AV_PIX_FMT_YUV440P12LE:
  229. case AV_PIX_FMT_YUV444P12LE:
  230. case AV_PIX_FMT_YUV420P14LE:
  231. case AV_PIX_FMT_YUV422P14LE:
  232. case AV_PIX_FMT_YUV444P14LE:
  233. case AV_PIX_FMT_YUV420P16LE:
  234. case AV_PIX_FMT_YUV422P16LE:
  235. case AV_PIX_FMT_YUV444P16LE:
  236. case AV_PIX_FMT_YUVA420P16LE:
  237. case AV_PIX_FMT_YUVA422P16LE:
  238. case AV_PIX_FMT_YUVA444P16LE:
  239. min[Y] = 16 * (1 << (desc->comp[0].depth - 8));
  240. min[U] = 16 * (1 << (desc->comp[1].depth - 8));
  241. min[V] = 16 * (1 << (desc->comp[2].depth - 8));
  242. min[A] = 0;
  243. max[Y] = 235 * (1 << (desc->comp[0].depth - 8));
  244. max[U] = 240 * (1 << (desc->comp[1].depth - 8));
  245. max[V] = 240 * (1 << (desc->comp[2].depth - 8));
  246. max[A] = (1 << desc->comp[0].depth) - 1;
  247. break;
  248. case AV_PIX_FMT_RGB48LE:
  249. case AV_PIX_FMT_RGBA64LE:
  250. min[0] = min[1] = min[2] = min[3] = 0;
  251. max[0] = max[1] = max[2] = max[3] = 65535;
  252. break;
  253. default:
  254. min[0] = min[1] = min[2] = min[3] = 0;
  255. max[0] = max[1] = max[2] = max[3] = 255 * (1 << (desc->comp[0].depth - 8));
  256. }
  257. s->is_yuv = s->is_rgb = 0;
  258. s->is_planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
  259. if (ff_fmt_is_in(inlink->format, yuv_pix_fmts)) s->is_yuv = 1;
  260. else if (ff_fmt_is_in(inlink->format, rgb_pix_fmts)) s->is_rgb = 1;
  261. if (s->is_rgb) {
  262. ff_fill_rgba_map(rgba_map, inlink->format);
  263. s->step = av_get_bits_per_pixel(desc) >> 3;
  264. if (s->is_16bit) {
  265. s->step = s->step >> 1;
  266. }
  267. }
  268. for (color = 0; color < desc->nb_components; color++) {
  269. double res;
  270. int comp = s->is_rgb ? rgba_map[color] : color;
  271. /* create the parsed expression */
  272. av_expr_free(s->comp_expr[color]);
  273. s->comp_expr[color] = NULL;
  274. ret = av_expr_parse(&s->comp_expr[color], s->comp_expr_str[color],
  275. var_names, funcs1_names, funcs1, NULL, NULL, 0, ctx);
  276. if (ret < 0) {
  277. av_log(ctx, AV_LOG_ERROR,
  278. "Error when parsing the expression '%s' for the component %d and color %d.\n",
  279. s->comp_expr_str[comp], comp, color);
  280. return AVERROR(EINVAL);
  281. }
  282. /* compute the lut */
  283. s->var_values[VAR_MAXVAL] = max[color];
  284. s->var_values[VAR_MINVAL] = min[color];
  285. for (val = 0; val < FF_ARRAY_ELEMS(s->lut[comp]); val++) {
  286. s->var_values[VAR_VAL] = val;
  287. s->var_values[VAR_CLIPVAL] = av_clip(val, min[color], max[color]);
  288. s->var_values[VAR_NEGVAL] =
  289. av_clip(min[color] + max[color] - s->var_values[VAR_VAL],
  290. min[color], max[color]);
  291. res = av_expr_eval(s->comp_expr[color], s->var_values, s);
  292. if (isnan(res)) {
  293. av_log(ctx, AV_LOG_ERROR,
  294. "Error when evaluating the expression '%s' for the value %d for the component %d.\n",
  295. s->comp_expr_str[color], val, comp);
  296. return AVERROR(EINVAL);
  297. }
  298. s->lut[comp][val] = av_clip((int)res, 0, max[A]);
  299. av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, s->lut[comp][val]);
  300. }
  301. }
  302. return 0;
  303. }
  304. static int filter_frame(AVFilterLink *inlink, AVFrame *in)
  305. {
  306. AVFilterContext *ctx = inlink->dst;
  307. LutContext *s = ctx->priv;
  308. AVFilterLink *outlink = ctx->outputs[0];
  309. AVFrame *out;
  310. int i, j, plane, direct = 0;
  311. if (av_frame_is_writable(in)) {
  312. direct = 1;
  313. out = in;
  314. } else {
  315. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  316. if (!out) {
  317. av_frame_free(&in);
  318. return AVERROR(ENOMEM);
  319. }
  320. av_frame_copy_props(out, in);
  321. }
  322. if (s->is_rgb && s->is_16bit && !s->is_planar) {
  323. /* packed, 16-bit */
  324. uint16_t *inrow, *outrow, *inrow0, *outrow0;
  325. const int w = inlink->w;
  326. const int h = in->height;
  327. const uint16_t (*tab)[256*256] = (const uint16_t (*)[256*256])s->lut;
  328. const int in_linesize = in->linesize[0] / 2;
  329. const int out_linesize = out->linesize[0] / 2;
  330. const int step = s->step;
  331. inrow0 = (uint16_t*) in ->data[0];
  332. outrow0 = (uint16_t*) out->data[0];
  333. for (i = 0; i < h; i ++) {
  334. inrow = inrow0;
  335. outrow = outrow0;
  336. for (j = 0; j < w; j++) {
  337. switch (step) {
  338. #if HAVE_BIGENDIAN
  339. case 4: outrow[3] = av_bswap16(tab[3][av_bswap16(inrow[3])]); // Fall-through
  340. case 3: outrow[2] = av_bswap16(tab[2][av_bswap16(inrow[2])]); // Fall-through
  341. case 2: outrow[1] = av_bswap16(tab[1][av_bswap16(inrow[1])]); // Fall-through
  342. default: outrow[0] = av_bswap16(tab[0][av_bswap16(inrow[0])]);
  343. #else
  344. case 4: outrow[3] = tab[3][inrow[3]]; // Fall-through
  345. case 3: outrow[2] = tab[2][inrow[2]]; // Fall-through
  346. case 2: outrow[1] = tab[1][inrow[1]]; // Fall-through
  347. default: outrow[0] = tab[0][inrow[0]];
  348. #endif
  349. }
  350. outrow += step;
  351. inrow += step;
  352. }
  353. inrow0 += in_linesize;
  354. outrow0 += out_linesize;
  355. }
  356. } else if (s->is_rgb && !s->is_planar) {
  357. /* packed */
  358. uint8_t *inrow, *outrow, *inrow0, *outrow0;
  359. const int w = inlink->w;
  360. const int h = in->height;
  361. const uint16_t (*tab)[256*256] = (const uint16_t (*)[256*256])s->lut;
  362. const int in_linesize = in->linesize[0];
  363. const int out_linesize = out->linesize[0];
  364. const int step = s->step;
  365. inrow0 = in ->data[0];
  366. outrow0 = out->data[0];
  367. for (i = 0; i < h; i ++) {
  368. inrow = inrow0;
  369. outrow = outrow0;
  370. for (j = 0; j < w; j++) {
  371. switch (step) {
  372. case 4: outrow[3] = tab[3][inrow[3]]; // Fall-through
  373. case 3: outrow[2] = tab[2][inrow[2]]; // Fall-through
  374. case 2: outrow[1] = tab[1][inrow[1]]; // Fall-through
  375. default: outrow[0] = tab[0][inrow[0]];
  376. }
  377. outrow += step;
  378. inrow += step;
  379. }
  380. inrow0 += in_linesize;
  381. outrow0 += out_linesize;
  382. }
  383. } else if (s->is_16bit) {
  384. // planar >8 bit depth
  385. uint16_t *inrow, *outrow;
  386. for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
  387. int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
  388. int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
  389. int h = AV_CEIL_RSHIFT(inlink->h, vsub);
  390. int w = AV_CEIL_RSHIFT(inlink->w, hsub);
  391. const uint16_t *tab = s->lut[plane];
  392. const int in_linesize = in->linesize[plane] / 2;
  393. const int out_linesize = out->linesize[plane] / 2;
  394. inrow = (uint16_t *)in ->data[plane];
  395. outrow = (uint16_t *)out->data[plane];
  396. for (i = 0; i < h; i++) {
  397. for (j = 0; j < w; j++) {
  398. #if HAVE_BIGENDIAN
  399. outrow[j] = av_bswap16(tab[av_bswap16(inrow[j])]);
  400. #else
  401. outrow[j] = tab[inrow[j]];
  402. #endif
  403. }
  404. inrow += in_linesize;
  405. outrow += out_linesize;
  406. }
  407. }
  408. } else {
  409. /* planar 8bit depth */
  410. uint8_t *inrow, *outrow;
  411. for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
  412. int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
  413. int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
  414. int h = AV_CEIL_RSHIFT(inlink->h, vsub);
  415. int w = AV_CEIL_RSHIFT(inlink->w, hsub);
  416. const uint16_t *tab = s->lut[plane];
  417. const int in_linesize = in->linesize[plane];
  418. const int out_linesize = out->linesize[plane];
  419. inrow = in ->data[plane];
  420. outrow = out->data[plane];
  421. for (i = 0; i < h; i++) {
  422. for (j = 0; j < w; j++)
  423. outrow[j] = tab[inrow[j]];
  424. inrow += in_linesize;
  425. outrow += out_linesize;
  426. }
  427. }
  428. }
  429. if (!direct)
  430. av_frame_free(&in);
  431. return ff_filter_frame(outlink, out);
  432. }
  433. static const AVFilterPad inputs[] = {
  434. { .name = "default",
  435. .type = AVMEDIA_TYPE_VIDEO,
  436. .filter_frame = filter_frame,
  437. .config_props = config_props,
  438. },
  439. { NULL }
  440. };
  441. static const AVFilterPad outputs[] = {
  442. { .name = "default",
  443. .type = AVMEDIA_TYPE_VIDEO,
  444. },
  445. { NULL }
  446. };
  447. #define DEFINE_LUT_FILTER(name_, description_) \
  448. AVFilter ff_vf_##name_ = { \
  449. .name = #name_, \
  450. .description = NULL_IF_CONFIG_SMALL(description_), \
  451. .priv_size = sizeof(LutContext), \
  452. .priv_class = &name_ ## _class, \
  453. .init = name_##_init, \
  454. .uninit = uninit, \
  455. .query_formats = query_formats, \
  456. .inputs = inputs, \
  457. .outputs = outputs, \
  458. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, \
  459. }
  460. #if CONFIG_LUT_FILTER
  461. #define lut_options options
  462. AVFILTER_DEFINE_CLASS(lut);
  463. static int lut_init(AVFilterContext *ctx)
  464. {
  465. return 0;
  466. }
  467. DEFINE_LUT_FILTER(lut, "Compute and apply a lookup table to the RGB/YUV input video.");
  468. #endif
  469. #if CONFIG_LUTYUV_FILTER
  470. #define lutyuv_options options
  471. AVFILTER_DEFINE_CLASS(lutyuv);
  472. static av_cold int lutyuv_init(AVFilterContext *ctx)
  473. {
  474. LutContext *s = ctx->priv;
  475. s->is_yuv = 1;
  476. return 0;
  477. }
  478. DEFINE_LUT_FILTER(lutyuv, "Compute and apply a lookup table to the YUV input video.");
  479. #endif
  480. #if CONFIG_LUTRGB_FILTER
  481. #define lutrgb_options options
  482. AVFILTER_DEFINE_CLASS(lutrgb);
  483. static av_cold int lutrgb_init(AVFilterContext *ctx)
  484. {
  485. LutContext *s = ctx->priv;
  486. s->is_rgb = 1;
  487. return 0;
  488. }
  489. DEFINE_LUT_FILTER(lutrgb, "Compute and apply a lookup table to the RGB input video.");
  490. #endif
  491. #if CONFIG_NEGATE_FILTER
  492. static const AVOption negate_options[] = {
  493. { "negate_alpha", NULL, OFFSET(negate_alpha), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
  494. { NULL }
  495. };
  496. AVFILTER_DEFINE_CLASS(negate);
  497. static av_cold int negate_init(AVFilterContext *ctx)
  498. {
  499. LutContext *s = ctx->priv;
  500. int i;
  501. av_log(ctx, AV_LOG_DEBUG, "negate_alpha:%d\n", s->negate_alpha);
  502. for (i = 0; i < 4; i++) {
  503. s->comp_expr_str[i] = av_strdup((i == 3 && !s->negate_alpha) ?
  504. "val" : "negval");
  505. if (!s->comp_expr_str[i]) {
  506. uninit(ctx);
  507. return AVERROR(ENOMEM);
  508. }
  509. }
  510. return 0;
  511. }
  512. DEFINE_LUT_FILTER(negate, "Negate input video.");
  513. #endif