26 .base_hdr_headroom = { 0, 1 },
27 .alternate_hdr_headroom = { 0, 1 },
32 for (
int c = 0;
c < 3;
c++) {
33 p->channels[
c] = (
struct AVGainMapChannel) {
34 .gain_map_min = { 0, 1 },
35 .gain_map_max = { 0, 1 },
37 .base_offset = { 1, 64 },
38 .alternate_offset = { 1, 64 },
43#define CHECK(cond) do { if (!(cond)) return AVERROR_INVALIDDATA; } while (0)
44#define CHECK_SIGNED(q) CHECK((q).den > 0);
45#define CHECK_UNSIGNED(q) CHECK((q).num >= 0 && (q).den > 0);
50 CHECK(p->nb_channels == 1 || p->nb_channels == 3);
54 for (
int c = 0;
c < p->nb_channels;
c++) {
55 const struct AVGainMapChannel *
const ch = &p->channels[
c];
59 CHECK(ch->gamma.num != 0);
76#define ISO21496_HEADER_SIZE 5
78#define ISO21496_FLAG_MULTICHANNEL (1 << 7)
79#define ISO21496_FLAG_USE_BASE_CG (1 << 6)
80#define ISO21496_FLAG_RESERVED 0x3f
84 return 4 * 4 + (size_t) nb_channels * 10 * 4;
100 uint32_t den = bytestream2_get_be32u(gb);
106 uint32_t
num = bytestream2_get_be32u(gb);
107 uint32_t den = bytestream2_get_be32u(gb);
125 const uint16_t minimum_version = bytestream2_get_be16(&gb);
126 const uint16_t writer_version = bytestream2_get_be16(&gb);
129 const uint8_t
flags = bytestream2_get_byte(&gb);
150 if ((
ret =
get_uq(&gb, &p->base_hdr_headroom)) < 0 ||
151 (
ret =
get_uq(&gb, &p->alternate_hdr_headroom)) < 0)
154 for (
int c = 0;
c < p->nb_channels;
c++) {
155 struct AVGainMapChannel *
const ch = &p->channels[
c];
156 if ((
ret =
get_sq(&gb, &ch->gain_map_min)) < 0 ||
157 (
ret =
get_sq(&gb, &ch->gain_map_max)) < 0 ||
159 (
ret =
get_sq(&gb, &ch->base_offset)) < 0 ||
160 (
ret =
get_sq(&gb, &ch->alternate_offset)) < 0)
165 for (
int c = p->nb_channels;
c < 3;
c++)
166 p->channels[
c] = p->channels[0];
173 bytestream2_put_be32(pb, (
unsigned) q.
num);
174 bytestream2_put_be32(pb, (
unsigned) q.
den);
194 if (p->use_base_color_space)
197 bytestream2_put_be16(&pb, p->version);
198 bytestream2_put_be16(&pb, p->version);
199 bytestream2_put_byte(&pb,
flags);
200 put_q(&pb, p->base_hdr_headroom);
201 put_q(&pb, p->alternate_hdr_headroom);
204 const struct AVGainMapChannel *
const ch = &p->channels[
c];
205 put_q(&pb, ch->gain_map_min);
206 put_q(&pb, ch->gain_map_max);
207 put_q(&pb, ch->gamma);
208 put_q(&pb, ch->base_offset);
209 put_q(&pb, ch->alternate_offset);
217 static_assert(
sizeof(p->channels[0]) ==
sizeof(
int[2]) * 5,
218 "AVGainMapChannel struct is tightly packed");
220 return !memcmp(&p->channels[0], &p->channels[1],
sizeof(p->channels[0])) &&
221 !memcmp(&p->channels[0], &p->channels[2],
sizeof(p->channels[0]));
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,...)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVFrameSideData * av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, size_t size, unsigned int flags)
Add new side data entry to an array.
#define AV_FRAME_SIDE_DATA_FLAG_REPLACE
Don't add a new entry if another of the same type exists.
@ AV_FRAME_DATA_GAIN_MAP_PARAMS
Parameters describing how to combine this gain map with its base image to form an alternate rendition...
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static size_t iso21496_payload_size(int nb_channels)
#define CHECK_UNSIGNED(q)
int av_gain_map_params_validate(const AVGainMapParams *p)
Returns >= 0 if the given AVGainMapParams struct contains valid data; or a negative AVERROR otherwise...
#define ISO21496_FLAG_MULTICHANNEL
#define ISO21496_FLAG_USE_BASE_CG
#define ISO21496_FLAG_RESERVED
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.
static void put_q(PutByteContext *pb, AVRational q)
AVGainMapParams * av_gain_map_params_alloc(size_t *size)
Allocate an AVGainMapParams structure and initialize it to default values.
static int get_uq(GetByteContext *gb, AVRational *out)
static int make_q(int64_t num, uint32_t den, AVRational *out)
int av_gain_map_channels_identical(const AVGainMapParams *p)
Returns 1 if all channels of the gain map have identical parameters, 0 otherwise.
static int get_sq(GetByteContext *gb, AVRational *out)
int av_gain_map_params_from_iso21496(AVGainMapParams *restrict p, const uint8_t *data, size_t size)
static void gain_map_params_default(AVGainMapParams *p)
AVGainMapParams * av_gain_map_params_create_side_data(AVFrameSideData ***fsd, int *nb_sd)
Allocate and add an AVGainMapParams structure to an existing AVFrameSideData array as AV_FRAME_DATA_G...
#define AV_GAIN_MAP_MAX_PAYLOAD_SIZE
#define AV_ISO21496_VERSION
Memory handling functions.
Structure to hold side data for an AVFrame.
Parameters describing how to combine a gain map rendition with its base rendition to recover the alte...
Rational number (pair of numerator and denominator).