Welcome to mirror list, hosted at ThFree Co, Russian Federation.

vf_colorlevels.c « libavfilter - github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 76adfbd8c8d039d6fdf36ec918f2a377b11ae8e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
/*
 * Copyright (c) 2013 Paul B Mahol
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "drawutils.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
#include "preserve_color.h"

#define R 0
#define G 1
#define B 2
#define A 3

typedef struct Range {
    double in_min, in_max;
    double out_min, out_max;
} Range;

typedef struct ColorLevelsContext {
    const AVClass *class;
    Range range[4];
    int preserve_color;

    int nb_comp;
    int depth;
    int max;
    int planar;
    int bpp;
    int step;
    uint8_t rgba_map[4];
    int linesize;

    int (*colorlevels_slice[2])(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
} ColorLevelsContext;

#define OFFSET(x) offsetof(ColorLevelsContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
static const AVOption colorlevels_options[] = {
    { "rimin", "set input red black point",    OFFSET(range[R].in_min),  AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
    { "gimin", "set input green black point",  OFFSET(range[G].in_min),  AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
    { "bimin", "set input blue black point",   OFFSET(range[B].in_min),  AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
    { "aimin", "set input alpha black point",  OFFSET(range[A].in_min),  AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, FLAGS },
    { "rimax", "set input red white point",    OFFSET(range[R].in_max),  AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
    { "gimax", "set input green white point",  OFFSET(range[G].in_max),  AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
    { "bimax", "set input blue white point",   OFFSET(range[B].in_max),  AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
    { "aimax", "set input alpha white point",  OFFSET(range[A].in_max),  AV_OPT_TYPE_DOUBLE, {.dbl=1}, -1, 1, FLAGS },
    { "romin", "set output red black point",   OFFSET(range[R].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0},  0, 1, FLAGS },
    { "gomin", "set output green black point", OFFSET(range[G].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0},  0, 1, FLAGS },
    { "bomin", "set output blue black point",  OFFSET(range[B].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0},  0, 1, FLAGS },
    { "aomin", "set output alpha black point", OFFSET(range[A].out_min), AV_OPT_TYPE_DOUBLE, {.dbl=0},  0, 1, FLAGS },
    { "romax", "set output red white point",   OFFSET(range[R].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1},  0, 1, FLAGS },
    { "gomax", "set output green white point", OFFSET(range[G].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1},  0, 1, FLAGS },
    { "bomax", "set output blue white point",  OFFSET(range[B].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1},  0, 1, FLAGS },
    { "aomax", "set output alpha white point", OFFSET(range[A].out_max), AV_OPT_TYPE_DOUBLE, {.dbl=1},  0, 1, FLAGS },
    { "preserve", "set preserve color mode",   OFFSET(preserve_color),   AV_OPT_TYPE_INT,    {.i64=0},  0, NB_PRESERVE-1, FLAGS, "preserve" },
    { "none",  "disabled",                     0,                        AV_OPT_TYPE_CONST,  {.i64=P_NONE}, 0, 0, FLAGS, "preserve" },
    { "lum",   "luminance",                    0,                        AV_OPT_TYPE_CONST,  {.i64=P_LUM},  0, 0, FLAGS, "preserve" },
    { "max",   "max",                          0,                        AV_OPT_TYPE_CONST,  {.i64=P_MAX},  0, 0, FLAGS, "preserve" },
    { "avg",   "average",                      0,                        AV_OPT_TYPE_CONST,  {.i64=P_AVG},  0, 0, FLAGS, "preserve" },
    { "sum",   "sum",                          0,                        AV_OPT_TYPE_CONST,  {.i64=P_SUM},  0, 0, FLAGS, "preserve" },
    { "nrm",   "norm",                         0,                        AV_OPT_TYPE_CONST,  {.i64=P_NRM},  0, 0, FLAGS, "preserve" },
    { "pwr",   "power",                        0,                        AV_OPT_TYPE_CONST,  {.i64=P_PWR},  0, 0, FLAGS, "preserve" },
    { NULL }
};

AVFILTER_DEFINE_CLASS(colorlevels);

typedef struct ThreadData {
    const uint8_t *srcrow[4];
    uint8_t *dstrow[4];
    int dst_linesize;
    int src_linesize;

    float coeff[4];

    int h;

    int imin[4];
    int omin[4];
} ThreadData;

#define DO_COMMON(type, clip, preserve, planar)                                 \
    const ThreadData *td = arg;                                                 \
    const int linesize = s->linesize;                                           \
    const int step = s->step;                                                   \
    const int process_h = td->h;                                                \
    const int slice_start = (process_h *  jobnr   ) / nb_jobs;                  \
    const int slice_end   = (process_h * (jobnr+1)) / nb_jobs;                  \
    const int src_linesize = td->src_linesize / sizeof(type);                   \
    const int dst_linesize = td->dst_linesize / sizeof(type);                   \
    const type *src_r = (const type *)(td->srcrow[R]) + src_linesize * slice_start; \
    const type *src_g = (const type *)(td->srcrow[G]) + src_linesize * slice_start; \
    const type *src_b = (const type *)(td->srcrow[B]) + src_linesize * slice_start; \
    const type *src_a = (const type *)(td->srcrow[A]) + src_linesize * slice_start; \
    type *dst_r = (type *)(td->dstrow[R]) + src_linesize * slice_start;         \
    type *dst_g = (type *)(td->dstrow[G]) + src_linesize * slice_start;         \
    type *dst_b = (type *)(td->dstrow[B]) + src_linesize * slice_start;         \
    type *dst_a = (type *)(td->dstrow[A]) + src_linesize * slice_start;         \
    const int imin_r = td->imin[R];                                             \
    const int imin_g = td->imin[G];                                             \
    const int imin_b = td->imin[B];                                             \
    const int imin_a = td->imin[A];                                             \
    const int omin_r = td->omin[R];                                             \
    const int omin_g = td->omin[G];                                             \
    const int omin_b = td->omin[B];                                             \
    const int omin_a = td->omin[A];                                             \
    const float coeff_r = td->coeff[R];                                         \
    const float coeff_g = td->coeff[G];                                         \
    const float coeff_b = td->coeff[B];                                         \
    const float coeff_a = td->coeff[A];                                         \
                                                                                \
    for (int y = slice_start; y < slice_end; y++) {                             \
        for (int x = 0; x < linesize; x += step) {                              \
            int ir, ig, ib, or, og, ob;                                         \
            ir = src_r[x];                                                      \
            ig = src_g[x];                                                      \
            ib = src_b[x];                                                      \
            if (preserve) {                                                     \
                float ratio, icolor, ocolor, max = s->max;                      \
                                                                                \
                or = (ir - imin_r) * coeff_r + omin_r;                          \
                og = (ig - imin_g) * coeff_g + omin_g;                          \
                ob = (ib - imin_b) * coeff_b + omin_b;                          \
                                                                                \
                preserve_color(s->preserve_color, ir, ig, ib, or, og, ob, max,  \
                              &icolor, &ocolor);                                \
                if (ocolor > 0.f) {                                             \
                    ratio = icolor / ocolor;                                    \
                                                                                \
                    or *= ratio;                                                \
                    og *= ratio;                                                \
                    ob *= ratio;                                                \
                }                                                               \
                                                                                \
                dst_r[x] = clip(or, depth);                                     \
                dst_g[x] = clip(og, depth);                                     \
                dst_b[x] = clip(ob, depth);                                     \
            } else {                                                            \
                dst_r[x] = clip((ir - imin_r) * coeff_r + omin_r, depth);       \
                dst_g[x] = clip((ig - imin_g) * coeff_g + omin_g, depth);       \
                dst_b[x] = clip((ib - imin_b) * coeff_b + omin_b, depth);       \
            }                                                                   \
        }                                                                       \
                                                                                \
        for (int x = 0; x < linesize && s->nb_comp == 4; x += step)             \
            dst_a[x] = clip((src_a[x] - imin_a) * coeff_a + omin_a, depth);     \
                                                                                \
        src_r += src_linesize;                                                  \
        src_g += src_linesize;                                                  \
        src_b += src_linesize;                                                  \
        src_a += src_linesize;                                                  \
                                                                                \
        dst_r += dst_linesize;                                                  \
        dst_g += dst_linesize;                                                  \
        dst_b += dst_linesize;                                                  \
        dst_a += dst_linesize;                                                  \
    }

#define CLIP8(x, depth) av_clip_uint8(x)
#define CLIP16(x, depth) av_clip_uint16(x)

static int colorlevels_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    DO_COMMON(uint8_t, CLIP8, 0, 0)
    return 0;
}

static int colorlevels_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;\
    DO_COMMON(uint16_t, CLIP16, 0, 0)
    return 0;
}

static int colorlevels_preserve_slice_8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    DO_COMMON(uint8_t, CLIP8, 1, 0)
    return 0;
}

static int colorlevels_preserve_slice_16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    DO_COMMON(uint16_t, CLIP16, 1, 0)
    return 0;
}

static int colorlevels_slice_8_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    DO_COMMON(uint8_t, CLIP8, 0, 1)
    return 0;
}

static int colorlevels_slice_9_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    const int depth = 9;
    DO_COMMON(uint16_t, av_clip_uintp2, 0, 1)
    return 0;
}

static int colorlevels_slice_10_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    const int depth = 10;
    DO_COMMON(uint16_t, av_clip_uintp2, 0, 1)
    return 0;
}

static int colorlevels_slice_12_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    const int depth = 12;
    DO_COMMON(uint16_t, av_clip_uintp2, 0, 1)
    return 0;
}

static int colorlevels_slice_14_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    const int depth = 14;
    DO_COMMON(uint16_t, av_clip_uintp2, 0, 1)
    return 0;
}

static int colorlevels_slice_16_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    DO_COMMON(uint16_t, CLIP16, 0, 1)
    return 0;
}

static int colorlevels_preserve_slice_8_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    DO_COMMON(uint8_t, CLIP8, 1, 1)
    return 0;
}

static int colorlevels_preserve_slice_9_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    const int depth = 9;
    DO_COMMON(uint16_t, av_clip_uintp2, 1, 1)
    return 0;
}

static int colorlevels_preserve_slice_10_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    const int depth = 10;
    DO_COMMON(uint16_t, av_clip_uintp2, 1, 1)
    return 0;
}

static int colorlevels_preserve_slice_12_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    const int depth = 12;
    DO_COMMON(uint16_t, av_clip_uintp2, 1, 1)
    return 0;
}

static int colorlevels_preserve_slice_14_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    const int depth = 14;
    DO_COMMON(uint16_t, av_clip_uintp2, 1, 1)
    return 0;
}

static int colorlevels_preserve_slice_16_planar(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
    ColorLevelsContext *s = ctx->priv;
    DO_COMMON(uint16_t, CLIP16, 1, 1)
    return 0;
}

static int config_input(AVFilterLink *inlink)
{
    AVFilterContext *ctx = inlink->dst;
    ColorLevelsContext *s = ctx->priv;
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);

    s->nb_comp = desc->nb_components;
    s->planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
    s->depth = desc->comp[0].depth;
    s->max = (1 << s->depth) - 1;
    s->bpp = (desc->comp[0].depth + 7) >> 3;
    s->step = s->planar ? 1 : av_get_padded_bits_per_pixel(desc) >> (3 + (s->bpp == 2));
    s->linesize = inlink->w * s->step;
    ff_fill_rgba_map(s->rgba_map, inlink->format);

    if (!s->planar) {
        s->colorlevels_slice[0] = colorlevels_slice_8;
        s->colorlevels_slice[1] = colorlevels_preserve_slice_8;
        if (s->bpp == 2) {
            s->colorlevels_slice[0] = colorlevels_slice_16;
            s->colorlevels_slice[1] = colorlevels_preserve_slice_16;
        }
    } else {
        switch (s->depth) {
        case 8:
            s->colorlevels_slice[0] = colorlevels_slice_8_planar;
            s->colorlevels_slice[1] = colorlevels_preserve_slice_8_planar;
            break;
        case 9:
            s->colorlevels_slice[0] = colorlevels_slice_9_planar;
            s->colorlevels_slice[1] = colorlevels_preserve_slice_9_planar;
            break;
        case 10:
            s->colorlevels_slice[0] = colorlevels_slice_10_planar;
            s->colorlevels_slice[1] = colorlevels_preserve_slice_10_planar;
            break;
        case 12:
            s->colorlevels_slice[0] = colorlevels_slice_12_planar;
            s->colorlevels_slice[1] = colorlevels_preserve_slice_12_planar;
            break;
        case 14:
            s->colorlevels_slice[0] = colorlevels_slice_14_planar;
            s->colorlevels_slice[1] = colorlevels_preserve_slice_14_planar;
            break;
        case 16:
            s->colorlevels_slice[0] = colorlevels_slice_16_planar;
            s->colorlevels_slice[1] = colorlevels_preserve_slice_16_planar;
            break;
        }
    }

    return 0;
}

static int filter_frame(AVFilterLink *inlink, AVFrame *in)
{
    AVFilterContext *ctx = inlink->dst;
    ColorLevelsContext *s = ctx->priv;
    AVFilterLink *outlink = ctx->outputs[0];
    const int step = s->step;
    ThreadData td;
    AVFrame *out;

    if (av_frame_is_writable(in)) {
        out = in;
    } else {
        out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
        if (!out) {
            av_frame_free(&in);
            return AVERROR(ENOMEM);
        }
        av_frame_copy_props(out, in);
    }

    td.h             = inlink->h;
    td.dst_linesize  = out->linesize[0];
    td.src_linesize  = in->linesize[0];
    if (s->planar) {
        td.srcrow[R] = in->data[2];
        td.dstrow[R] = out->data[2];
        td.srcrow[G] = in->data[0];
        td.dstrow[G] = out->data[0];
        td.srcrow[B] = in->data[1];
        td.dstrow[B] = out->data[1];
        td.srcrow[A] = in->data[3];
        td.dstrow[A] = out->data[3];
    } else {
        td.srcrow[R] = in->data[0]  + s->rgba_map[R] * s->bpp;
        td.dstrow[R] = out->data[0] + s->rgba_map[R] * s->bpp;
        td.srcrow[G] = in->data[0]  + s->rgba_map[G] * s->bpp;
        td.dstrow[G] = out->data[0] + s->rgba_map[G] * s->bpp;
        td.srcrow[B] = in->data[0]  + s->rgba_map[B] * s->bpp;
        td.dstrow[B] = out->data[0] + s->rgba_map[B] * s->bpp;
        td.srcrow[A] = in->data[0]  + s->rgba_map[A] * s->bpp;
        td.dstrow[A] = out->data[0] + s->rgba_map[A] * s->bpp;
    }

    switch (s->bpp) {
    case 1:
        for (int i = 0; i < s->nb_comp; i++) {
            Range *r = &s->range[i];
            const uint8_t offset = s->rgba_map[i];
            const uint8_t *srcrow = in->data[0];
            int imin = lrint(r->in_min  * UINT8_MAX);
            int imax = lrint(r->in_max  * UINT8_MAX);
            int omin = lrint(r->out_min * UINT8_MAX);
            int omax = lrint(r->out_max * UINT8_MAX);
            float coeff;

            if (imin < 0) {
                imin = UINT8_MAX;
                for (int y = 0; y < inlink->h; y++) {
                    const uint8_t *src = srcrow;

                    for (int x = 0; x < s->linesize; x += step)
                        imin = FFMIN(imin, src[x + offset]);
                    srcrow += in->linesize[0];
                }
            }
            if (imax < 0) {
                srcrow = in->data[0];
                imax = 0;
                for (int y = 0; y < inlink->h; y++) {
                    const uint8_t *src = srcrow;

                    for (int x = 0; x < s->linesize; x += step)
                        imax = FFMAX(imax, src[x + offset]);
                    srcrow += in->linesize[0];
                }
            }

            coeff = (omax - omin) / (double)(imax - imin);

            td.coeff[i] = coeff;
            td.imin[i]  = imin;
            td.omin[i]  = omin;
        }
        break;
    case 2:
        for (int i = 0; i < s->nb_comp; i++) {
            Range *r = &s->range[i];
            const uint8_t offset = s->rgba_map[i];
            const uint8_t *srcrow = in->data[0];
            int imin = lrint(r->in_min  * UINT16_MAX);
            int imax = lrint(r->in_max  * UINT16_MAX);
            int omin = lrint(r->out_min * UINT16_MAX);
            int omax = lrint(r->out_max * UINT16_MAX);
            float coeff;

            if (imin < 0) {
                imin = UINT16_MAX;
                for (int y = 0; y < inlink->h; y++) {
                    const uint16_t *src = (const uint16_t *)srcrow;

                    for (int x = 0; x < s->linesize; x += step)
                        imin = FFMIN(imin, src[x + offset]);
                    srcrow += in->linesize[0];
                }
            }
            if (imax < 0) {
                srcrow = in->data[0];
                imax = 0;
                for (int y = 0; y < inlink->h; y++) {
                    const uint16_t *src = (const uint16_t *)srcrow;

                    for (int x = 0; x < s->linesize; x += step)
                        imax = FFMAX(imax, src[x + offset]);
                    srcrow += in->linesize[0];
                }
            }

            coeff = (omax - omin) / (double)(imax - imin);

            td.coeff[i] = coeff;
            td.imin[i]  = imin;
            td.omin[i]  = omin;
        }
        break;
    }

    ff_filter_execute(ctx, s->colorlevels_slice[s->preserve_color > 0], &td, NULL,
                      FFMIN(inlink->h, ff_filter_get_nb_threads(ctx)));

    if (in != out)
        av_frame_free(&in);
    return ff_filter_frame(outlink, out);
}

static const AVFilterPad colorlevels_inputs[] = {
    {
        .name         = "default",
        .type         = AVMEDIA_TYPE_VIDEO,
        .filter_frame = filter_frame,
        .config_props = config_input,
    },
};

static const AVFilterPad colorlevels_outputs[] = {
    {
        .name = "default",
        .type = AVMEDIA_TYPE_VIDEO,
    },
};

const AVFilter ff_vf_colorlevels = {
    .name          = "colorlevels",
    .description   = NULL_IF_CONFIG_SMALL("Adjust the color levels."),
    .priv_size     = sizeof(ColorLevelsContext),
    .priv_class    = &colorlevels_class,
    FILTER_INPUTS(colorlevels_inputs),
    FILTER_OUTPUTS(colorlevels_outputs),
    FILTER_PIXFMTS(AV_PIX_FMT_0RGB,   AV_PIX_FMT_0BGR,
                   AV_PIX_FMT_ARGB,   AV_PIX_FMT_ABGR,
                   AV_PIX_FMT_RGB0,   AV_PIX_FMT_BGR0,
                   AV_PIX_FMT_RGB24,  AV_PIX_FMT_BGR24,
                   AV_PIX_FMT_RGB48,  AV_PIX_FMT_BGR48,
                   AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64,
                   AV_PIX_FMT_RGBA,   AV_PIX_FMT_BGRA,
                   AV_PIX_FMT_GBRP,   AV_PIX_FMT_GBRAP,
                   AV_PIX_FMT_GBRP9,
                   AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRAP10,
                   AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
                   AV_PIX_FMT_GBRP14,
                   AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16),
    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
    .process_command = ff_filter_process_command,
};