FFmpeg
Loading...
Searching...
No Matches
gain_map.c File Reference
#include "gain_map.h"
#include "mem.h"
#include "libavcodec/bytestream.h"

Go to the source code of this file.

Macros

#define CHECK(cond)
 
#define CHECK_SIGNED(q)
 
#define CHECK_UNSIGNED(q)
 
#define ISO21496_HEADER_SIZE   5
 
#define ISO21496_FLAG_MULTICHANNEL   (1 << 7)
 
#define ISO21496_FLAG_USE_BASE_CG   (1 << 6)
 
#define ISO21496_FLAG_RESERVED   0x3f
 

Functions

static void gain_map_params_default (AVGainMapParams *p)
 
int av_gain_map_params_validate (const AVGainMapParams *p)
 Returns >= 0 if the given AVGainMapParams struct contains valid data; or a negative AVERROR otherwise.
 
static size_t iso21496_payload_size (int nb_channels)
 
static int make_q (int64_t num, uint32_t den, AVRational *out)
 
static int get_sq (GetByteContext *gb, AVRational *out)
 
static int get_uq (GetByteContext *gb, AVRational *out)
 
int av_gain_map_params_from_iso21496 (AVGainMapParams *restrict p, const uint8_t *data, size_t size)
 
static void put_q (PutByteContext *pb, AVRational q)
 
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.
 
int av_gain_map_channels_identical (const AVGainMapParams *p)
 Returns 1 if all channels of the gain map have identical parameters, 0 otherwise.
 
AVGainMapParams * av_gain_map_params_alloc (size_t *size)
 Allocate an AVGainMapParams structure and initialize it to default values.
 
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_GAIN_MAP_PARAMS side data.
 

Macro Definition Documentation

◆ CHECK

#define CHECK ( cond)
Value:
do { if (!(cond)) return AVERROR_INVALIDDATA; } while (0)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
int(* cond)(enum AVPixelFormat pix_fmt)

Definition at line 43 of file gain_map.c.

Referenced by av_gain_map_params_validate().

◆ CHECK_SIGNED

#define CHECK_SIGNED ( q)
Value:
CHECK((q).den > 0);
#define CHECK(call)
Definition cbs_apv.c:59

Definition at line 44 of file gain_map.c.

Referenced by av_gain_map_params_validate().

◆ CHECK_UNSIGNED

#define CHECK_UNSIGNED ( q)
Value:
CHECK((q).num >= 0 && (q).den > 0);
int num
Definition error.c:23

Definition at line 45 of file gain_map.c.

Referenced by av_gain_map_params_validate().

◆ ISO21496_HEADER_SIZE

#define ISO21496_HEADER_SIZE   5

Definition at line 76 of file gain_map.c.

◆ ISO21496_FLAG_MULTICHANNEL

#define ISO21496_FLAG_MULTICHANNEL   (1 << 7)

Definition at line 78 of file gain_map.c.

Referenced by av_gain_map_params_from_iso21496(), and av_gain_map_params_to_iso21496().

◆ ISO21496_FLAG_USE_BASE_CG

#define ISO21496_FLAG_USE_BASE_CG   (1 << 6)

Definition at line 79 of file gain_map.c.

Referenced by av_gain_map_params_from_iso21496(), and av_gain_map_params_to_iso21496().

◆ ISO21496_FLAG_RESERVED

#define ISO21496_FLAG_RESERVED   0x3f

Definition at line 80 of file gain_map.c.

Referenced by av_gain_map_params_from_iso21496().

Function Documentation

◆ gain_map_params_default()

static void gain_map_params_default ( AVGainMapParams * p)
static

Definition at line 23 of file gain_map.c.

Referenced by av_gain_map_params_alloc(), and av_gain_map_params_create_side_data().

◆ av_gain_map_params_validate()

int av_gain_map_params_validate ( const AVGainMapParams * p)

