31#define ISO21496_HEADER_SIZE 5
33#define ISO21496_FLAG_MULTICHANNEL (1 << 7)
34#define ISO21496_FLAG_USE_BASE_CG (1 << 6)
35#define ISO21496_FLAG_RESERVED 0x3f
39 return 4 * 4 + (size_t) nb_channels * 10 * 4;
55 uint32_t den = bytestream2_get_be32u(gb);
61 uint32_t
num = bytestream2_get_be32u(gb);
62 uint32_t den = bytestream2_get_be32u(gb);
80 const uint16_t minimum_version = bytestream2_get_be16(&gb);
81 const uint16_t writer_version = bytestream2_get_be16(&gb);
84 const uint8_t
flags = bytestream2_get_byte(&gb);
105 if ((ret =
get_uq(&gb, &p->base_hdr_headroom)) < 0 ||
106 (ret =
get_uq(&gb, &p->alternate_hdr_headroom)) < 0)
109 for (
int c = 0;
c < p->nb_channels;
c++) {
110 struct AVGainMapChannel *
const ch = &p->channels[
c];
111 if ((ret =
get_sq(&gb, &ch->gain_map_min)) < 0 ||
112 (ret =
get_sq(&gb, &ch->gain_map_max)) < 0 ||
113 (ret =
get_uq(&gb, &ch->gamma)) < 0 ||
114 (ret =
get_sq(&gb, &ch->base_offset)) < 0 ||
115 (ret =
get_sq(&gb, &ch->alternate_offset)) < 0)
120 for (
int c = p->nb_channels;
c < 3;
c++)
121 p->channels[
c] = p->channels[0];
128 bytestream2_put_be32(pb, (
unsigned) q.
num);
129 bytestream2_put_be32(pb, (
unsigned) q.
den);
152 if (p->use_base_color_space)
155 bytestream2_put_be16(&pb, p->version);
156 bytestream2_put_be16(&pb, p->version);
157 bytestream2_put_byte(&pb,
flags);
158 put_q(&pb, p->base_hdr_headroom);
159 put_q(&pb, p->alternate_hdr_headroom);
162 const struct AVGainMapChannel *
const ch = &p->channels[
c];
163 put_q(&pb, ch->gain_map_min);
164 put_q(&pb, ch->gain_map_max);
165 put_q(&pb, ch->gamma);
166 put_q(&pb, ch->base_offset);
167 put_q(&pb, ch->alternate_offset);
185 p->use_base_color_space &&
186 av_cmp_q(p->alternate_hdr_headroom, p->base_hdr_headroom) != 0;
189#define XMP_GAIN_MAP_TEMPLATE \
190 "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"XMP Core 5.5.0\">\n" \
191 " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" \
192 " <rdf:Description rdf:about=\"\"\n" \
193 " xmlns:hdrgm=\"" FF_GAIN_MAP_XMP_NAMESPACE "\"\n" \
194 " hdrgm:Version=\"1.0\"\n" \
195 " hdrgm:GainMapMin=\"%g\"\n" \
196 " hdrgm:GainMapMax=\"%g\"\n" \
197 " hdrgm:Gamma=\"%g\"\n" \
198 " hdrgm:OffsetSDR=\"%g\"\n" \
199 " hdrgm:OffsetHDR=\"%g\"\n" \
200 " hdrgm:HDRCapacityMin=\"%g\"\n" \
201 " hdrgm:HDRCapacityMax=\"%g\"\n" \
202 " hdrgm:BaseRenditionIsHDR=\"%s\"/>\n" \
207 "XMP buffer too small for template and values");
217 const struct AVGainMapChannel *
const ch = &p->channels[0];
220 AVRational hdr_cap_min = p->base_hdr_headroom;
221 AVRational hdr_cap_max = p->alternate_hdr_headroom;
223 const int base_is_hdr =
av_cmp_q(p->base_hdr_headroom,
224 p->alternate_hdr_headroom) > 0;
236 base_is_hdr ?
"True" :
"False");
237 if (ret < 0 || ret >=
size)
simple assert() macros that are a bit more flexible than ISO C assert().
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define flags(name, subs,...)
common internal and external API header
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static size_t iso21496_payload_size(int nb_channels)
#define ISO21496_FLAG_MULTICHANNEL
int ff_gain_map_params_check_xmp(const AVGainMapParams *p)
Returns 1 if the gain map parameters are compatible with the XMP-based encoding, or 0 otherwise.
#define ISO21496_FLAG_USE_BASE_CG
#define ISO21496_FLAG_RESERVED
int ff_gain_map_params_from_iso21496(AVGainMapParams *restrict p, const uint8_t *data, size_t size)
static void put_q(PutByteContext *pb, AVRational q)
static int get_uq(GetByteContext *gb, AVRational *out)
static int make_q(int64_t num, uint32_t den, AVRational *out)
static int get_sq(GetByteContext *gb, AVRational *out)
int ff_gain_map_params_to_xmp(const AVGainMapParams *p, char *buf)
Serialize an AVGainMapParams as an Ultra HDR XMP packet.
#define XMP_GAIN_MAP_TEMPLATE
int ff_gain_map_params_to_iso21496(const AVGainMapParams *p, uint8_t *buf)
Serialize an AVGainMapParams as an ISO 21496-1 gain map metadata blob.
Serialization of AVGainMapParams into the metadata blobs that image formats carry it in,...
#define FF_GAIN_MAP_XMP_MAX_LEN
#define FF_GAIN_MAP_MAX_PAYLOAD_SIZE
#define FF_GAIN_MAP_VERSION
int av_gain_map_params_validate(const AVGainMapParams *p)
Returns >= 0 if the given AVGainMapParams struct contains valid data; or a negative AVERROR otherwise...
int av_gain_map_channels_identical(const AVGainMapParams *p)
Returns 1 if all channels of the gain map have identical parameters, 0 otherwise.
#define FFSWAP(type, a, b)
Memory handling functions.
Utilities for rational number calculation.
Parameters describing how to combine a gain map rendition with its base rendition to recover the alte...
Rational number (pair of numerator and denominator).