FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/hdr_dynamic_metadata.c
Date: 2026-11-08 03:48:22
Exec Total Coverage
Lines: 411 459 89.5%
Functions: 8 8 100.0%
Branches: 307 386 79.5%

Line Branch Exec Source
1 /**
2 * Copyright (c) 2018 Mohammad Izadi <moh.izadi at gmail.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "avassert.h"
22 #include "hdr_dynamic_metadata.h"
23 #include "mem.h"
24 #include "libavcodec/defs.h"
25 #include "libavcodec/get_bits.h"
26 #include "libavcodec/put_bits.h"
27
28 static const int64_t luminance_den = 1;
29 static const int32_t peak_luminance_den = 15;
30 static const int64_t rgb_den = 100000;
31 static const int32_t fraction_pixel_den = 1000;
32 static const int32_t knee_point_den = 4095;
33 static const int32_t bezier_anchor_den = 1023;
34 static const int32_t saturation_weight_den = 8;
35
36 22 AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size)
37 {
38 22 AVDynamicHDRPlus *hdr_plus = av_mallocz(sizeof(AVDynamicHDRPlus));
39
40
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 3 times.
22 if (size)
41
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
19 *size = hdr_plus ? sizeof(*hdr_plus) : 0;
42
43 22 return hdr_plus;
44 }
45
46 1 AVDynamicHDRPlus *av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
47 {
48 1 AVFrameSideData *side_data = av_frame_new_side_data(frame,
49 AV_FRAME_DATA_DYNAMIC_HDR_PLUS,
50 sizeof(AVDynamicHDRPlus));
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!side_data)
52 ✗ return NULL;
53
54 1 memset(side_data->data, 0, sizeof(AVDynamicHDRPlus));
55
56 1 return (AVDynamicHDRPlus *)side_data->data;
57 }
58
59 22 int av_dynamic_hdr_plus_from_t35(AVDynamicHDRPlus *s, const uint8_t *data,
60 size_t size)
61 {
62 uint8_t padded_buf[AV_HDR_PLUS_MAX_PAYLOAD_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
63 22 GetBitContext gbc, *gb = &gbc;
64 int ret;
65
66
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 21 times.
22 if (!s)
67 1 return AVERROR(EINVAL);
68
69
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
21 if (size > AV_HDR_PLUS_MAX_PAYLOAD_SIZE)
70 1 return AVERROR(EINVAL);
71
72 20 memcpy(padded_buf, data, size);
73 // Zero-initialize the buffer padding to avoid overreads into uninitialized data.
74 20 memset(padded_buf + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
75
76 20 ret = init_get_bits8(gb, padded_buf, size);
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (ret < 0)
78 ✗ return ret;
79
80
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (get_bits_left(gb) < 10)
81 ✗ return AVERROR_INVALIDDATA;
82
83 20 s->application_version = get_bits(gb, 8);
84 20 s->num_windows = get_bits(gb, 2);
85
86
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
20 if (s->num_windows < 1 || s->num_windows > 3) {
87 ✗ return AVERROR_INVALIDDATA;
88 }
89
90
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (get_bits_left(gb) < ((19 * 8 + 1) * (s->num_windows - 1)))
91 ✗ return AVERROR_INVALIDDATA;
92
93
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
21 for (int w = 1; w < s->num_windows; w++) {
94 // The corners are set to absolute coordinates here. They should be
95 // converted to the relative coordinates (in [0, 1]) in the decoder.
96 1 AVHDRPlusColorTransformParams *params = &s->params[w];
97 1 params->window_upper_left_corner_x =
98 1 (AVRational){get_bits(gb, 16), 1};
99 1 params->window_upper_left_corner_y =
100 1 (AVRational){get_bits(gb, 16), 1};
101 1 params->window_lower_right_corner_x =
102 1 (AVRational){get_bits(gb, 16), 1};
103 1 params->window_lower_right_corner_y =
104 1 (AVRational){get_bits(gb, 16), 1};
105
106 1 params->center_of_ellipse_x = get_bits(gb, 16);
107 1 params->center_of_ellipse_y = get_bits(gb, 16);
108 1 params->rotation_angle = get_bits(gb, 8);
109 1 params->semimajor_axis_internal_ellipse = get_bits(gb, 16);
110 1 params->semimajor_axis_external_ellipse = get_bits(gb, 16);
111 1 params->semiminor_axis_external_ellipse = get_bits(gb, 16);
112 1 params->overlap_process_option = get_bits1(gb);
113 }
114
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (get_bits_left(gb) < 28)
116 ✗ return AVERROR_INVALIDDATA;
117
118 20 s->targeted_system_display_maximum_luminance =
119 20 (AVRational){get_bits_long(gb, 27), luminance_den};
120 20 s->targeted_system_display_actual_peak_luminance_flag = get_bits1(gb);
121
122
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 19 times.
20 if (s->targeted_system_display_actual_peak_luminance_flag) {
123 int rows, cols;
124
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (get_bits_left(gb) < 10)
125 ✗ return AVERROR_INVALIDDATA;
126 1 rows = get_bits(gb, 5);
127 1 cols = get_bits(gb, 5);
128
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
1 if (((rows < 2) || (rows > 25)) || ((cols < 2) || (cols > 25))) {
129 ✗ return AVERROR_INVALIDDATA;
130 }
131 1 s->num_rows_targeted_system_display_actual_peak_luminance = rows;
132 1 s->num_cols_targeted_system_display_actual_peak_luminance = cols;
133
134
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (get_bits_left(gb) < (rows * cols * 4))
135 ✗ return AVERROR_INVALIDDATA;
136
137
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int i = 0; i < rows; i++) {
138
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (int j = 0; j < cols; j++) {
139 6 s->targeted_system_display_actual_peak_luminance[i][j] =
140 6 (AVRational){get_bits(gb, 4), peak_luminance_den};
141 }
142 }
143 }
144
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 20 times.
41 for (int w = 0; w < s->num_windows; w++) {
145 21 AVHDRPlusColorTransformParams *params = &s->params[w];
146
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
21 if (get_bits_left(gb) < (3 * 17 + 17 + 4))
147 ✗ return AVERROR_INVALIDDATA;
148
149
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 21 times.
84 for (int i = 0; i < 3; i++) {
150 63 params->maxscl[i] =
151 63 (AVRational){get_bits(gb, 17), rgb_den};
152 }
153 21 params->average_maxrgb =
154 21 (AVRational){get_bits(gb, 17), rgb_den};
155 21 params->num_distribution_maxrgb_percentiles = get_bits(gb, 4);
156
157 21 if (get_bits_left(gb) <
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 (params->num_distribution_maxrgb_percentiles * 24))
159 ✗ return AVERROR_INVALIDDATA;
160
161
2/2
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 21 times.
195 for (int i = 0; i < params->num_distribution_maxrgb_percentiles; i++) {
162 174 params->distribution_maxrgb[i].percentage = get_bits(gb, 7);
163 174 params->distribution_maxrgb[i].percentile =
164 174 (AVRational){get_bits(gb, 17), rgb_den};
165 }
166
167
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
21 if (get_bits_left(gb) < 10)
168 ✗ return AVERROR_INVALIDDATA;
169
170 21 params->fraction_bright_pixels = (AVRational){get_bits(gb, 10), fraction_pixel_den};
171 }
172
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (get_bits_left(gb) < 1)
173 ✗ return AVERROR_INVALIDDATA;
174 20 s->mastering_display_actual_peak_luminance_flag = get_bits1(gb);
175
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 19 times.
20 if (s->mastering_display_actual_peak_luminance_flag) {
176 int rows, cols;
177
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (get_bits_left(gb) < 10)
178 ✗ return AVERROR_INVALIDDATA;
179 1 rows = get_bits(gb, 5);
180 1 cols = get_bits(gb, 5);
181
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
1 if (((rows < 2) || (rows > 25)) || ((cols < 2) || (cols > 25))) {
182 ✗ return AVERROR_INVALIDDATA;
183 }
184 1 s->num_rows_mastering_display_actual_peak_luminance = rows;
185 1 s->num_cols_mastering_display_actual_peak_luminance = cols;
186
187
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (get_bits_left(gb) < (rows * cols * 4))
188 ✗ return AVERROR_INVALIDDATA;
189
190
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < rows; i++) {
191
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for (int j = 0; j < cols; j++) {
192 6 s->mastering_display_actual_peak_luminance[i][j] =
193 6 (AVRational){get_bits(gb, 4), peak_luminance_den};
194 }
195 }
196 }
197
198
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 20 times.
41 for (int w = 0; w < s->num_windows; w++) {
199 21 AVHDRPlusColorTransformParams *params = &s->params[w];
200
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
21 if (get_bits_left(gb) < 1)
201 ✗ return AVERROR_INVALIDDATA;
202
203 21 params->tone_mapping_flag = get_bits1(gb);
204
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1 times.
21 if (params->tone_mapping_flag) {
205
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (get_bits_left(gb) < 28)
206 ✗ return AVERROR_INVALIDDATA;
207
208 20 params->knee_point_x =
209 20 (AVRational){get_bits(gb, 12), knee_point_den};
210 20 params->knee_point_y =
211 20 (AVRational){get_bits(gb, 12), knee_point_den};
212 20 params->num_bezier_curve_anchors = get_bits(gb, 4);
213
214
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
20 if (get_bits_left(gb) < (params->num_bezier_curve_anchors * 10))
215 ✗ return AVERROR_INVALIDDATA;
216
217
2/2
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 20 times.
194 for (int i = 0; i < params->num_bezier_curve_anchors; i++) {
218 174 params->bezier_curve_anchors[i] =
219 174 (AVRational){get_bits(gb, 10), bezier_anchor_den};
220 }
221 }
222
223
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
21 if (get_bits_left(gb) < 1)
224 ✗ return AVERROR_INVALIDDATA;
225 21 params->color_saturation_mapping_flag = get_bits1(gb);
226
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 19 times.
21 if (params->color_saturation_mapping_flag) {
227
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (get_bits_left(gb) < 6)
228 ✗ return AVERROR_INVALIDDATA;
229 2 params->color_saturation_weight =
230 2 (AVRational){get_bits(gb, 6), saturation_weight_den};
231 }
232 }
233
234 20 return 0;
235 }
236
237 21 int av_dynamic_hdr_plus_to_t35(const AVDynamicHDRPlus *s, uint8_t **data, size_t *size)
238 {
239 uint8_t *buf;
240 size_t size_bits, size_bytes;
241 21 PutBitContext pbc, *pb = &pbc;
242
243
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
21 if (!s)
244 1 return AVERROR(EINVAL);
245
6/6
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 15 times.
20 if ((!data || *data) && !size)
246 1 return AVERROR(EINVAL);
247 /* The caps put the payload at exactly 907 bytes; the assert cannot fire. */
248
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 18 times.
19 if (s->num_windows > FF_ARRAY_ELEMS(s->params))
249 1 return AVERROR(EINVAL);
250
251
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 16 times.
42 for (int w = 0; w < s->num_windows; w++) {
252 26 const AVHDRPlusColorTransformParams *p = &s->params[w];
253
254
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 25 times.
26 if (p->num_distribution_maxrgb_percentiles >
255 FF_ARRAY_ELEMS(p->distribution_maxrgb))
256 1 return AVERROR(EINVAL);
257
258 /* The anchors are only read while tone mapping is enabled. */
259
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 9 times.
25 if (p->tone_mapping_flag &&
260
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 15 times.
16 p->num_bezier_curve_anchors >
261 FF_ARRAY_ELEMS(p->bezier_curve_anchors))
262 1 return AVERROR(EINVAL);
263 }
264
265 /* The peak-luminance pairs use a row count and a column count, and are
266 * only read when their flag is set, so check them the same way. */
267
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 11 times.
16 if (s->targeted_system_display_actual_peak_luminance_flag) {
268
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 if (s->num_rows_targeted_system_display_actual_peak_luminance >
269 4 FF_ARRAY_ELEMS(s->targeted_system_display_actual_peak_luminance) ||
270
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 s->num_cols_targeted_system_display_actual_peak_luminance >
271 FF_ARRAY_ELEMS(s->targeted_system_display_actual_peak_luminance[0]))
272 2 return AVERROR(EINVAL);
273 }
274
275
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 11 times.
14 if (s->mastering_display_actual_peak_luminance_flag) {
276
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (s->num_rows_mastering_display_actual_peak_luminance >
277 2 FF_ARRAY_ELEMS(s->mastering_display_actual_peak_luminance) ||
278
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 s->num_cols_mastering_display_actual_peak_luminance >
279 FF_ARRAY_ELEMS(s->mastering_display_actual_peak_luminance[0]))
280 2 return AVERROR(EINVAL);
281 }
282
283 /**
284 * Buffer size per CTA-861-H p.253-254:
285 * 48 header bits (excluded from the serialized payload)
286 * 8 bits for application_mode
287 * 2 bits for num_windows
288 * 153 bits for window geometry, for each window above 1
289 * 27 bits for targeted_system_display_maximum_luminance
290 * 1-2511 bits for targeted system display peak luminance information
291 * 82-442 bits per window for pixel distribution information
292 * 1-2511 bits for mastering display peak luminance information
293 * 1-179 bits per window for tonemapping information
294 * 1-7 bits per window for color saturation mapping information
295 * Total: 123-7249 bits, excluding trimmed header bits
296 */
297 12 size_bits = 8;
298
299 12 size_bits += 2;
300
301
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
16 for (int w = 1; w < s->num_windows; w++)
302 4 size_bits += 153;
303
304 12 size_bits += 27;
305
306 12 size_bits += 1;
307
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
12 if (s->targeted_system_display_actual_peak_luminance_flag)
308 1 size_bits += 10 +
309 1 s->num_rows_targeted_system_display_actual_peak_luminance *
310 1 s->num_cols_targeted_system_display_actual_peak_luminance * 4;
311
312
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 12 times.
28 for (int w = 0; w < s->num_windows; w++)
313 16 size_bits += 72 + s->params[w].num_distribution_maxrgb_percentiles * 24 + 10;
314
315 12 size_bits += 1;
316
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
12 if (s->mastering_display_actual_peak_luminance_flag)
317 1 size_bits += 10 +
318 1 s->num_rows_mastering_display_actual_peak_luminance *
319 1 s->num_cols_mastering_display_actual_peak_luminance * 4;
320
321
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 12 times.
28 for (int w = 0; w < s->num_windows; w++) {
322 16 size_bits += 1;
323
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
16 if (s->params[w].tone_mapping_flag)
324 11 size_bits += 28 + s->params[w].num_bezier_curve_anchors * 10;
325
326 16 size_bits += 1;
327
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 if (s->params[w].color_saturation_mapping_flag)
328 8 size_bits += 6;
329 }
330
331 12 size_bytes = (size_bits + 7) / 8;
332
333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 av_assert0(size_bytes <= AV_HDR_PLUS_MAX_PAYLOAD_SIZE);
334
335
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 if (!data) {
336 4 *size = size_bytes;
337 4 return 0;
338
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 } else if (*data) {
339
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (*size < size_bytes)
340 1 return AVERROR_BUFFER_TOO_SMALL;
341 3 buf = *data;
342 } else {
343 4 buf = av_malloc(size_bytes);
344
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!buf)
345 ✗ return AVERROR(ENOMEM);
346 }
347
348 7 init_put_bits(pb, buf, size_bytes);
349
350 // application_mode is set to Application Version 1
351 7 put_bits(pb, 8, 1);
352
353 // Payload as per CTA-861-H p.253-254
354 7 put_bits(pb, 2, s->num_windows);
355
356
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 for (int w = 1; w < s->num_windows; w++) {
357 1 put_bits(pb, 16, s->params[w].window_upper_left_corner_x.num / s->params[w].window_upper_left_corner_x.den);
358 1 put_bits(pb, 16, s->params[w].window_upper_left_corner_y.num / s->params[w].window_upper_left_corner_y.den);
359 1 put_bits(pb, 16, s->params[w].window_lower_right_corner_x.num / s->params[w].window_lower_right_corner_x.den);
360 1 put_bits(pb, 16, s->params[w].window_lower_right_corner_y.num / s->params[w].window_lower_right_corner_y.den);
361 1 put_bits(pb, 16, s->params[w].center_of_ellipse_x);
362 1 put_bits(pb, 16, s->params[w].center_of_ellipse_y);
363 1 put_bits(pb, 8, s->params[w].rotation_angle);
364 1 put_bits(pb, 16, s->params[w].semimajor_axis_internal_ellipse);
365 1 put_bits(pb, 16, s->params[w].semimajor_axis_external_ellipse);
366 1 put_bits(pb, 16, s->params[w].semiminor_axis_external_ellipse);
367 1 put_bits(pb, 1, s->params[w].overlap_process_option);
368 }
369
370 7 put_bits(pb, 27, s->targeted_system_display_maximum_luminance.num * luminance_den /
371 7 s->targeted_system_display_maximum_luminance.den);
372 7 put_bits(pb, 1, s->targeted_system_display_actual_peak_luminance_flag);
373
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if (s->targeted_system_display_actual_peak_luminance_flag) {
374 1 put_bits(pb, 5, s->num_rows_targeted_system_display_actual_peak_luminance);
375 1 put_bits(pb, 5, s->num_cols_targeted_system_display_actual_peak_luminance);
376
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int i = 0; i < s->num_rows_targeted_system_display_actual_peak_luminance; i++) {
377
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (int j = 0; j < s->num_cols_targeted_system_display_actual_peak_luminance; j++)
378 6 put_bits(pb, 4, s->targeted_system_display_actual_peak_luminance[i][j].num * peak_luminance_den /
379 6 s->targeted_system_display_actual_peak_luminance[i][j].den);
380 }
381 }
382
383
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 7 times.
15 for (int w = 0; w < s->num_windows; w++) {
384
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
32 for (int i = 0; i < 3; i++)
385 24 put_bits(pb, 17, s->params[w].maxscl[i].num * rgb_den / s->params[w].maxscl[i].den);
386 8 put_bits(pb, 17, s->params[w].average_maxrgb.num * rgb_den / s->params[w].average_maxrgb.den);
387 8 put_bits(pb, 4, s->params[w].num_distribution_maxrgb_percentiles);
388
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 8 times.
65 for (int i = 0; i < s->params[w].num_distribution_maxrgb_percentiles; i++) {
389 57 put_bits(pb, 7, s->params[w].distribution_maxrgb[i].percentage);
390 57 put_bits(pb, 17, s->params[w].distribution_maxrgb[i].percentile.num * rgb_den /
391 57 s->params[w].distribution_maxrgb[i].percentile.den);
392 }
393 8 put_bits(pb, 10, s->params[w].fraction_bright_pixels.num * fraction_pixel_den /
394 8 s->params[w].fraction_bright_pixels.den);
395 }
396
397 7 put_bits(pb, 1, s->mastering_display_actual_peak_luminance_flag);
398
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if (s->mastering_display_actual_peak_luminance_flag) {
399 1 put_bits(pb, 5, s->num_rows_mastering_display_actual_peak_luminance);
400 1 put_bits(pb, 5, s->num_cols_mastering_display_actual_peak_luminance);
401
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < s->num_rows_mastering_display_actual_peak_luminance; i++) {
402
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for (int j = 0; j < s->num_cols_mastering_display_actual_peak_luminance; j++)
403 6 put_bits(pb, 4, s->mastering_display_actual_peak_luminance[i][j].num * peak_luminance_den /
404 6 s->mastering_display_actual_peak_luminance[i][j].den);
405 }
406 }
407
408
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 7 times.
15 for (int w = 0; w < s->num_windows; w++) {
409 8 put_bits(pb, 1, s->params[w].tone_mapping_flag);
410
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (s->params[w].tone_mapping_flag) {
411 7 put_bits(pb, 12, s->params[w].knee_point_x.num * knee_point_den / s->params[w].knee_point_x.den);
412 7 put_bits(pb, 12, s->params[w].knee_point_y.num * knee_point_den / s->params[w].knee_point_y.den);
413 7 put_bits(pb, 4, s->params[w].num_bezier_curve_anchors);
414
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 7 times.
64 for (int i = 0; i < s->params[w].num_bezier_curve_anchors; i++)
415 57 put_bits(pb, 10, s->params[w].bezier_curve_anchors[i].num * bezier_anchor_den /
416 57 s->params[w].bezier_curve_anchors[i].den);
417 }
418 8 put_bits(pb, 1, s->params[w].color_saturation_mapping_flag);
419
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (s->params[w].color_saturation_mapping_flag)
420 2 put_bits(pb, 6, s->params[w].color_saturation_weight.num * saturation_weight_den /
421 2 s->params[w].color_saturation_weight.den);
422 }
423
424 7 flush_put_bits(pb);
425
426 7 *data = buf;
427
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (size)
428 7 *size = size_bytes;
429 7 return 0;
430 }
431
432 4 AVDynamicHDRSmpte2094App5 *av_dynamic_hdr_smpte2094_app5_alloc(size_t *size)
433 {
434 4 AVDynamicHDRSmpte2094App5 *smpte2094_app5 = av_mallocz(sizeof(AVDynamicHDRSmpte2094App5));
435
436
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (size)
437
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 *size = smpte2094_app5 ? sizeof(*smpte2094_app5) : 0;
438
439 4 return smpte2094_app5;
440 }
441
442 1 AVDynamicHDRSmpte2094App5 *av_dynamic_hdr_smpte2094_app5_create_side_data(AVFrame *frame)
443 {
444 1 AVFrameSideData *side_data = av_frame_new_side_data(frame,
445 AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5,
446 sizeof(AVDynamicHDRSmpte2094App5));
447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!side_data)
448 ✗ return NULL;
449
450 1 memset(side_data->data, 0, sizeof(AVDynamicHDRSmpte2094App5));
451
452 1 return (AVDynamicHDRSmpte2094App5 *)side_data->data;
453 }
454
455 #define GET_BITS_OR_FAIL(var, n) \
456 do { \
457 if (get_bits_left(gb) < n) { \
458 ret = AVERROR_INVALIDDATA; \
459 goto end; \
460 } \
461 var = get_bits(gb, n); \
462 } while (0)
463
464 5 int av_dynamic_hdr_smpte2094_app5_from_t35(AVDynamicHDRSmpte2094App5 *s, const uint8_t *data,
465 size_t size)
466 {
467 5 GetBitContext gbc, *gb = &gbc;
468 int ret, reserved_zero;
469 5 size_t padded_size = size + AV_INPUT_BUFFER_PADDING_SIZE;
470
471
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 if (!s)
472 1 return AVERROR(EINVAL);
473
474 4 uint8_t *padded_data = av_mallocz(padded_size);
475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!padded_data)
476 ✗ return AVERROR(ENOMEM);
477
478 4 memcpy(padded_data, data, size);
479 4 ret = init_get_bits8(gb, padded_data, size);
480
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0)
481 ✗ goto end;
482
483 // Table C.1
484
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 GET_BITS_OR_FAIL(s->application_version, 3);
485
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 GET_BITS_OR_FAIL(s->minimum_application_version, 3);
486
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 GET_BITS_OR_FAIL(reserved_zero, 2);
487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (reserved_zero) {
488 ✗ ret = AVERROR_INVALIDDATA;
489 ✗ goto end;
490 }
491
492 // Table C.2
493
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 GET_BITS_OR_FAIL(s->has_custom_hdr_reference_white_flag, 1);
494
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 GET_BITS_OR_FAIL(s->has_adaptive_tone_map_flag, 1);
495
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 GET_BITS_OR_FAIL(reserved_zero, 6);
496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (reserved_zero) {
497 ✗ ret = AVERROR_INVALIDDATA;
498 ✗ goto end;
499 }
500
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (s->has_custom_hdr_reference_white_flag)
501
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 GET_BITS_OR_FAIL(s->hdr_reference_white, 16);
502
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (!s->has_adaptive_tone_map_flag) {
503 1 ret = 0;
504 1 goto end;
505 }
506
507 // Table C.3
508
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 GET_BITS_OR_FAIL(s->baseline_hdr_headroom, 16);
509
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 GET_BITS_OR_FAIL(s->use_reference_white_tone_mapping_flag, 1);
510
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (s->use_reference_white_tone_mapping_flag) {
511
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 GET_BITS_OR_FAIL(reserved_zero, 7);
512
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 ret = reserved_zero ? AVERROR_INVALIDDATA : 0;
513 1 goto end;
514 }
515
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GET_BITS_OR_FAIL(s->num_alternate_images, 3);
516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->num_alternate_images > 4) {
517 ✗ ret = AVERROR_INVALIDDATA;
518 ✗ goto end;
519 }
520
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GET_BITS_OR_FAIL(s->gain_application_space_chromaticities_flag, 2);
521
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GET_BITS_OR_FAIL(s->has_common_component_mix_params_flag, 1);
522
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GET_BITS_OR_FAIL(s->has_common_curve_params_flag, 1);
523
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (s->gain_application_space_chromaticities_flag == 3)
524
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (int r = 0; r < 8; r++)
525
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 GET_BITS_OR_FAIL(s->gain_application_space_chromaticities[r], 16);
526
527
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
7 for (int a = 0; a < s->num_alternate_images; a++) {
528
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
5 GET_BITS_OR_FAIL(s->alternate_hdr_headrooms[a], 16);
529
530 // Table C.4
531
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
5 if (!a || !s->has_common_component_mix_params_flag) {
532
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 GET_BITS_OR_FAIL(s->component_mixing_type[a], 2);
533
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (s->component_mixing_type[a] != 3) {
534
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 GET_BITS_OR_FAIL(reserved_zero, 6);
535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (reserved_zero) {
536 ✗ ret = AVERROR_INVALIDDATA;
537 ✗ goto end;
538 }
539 } else {
540
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
14 for (int k = 0; k < 6; k++)
541
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 GET_BITS_OR_FAIL(s->has_component_mixing_coefficient_flag[a][k], 1);
542
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
14 for (int k = 0; k < 6; k++) {
543
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (s->has_component_mixing_coefficient_flag[a][k]) {
544
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 GET_BITS_OR_FAIL(s->component_mixing_coefficient[a][k], 16);
545 } else {
546 6 s->component_mixing_coefficient[a][k] = 0;
547 }
548 }
549 }
550 } else {
551 2 s->component_mixing_type[a] = s->component_mixing_type[0];
552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->component_mixing_type[a] == 3) {
553 ✗ for (int k = 0; k < 6; k++) {
554 ✗ s->has_component_mixing_coefficient_flag[a][k] =
555 ✗ s->has_component_mixing_coefficient_flag[0][k];
556 ✗ s->component_mixing_coefficient[a][k] = s->component_mixing_coefficient[0][k];
557 }
558 }
559 }
560
561 // Table C.5
562
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
5 if (!a || !s->has_common_curve_params_flag) {
563
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 GET_BITS_OR_FAIL(s->gain_curve_num_control_points_minus_1[a], 5);
564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (s->gain_curve_num_control_points_minus_1[a] > 31) {
565 ✗ ret = AVERROR_INVALIDDATA;
566 ✗ goto end;
567 }
568
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 GET_BITS_OR_FAIL(s->gain_curve_use_pchip_slope_flag[a], 1);
569
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 GET_BITS_OR_FAIL(reserved_zero, 2);
570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (reserved_zero) {
571 ✗ ret = AVERROR_INVALIDDATA;
572 ✗ goto end;
573 }
574
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
10 for (int c = 0; c <= s->gain_curve_num_control_points_minus_1[a]; c++) {
575
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
7 GET_BITS_OR_FAIL(s->gain_curve_control_points_x[a][c], 16);
576 }
577 } else {
578 2 s->gain_curve_num_control_points_minus_1[a] =
579 2 s->gain_curve_num_control_points_minus_1[0];
580 2 s->gain_curve_use_pchip_slope_flag[a] = s->gain_curve_use_pchip_slope_flag[0];
581
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (int c = 0; c <= s->gain_curve_num_control_points_minus_1[a]; c++) {
582 6 s->gain_curve_control_points_x[a][c] = s->gain_curve_control_points_x[0][c];
583 }
584 }
585
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5 times.
18 for (int c = 0; c <= s->gain_curve_num_control_points_minus_1[a]; c++)
586
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
13 GET_BITS_OR_FAIL(s->gain_curve_control_points_y[a][c], 16);
587
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (!s->gain_curve_use_pchip_slope_flag[a]) {
588
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 for (int c = 0; c <= s->gain_curve_num_control_points_minus_1[a]; c++)
589
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 GET_BITS_OR_FAIL(s->gain_curve_control_points_theta[a][c], 16);
590 }
591 }
592 2 ret = 0;
593 4 end:
594 4 av_free(padded_data);
595 4 return ret;
596 }
597
598 10 int av_dynamic_hdr_smpte2094_app5_to_t35(const AVDynamicHDRSmpte2094App5 *s, uint8_t **data,
599 size_t *size)
600 {
601 uint8_t *buf;
602 size_t size_bytes, size_bits;
603 10 PutBitContext pbc, *pb = &pbc;
604
605
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 if (!s)
606 1 return AVERROR(EINVAL);
607
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
9 if ((!data || *data) && !size)
608 ✗ return AVERROR(EINVAL);
609
610
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 7 times.
9 if (s->application_version >= 8 || s->minimum_application_version >= 3)
611 2 return AVERROR_INVALIDDATA;
612 7 size_bits = 0;
613 7 size_bits += 3 + 3 + 2;
614 7 size_bits += 1 + 1 + 6;
615
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
7 if (s->has_custom_hdr_reference_white_flag)
616 3 size_bits += 16;
617
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
7 if (s->has_adaptive_tone_map_flag) {
618 4 size_bits += 16 + 1;
619
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (s->use_reference_white_tone_mapping_flag) {
620 1 size_bits += 7;
621 } else {
622 3 size_bits += 3 + 2 + 1 + 1;
623
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (s->gain_application_space_chromaticities_flag == 3)
624 1 size_bits += 16 * 8;
625
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (s->num_alternate_images > 4)
626 1 return AVERROR_INVALIDDATA;
627
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
7 for (int a = 0; a < s->num_alternate_images; a++) {
628 5 size_bits += 16;
629
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
5 if (!a || !s->has_common_component_mix_params_flag) {
630 3 size_bits += 2;
631
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (s->component_mixing_type[a] != 3) {
632 1 size_bits += 6;
633 } else {
634 2 size_bits += 6;
635
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
14 for (int k = 0; k < 6; k++)
636
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (s->has_component_mixing_coefficient_flag[a][k])
637 6 size_bits += 16;
638 }
639 }
640
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
5 if (!a || !s->has_common_curve_params_flag) {
641 3 size_bits += 5 + 1 + 2;
642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (s->gain_curve_num_control_points_minus_1[a] > 31)
643 ✗ return AVERROR_INVALIDDATA;
644 3 size_bits += 16 * (s->gain_curve_num_control_points_minus_1[a] + 1);
645 }
646 5 size_bits += 16 * (s->gain_curve_num_control_points_minus_1[a] + 1);
647
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (!s->gain_curve_use_pchip_slope_flag[a])
648 2 size_bits += 16 * (s->gain_curve_num_control_points_minus_1[a] + 1);
649 }
650 }
651 }
652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (size_bits % 8)
653 ✗ return AVERROR_INVALIDDATA;
654 6 size_bytes = size_bits >> 3;
655
656
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 if (!data) {
657 1 *size = size_bytes;
658 1 return 0;
659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 } else if (*data) {
660 ✗ if (*size < size_bytes)
661 ✗ return AVERROR_BUFFER_TOO_SMALL;
662 ✗ buf = *data;
663 } else {
664 5 buf = av_malloc(size_bytes);
665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!buf)
666 ✗ return AVERROR(ENOMEM);
667 }
668
669 5 init_put_bits(pb, buf, size_bytes);
670
671 // Table C.1
672 5 put_bits(pb, 3, s->application_version);
673 5 put_bits(pb, 3, s->minimum_application_version);
674 5 put_bits(pb, 2, 0); // reserved_zero
675
676 // Table C.2
677 5 put_bits(pb, 1, s->has_custom_hdr_reference_white_flag);
678 5 put_bits(pb, 1, s->has_adaptive_tone_map_flag);
679 5 put_bits(pb, 6, 0); // reserved_zero
680
681
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (s->has_custom_hdr_reference_white_flag)
682 2 put_bits(pb, 16, s->hdr_reference_white);
683
684
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
5 if (s->has_adaptive_tone_map_flag) {
685 // Table C.3
686 3 put_bits(pb, 16, s->baseline_hdr_headroom);
687 3 put_bits(pb, 1, s->use_reference_white_tone_mapping_flag);
688
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (s->use_reference_white_tone_mapping_flag) {
689 1 put_bits(pb, 7, 0); // reserved_zero
690 } else {
691 2 put_bits(pb, 3, s->num_alternate_images);
692 2 put_bits(pb, 2, s->gain_application_space_chromaticities_flag);
693 2 put_bits(pb, 1, s->has_common_component_mix_params_flag);
694 2 put_bits(pb, 1, s->has_common_curve_params_flag);
695
696
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (s->gain_application_space_chromaticities_flag == 3)
697
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (int r = 0; r < 8; r++)
698 8 put_bits(pb, 16, s->gain_application_space_chromaticities[r]);
699
700
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
7 for (int a = 0; a < s->num_alternate_images; a++) {
701 5 put_bits(pb, 16, s->alternate_hdr_headrooms[a]);
702
703 // Table C.4
704
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
5 if (!a || !s->has_common_component_mix_params_flag) {
705 3 put_bits(pb, 2, s->component_mixing_type[a]);
706
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (s->component_mixing_type[a] != 3) {
707 1 put_bits(pb, 6, 0); // reserved_zero
708 } else {
709
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
14 for (int k = 0; k < 6; k++)
710 12 put_bits(pb, 1, s->has_component_mixing_coefficient_flag[a][k]);
711
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
14 for (int k = 0; k < 6; k++)
712
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (s->has_component_mixing_coefficient_flag[a][k])
713 6 put_bits(pb, 16, s->component_mixing_coefficient[a][k]);
714 }
715 }
716
717 // Table C.5
718
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
5 if (!a || !s->has_common_curve_params_flag) {
719 3 put_bits(pb, 5, s->gain_curve_num_control_points_minus_1[a]);
720 3 put_bits(pb, 1, s->gain_curve_use_pchip_slope_flag[a]);
721 3 put_bits(pb, 2, 0); // reserved_zero
722
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
10 for (int c = 0; c <= s->gain_curve_num_control_points_minus_1[a]; c++)
723 7 put_bits(pb, 16, s->gain_curve_control_points_x[a][c]);
724 }
725
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5 times.
18 for (int c = 0; c <= s->gain_curve_num_control_points_minus_1[a]; c++)
726 13 put_bits(pb, 16, s->gain_curve_control_points_y[a][c]);
727
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (!s->gain_curve_use_pchip_slope_flag[a]) {
728
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 for (int c = 0; c <= s->gain_curve_num_control_points_minus_1[a]; c++)
729 4 put_bits(pb, 16, s->gain_curve_control_points_theta[a][c]);
730 }
731 }
732 }
733 }
734
735 5 flush_put_bits(pb);
736
737 5 *data = buf;
738
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (size)
739 5 *size = size_bytes;
740 5 return 0;
741 }
742