aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/fflcms2.h
blob: ad6c8c47cfd241d851269b1d21dba87c85f3bbc7 (plain) (blame)
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
/*
 * Copyright (c) 2022 Niklas Haas
 * 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
 */

/**
 * @file
 * Various functions for dealing with ICC profiles
 */

#ifndef AVFILTER_FFLCMS2_H
#define AVFILTER_FFLCMS2_H

#include "libavutil/frame.h"
#include "libavutil/pixfmt.h"
#include "colorspace.h"

#include <lcms2.h>

typedef struct FFIccContext {
    void *avctx;
    cmsContext ctx;
    cmsToneCurve *curves[AVCOL_TRC_NB]; /* tone curve cache */
} FFIccContext;

/**
 * Initializes an FFIccContext. This must be done prior to using it.
 *
 * Returns 0 on success, or a negative error code.
 */
int ff_icc_context_init(FFIccContext *s, void *avctx);
void ff_icc_context_uninit(FFIccContext *s);

/**
 * Generate an ICC profile for a given combination of color primaries and
 * transfer function. Both values must be set to valid entries (not
 * "undefined") for this function to work.
 *
 * Returns 0 on success, or a negative error code.
 */
int ff_icc_profile_generate(FFIccContext *s,
                            enum AVColorPrimaries color_prim,
                            enum AVColorTransferCharacteristic color_trc,
                            cmsHPROFILE *out_profile);

/**
 * Attach an ICC profile to a frame. Helper wrapper around cmsSaveProfileToMem
 * and av_frame_new_side_data_from_buf.
 *
 * Returns 0 on success, or a negative error code.
 */
int ff_icc_profile_attach(FFIccContext *s, cmsHPROFILE profile, AVFrame *frame);

/**
 * Read the color primaries and white point coefficients encoded by an ICC
 * profile, and return the raw values in `out_primaries`.
 *
 * Returns 0 on success, or a negative error code.
 */
int ff_icc_profile_read_primaries(FFIccContext *s, cmsHPROFILE profile,
                                  struct ColorPrimaries *out_primaries);

/**
 * Attempt detecting the transfer characteristic that best approximates the
 * transfer function encoded by an ICC profile. Sets `out_trc` to
 * AVCOL_TRC_UNSPECIFIED if no clear match can be identified.
 *
 * Returns 0 on success (including no match), or a negative error code.
 */
int ff_icc_profile_detect_transfer(FFIccContext *s, cmsHPROFILE profile,
                                   enum AVColorTransferCharacteristic *out_trc);

#endif /* AVFILTER_FFLCMS2_H */