FFmpeg
Loading...
Searching...
No Matches
vf_colorlevels.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Paul B Mahol
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#include "libavutil/opt.h"
22#include "libavutil/pixdesc.h"
23#include "avfilter.h"
24#include "drawutils.h"
25#include "filters.h"
26#include "video.h"
27#include "preserve_color.h"
28
29#define R 0
30#define G 1
31#define B 2
32#define A 3
33
34typedef struct Range {
35 double in_min, in_max;
37} Range;
38
39typedef struct ColorLevelsContext {
40 const AVClass *class;
43
45 int depth;
46 int max;
47 int planar;
48 int bpp;
49 int step;
50 uint8_t rgba_map[4];
52
53 int (*colorlevels_slice[2])(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
55
56#define OFFSET(x) offsetof(ColorLevelsContext, x)
57#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
58static const AVOption colorlevels_options[] = {
59 { "rimin", "set input red black point", OFFSET(range[R].in_min), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
60 { "gimin", "set input green black point", OFFSET(range[G].in_min), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
61 { "bimin", "set input blue black point", OFFSET(range[B].in_min), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
62 { "aimin", "set input alpha black point", OFFSET(range[A].in_min), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
63 { "rimax", "set input red white point", OFFSET(range[R].in_max), AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
64 { "gimax", "set input green white point", OFFSET(range[G].in_max), AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
65 { "bimax", "set input blue white point", OFFSET(range[B].in_max), AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
66 { "aimax", "set input alpha white point", OFFSET(range[A].in_max), AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
67 { "romin", "set output red black point", OFFSET(range[R].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 1, FLAGS },
68 { "gomin", "set output green black point", OFFSET(range[G].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 1, FLAGS },
69 { "bomin", "set output blue black point", OFFSET(range[B].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 1, FLAGS },
70 { "aomin", "set output alpha black point", OFFSET(range[A].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 1, FLAGS },
71 { "romax", "set output red white point", OFFSET(range[R].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
72 { "gomax", "set output green white point", OFFSET(range[G].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
73 { "bomax", "set output blue white point", OFFSET(range[B].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
74 { "aomax", "set output alpha white point", OFFSET(range[A].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
75 { "preserve", "set preserve color mode", OFFSET(preserve_color), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_PRESERVE-1, FLAGS, .unit = "preserve" },
76 { "none", "disabled", 0, AV_OPT_TYPE_CONST, {.i64=P_NONE}, 0, 0, FLAGS, .unit = "preserve" },
77 { "lum", "luminance", 0, AV_OPT_TYPE_CONST, {.i64=P_LUM}, 0, 0, FLAGS, .unit = "preserve" },
78 { "max", "max", 0, AV_OPT_TYPE_CONST, {.i64=P_MAX}, 0, 0, FLAGS, .unit = "preserve" },
79 { "avg", "average", 0, AV_OPT_TYPE_CONST, {.i64=P_AVG}, 0, 0, FLAGS, .unit = "preserve" },
80 { "sum", "sum", 0, AV_OPT_TYPE_CONST, {.i64=P_SUM}, 0, 0, FLAGS, .unit = "preserve" },
81 { "nrm", "norm", 0, AV_OPT_TYPE_CONST, {.i64=P_NRM}, 0, 0, FLAGS, .unit = "preserve" },
82 { "pwr", "power", 0, AV_OPT_TYPE_CONST, {.i64=P_PWR}, 0, 0, FLAGS, .unit = "preserve" },
83 { NULL }
84};
85
87
88typedef struct ThreadData {
89 const uint8_t *srcrow[4];
90 uint8_t *dstrow[4];
92 int src_linesize;
93
94 float coeff[4];
95
96 int h;
97
98 float fimin[4];
99 float fomin[4];
100 int imin[4];
101 int omin[4];
102} ThreadData;
103
104#define DO_COMMON(type, ptype, clip, preserve, planar) \
105 const ThreadData *td = arg; \
106 const int linesize = s->linesize; \
107 const int step = s->step; \
108 const int process_h = td->h; \
109 const int slice_start = ff_slice_pos(process_h, jobnr, nb_jobs); \
110 const int slice_end = ff_slice_pos(process_h, jobnr + 1, nb_jobs); \
111 const int src_linesize = td->src_linesize / sizeof(type); \
112 const int dst_linesize = td->dst_linesize / sizeof(type); \
113 const type *src_r = (const type *)(td->srcrow[R]) + src_linesize * slice_start; \
114 const type *src_g = (const type *)(td->srcrow[G]) + src_linesize * slice_start; \
115 const type *src_b = (const type *)(td->srcrow[B]) + src_linesize * slice_start; \
116 const type *src_a = (const type *)(td->srcrow[A]) + src_linesize * slice_start; \
117 type *dst_r = (type *)(td->dstrow[R]) + src_linesize * slice_start; \
118 type *dst_g = (type *)(td->dstrow[G]) + src_linesize * slice_start; \
119 type *dst_b = (type *)(td->dstrow[B]) + src_linesize * slice_start; \
120 type *dst_a = (type *)(td->dstrow[A]) + src_linesize * slice_start; \
121 const ptype imin_r = s->depth == 32 ? td->fimin[R] : td->imin[R]; \
122 const ptype imin_g = s->depth == 32 ? td->fimin[G] : td->imin[G]; \
123 const ptype imin_b = s->depth == 32 ? td->fimin[B] : td->imin[B]; \
124 const ptype imin_a = s->depth == 32 ? td->fimin[A] : td->imin[A]; \
125 const ptype omin_r = s->depth == 32 ? td->fomin[R] : td->omin[R]; \
126 const ptype omin_g = s->depth == 32 ? td->fomin[G] : td->omin[G]; \
127 const ptype omin_b = s->depth == 32 ? td->fomin[B] : td->omin[B]; \
128 const ptype omin_a = s->depth == 32 ? td->fomin[A] : td->omin[A]; \
129 const float coeff_r = td->coeff[R]; \
130 const float coeff_g = td->coeff[G]; \
131 const float coeff_b = td->coeff[B]; \
132 const float coeff_a = td->coeff[A]; \
133 \
134 for (int y = slice_start; y < slice_end; y++) { \
135 for (int x = 0; x < linesize; x += step) { \
136 ptype ir, ig, ib, or, og, ob; \
137 ir = src_r[x]; \
138 ig = src_g[x]; \
139 ib = src_b[x]; \
140 if (preserve) { \
141 float ratio, icolor, ocolor, max = s->depth==32 ? 1.f : s->max; \
142 \
143 or = (ir - imin_r) * coeff_r + omin_r; \
144 og = (ig - imin_g) * coeff_g + omin_g; \
145 ob = (ib - imin_b) * coeff_b + omin_b; \
146 \
147 preserve_color(s->preserve_color, ir, ig, ib, or, og, ob, max, \
148 &icolor, &ocolor); \
149 if (ocolor > 0.f) { \
150 ratio = icolor / ocolor; \
151 \
152 or *= ratio; \
153 og *= ratio; \
154 ob *= ratio; \
155 } \
156 \
157 dst_r[x] = clip(or, depth); \
158 dst_g[x] = clip(og, depth); \
159 dst_b[x] = clip(ob, depth); \
160 } else { \
161 dst_r[x] = clip((ir - imin_r) * coeff_r + omin_r, depth); \
162 dst_g[x] = clip((ig - imin_g) * coeff_g + omin_g, depth); \
163 dst_b[x] = clip((ib - imin_b) * coeff_b + omin_b, depth); \
164 } \
165 } \
166 \
167 for (int x = 0; x < linesize && s->nb_comp == 4; x += step) \
168 dst_a[x] = clip((src_a[x] - imin_a) * coeff_a + omin_a, depth); \
169 \
170 src_r += src_linesize; \
171 src_g += src_linesize; \
172 src_b += src_linesize; \
173 src_a += src_linesize; \
174 \
175 dst_r += dst_linesize; \
176 dst_g += dst_linesize; \
177 dst_b += dst_linesize; \
178 dst_a += dst_linesize; \
179 }
180
181#define CLIP8(x, depth) av_clip_uint8(x)
182#define CLIP16(x, depth) av_clip_uint16(x)
183#define NOCLIP(x, depth) (x)
184
185static int colorlevels_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
186{
187 ColorLevelsContext *s = ctx->priv;
188 DO_COMMON(uint8_t, int, CLIP8, 0, 0)
189 return 0;
190}
191
192static int colorlevels_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
193{
194 ColorLevelsContext *s = ctx->priv;\
195 DO_COMMON(uint16_t, int, CLIP16, 0, 0)
196 return 0;
197}
198
199static int colorlevels_preserve_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
200{
201 ColorLevelsContext *s = ctx->priv;
202 DO_COMMON(uint8_t, int, CLIP8, 1, 0)
203 return 0;
204}
205
206static int colorlevels_preserve_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
207{
208 ColorLevelsContext *s = ctx->priv;
209 DO_COMMON(uint16_t, int, CLIP16, 1, 0)
210 return 0;
211}
212
213static int colorlevels_slice_8_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
214{
215 ColorLevelsContext *s = ctx->priv;
216 DO_COMMON(uint8_t, int, CLIP8, 0, 1)
217 return 0;
218}
219
220static int colorlevels_slice_9_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
221{
222 ColorLevelsContext *s = ctx->priv;
223 const int depth = 9;
224 DO_COMMON(uint16_t, int, av_clip_uintp2, 0, 1)
225 return 0;
226}
227
228static int colorlevels_slice_10_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
229{
230 ColorLevelsContext *s = ctx->priv;
231 const int depth = 10;
232 DO_COMMON(uint16_t, int, av_clip_uintp2, 0, 1)
233 return 0;
234}
235
236static int colorlevels_slice_12_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
237{
238 ColorLevelsContext *s = ctx->priv;
239 const int depth = 12;
240 DO_COMMON(uint16_t, int, av_clip_uintp2, 0, 1)
241 return 0;
242}
243
244static int colorlevels_slice_14_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
245{
246 ColorLevelsContext *s = ctx->priv;
247 const int depth = 14;
248 DO_COMMON(uint16_t, int, av_clip_uintp2, 0, 1)
249 return 0;
250}
251
252static int colorlevels_slice_16_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
253{
254 ColorLevelsContext *s = ctx->priv;
255 DO_COMMON(uint16_t, int, CLIP16, 0, 1)
256 return 0;
257}
258
259static int colorlevels_slice_32_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
260{
261 ColorLevelsContext *s = ctx->priv;
262 DO_COMMON(float, float, NOCLIP, 0, 1)
263 return 0;
264}
265
266static int colorlevels_preserve_slice_8_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
267{
268 ColorLevelsContext *s = ctx->priv;
269 DO_COMMON(uint8_t, int, CLIP8, 1, 1)
270 return 0;
271}
272
273static int colorlevels_preserve_slice_9_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
274{
275 ColorLevelsContext *s = ctx->priv;
276 const int depth = 9;
277 DO_COMMON(uint16_t, int, av_clip_uintp2, 1, 1)
278 return 0;
279}
280
281static int colorlevels_preserve_slice_10_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
282{
283 ColorLevelsContext *s = ctx->priv;
284 const int depth = 10;
285 DO_COMMON(uint16_t, int, av_clip_uintp2, 1, 1)
286 return 0;
287}
288
289static int colorlevels_preserve_slice_12_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
290{
291 ColorLevelsContext *s = ctx->priv;
292 const int depth = 12;
293 DO_COMMON(uint16_t, int, av_clip_uintp2, 1, 1)
294 return 0;
295}
296
297static int colorlevels_preserve_slice_14_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
298{
299 ColorLevelsContext *s = ctx->priv;
300 const int depth = 14;
301 DO_COMMON(uint16_t, int, av_clip_uintp2, 1, 1)
302 return 0;
303}
304
305static int colorlevels_preserve_slice_16_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
306{
307 ColorLevelsContext *s = ctx->priv;
308 DO_COMMON(uint16_t, int, CLIP16, 1, 1)
309 return 0;
310}
311
312static int colorlevels_preserve_slice_32_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
313{
314 ColorLevelsContext *s = ctx->priv;
315 DO_COMMON(float, float, NOCLIP, 1, 1)
316 return 0;
317}
318
319static int config_input(AVFilterLink *inlink)
320{
321 AVFilterContext *ctx = inlink->dst;
322 ColorLevelsContext *s = ctx->priv;
324
325 s->nb_comp = desc->nb_components;
326 s->planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
327 s->depth = desc->comp[0].depth;
328 s->max = (1 << s->depth) - 1;
329 s->bpp = (desc->comp[0].depth + 7) >> 3;
330 s->step = s->planar ? 1 : av_get_padded_bits_per_pixel(desc) >> (3 + (s->bpp == 2));
331 s->linesize = inlink->w * s->step;
332 ff_fill_rgba_map(s->rgba_map, inlink->format);
333
334 if (!s->planar) {
335 s->colorlevels_slice[0] = colorlevels_slice_8;
336 s->colorlevels_slice[1] = colorlevels_preserve_slice_8;
337 if (s->bpp == 2) {
338 s->colorlevels_slice[0] = colorlevels_slice_16;
339 s->colorlevels_slice[1] = colorlevels_preserve_slice_16;
340 }
341 } else {
342 switch (s->depth) {
343 case 8:
344 s->colorlevels_slice[0] = colorlevels_slice_8_planar;
345 s->colorlevels_slice[1] = colorlevels_preserve_slice_8_planar;
346 break;
347 case 9:
348 s->colorlevels_slice[0] = colorlevels_slice_9_planar;
349 s->colorlevels_slice[1] = colorlevels_preserve_slice_9_planar;
350 break;
351 case 10:
352 s->colorlevels_slice[0] = colorlevels_slice_10_planar;
353 s->colorlevels_slice[1] = colorlevels_preserve_slice_10_planar;
354 break;
355 case 12:
356 s->colorlevels_slice[0] = colorlevels_slice_12_planar;
357 s->colorlevels_slice[1] = colorlevels_preserve_slice_12_planar;
358 break;
359 case 14:
360 s->colorlevels_slice[0] = colorlevels_slice_14_planar;
361 s->colorlevels_slice[1] = colorlevels_preserve_slice_14_planar;
362 break;
363 case 16:
364 s->colorlevels_slice[0] = colorlevels_slice_16_planar;
365 s->colorlevels_slice[1] = colorlevels_preserve_slice_16_planar;
366 break;
367 case 32:
368 s->colorlevels_slice[0] = colorlevels_slice_32_planar;
369 s->colorlevels_slice[1] = colorlevels_preserve_slice_32_planar;
370 break;
371 }
372 }
373
374 return 0;
375}
376
377static int filter_frame(AVFilterLink *inlink, AVFrame *in)
378{
379 AVFilterContext *ctx = inlink->dst;
380 ColorLevelsContext *s = ctx->priv;
381 AVFilterLink *outlink = ctx->outputs[0];
382 const int step = s->step;
383 ThreadData td;
384 AVFrame *out;
385
386 if (av_frame_is_writable(in)) {
387 out = in;
388 } else {
389 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
390 if (!out) {
391 av_frame_free(&in);
392 return AVERROR(ENOMEM);
393 }
395 }
396
397 td.h = inlink->h;
398 td.dst_linesize = out->linesize[0];
399 td.src_linesize = in->linesize[0];
400 if (s->planar) {
401 td.srcrow[R] = in->data[2];
402 td.dstrow[R] = out->data[2];
403 td.srcrow[G] = in->data[0];
404 td.dstrow[G] = out->data[0];
405 td.srcrow[B] = in->data[1];
406 td.dstrow[B] = out->data[1];
407 td.srcrow[A] = in->data[3];
408 td.dstrow[A] = out->data[3];
409 } else {
410 td.srcrow[R] = in->data[0] + s->rgba_map[R] * s->bpp;
411 td.dstrow[R] = out->data[0] + s->rgba_map[R] * s->bpp;
412 td.srcrow[G] = in->data[0] + s->rgba_map[G] * s->bpp;
413 td.dstrow[G] = out->data[0] + s->rgba_map[G] * s->bpp;
414 td.srcrow[B] = in->data[0] + s->rgba_map[B] * s->bpp;
415 td.dstrow[B] = out->data[0] + s->rgba_map[B] * s->bpp;
416 td.srcrow[A] = in->data[0] + s->rgba_map[A] * s->bpp;
417 td.dstrow[A] = out->data[0] + s->rgba_map[A] * s->bpp;
418 }
419
420 switch (s->bpp) {
421 case 1:
422 for (int i = 0; i < s->nb_comp; i++) {
423 Range *r = &s->range[i];
424 const uint8_t offset = s->rgba_map[i];
425 const uint8_t *srcrow = in->data[0];
426 int imin = lrint(r->in_min * UINT8_MAX);
427 int imax = lrint(r->in_max * UINT8_MAX);
428 int omin = lrint(r->out_min * UINT8_MAX);
429 int omax = lrint(r->out_max * UINT8_MAX);
430 float coeff;
431
432 if (imin < 0) {
433 imin = UINT8_MAX;
434 for (int y = 0; y < inlink->h; y++) {
435 const uint8_t *src = srcrow;
436
437 for (int x = 0; x < s->linesize; x += step)
438 imin = FFMIN(imin, src[x + offset]);
439 srcrow += in->linesize[0];
440 }
441 }
442 if (imax < 0) {
443 srcrow = in->data[0];
444 imax = 0;
445 for (int y = 0; y < inlink->h; y++) {
446 const uint8_t *src = srcrow;
447
448 for (int x = 0; x < s->linesize; x += step)
449 imax = FFMAX(imax, src[x + offset]);
450 srcrow += in->linesize[0];
451 }
452 }
453
454 coeff = (omax - omin) / (double)(imax - imin);
455
456 td.coeff[i] = coeff;
457 td.imin[i] = imin;
458 td.omin[i] = omin;
459 }
460 break;
461 case 2:
462 for (int i = 0; i < s->nb_comp; i++) {
463 Range *r = &s->range[i];
464 const uint8_t offset = s->rgba_map[i];
465 const uint8_t *srcrow = in->data[0];
466 int imin = lrint(r->in_min * UINT16_MAX);
467 int imax = lrint(r->in_max * UINT16_MAX);
468 int omin = lrint(r->out_min * UINT16_MAX);
469 int omax = lrint(r->out_max * UINT16_MAX);
470 float coeff;
471
472 if (imin < 0) {
473 imin = UINT16_MAX;
474 for (int y = 0; y < inlink->h; y++) {
475 const uint16_t *src = (const uint16_t *)srcrow;
476
477 for (int x = 0; x < s->linesize; x += step)
478 imin = FFMIN(imin, src[x + offset]);
479 srcrow += in->linesize[0];
480 }
481 }
482 if (imax < 0) {
483 srcrow = in->data[0];
484 imax = 0;
485 for (int y = 0; y < inlink->h; y++) {
486 const uint16_t *src = (const uint16_t *)srcrow;
487
488 for (int x = 0; x < s->linesize; x += step)
489 imax = FFMAX(imax, src[x + offset]);
490 srcrow += in->linesize[0];
491 }
492 }
493
494 coeff = (omax - omin) / (double)(imax - imin);
495
496 td.coeff[i] = coeff;
497 td.imin[i] = imin;
498 td.omin[i] = omin;
499 }
500 break;
501 case 4:
502 for (int i = 0; i < s->nb_comp; i++) {
503 Range *r = &s->range[i];
504 const uint8_t offset = s->rgba_map[i];
505 const uint8_t *srcrow = in->data[0];
506 float imin = r->in_min;
507 float imax = r->in_max;
508 float omin = r->out_min;
509 float omax = r->out_max;
510 float coeff;
511
512 if (imin < 0.f) {
513 imin = 1.f;
514 for (int y = 0; y < inlink->h; y++) {
515 const float *src = (const float *)srcrow;
516
517 for (int x = 0; x < s->linesize; x += step)
518 imin = fminf(imin, src[x + offset]);
519 srcrow += in->linesize[0];
520 }
521 }
522 if (imax < 0.f) {
523 srcrow = in->data[0];
524 imax = 0.f;
525 for (int y = 0; y < inlink->h; y++) {
526 const float *src = (const float *)srcrow;
527
528 for (int x = 0; x < s->linesize; x += step)
529 imax = fmaxf(imax, src[x + offset]);
530 srcrow += in->linesize[0];
531 }
532 }
533
534 coeff = (omax - omin) / (double)(imax - imin);
535
536 td.coeff[i] = coeff;
537 td.fimin[i] = imin;
538 td.fomin[i] = omin;
539 }
540 break;
541 }
542
543 ff_filter_execute(ctx, s->colorlevels_slice[s->preserve_color > 0], &td, NULL,
545
546 if (in != out)
547 av_frame_free(&in);
548 return ff_filter_frame(outlink, out);
549}
550
552 {
553 .name = "default",
554 .type = AVMEDIA_TYPE_VIDEO,
555 .filter_frame = filter_frame,
556 .config_props = config_input,
557 },
558};
559
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_colorlevels
#define A(x)
Definition vpx_arith.h:28
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition avfilter.c:906
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition avfilter.c:1696
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition avfilter.c:846
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FLAGS
Definition cmdutils.c:598
#define av_clip_uintp2
Definition common.h:124
#define NULL
Definition coverity.c:32
float fminf(float, float)
float fmaxf(float, float)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition drawutils.c:80
misc drawing utilities
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition opt.h:266
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition avfilter.h:196
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition avfilter.h:166
#define AVERROR(e)
Definition error.h:45
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition frame.c:535
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define B
Definition huffyuv.h:42
#define R
Definition huffyuv.h:44
#define G
Definition huffyuv.h:43
#define r
Definition input.c:42
unsigned offset
Definition libaomenc.c:763
const char * arg
Definition jacosubdec.c:65
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_PIXFMTS(...)
Definition filters.h:250
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
const char * desc
Definition libsvtav1.c:83
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
enum AVColorRange range
AVOptions.
int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel for the pixel format described by pixdesc, including any padding ...
Definition pixdesc.c:3425
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition pixdesc.h:132
#define AV_PIX_FMT_GBRAP12
Definition pixfmt.h:569
#define AV_PIX_FMT_GBRPF32
Definition pixfmt.h:584
#define AV_PIX_FMT_GBRAP16
Definition pixfmt.h:571
#define AV_PIX_FMT_GBRP9
Definition pixfmt.h:563
#define AV_PIX_FMT_BGR48
Definition pixfmt.h:536
#define AV_PIX_FMT_GBRP10
Definition pixfmt.h:564
#define AV_PIX_FMT_RGBA64
Definition pixfmt.h:535
#define AV_PIX_FMT_GBRP12
Definition pixfmt.h:565
#define AV_PIX_FMT_RGB48
Definition pixfmt.h:531
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition pixfmt.h:265
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition pixfmt.h:99
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition pixfmt.h:101
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition pixfmt.h:264
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition pixfmt.h:212
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition pixfmt.h:263
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition pixfmt.h:262
#define AV_PIX_FMT_BGRA64
Definition pixfmt.h:540
#define AV_PIX_FMT_GBRAP10
Definition pixfmt.h:568
#define AV_PIX_FMT_GBRP16
Definition pixfmt.h:567
#define AV_PIX_FMT_GBRP14
Definition pixfmt.h:566
#define AV_PIX_FMT_GBRAPF32
Definition pixfmt.h:585
@ P_NONE
@ P_SUM
@ P_NRM
@ NB_PRESERVE
@ P_MAX
@ P_AVG
@ P_PWR
@ P_LUM
static void preserve_color(int preserve_color, float ir, float ig, float ib, float r, float g, float b, float max, float *icolor, float *ocolor)
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:273
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
int(* colorlevels_slice[2])(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
double out_min
double in_min
double out_max
double in_max
Used for passing data between threads.
Definition dsddec.c:71
float fimin[4]
uint8_t * dstrow[4]
int src_linesize
Definition vf_bm3d.c:55
float coeff[4]
float fomin[4]
const uint8_t * srcrow[4]
#define lrint
Definition tablegen.h:53
static int imin(const int a, const int b)
Definition internal.h:182
static int imax(const int a, const int b)
Definition internal.h:177
#define src
Definition vp8dsp.c:248
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
#define CLIP8(x, depth)
Definition vf_amplify.c:140
#define CLIP16(x, depth)
Definition vf_amplify.c:141
#define DO_COMMON(type, ptype, clip, preserve, planar)
static const AVOption colorlevels_options[]
static int colorlevels_preserve_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_slice_32_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_preserve_slice_16_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_slice_12_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_slice_16_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int config_input(AVFilterLink *inlink)
static int colorlevels_slice_10_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_slice_8_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_slice_9_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_slice_14_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int colorlevels_preserve_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_preserve_slice_9_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define NOCLIP(x, depth)
static int colorlevels_preserve_slice_8_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_preserve_slice_12_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_preserve_slice_32_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int colorlevels_preserve_slice_14_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define OFFSET(x)
static int colorlevels_preserve_slice_10_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const AVFilterPad colorlevels_inputs[]
static const double coeff[2][5]
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition video.c:37
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition video.c:89