vf_lut.c 19 KB

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