FFmpeg
Loading...
Searching...
No Matches
gain_map.h
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVUTIL_GAIN_MAP_H
20#define AVUTIL_GAIN_MAP_H
21
22#include <stddef.h>
23
24#include "rational.h"
25#include "frame.h"
26
27#define AV_ISO21496_VERSION 0
28#define AV_ISO21496_IDENTIFIER "urn:iso:std:iso:ts:21496:-1"
29
30/**
31 * Parameters describing how to combine a gain map rendition with its base
32 * rendition to recover the alternate rendition, as defined by
33 * ISO 21496-1:2025 "Digital photography - Gain map metadata for image
34 * conversion".
35 *
36 * Note: sizeof(AVGainMapParams) is not part of the ABI. New fields may be
37 * added at the end of the struct.
38 */
39typedef struct AVGainMapParams {
40 /**
41 * The version of this gain map struct. Reserved to allow future
42 * extensions of the struct. Must be <= AV_ISO21496_VERSION.
43 */
45
46 /**
47 * If non-zero, the gain map is applied in the colour space of the base
48 * rendition; otherwise in that of the alternate rendition.
49 */
51
52 /**
53 * log2 of the display headroom at which the base rendition is shown
54 * unmodified, and at which the map is applied in full.
55 */
58
60 /**
61 * log2-domain minimum and maximum gain applied by the map, i.e. the
62 * values the map's 0.0 and 1.0 endpoints decode to.
63 */
66
67 /**
68 * Encoding gamma of the stored map values. Must be > 0.
69 */
71
72 /**
73 * Small constants added before the log-domain math to avoid a
74 * singularity at zero.
75 */
78 } channels[3]; /* R, G, B */
79
80 /**
81 * Must be 1 or 3. If 1, all channels share the same set of parameters.
82 */
85
86/**
87 * Parse the payload of an ISO 21496-1 gain map metadata blob.
88 *
89 * @param p struct to fill; overwritten on success, untouched on failure
90 * @param data payload, excluding container-specific identifiers
91 * @param size size of `data` in bytes
92 *
93 * @return >= 0 on success, or a negative AVERROR on failure
94 */
96 size_t size);
97
98#define AV_GAIN_MAP_MAX_PAYLOAD_SIZE 141 /* = 5 + 2*8 + 3*5*8 */
99
100/**
101 * Serialize an AVGainMapParams as an ISO 21496-1 gain map metadata blob.
102 *
103 * The output starts at the minimum_version field; the caller should prepend
104 * whatever identifier its container requires.
105 *
106 * @param p parameters to serialize
107 * @param buf Byte buffer to fill with the serialized data. Must contain at
108 * least AV_GAIN_MAP_MAX_PAYLOAD_SIZE bytes.
109 *
110 * @return Number of bytes written on success, or a negative AVERROR on failure
111 *
112 * @note Always succeeds if av_gain_map_params_validate() returns >= 0.
113 */
114int av_gain_map_params_to_iso21496(const AVGainMapParams *p, uint8_t *buf);
115
116/**
117 * Returns >= 0 if the given AVGainMapParams struct contains valid data;
118 * or a negative AVERROR otherwise.
119 */
121
122/**
123 * Returns 1 if all channels of the gain map have identical parameters,
124 * 0 otherwise.
125 */
127
128/**
129 * Allocate an AVGainMapParams structure and initialize it to default values.
130 * The resulting pointer must be freed using av_free().
131 *
132 * @param size if non-NULL, set to sizeof(AVGainMapParams)
133 * @return the newly allocated struct, or NULL on failure
134 */
136
137/**
138 * Allocate and add an AVGainMapParams structure to an existing AVFrameSideData
139 * array as AV_FRAME_DATA_GAIN_MAP_PARAMS side data.
140 *
141 * @return the newly allocated struct, or NULL on failure
142 */
144
145#endif /* AVUTIL_GAIN_MAP_H */
channels
Definition aptx.h:31
reference-counted frame API
int av_gain_map_params_validate(const AVGainMapParams *p)
Returns >= 0 if the given AVGainMapParams struct contains valid data; or a negative AVERROR otherwise...
Definition gain_map.c:47
int av_gain_map_params_to_iso21496(const AVGainMapParams *p, uint8_t *buf)
Serialize an AVGainMapParams as an ISO 21496-1 gain map metadata blob.
Definition gain_map.c:177
AVGainMapParams * av_gain_map_params_alloc(size_t *size)
Allocate an AVGainMapParams structure and initialize it to default values.
Definition gain_map.c:224
AVGainMapParams * av_gain_map_params_create_side_data(AVFrameSideData ***sd, int *nb_sd)
Allocate and add an AVGainMapParams structure to an existing AVFrameSideData array as AV_FRAME_DATA_G...
Definition gain_map.c:238
int av_gain_map_channels_identical(const AVGainMapParams *p)
Returns 1 if all channels of the gain map have identical parameters, 0 otherwise.
Definition gain_map.c:215
int av_gain_map_params_from_iso21496(AVGainMapParams *p, const uint8_t *data, size_t size)
Parse the payload of an ISO 21496-1 gain map metadata blob.
const char data[16]
Definition mxf.c:149
Utilities for rational number calculation.
Structure to hold side data for an AVFrame.
Definition frame.h:334
AVRational gain_map_min
log2-domain minimum and maximum gain applied by the map, i.e.
Definition gain_map.h:64
AVRational base_offset
Small constants added before the log-domain math to avoid a singularity at zero.
Definition gain_map.h:76
AVRational gamma
Encoding gamma of the stored map values.
Definition gain_map.h:70
Parameters describing how to combine a gain map rendition with its base rendition to recover the alte...
Definition gain_map.h:39
AVRational alternate_hdr_headroom
Definition gain_map.h:57
int version
The version of this gain map struct.
Definition gain_map.h:44
int nb_channels
Must be 1 or 3.
Definition gain_map.h:83
int use_base_color_space
If non-zero, the gain map is applied in the colour space of the base rendition; otherwise in that of ...
Definition gain_map.h:50
AVRational base_hdr_headroom
log2 of the display headroom at which the base rendition is shown unmodified, and at which the map is...
Definition gain_map.h:56
Rational number (pair of numerator and denominator).
Definition rational.h:58
int size