Returns >= 0 if the given AVGainMapParams struct contains valid data; or a negative AVERROR otherwise.

Note: The ISO spec declares these as signed, but a negative value makes no numeric sense and would result in infinities in the middle of the valid signal range; so just constrain them to be unsigned as a safeguard. Note that the Adobe hdrgm spec explicitly requires them to be nonnegative as well, so this avoids an inconsistency.

Definition at line 47 of file gain_map.c.

Referenced by av_gain_map_params_from_iso21496(), av_gain_map_params_to_iso21496(), ff_gain_map_params_check_xmp(), ff_mjpeg_add_gain_map_size(), and process_frame().

◆ iso21496_payload_size()

static size_t iso21496_payload_size ( int nb_channels)
static

Definition at line 82 of file gain_map.c.

Referenced by av_gain_map_params_from_iso21496().

◆ make_q()

static int make_q ( int64_t num,
uint32_t den,
AVRational * out )
static

Definition at line 87 of file gain_map.c.

Referenced by get_sq(), and get_uq().

◆ get_sq()

static int get_sq ( GetByteContext * gb,
AVRational * out )
static

Definition at line 97 of file gain_map.c.

Referenced by av_gain_map_params_from_iso21496().

◆ get_uq()

static int get_uq ( GetByteContext * gb,
AVRational * out )
static

Definition at line 104 of file gain_map.c.

Referenced by av_gain_map_params_from_iso21496().

◆ av_gain_map_params_from_iso21496()

int av_gain_map_params_from_iso21496 ( AVGainMapParams *restrict p,
const uint8_t * data,
size_t size )

While the spec does not require reserved bits to be 0, older versions of the ISO 21496-1 draft specification had extra flags that got removed from the final publication, so conservatively error out just in case; unless the writer version is >0 in which case these may be genuine additions to later revisions of the published spec, the validity of ignoring which is already guarded by the minimum_version check.

Definition at line 111 of file gain_map.c.

Referenced by mjpeg_decode_app(), and mov_parse_heif_layered_video_tmap().

◆ put_q()

static void put_q ( PutByteContext * pb,
AVRational q )
static

Definition at line 171 of file gain_map.c.

Referenced by av_gain_map_params_to_iso21496().

◆ av_gain_map_params_to_iso21496()

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.

The output starts at the minimum_version field; the caller should prepend whatever identifier its container requires.

Parameters
pparameters to serialize
bufByte buffer to fill with the serialized data. Must contain at least AV_GAIN_MAP_MAX_PAYLOAD_SIZE bytes.
Returns
Number of bytes written on success, or a negative AVERROR on failure
Note
Always succeeds if av_gain_map_params_validate() returns >= 0.

Definition at line 177 of file gain_map.c.

Referenced by jpeg_put_comments().

◆ av_gain_map_channels_identical()

int av_gain_map_channels_identical ( const AVGainMapParams * p)

Returns 1 if all channels of the gain map have identical parameters, 0 otherwise.

Definition at line 215 of file gain_map.c.

Referenced by av_gain_map_params_to_iso21496(), and ff_gain_map_params_check_xmp().

◆ av_gain_map_params_alloc()

AVGainMapParams * av_gain_map_params_alloc ( size_t * size)

Allocate an AVGainMapParams structure and initialize it to default values.

The resulting pointer must be freed using av_free().

Parameters
sizeif non-NULL, set to sizeof(AVGainMapParams)
Returns
the newly allocated struct, or NULL on failure

Definition at line 224 of file gain_map.c.

Referenced by init(), mjpeg_decode_app(), mov_parse_heif_layered_video_auxl_gmap(), and mov_parse_heif_layered_video_tmap().

◆ av_gain_map_params_create_side_data()

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_GAIN_MAP_PARAMS side data.

Returns
the newly allocated struct, or NULL on failure

Definition at line 238 of file gain_map.c.

Referenced by process_frame().