vf_curves.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*
  2. * Copyright (c) 2013 Clément Bœsch
  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. #include "libavutil/opt.h"
  21. #include "libavutil/bprint.h"
  22. #include "libavutil/eval.h"
  23. #include "libavutil/file.h"
  24. #include "libavutil/intreadwrite.h"
  25. #include "libavutil/avassert.h"
  26. #include "libavutil/pixdesc.h"
  27. #include "avfilter.h"
  28. #include "drawutils.h"
  29. #include "formats.h"
  30. #include "internal.h"
  31. #include "video.h"
  32. #define R 0
  33. #define G 1
  34. #define B 2
  35. #define A 3
  36. struct keypoint {
  37. double x, y;
  38. struct keypoint *next;
  39. };
  40. #define NB_COMP 3
  41. enum preset {
  42. PRESET_NONE,
  43. PRESET_COLOR_NEGATIVE,
  44. PRESET_CROSS_PROCESS,
  45. PRESET_DARKER,
  46. PRESET_INCREASE_CONTRAST,
  47. PRESET_LIGHTER,
  48. PRESET_LINEAR_CONTRAST,
  49. PRESET_MEDIUM_CONTRAST,
  50. PRESET_NEGATIVE,
  51. PRESET_STRONG_CONTRAST,
  52. PRESET_VINTAGE,
  53. NB_PRESETS,
  54. };
  55. typedef struct {
  56. const AVClass *class;
  57. enum preset preset;
  58. char *comp_points_str[NB_COMP + 1];
  59. char *comp_points_str_all;
  60. uint8_t graph[NB_COMP + 1][256];
  61. char *psfile;
  62. uint8_t rgba_map[4];
  63. int step;
  64. } CurvesContext;
  65. typedef struct ThreadData {
  66. AVFrame *in, *out;
  67. } ThreadData;
  68. #define OFFSET(x) offsetof(CurvesContext, x)
  69. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  70. static const AVOption curves_options[] = {
  71. { "preset", "select a color curves preset", OFFSET(preset), AV_OPT_TYPE_INT, {.i64=PRESET_NONE}, PRESET_NONE, NB_PRESETS-1, FLAGS, "preset_name" },
  72. { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NONE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  73. { "color_negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_COLOR_NEGATIVE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  74. { "cross_process", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_CROSS_PROCESS}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  75. { "darker", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_DARKER}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  76. { "increase_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_INCREASE_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  77. { "lighter", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LIGHTER}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  78. { "linear_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_LINEAR_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  79. { "medium_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_MEDIUM_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  80. { "negative", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_NEGATIVE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  81. { "strong_contrast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_STRONG_CONTRAST}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  82. { "vintage", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PRESET_VINTAGE}, INT_MIN, INT_MAX, FLAGS, "preset_name" },
  83. { "master","set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
  84. { "m", "set master points coordinates",OFFSET(comp_points_str[NB_COMP]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
  85. { "red", "set red points coordinates", OFFSET(comp_points_str[0]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
  86. { "r", "set red points coordinates", OFFSET(comp_points_str[0]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
  87. { "green", "set green points coordinates", OFFSET(comp_points_str[1]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
  88. { "g", "set green points coordinates", OFFSET(comp_points_str[1]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
  89. { "blue", "set blue points coordinates", OFFSET(comp_points_str[2]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
  90. { "b", "set blue points coordinates", OFFSET(comp_points_str[2]), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
  91. { "all", "set points coordinates for all components", OFFSET(comp_points_str_all), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
  92. { "psfile", "set Photoshop curves file name", OFFSET(psfile), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
  93. { NULL }
  94. };
  95. AVFILTER_DEFINE_CLASS(curves);
  96. static const struct {
  97. const char *r;
  98. const char *g;
  99. const char *b;
  100. const char *master;
  101. } curves_presets[] = {
  102. [PRESET_COLOR_NEGATIVE] = {
  103. "0/1 0.129/1 0.466/0.498 0.725/0 1/0",
  104. "0/1 0.109/1 0.301/0.498 0.517/0 1/0",
  105. "0/1 0.098/1 0.235/0.498 0.423/0 1/0",
  106. },
  107. [PRESET_CROSS_PROCESS] = {
  108. "0.25/0.156 0.501/0.501 0.686/0.745",
  109. "0.25/0.188 0.38/0.501 0.745/0.815 1/0.815",
  110. "0.231/0.094 0.709/0.874",
  111. },
  112. [PRESET_DARKER] = { .master = "0.5/0.4" },
  113. [PRESET_INCREASE_CONTRAST] = { .master = "0.149/0.066 0.831/0.905 0.905/0.98" },
  114. [PRESET_LIGHTER] = { .master = "0.4/0.5" },
  115. [PRESET_LINEAR_CONTRAST] = { .master = "0.305/0.286 0.694/0.713" },
  116. [PRESET_MEDIUM_CONTRAST] = { .master = "0.286/0.219 0.639/0.643" },
  117. [PRESET_NEGATIVE] = { .master = "0/1 1/0" },
  118. [PRESET_STRONG_CONTRAST] = { .master = "0.301/0.196 0.592/0.6 0.686/0.737" },
  119. [PRESET_VINTAGE] = {
  120. "0/0.11 0.42/0.51 1/0.95",
  121. "0.50/0.48",
  122. "0/0.22 0.49/0.44 1/0.8",
  123. }
  124. };
  125. static struct keypoint *make_point(double x, double y, struct keypoint *next)
  126. {
  127. struct keypoint *point = av_mallocz(sizeof(*point));
  128. if (!point)
  129. return NULL;
  130. point->x = x;
  131. point->y = y;
  132. point->next = next;
  133. return point;
  134. }
  135. static int parse_points_str(AVFilterContext *ctx, struct keypoint **points, const char *s)
  136. {
  137. char *p = (char *)s; // strtod won't alter the string
  138. struct keypoint *last = NULL;
  139. /* construct a linked list based on the key points string */
  140. while (p && *p) {
  141. struct keypoint *point = make_point(0, 0, NULL);
  142. if (!point)
  143. return AVERROR(ENOMEM);
  144. point->x = av_strtod(p, &p); if (p && *p) p++;
  145. point->y = av_strtod(p, &p); if (p && *p) p++;
  146. if (point->x < 0 || point->x > 1 || point->y < 0 || point->y > 1) {
  147. av_log(ctx, AV_LOG_ERROR, "Invalid key point coordinates (%f;%f), "
  148. "x and y must be in the [0;1] range.\n", point->x, point->y);
  149. return AVERROR(EINVAL);
  150. }
  151. if (!*points)
  152. *points = point;
  153. if (last) {
  154. if ((int)(last->x * 255) >= (int)(point->x * 255)) {
  155. av_log(ctx, AV_LOG_ERROR, "Key point coordinates (%f;%f) "
  156. "and (%f;%f) are too close from each other or not "
  157. "strictly increasing on the x-axis\n",
  158. last->x, last->y, point->x, point->y);
  159. return AVERROR(EINVAL);
  160. }
  161. last->next = point;
  162. }
  163. last = point;
  164. }
  165. /* auto insert first key point if missing at x=0 */
  166. if (!*points) {
  167. last = make_point(0, 0, NULL);
  168. if (!last)
  169. return AVERROR(ENOMEM);
  170. last->x = last->y = 0;
  171. *points = last;
  172. } else if ((*points)->x != 0.) {
  173. struct keypoint *newfirst = make_point(0, 0, *points);
  174. if (!newfirst)
  175. return AVERROR(ENOMEM);
  176. *points = newfirst;
  177. }
  178. av_assert0(last);
  179. /* auto insert last key point if missing at x=1 */
  180. if (last->x != 1.) {
  181. struct keypoint *point = make_point(1, 1, NULL);
  182. if (!point)
  183. return AVERROR(ENOMEM);
  184. last->next = point;
  185. }
  186. return 0;
  187. }
  188. static int get_nb_points(const struct keypoint *d)
  189. {
  190. int n = 0;
  191. while (d) {
  192. n++;
  193. d = d->next;
  194. }
  195. return n;
  196. }
  197. /**
  198. * Natural cubic spline interpolation
  199. * Finding curves using Cubic Splines notes by Steven Rauch and John Stockie.
  200. * @see http://people.math.sfu.ca/~stockie/teaching/macm316/notes/splines.pdf
  201. */
  202. static int interpolate(AVFilterContext *ctx, uint8_t *y, const struct keypoint *points)
  203. {
  204. int i, ret = 0;
  205. const struct keypoint *point;
  206. double xprev = 0;
  207. int n = get_nb_points(points); // number of splines
  208. double (*matrix)[3] = av_calloc(n, sizeof(*matrix));
  209. double *h = av_malloc((n - 1) * sizeof(*h));
  210. double *r = av_calloc(n, sizeof(*r));
  211. if (!matrix || !h || !r) {
  212. ret = AVERROR(ENOMEM);
  213. goto end;
  214. }
  215. /* h(i) = x(i+1) - x(i) */
  216. i = -1;
  217. for (point = points; point; point = point->next) {
  218. if (i != -1)
  219. h[i] = point->x - xprev;
  220. xprev = point->x;
  221. i++;
  222. }
  223. /* right-side of the polynomials, will be modified to contains the solution */
  224. point = points;
  225. for (i = 1; i < n - 1; i++) {
  226. double yp = point->y,
  227. yc = point->next->y,
  228. yn = point->next->next->y;
  229. r[i] = 6 * ((yn-yc)/h[i] - (yc-yp)/h[i-1]);
  230. point = point->next;
  231. }
  232. #define BD 0 /* sub diagonal (below main) */
  233. #define MD 1 /* main diagonal (center) */
  234. #define AD 2 /* sup diagonal (above main) */
  235. /* left side of the polynomials into a tridiagonal matrix. */
  236. matrix[0][MD] = matrix[n - 1][MD] = 1;
  237. for (i = 1; i < n - 1; i++) {
  238. matrix[i][BD] = h[i-1];
  239. matrix[i][MD] = 2 * (h[i-1] + h[i]);
  240. matrix[i][AD] = h[i];
  241. }
  242. /* tridiagonal solving of the linear system */
  243. for (i = 1; i < n; i++) {
  244. double den = matrix[i][MD] - matrix[i][BD] * matrix[i-1][AD];
  245. double k = den ? 1./den : 1.;
  246. matrix[i][AD] *= k;
  247. r[i] = (r[i] - matrix[i][BD] * r[i - 1]) * k;
  248. }
  249. for (i = n - 2; i >= 0; i--)
  250. r[i] = r[i] - matrix[i][AD] * r[i + 1];
  251. /* compute the graph with x=[0..255] */
  252. i = 0;
  253. point = points;
  254. av_assert0(point->next); // always at least 2 key points
  255. while (point->next) {
  256. double yc = point->y;
  257. double yn = point->next->y;
  258. double a = yc;
  259. double b = (yn-yc)/h[i] - h[i]*r[i]/2. - h[i]*(r[i+1]-r[i])/6.;
  260. double c = r[i] / 2.;
  261. double d = (r[i+1] - r[i]) / (6.*h[i]);
  262. int x;
  263. int x_start = point->x * 255;
  264. int x_end = point->next->x * 255;
  265. av_assert0(x_start >= 0 && x_start <= 255 &&
  266. x_end >= 0 && x_end <= 255);
  267. for (x = x_start; x <= x_end; x++) {
  268. double xx = (x - x_start) * 1/255.;
  269. double yy = a + b*xx + c*xx*xx + d*xx*xx*xx;
  270. y[x] = av_clipf(yy, 0, 1) * 255;
  271. av_log(ctx, AV_LOG_DEBUG, "f(%f)=%f -> y[%d]=%d\n", xx, yy, x, y[x]);
  272. }
  273. point = point->next;
  274. i++;
  275. }
  276. end:
  277. av_free(matrix);
  278. av_free(h);
  279. av_free(r);
  280. return ret;
  281. }
  282. static int parse_psfile(AVFilterContext *ctx, const char *fname)
  283. {
  284. CurvesContext *curves = ctx->priv;
  285. uint8_t *buf;
  286. size_t size;
  287. int i, ret, av_unused(version), nb_curves;
  288. AVBPrint ptstr;
  289. static const int comp_ids[] = {3, 0, 1, 2};
  290. av_bprint_init(&ptstr, 0, AV_BPRINT_SIZE_AUTOMATIC);
  291. ret = av_file_map(fname, &buf, &size, 0, NULL);
  292. if (ret < 0)
  293. return ret;
  294. #define READ16(dst) do { \
  295. if (size < 2) { \
  296. ret = AVERROR_INVALIDDATA; \
  297. goto end; \
  298. } \
  299. dst = AV_RB16(buf); \
  300. buf += 2; \
  301. size -= 2; \
  302. } while (0)
  303. READ16(version);
  304. READ16(nb_curves);
  305. for (i = 0; i < FFMIN(nb_curves, FF_ARRAY_ELEMS(comp_ids)); i++) {
  306. int nb_points, n;
  307. av_bprint_clear(&ptstr);
  308. READ16(nb_points);
  309. for (n = 0; n < nb_points; n++) {
  310. int y, x;
  311. READ16(y);
  312. READ16(x);
  313. av_bprintf(&ptstr, "%f/%f ", x / 255., y / 255.);
  314. }
  315. if (*ptstr.str) {
  316. char **pts = &curves->comp_points_str[comp_ids[i]];
  317. if (!*pts) {
  318. *pts = av_strdup(ptstr.str);
  319. av_log(ctx, AV_LOG_DEBUG, "curves %d (intid=%d) [%d points]: [%s]\n",
  320. i, comp_ids[i], nb_points, *pts);
  321. if (!*pts) {
  322. ret = AVERROR(ENOMEM);
  323. goto end;
  324. }
  325. }
  326. }
  327. }
  328. end:
  329. av_bprint_finalize(&ptstr, NULL);
  330. av_file_unmap(buf, size);
  331. return ret;
  332. }
  333. static av_cold int init(AVFilterContext *ctx)
  334. {
  335. int i, j, ret;
  336. CurvesContext *curves = ctx->priv;
  337. struct keypoint *comp_points[NB_COMP + 1] = {0};
  338. char **pts = curves->comp_points_str;
  339. const char *allp = curves->comp_points_str_all;
  340. //if (!allp && curves->preset != PRESET_NONE && curves_presets[curves->preset].all)
  341. // allp = curves_presets[curves->preset].all;
  342. if (allp) {
  343. for (i = 0; i < NB_COMP; i++) {
  344. if (!pts[i])
  345. pts[i] = av_strdup(allp);
  346. if (!pts[i])
  347. return AVERROR(ENOMEM);
  348. }
  349. }
  350. if (curves->psfile) {
  351. ret = parse_psfile(ctx, curves->psfile);
  352. if (ret < 0)
  353. return ret;
  354. }
  355. if (curves->preset != PRESET_NONE) {
  356. #define SET_COMP_IF_NOT_SET(n, name) do { \
  357. if (!pts[n] && curves_presets[curves->preset].name) { \
  358. pts[n] = av_strdup(curves_presets[curves->preset].name); \
  359. if (!pts[n]) \
  360. return AVERROR(ENOMEM); \
  361. } \
  362. } while (0)
  363. SET_COMP_IF_NOT_SET(0, r);
  364. SET_COMP_IF_NOT_SET(1, g);
  365. SET_COMP_IF_NOT_SET(2, b);
  366. SET_COMP_IF_NOT_SET(3, master);
  367. }
  368. for (i = 0; i < NB_COMP + 1; i++) {
  369. ret = parse_points_str(ctx, comp_points + i, curves->comp_points_str[i]);
  370. if (ret < 0)
  371. return ret;
  372. ret = interpolate(ctx, curves->graph[i], comp_points[i]);
  373. if (ret < 0)
  374. return ret;
  375. }
  376. if (pts[NB_COMP]) {
  377. for (i = 0; i < NB_COMP; i++)
  378. for (j = 0; j < 256; j++)
  379. curves->graph[i][j] = curves->graph[NB_COMP][curves->graph[i][j]];
  380. }
  381. if (av_log_get_level() >= AV_LOG_VERBOSE) {
  382. for (i = 0; i < NB_COMP; i++) {
  383. struct keypoint *point = comp_points[i];
  384. av_log(ctx, AV_LOG_VERBOSE, "#%d points:", i);
  385. while (point) {
  386. av_log(ctx, AV_LOG_VERBOSE, " (%f;%f)", point->x, point->y);
  387. point = point->next;
  388. }
  389. av_log(ctx, AV_LOG_VERBOSE, "\n");
  390. av_log(ctx, AV_LOG_VERBOSE, "#%d values:", i);
  391. for (j = 0; j < 256; j++)
  392. av_log(ctx, AV_LOG_VERBOSE, " %02X", curves->graph[i][j]);
  393. av_log(ctx, AV_LOG_VERBOSE, "\n");
  394. }
  395. }
  396. for (i = 0; i < NB_COMP + 1; i++) {
  397. struct keypoint *point = comp_points[i];
  398. while (point) {
  399. struct keypoint *next = point->next;
  400. av_free(point);
  401. point = next;
  402. }
  403. }
  404. return 0;
  405. }
  406. static int query_formats(AVFilterContext *ctx)
  407. {
  408. static const enum AVPixelFormat pix_fmts[] = {
  409. AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
  410. AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA,
  411. AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR,
  412. AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR,
  413. AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0,
  414. AV_PIX_FMT_NONE
  415. };
  416. ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
  417. return 0;
  418. }
  419. static int config_input(AVFilterLink *inlink)
  420. {
  421. CurvesContext *curves = inlink->dst->priv;
  422. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  423. ff_fill_rgba_map(curves->rgba_map, inlink->format);
  424. curves->step = av_get_padded_bits_per_pixel(desc) >> 3;
  425. return 0;
  426. }
  427. static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  428. {
  429. int x, y;
  430. const CurvesContext *curves = ctx->priv;
  431. const ThreadData *td = arg;
  432. const AVFrame *in = td->in;
  433. const AVFrame *out = td->out;
  434. const int direct = out == in;
  435. const int step = curves->step;
  436. const uint8_t r = curves->rgba_map[R];
  437. const uint8_t g = curves->rgba_map[G];
  438. const uint8_t b = curves->rgba_map[B];
  439. const uint8_t a = curves->rgba_map[A];
  440. const int slice_start = (in->height * jobnr ) / nb_jobs;
  441. const int slice_end = (in->height * (jobnr+1)) / nb_jobs;
  442. uint8_t *dst = out->data[0] + slice_start * out->linesize[0];
  443. const uint8_t *src = in->data[0] + slice_start * in->linesize[0];
  444. for (y = slice_start; y < slice_end; y++) {
  445. for (x = 0; x < in->width * step; x += step) {
  446. dst[x + r] = curves->graph[R][src[x + r]];
  447. dst[x + g] = curves->graph[G][src[x + g]];
  448. dst[x + b] = curves->graph[B][src[x + b]];
  449. if (!direct && step == 4)
  450. dst[x + a] = src[x + a];
  451. }
  452. dst += out->linesize[0];
  453. src += in ->linesize[0];
  454. }
  455. return 0;
  456. }
  457. static int filter_frame(AVFilterLink *inlink, AVFrame *in)
  458. {
  459. AVFilterContext *ctx = inlink->dst;
  460. AVFilterLink *outlink = ctx->outputs[0];
  461. AVFrame *out;
  462. ThreadData td;
  463. if (av_frame_is_writable(in)) {
  464. out = in;
  465. } else {
  466. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  467. if (!out) {
  468. av_frame_free(&in);
  469. return AVERROR(ENOMEM);
  470. }
  471. av_frame_copy_props(out, in);
  472. }
  473. td.in = in;
  474. td.out = out;
  475. ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(outlink->h, ctx->graph->nb_threads));
  476. if (out != in)
  477. av_frame_free(&in);
  478. return ff_filter_frame(outlink, out);
  479. }
  480. static const AVFilterPad curves_inputs[] = {
  481. {
  482. .name = "default",
  483. .type = AVMEDIA_TYPE_VIDEO,
  484. .filter_frame = filter_frame,
  485. .config_props = config_input,
  486. },
  487. { NULL }
  488. };
  489. static const AVFilterPad curves_outputs[] = {
  490. {
  491. .name = "default",
  492. .type = AVMEDIA_TYPE_VIDEO,
  493. },
  494. { NULL }
  495. };
  496. AVFilter ff_vf_curves = {
  497. .name = "curves",
  498. .description = NULL_IF_CONFIG_SMALL("Adjust components curves."),
  499. .priv_size = sizeof(CurvesContext),
  500. .init = init,
  501. .query_formats = query_formats,
  502. .inputs = curves_inputs,
  503. .outputs = curves_outputs,
  504. .priv_class = &curves_class,
  505. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
  506. };