FFmpeg
fflcms2.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Niklas Haas
3  * This file is part of FFmpeg.
4  *
5  * FFmpeg is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * FFmpeg is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with FFmpeg; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file
22  * Various functions for dealing with ICC profiles
23  */
24 
25 #ifndef AVCODEC_FFLCMS2_H
26 #define AVCODEC_FFLCMS2_H
27 
28 #include "libavutil/csp.h"
29 #include "libavutil/frame.h"
30 #include "libavutil/pixfmt.h"
31 
32 #include <lcms2.h>
33 
34 typedef struct FFIccContext {
35  void *avctx;
36  cmsContext ctx;
37  cmsToneCurve *curves[AVCOL_TRC_NB]; /* tone curve cache */
38 } FFIccContext;
39 
40 /**
41  * Initializes an FFIccContext. This must be done prior to using it.
42  *
43  * Returns 0 on success, or a negative error code.
44  */
45 int ff_icc_context_init(FFIccContext *s, void *avctx);
47 
48 /**
49  * Generate an ICC profile for a given combination of color primaries and
50  * transfer function. Both values must be set to valid entries (not
51  * "undefined") for this function to work.
52  *
53  * Returns 0 on success, or a negative error code.
54  */
56  enum AVColorPrimaries color_prim,
57  enum AVColorTransferCharacteristic color_trc,
58  cmsHPROFILE *out_profile);
59 
60 /**
61  * Attach an ICC profile to a frame. Helper wrapper around cmsSaveProfileToMem
62  * and av_frame_new_side_data_from_buf.
63  *
64  * Returns 0 on success, or a negative error code.
65  */
67 
68 /**
69  * Sanitize an ICC profile to try and fix badly broken values.
70  *
71  * Returns 0 on success, or a negative error code.
72  */
74 
75 /**
76  * Read the color primaries and white point coefficients encoded by an ICC
77  * profile, and return the raw values in `out_primaries`.
78  *
79  * Returns 0 on success, or a negative error code.
80  */
82  AVColorPrimariesDesc *out_primaries);
83 
84 /**
85  * Attempt detecting the transfer characteristic that best approximates the
86  * transfer function encoded by an ICC profile. Sets `out_trc` to
87  * AVCOL_TRC_UNSPECIFIED if no clear match can be identified.
88  *
89  * Returns 0 on success (including no match), or a negative error code.
90  */
92  enum AVColorTransferCharacteristic *out_trc);
93 
94 #endif /* AVCODEC_FFLCMS2_H */
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:580
AVColorPrimariesDesc
Struct that contains both white point location and primaries location, providing the complete descrip...
Definition: csp.h:78
ff_icc_profile_sanitize
int ff_icc_profile_sanitize(FFIccContext *s, cmsHPROFILE profile)
Sanitize an ICC profile to try and fix badly broken values.
Definition: fflcms2.c:213
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AVCOL_TRC_NB
@ AVCOL_TRC_NB
Not part of ABI.
Definition: pixfmt.h:602
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:555
ff_icc_context_init
int ff_icc_context_init(FFIccContext *s, void *avctx)
Initializes an FFIccContext.
Definition: fflcms2.c:30
ff_icc_profile_attach
int ff_icc_profile_attach(FFIccContext *s, cmsHPROFILE profile, AVFrame *frame)
Attach an ICC profile to a frame.
Definition: fflcms2.c:172
s
#define s(width, name)
Definition: cbs_vp9.c:198
FFIccContext::curves
cmsToneCurve * curves[AVCOL_TRC_NB]
Definition: fflcms2.h:37
frame.h
csp.h
FFIccContext::avctx
void * avctx
Definition: fflcms2.h:35
FFIccContext
Definition: fflcms2.h:34
profile
int profile
Definition: mxfenc.c:2228
pixfmt.h
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
ff_icc_context_uninit
void ff_icc_context_uninit(FFIccContext *s)
Definition: fflcms2.c:42
FFIccContext::ctx
cmsContext ctx
Definition: fflcms2.h:36
ff_icc_profile_detect_transfer
int ff_icc_profile_detect_transfer(FFIccContext *s, cmsHPROFILE profile, enum AVColorTransferCharacteristic *out_trc)
Attempt detecting the transfer characteristic that best approximates the transfer function encoded by...
Definition: fflcms2.c:302
ff_icc_profile_generate
int ff_icc_profile_generate(FFIccContext *s, enum AVColorPrimaries color_prim, enum AVColorTransferCharacteristic color_trc, cmsHPROFILE *out_profile)
Generate an ICC profile for a given combination of color primaries and transfer function.
Definition: fflcms2.c:145
ff_icc_profile_read_primaries
int ff_icc_profile_read_primaries(FFIccContext *s, cmsHPROFILE profile, AVColorPrimariesDesc *out_primaries)
Read the color primaries and white point coefficients encoded by an ICC profile, and return the raw v...
Definition: fflcms2.c:255