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.

588 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. static const enum AVPixelFormat yuv_pix_fmts[] = { YUV_FORMATS, AV_PIX_FMT_NONE };
  126. static const enum AVPixelFormat rgb_pix_fmts[] = { RGB_FORMATS, AV_PIX_FMT_NONE };
  127. static const enum AVPixelFormat all_pix_fmts[] = { RGB_FORMATS, YUV_FORMATS, AV_PIX_FMT_NONE };
  128. static int query_formats(AVFilterContext *ctx)
  129. {
  130. LutContext *s = ctx->priv;
  131. const enum AVPixelFormat *pix_fmts = s->is_rgb ? rgb_pix_fmts :
  132. s->is_yuv ? yuv_pix_fmts :
  133. all_pix_fmts;
  134. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  135. if (!fmts_list)
  136. return AVERROR(ENOMEM);
  137. return ff_set_common_formats(ctx, fmts_list);
  138. }
  139. /**
  140. * Clip value val in the minval - maxval range.
  141. */
  142. static double clip(void *opaque, double val)
  143. {
  144. LutContext *s = opaque;
  145. double minval = s->var_values[VAR_MINVAL];
  146. double maxval = s->var_values[VAR_MAXVAL];
  147. return av_clip(val, minval, maxval);
  148. }
  149. /**
  150. * Compute gamma correction for value val, assuming the minval-maxval
  151. * range, val is clipped to a value contained in the same interval.
  152. */
  153. static double compute_gammaval(void *opaque, double gamma)
  154. {
  155. LutContext *s = opaque;
  156. double val = s->var_values[VAR_CLIPVAL];
  157. double minval = s->var_values[VAR_MINVAL];
  158. double maxval = s->var_values[VAR_MAXVAL];
  159. return pow((val-minval)/(maxval-minval), gamma) * (maxval-minval)+minval;
  160. }
  161. /**
  162. * Compute ITU Rec.709 gamma correction of value val.
  163. */
  164. static double compute_gammaval709(void *opaque, double gamma)
  165. {
  166. LutContext *s = opaque;
  167. double val = s->var_values[VAR_CLIPVAL];
  168. double minval = s->var_values[VAR_MINVAL];
  169. double maxval = s->var_values[VAR_MAXVAL];
  170. double level = (val - minval) / (maxval - minval);
  171. level = level < 0.018 ? 4.5 * level
  172. : 1.099 * pow(level, 1.0 / gamma) - 0.099;
  173. return level * (maxval - minval) + minval;
  174. }
  175. static double (* const funcs1[])(void *, double) = {
  176. clip,
  177. compute_gammaval,
  178. compute_gammaval709,
  179. NULL
  180. };
  181. static const char * const funcs1_names[] = {
  182. "clip",
  183. "gammaval",
  184. "gammaval709",
  185. NULL
  186. };
  187. static int config_props(AVFilterLink *inlink)
  188. {
  189. AVFilterContext *ctx = inlink->dst;
  190. LutContext *s = ctx->priv;
  191. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  192. uint8_t rgba_map[4]; /* component index -> RGBA color index map */
  193. int min[4], max[4];
  194. int val, color, ret;
  195. s->hsub = desc->log2_chroma_w;
  196. s->vsub = desc->log2_chroma_h;
  197. s->var_values[VAR_W] = inlink->w;
  198. s->var_values[VAR_H] = inlink->h;
  199. s->is_16bit = desc->comp[0].depth > 8;
  200. switch (inlink->format) {
  201. case AV_PIX_FMT_YUV410P:
  202. case AV_PIX_FMT_YUV411P:
  203. case AV_PIX_FMT_YUV420P:
  204. case AV_PIX_FMT_YUV422P:
  205. case AV_PIX_FMT_YUV440P:
  206. case AV_PIX_FMT_YUV444P:
  207. case AV_PIX_FMT_YUVA420P:
  208. case AV_PIX_FMT_YUVA422P:
  209. case AV_PIX_FMT_YUVA444P:
  210. case AV_PIX_FMT_YUV420P9LE:
  211. case AV_PIX_FMT_YUV422P9LE:
  212. case AV_PIX_FMT_YUV444P9LE:
  213. case AV_PIX_FMT_YUVA420P9LE:
  214. case AV_PIX_FMT_YUVA422P9LE:
  215. case AV_PIX_FMT_YUVA444P9LE:
  216. case AV_PIX_FMT_YUV420P10LE:
  217. case AV_PIX_FMT_YUV422P10LE:
  218. case AV_PIX_FMT_YUV440P10LE:
  219. case AV_PIX_FMT_YUV444P10LE:
  220. case AV_PIX_FMT_YUVA420P10LE:
  221. case AV_PIX_FMT_YUVA422P10LE:
  222. case AV_PIX_FMT_YUVA444P10LE:
  223. case AV_PIX_FMT_YUV420P12LE:
  224. case AV_PIX_FMT_YUV422P12LE:
  225. case AV_PIX_FMT_YUV440P12LE:
  226. case AV_PIX_FMT_YUV444P12LE:
  227. case AV_PIX_FMT_YUV420P14LE:
  228. case AV_PIX_FMT_YUV422P14LE:
  229. case AV_PIX_FMT_YUV444P14LE:
  230. case AV_PIX_FMT_YUV420P16LE:
  231. case AV_PIX_FMT_YUV422P16LE:
  232. case AV_PIX_FMT_YUV444P16LE:
  233. case AV_PIX_FMT_YUVA420P16LE:
  234. case AV_PIX_FMT_YUVA422P16LE:
  235. case AV_PIX_FMT_YUVA444P16LE:
  236. min[Y] = 16 * (1 << (desc->comp[0].depth - 8));
  237. min[U] = 16 * (1 << (desc->comp[1].depth - 8));
  238. min[V] = 16 * (1 << (desc->comp[2].depth - 8));
  239. min[A] = 0;
  240. max[Y] = 235 * (1 << (desc->comp[0].depth - 8));
  241. max[U] = 240 * (1 << (desc->comp[1].depth - 8));
  242. max[V] = 240 * (1 << (desc->comp[2].depth - 8));
  243. max[A] = (1 << desc->comp[0].depth) - 1;
  244. break;
  245. case AV_PIX_FMT_RGB48LE:
  246. case AV_PIX_FMT_RGBA64LE:
  247. min[0] = min[1] = min[2] = min[3] = 0;
  248. max[0] = max[1] = max[2] = max[3] = 65535;
  249. break;
  250. default:
  251. min[0] = min[1] = min[2] = min[3] = 0;
  252. max[0] = max[1] = max[2] = max[3] = 255 * (1 << (desc->comp[0].depth - 8));
  253. }
  254. s->is_yuv = s->is_rgb = 0;
  255. s->is_planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
  256. if (ff_fmt_is_in(inlink->format, yuv_pix_fmts)) s->is_yuv = 1;
  257. else if (ff_fmt_is_in(inlink->format, rgb_pix_fmts)) s->is_rgb = 1;
  258. if (s->is_rgb) {
  259. ff_fill_rgba_map(rgba_map, inlink->format);
  260. s->step = av_get_bits_per_pixel(desc) >> 3;
  261. if (s->is_16bit) {
  262. s->step = s->step >> 1;
  263. }
  264. }
  265. for (color = 0; color < desc->nb_components; color++) {
  266. double res;
  267. int comp = s->is_rgb ? rgba_map[color] : color;
  268. /* create the parsed expression */
  269. av_expr_free(s->comp_expr[color]);
  270. s->comp_expr[color] = NULL;
  271. ret = av_expr_parse(&s->comp_expr[color], s->comp_expr_str[color],
  272. var_names, funcs1_names, funcs1, NULL, NULL, 0, ctx);
  273. if (ret < 0) {
  274. av_log(ctx, AV_LOG_ERROR,
  275. "Error when parsing the expression '%s' for the component %d and color %d.\n",
  276. s->comp_expr_str[comp], comp, color);
  277. return AVERROR(EINVAL);
  278. }
  279. /* compute the lut */
  280. s->var_values[VAR_MAXVAL] = max[color];
  281. s->var_values[VAR_MINVAL] = min[color];
  282. for (val = 0; val < FF_ARRAY_ELEMS(s->lut[comp]); val++) {
  283. s->var_values[VAR_VAL] = val;
  284. s->var_values[VAR_CLIPVAL] = av_clip(val, min[color], max[color]);
  285. s->var_values[VAR_NEGVAL] =
  286. av_clip(min[color] + max[color] - s->var_values[VAR_VAL],
  287. min[color], max[color]);
  288. res = av_expr_eval(s->comp_expr[color], s->var_values, s);
  289. if (isnan(res)) {
  290. av_log(ctx, AV_LOG_ERROR,
  291. "Error when evaluating the expression '%s' for the value %d for the component %d.\n",
  292. s->comp_expr_str[color], val, comp);
  293. return AVERROR(EINVAL);
  294. }
  295. s->lut[comp][val] = av_clip((int)res, 0, max[A]);
  296. av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, s->lut[comp][val]);
  297. }
  298. }
  299. return 0;
  300. }
  301. static int filter_frame(AVFilterLink *inlink, AVFrame *in)
  302. {
  303. AVFilterContext *ctx = inlink->dst;
  304. LutContext *s = ctx->priv;
  305. AVFilterLink *outlink = ctx->outputs[0];
  306. AVFrame *out;
  307. int i, j, plane, direct = 0;
  308. if (av_frame_is_writable(in)) {
  309. direct = 1;
  310. out = in;
  311. } else {
  312. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  313. if (!out) {
  314. av_frame_free(&in);
  315. return AVERROR(ENOMEM);
  316. }
  317. av_frame_copy_props(out, in);
  318. }
  319. if (s->is_rgb && s->is_16bit && !s->is_planar) {
  320. /* packed, 16-bit */
  321. uint16_t *inrow, *outrow, *inrow0, *outrow0;
  322. const int w = inlink->w;
  323. const int h = in->height;
  324. const uint16_t (*tab)[256*256] = (const uint16_t (*)[256*256])s->lut;
  325. const int in_linesize = in->linesize[0] / 2;
  326. const int out_linesize = out->linesize[0] / 2;
  327. const int step = s->step;
  328. inrow0 = (uint16_t*) in ->data[0];
  329. outrow0 = (uint16_t*) out->data[0];
  330. for (i = 0; i < h; i ++) {
  331. inrow = inrow0;
  332. outrow = outrow0;
  333. for (j = 0; j < w; j++) {
  334. switch (step) {
  335. #if HAVE_BIGENDIAN
  336. case 4: outrow[3] = av_bswap16(tab[3][av_bswap16(inrow[3])]); // Fall-through
  337. case 3: outrow[2] = av_bswap16(tab[2][av_bswap16(inrow[2])]); // Fall-through
  338. case 2: outrow[1] = av_bswap16(tab[1][av_bswap16(inrow[1])]); // Fall-through
  339. default: outrow[0] = av_bswap16(tab[0][av_bswap16(inrow[0])]);
  340. #else
  341. case 4: outrow[3] = tab[3][inrow[3]]; // Fall-through
  342. case 3: outrow[2] = tab[2][inrow[2]]; // Fall-through
  343. case 2: outrow[1] = tab[1][inrow[1]]; // Fall-through
  344. default: outrow[0] = tab[0][inrow[0]];
  345. #endif
  346. }
  347. outrow += step;
  348. inrow += step;
  349. }
  350. inrow0 += in_linesize;
  351. outrow0 += out_linesize;
  352. }
  353. } else if (s->is_rgb && !s->is_planar) {
  354. /* packed */
  355. uint8_t *inrow, *outrow, *inrow0, *outrow0;
  356. const int w = inlink->w;
  357. const int h = in->height;
  358. const uint16_t (*tab)[256*256] = (const uint16_t (*)[256*256])s->lut;
  359. const int in_linesize = in->linesize[0];
  360. const int out_linesize = out->linesize[0];
  361. const int step = s->step;
  362. inrow0 = in ->data[0];
  363. outrow0 = out->data[0];
  364. for (i = 0; i < h; i ++) {
  365. inrow = inrow0;
  366. outrow = outrow0;
  367. for (j = 0; j < w; j++) {
  368. switch (step) {
  369. case 4: outrow[3] = tab[3][inrow[3]]; // Fall-through
  370. case 3: outrow[2] = tab[2][inrow[2]]; // Fall-through
  371. case 2: outrow[1] = tab[1][inrow[1]]; // Fall-through
  372. default: outrow[0] = tab[0][inrow[0]];
  373. }
  374. outrow += step;
  375. inrow += step;
  376. }
  377. inrow0 += in_linesize;
  378. outrow0 += out_linesize;
  379. }
  380. } else if (s->is_16bit) {
  381. // planar >8 bit depth
  382. uint16_t *inrow, *outrow;
  383. for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
  384. int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
  385. int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
  386. int h = AV_CEIL_RSHIFT(inlink->h, vsub);
  387. int w = AV_CEIL_RSHIFT(inlink->w, hsub);
  388. const uint16_t *tab = s->lut[plane];
  389. const int in_linesize = in->linesize[plane] / 2;
  390. const int out_linesize = out->linesize[plane] / 2;
  391. inrow = (uint16_t *)in ->data[plane];
  392. outrow = (uint16_t *)out->data[plane];
  393. for (i = 0; i < h; i++) {
  394. for (j = 0; j < w; j++) {
  395. #if HAVE_BIGENDIAN
  396. outrow[j] = av_bswap16(tab[av_bswap16(inrow[j])]);
  397. #else
  398. outrow[j] = tab[inrow[j]];
  399. #endif
  400. }
  401. inrow += in_linesize;
  402. outrow += out_linesize;
  403. }
  404. }
  405. } else {
  406. /* planar 8bit depth */
  407. uint8_t *inrow, *outrow;
  408. for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
  409. int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
  410. int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
  411. int h = AV_CEIL_RSHIFT(inlink->h, vsub);
  412. int w = AV_CEIL_RSHIFT(inlink->w, hsub);
  413. const uint16_t *tab = s->lut[plane];
  414. const int in_linesize = in->linesize[plane];
  415. const int out_linesize = out->linesize[plane];
  416. inrow = in ->data[plane];
  417. outrow = out->data[plane];
  418. for (i = 0; i < h; i++) {
  419. for (j = 0; j < w; j++)
  420. outrow[j] = tab[inrow[j]];
  421. inrow += in_linesize;
  422. outrow += out_linesize;
  423. }
  424. }
  425. }
  426. if (!direct)
  427. av_frame_free(&in);
  428. return ff_filter_frame(outlink, out);
  429. }
  430. static const AVFilterPad inputs[] = {
  431. { .name = "default",
  432. .type = AVMEDIA_TYPE_VIDEO,
  433. .filter_frame = filter_frame,
  434. .config_props = config_props,
  435. },
  436. { NULL }
  437. };
  438. static const AVFilterPad outputs[] = {
  439. { .name = "default",
  440. .type = AVMEDIA_TYPE_VIDEO,
  441. },
  442. { NULL }
  443. };
  444. #define DEFINE_LUT_FILTER(name_, description_) \
  445. AVFilter ff_vf_##name_ = { \
  446. .name = #name_, \
  447. .description = NULL_IF_CONFIG_SMALL(description_), \
  448. .priv_size = sizeof(LutContext), \
  449. .priv_class = &name_ ## _class, \
  450. .init = name_##_init, \
  451. .uninit = uninit, \
  452. .query_formats = query_formats, \
  453. .inputs = inputs, \
  454. .outputs = outputs, \
  455. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, \
  456. }
  457. #if CONFIG_LUT_FILTER
  458. #define lut_options options
  459. AVFILTER_DEFINE_CLASS(lut);
  460. static int lut_init(AVFilterContext *ctx)
  461. {
  462. return 0;
  463. }
  464. DEFINE_LUT_FILTER(lut, "Compute and apply a lookup table to the RGB/YUV input video.");
  465. #endif
  466. #if CONFIG_LUTYUV_FILTER
  467. #define lutyuv_options options
  468. AVFILTER_DEFINE_CLASS(lutyuv);
  469. static av_cold int lutyuv_init(AVFilterContext *ctx)
  470. {
  471. LutContext *s = ctx->priv;
  472. s->is_yuv = 1;
  473. return 0;
  474. }
  475. DEFINE_LUT_FILTER(lutyuv, "Compute and apply a lookup table to the YUV input video.");
  476. #endif
  477. #if CONFIG_LUTRGB_FILTER
  478. #define lutrgb_options options
  479. AVFILTER_DEFINE_CLASS(lutrgb);
  480. static av_cold int lutrgb_init(AVFilterContext *ctx)
  481. {
  482. LutContext *s = ctx->priv;
  483. s->is_rgb = 1;
  484. return 0;
  485. }
  486. DEFINE_LUT_FILTER(lutrgb, "Compute and apply a lookup table to the RGB input video.");
  487. #endif
  488. #if CONFIG_NEGATE_FILTER
  489. static const AVOption negate_options[] = {
  490. { "negate_alpha", NULL, OFFSET(negate_alpha), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
  491. { NULL }
  492. };
  493. AVFILTER_DEFINE_CLASS(negate);
  494. static av_cold int negate_init(AVFilterContext *ctx)
  495. {
  496. LutContext *s = ctx->priv;
  497. int i;
  498. av_log(ctx, AV_LOG_DEBUG, "negate_alpha:%d\n", s->negate_alpha);
  499. for (i = 0; i < 4; i++) {
  500. s->comp_expr_str[i] = av_strdup((i == 3 && !s->negate_alpha) ?
  501. "val" : "negval");
  502. if (!s->comp_expr_str[i]) {
  503. uninit(ctx);
  504. return AVERROR(ENOMEM);
  505. }
  506. }
  507. return 0;
  508. }
  509. DEFINE_LUT_FILTER(negate, "Negate input video.");
  510. #endif