FFmpeg
dynamic_hdr_vivid.c
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 #include "dynamic_hdr_vivid.h"
20 #include "get_bits.h"
21 
22 static const int32_t maxrgb_den = 4095;
24 static const int32_t maximum_luminance_den = 4095;
25 static const int32_t base_param_m_p_den = 16383;
26 static const int32_t base_param_m_m_den = 10;
27 static const int32_t base_param_m_a_den = 1023;
28 static const int32_t base_param_m_b_den = 1023;
29 static const int32_t base_param_m_n_den = 10;
30 static const int32_t base_param_Delta_den = 127;
31 
33  int size)
34 {
35  GetBitContext gbc, *gb = &gbc;
36  int ret;
37 
38  if (!s)
39  return AVERROR(ENOMEM);
40 
41  ret = init_get_bits8(gb, data, size);
42  if (ret < 0)
43  return ret;
44 
45  if (get_bits_left(gb) < 8)
46  return AVERROR_INVALIDDATA;
47 
48  s->system_start_code = get_bits(gb, 8);
49  // T/UWA 005.1-2022, table 11
50  if (s->system_start_code >= 0x01 && s->system_start_code <= 0x07) {
51  s->num_windows = 1;
52 
53  if (get_bits_left(gb) < 12 * 4 * s->num_windows)
54  return AVERROR_INVALIDDATA;
55  for (int w = 0; w < s->num_windows; w++) {
56  AVHDRVividColorTransformParams *params = &s->params[w];
57 
58  params->minimum_maxrgb = (AVRational){get_bits(gb, 12), maxrgb_den};
59  params->average_maxrgb = (AVRational){get_bits(gb, 12), maxrgb_den};
60  params->variance_maxrgb = (AVRational){get_bits(gb, 12), maxrgb_den};
61  params->maximum_maxrgb = (AVRational){get_bits(gb, 12), maxrgb_den};
62  }
63 
64  if (get_bits_left(gb) < 2 * s->num_windows)
65  return AVERROR_INVALIDDATA;
66  for (int w = 0; w < s->num_windows; w++) {
67  AVHDRVividColorTransformParams *params = &s->params[w];
68 
69  params->tone_mapping_mode_flag = get_bits(gb, 1);
70  if (params->tone_mapping_mode_flag) {
71  if (get_bits_left(gb) < 1 )
72  return AVERROR_INVALIDDATA;
73  params->tone_mapping_param_num = get_bits(gb, 1) + 1;
74  for (int i = 0; i < params->tone_mapping_param_num; i++) {
75  AVHDRVividColorToneMappingParams *tm_params = &params->tm_params[i];
76 
77  if (get_bits_left(gb) < 13)
78  return AVERROR_INVALIDDATA;
80  tm_params->base_enable_flag = get_bits(gb, 1);
81  if (tm_params->base_enable_flag) {
82  if (get_bits_left(gb) < (14 + 6 + 10 + 10 + 6 + 8 + 10))
83  return AVERROR_INVALIDDATA;
84  tm_params->base_param_m_p = (AVRational){get_bits(gb, 14), base_param_m_p_den};
85  tm_params->base_param_m_m = (AVRational){get_bits(gb, 6), base_param_m_m_den};
86  tm_params->base_param_m_a = (AVRational){get_bits(gb, 10), base_param_m_a_den};
87  tm_params->base_param_m_b = (AVRational){get_bits(gb, 10), base_param_m_b_den};
88  tm_params->base_param_m_n = (AVRational){get_bits(gb, 6), base_param_m_n_den};
89  tm_params->base_param_k1 = get_bits(gb, 2);
90  tm_params->base_param_k2 = get_bits(gb, 2);
91  tm_params->base_param_k3 = get_bits(gb, 4);
92  tm_params->base_param_Delta_enable_mode = get_bits(gb, 3);
94  }
95  if (get_bits_left(gb) < 1)
96  return AVERROR_INVALIDDATA;
97  tm_params->three_Spline_enable_flag = get_bits(gb, 1);
98  if (tm_params->three_Spline_enable_flag) {
99  AVHDRVivid3SplineParams *three_spline;
100 
101  if (get_bits_left(gb) < 1 + tm_params->three_Spline_num * (2 + 12 + 28 + 1))
102  return AVERROR_INVALIDDATA;
103  tm_params->three_Spline_num = get_bits(gb, 1) + 1;
104  if (tm_params->three_Spline_num > FF_ARRAY_ELEMS(tm_params->three_spline))
105  return AVERROR_INVALIDDATA;
106  for (int j = 0; j < tm_params->three_Spline_num; j++) {
107  three_spline = &tm_params->three_spline[j];
108  three_spline->th_mode = get_bits(gb, 2);
109  if (three_spline->th_mode == 0 || three_spline->th_mode == 2) {
110  if (get_bits_left(gb) < 8)
111  return AVERROR_INVALIDDATA;
112  three_spline->th_enable_mb = (AVRational){get_bits(gb, 8), 255};
113  }
114  three_spline->th_enable = (AVRational){get_bits(gb, 12), 4095};
115  three_spline->th_delta1 = (AVRational){get_bits(gb, 10), 1023};
116  three_spline->th_delta2 = (AVRational){get_bits(gb, 10), 1023};
117  three_spline->enable_strength = (AVRational){get_bits(gb, 8), 255};
118  }
119 #if FF_API_HDR_VIVID_THREE_SPLINE
120  three_spline = &tm_params->three_spline[0];
122  tm_params->three_Spline_TH_mode = three_spline->th_mode;
123  tm_params->three_Spline_TH_enable_MB = three_spline->th_enable_mb;
124  tm_params->three_Spline_TH_enable = three_spline->th_enable;
125  tm_params->three_Spline_TH_Delta1 = three_spline->th_delta1;
126  tm_params->three_Spline_TH_Delta2 = three_spline->th_delta2;
127  tm_params->three_Spline_enable_Strength = three_spline->enable_strength;
129 #endif
130  }
131  }
132  }
133 
134  params->color_saturation_mapping_flag = get_bits(gb, 1);
135  if (params->color_saturation_mapping_flag) {
136  if (get_bits_left(gb) < 3 + params->color_saturation_num * 8)
137  return AVERROR_INVALIDDATA;
138 
139  params->color_saturation_num = get_bits(gb, 3);
140  for (int i = 0; i < params->color_saturation_num; i++) {
142  }
143  }
144  }
145  }
146 
147  return 0;
148 }
AVHDRVividColorTransformParams::maximum_maxrgb
AVRational maximum_maxrgb
Indicates the maximum brightness of the displayed content.
Definition: hdr_dynamic_vivid_metadata.h:260
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
AVHDRVividColorToneMappingParams::base_param_k2
int base_param_k2
indicates k2_0 in the base parameter, base_param_k2 <= 1: k2_0 = base_param_k2 base_param_k2 > 1: res...
Definition: hdr_dynamic_vivid_metadata.h:137
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:695
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVHDRVividColorToneMappingParams::base_param_Delta
AVRational base_param_Delta
base_param_Delta in the base parameter, in multiples of 1.0/127.
Definition: hdr_dynamic_vivid_metadata.h:157
AVHDRVividColorToneMappingParams::base_enable_flag
int base_enable_flag
This flag indicates that transfer the base paramter(for value of 1)
Definition: hdr_dynamic_vivid_metadata.h:88
AVHDRVividColorToneMappingParams::three_Spline_num
int three_Spline_num
The number of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:169
AVHDRVividColorTransformParams::tone_mapping_param_num
int tone_mapping_param_num
The number of tone mapping param.
Definition: hdr_dynamic_vivid_metadata.h:272
color_saturation_gain_den
static const int32_t color_saturation_gain_den
Definition: dynamic_hdr_vivid.c:23
w
uint8_t w
Definition: llviddspenc.c:38
AVHDRVividColorTransformParams::variance_maxrgb
AVRational variance_maxrgb
Indicates the variance brightness of the displayed content.
Definition: hdr_dynamic_vivid_metadata.h:253
AVHDRVivid3SplineParams::enable_strength
AVRational enable_strength
3Spline_enable_Strength of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:70
data
const char data[16]
Definition: mxf.c:149
AVHDRVividColorToneMappingParams::three_Spline_TH_mode
attribute_deprecated int three_Spline_TH_mode
The mode of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:178
AVHDRVivid3SplineParams::th_mode
int th_mode
The mode of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:35
AVHDRVividColorTransformParams::color_saturation_num
int color_saturation_num
The number of color saturation param.
Definition: hdr_dynamic_vivid_metadata.h:289
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
AVHDRVividColorToneMappingParams::three_Spline_enable_flag
int three_Spline_enable_flag
indicates 3Spline_enable_flag in the base parameter, This flag indicates that transfer three Spline o...
Definition: hdr_dynamic_vivid_metadata.h:163
AVHDRVividColorTransformParams::tm_params
AVHDRVividColorToneMappingParams tm_params[2]
The color tone mapping parameters.
Definition: hdr_dynamic_vivid_metadata.h:277
AVHDRVivid3SplineParams::th_delta1
AVRational th_delta1
3Spline_TH_Delta1 of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:56
GetBitContext
Definition: get_bits.h:108
AVHDRVividColorToneMappingParams::three_Spline_TH_Delta1
attribute_deprecated AVRational three_Spline_TH_Delta1
3Spline_TH_Delta1 of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:204
base_param_m_a_den
static const int32_t base_param_m_a_den
Definition: dynamic_hdr_vivid.c:27
base_param_m_m_den
static const int32_t base_param_m_m_den
Definition: dynamic_hdr_vivid.c:26
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
s
#define s(width, name)
Definition: cbs_vp9.c:198
get_bits.h
AVHDRVividColorTransformParams::color_saturation_gain
AVRational color_saturation_gain[8]
Indicates the color correction strength parameter.
Definition: hdr_dynamic_vivid_metadata.h:296
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVHDRVividColorToneMappingParams::three_Spline_TH_enable_MB
attribute_deprecated AVRational three_Spline_TH_enable_MB
three_Spline_TH_enable_MB is in the range of 0.0 to 1.0, inclusive and in multiples of 1....
Definition: hdr_dynamic_vivid_metadata.h:186
AVDynamicHDRVivid
This struct represents dynamic metadata for color volume transform - CUVA 005.1:2021 standard.
Definition: hdr_dynamic_vivid_metadata.h:310
AVHDRVividColorTransformParams::color_saturation_mapping_flag
int color_saturation_mapping_flag
This flag indicates that the metadata for the color saturation mapping in the processing window is pr...
Definition: hdr_dynamic_vivid_metadata.h:283
AVHDRVividColorTransformParams::tone_mapping_mode_flag
int tone_mapping_mode_flag
This flag indicates that the metadata for the tone mapping function in the processing window is prese...
Definition: hdr_dynamic_vivid_metadata.h:266
base_param_m_n_den
static const int32_t base_param_m_n_den
Definition: dynamic_hdr_vivid.c:29
AVHDRVividColorToneMappingParams::three_Spline_TH_Delta2
attribute_deprecated AVRational three_Spline_TH_Delta2
3Spline_TH_Delta2 of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:213
size
int size
Definition: twinvq_data.h:10344
AVHDRVividColorTransformParams::average_maxrgb
AVRational average_maxrgb
Indicates the average brightness of the displayed content.
Definition: hdr_dynamic_vivid_metadata.h:246
AVHDRVividColorToneMappingParams::three_Spline_enable_Strength
attribute_deprecated AVRational three_Spline_enable_Strength
3Spline_enable_Strength of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:222
AVHDRVividColorToneMappingParams::three_Spline_TH_enable
attribute_deprecated AVRational three_Spline_TH_enable
3Spline_TH_enable of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:195
AVHDRVividColorToneMappingParams::base_param_k1
int base_param_k1
indicates k1_0 in the base parameter, base_param_k1 <= 1: k1_0 = base_param_k1 base_param_k1 > 1: res...
Definition: hdr_dynamic_vivid_metadata.h:130
base_param_m_b_den
static const int32_t base_param_m_b_den
Definition: dynamic_hdr_vivid.c:28
ff_parse_itu_t_t35_to_dynamic_hdr_vivid
int ff_parse_itu_t_t35_to_dynamic_hdr_vivid(AVDynamicHDRVivid *s, const uint8_t *data, int size)
Parse the user data registered ITU-T T.35 to AVbuffer (AVDynamicHDRVivid).
Definition: dynamic_hdr_vivid.c:32
maxrgb_den
static const int32_t maxrgb_den
Definition: dynamic_hdr_vivid.c:22
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVHDRVividColorToneMappingParams::targeted_system_display_maximum_luminance
AVRational targeted_system_display_maximum_luminance
The nominal maximum display luminance of the targeted system display, in multiples of 1....
Definition: hdr_dynamic_vivid_metadata.h:83
AVHDRVividColorTransformParams
Color transform parameters at a processing window in a dynamic metadata for CUVA 005....
Definition: hdr_dynamic_vivid_metadata.h:233
AVHDRVividColorToneMappingParams::base_param_Delta_enable_mode
int base_param_Delta_enable_mode
This flag indicates that delta mode of base paramter(for value of 1)
Definition: hdr_dynamic_vivid_metadata.h:150
maximum_luminance_den
static const int32_t maximum_luminance_den
Definition: dynamic_hdr_vivid.c:24
ret
ret
Definition: filter_design.txt:187
AVHDRVivid3SplineParams
HDR Vivid three spline params.
Definition: hdr_dynamic_vivid_metadata.h:30
AVHDRVividColorTransformParams::minimum_maxrgb
AVRational minimum_maxrgb
Indicates the minimum brightness of the displayed content.
Definition: hdr_dynamic_vivid_metadata.h:239
AVHDRVividColorToneMappingParams::base_param_m_n
AVRational base_param_m_n
base_param_m_n in the base parameter, in multiples of 1.0/10.
Definition: hdr_dynamic_vivid_metadata.h:123
AVHDRVividColorToneMappingParams::base_param_m_a
AVRational base_param_m_a
base_param_m_a in the base parameter, in multiples of 1.0/1023.
Definition: hdr_dynamic_vivid_metadata.h:109
AVHDRVivid3SplineParams::th_enable
AVRational th_enable
3Spline_TH_enable of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:49
AVHDRVividColorToneMappingParams
Color tone mapping parameters at a processing window in a dynamic metadata for CUVA 005....
Definition: hdr_dynamic_vivid_metadata.h:77
base_param_Delta_den
static const int32_t base_param_Delta_den
Definition: dynamic_hdr_vivid.c:30
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
dynamic_hdr_vivid.h
base_param_m_p_den
static const int32_t base_param_m_p_den
Definition: dynamic_hdr_vivid.c:25
int32_t
int32_t
Definition: audioconvert.c:56
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AVHDRVividColorToneMappingParams::base_param_k3
int base_param_k3
indicates k3_0 in the base parameter, base_param_k3 == 1: k3_0 = base_param_k3 base_param_k3 == 2: k3...
Definition: hdr_dynamic_vivid_metadata.h:145
AVHDRVivid3SplineParams::th_delta2
AVRational th_delta2
3Spline_TH_Delta2 of three Spline.
Definition: hdr_dynamic_vivid_metadata.h:63
AVHDRVivid3SplineParams::th_enable_mb
AVRational th_enable_mb
three_Spline_TH_enable_MB is in the range of 0.0 to 1.0, inclusive and in multiples of 1....
Definition: hdr_dynamic_vivid_metadata.h:42
AVHDRVividColorToneMappingParams::three_spline
AVHDRVivid3SplineParams three_spline[2]
Definition: hdr_dynamic_vivid_metadata.h:225
AVHDRVividColorToneMappingParams::base_param_m_p
AVRational base_param_m_p
base_param_m_p in the base parameter, in multiples of 1.0/16383.
Definition: hdr_dynamic_vivid_metadata.h:95
AVHDRVividColorToneMappingParams::base_param_m_b
AVRational base_param_m_b
base_param_m_b in the base parameter, in multiples of 1/1023.
Definition: hdr_dynamic_vivid_metadata.h:116
AVHDRVividColorToneMappingParams::base_param_m_m
AVRational base_param_m_m
base_param_m_m in the base parameter, in multiples of 1.0/10.
Definition: hdr_dynamic_vivid_metadata.h:102