33#define LUMINANCE_DEN 1
34#define PEAK_LUMINANCE_DEN 15
36#define FRACTION_PIXEL_DEN 1000
37#define KNEE_POINT_DEN 4095
38#define BEZIER_ANCHOR_DEN 1023
39#define SATURATION_DEN 8
50 printf(
" %s %dx%d:", label, rows, cols);
51 for (
int i = 0;
i < rows;
i++)
52 for (
int j = 0; j < cols; j++)
53 printf(
" %d/%d", m[
i][j].num, m[
i][j].den);
63 printf(
" corners: ul=%d/%d,%d/%d lr=%d/%d,%d/%d\n",
64 p->window_upper_left_corner_x.num,
65 p->window_upper_left_corner_x.den,
66 p->window_upper_left_corner_y.num,
67 p->window_upper_left_corner_y.den,
68 p->window_lower_right_corner_x.num,
69 p->window_lower_right_corner_x.den,
70 p->window_lower_right_corner_y.num,
71 p->window_lower_right_corner_y.den);
72 printf(
" ellipse: center=%u,%u rotation=%u semimajor_int=%u"
73 " semimajor_ext=%u semiminor_ext=%u overlap=%u\n",
74 p->center_of_ellipse_x, p->center_of_ellipse_y,
75 p->rotation_angle, p->semimajor_axis_internal_ellipse,
76 p->semimajor_axis_external_ellipse,
77 p->semiminor_axis_external_ellipse,
78 p->overlap_process_option);
80 printf(
" maxscl: %d/%d %d/%d %d/%d average_maxrgb=%d/%d\n",
81 p->maxscl[0].num, p->maxscl[0].den,
82 p->maxscl[1].num, p->maxscl[1].den,
83 p->maxscl[2].num, p->maxscl[2].den,
84 p->average_maxrgb.num, p->average_maxrgb.den);
85 printf(
" distribution_maxrgb: n=%u",
86 p->num_distribution_maxrgb_percentiles);
87 for (
int i = 0;
i < p->num_distribution_maxrgb_percentiles;
i++)
88 printf(
" %u%%=%d/%d", p->distribution_maxrgb[
i].percentage,
89 p->distribution_maxrgb[
i].percentile.num,
90 p->distribution_maxrgb[
i].percentile.den);
91 printf(
"\n fraction_bright_pixels=%d/%d\n",
92 p->fraction_bright_pixels.num, p->fraction_bright_pixels.den);
93 printf(
" tone_mapping_flag=%u", p->tone_mapping_flag);
94 if (p->tone_mapping_flag) {
95 printf(
" knee=%d/%d,%d/%d anchors=%u:",
96 p->knee_point_x.num, p->knee_point_x.den,
97 p->knee_point_y.num, p->knee_point_y.den,
98 p->num_bezier_curve_anchors);
99 for (
int i = 0;
i < p->num_bezier_curve_anchors;
i++)
100 printf(
" %d/%d", p->bezier_curve_anchors[
i].num,
101 p->bezier_curve_anchors[
i].den);
103 printf(
"\n color_saturation_mapping_flag=%u",
104 p->color_saturation_mapping_flag);
105 if (p->color_saturation_mapping_flag)
106 printf(
" weight=%d/%d", p->color_saturation_weight.num,
107 p->color_saturation_weight.den);
114 printf(
" application_version=%u num_windows=%u"
115 " targeted_system_display_maximum_luminance=%d/%d\n",
116 s->application_version,
s->num_windows,
117 s->targeted_system_display_maximum_luminance.num,
118 s->targeted_system_display_maximum_luminance.den);
119 printf(
" targeted_system_display_actual_peak_luminance_flag=%u\n",
120 s->targeted_system_display_actual_peak_luminance_flag);
121 if (
s->targeted_system_display_actual_peak_luminance_flag)
123 s->num_rows_targeted_system_display_actual_peak_luminance,
124 s->num_cols_targeted_system_display_actual_peak_luminance,
125 s->targeted_system_display_actual_peak_luminance);
126 printf(
" mastering_display_actual_peak_luminance_flag=%u\n",
127 s->mastering_display_actual_peak_luminance_flag);
128 if (
s->mastering_display_actual_peak_luminance_flag)
130 s->num_rows_mastering_display_actual_peak_luminance,
131 s->num_cols_mastering_display_actual_peak_luminance,
132 s->mastering_display_actual_peak_luminance);
133 for (
int w = 0;
w <
s->num_windows;
w++)
140 printf(
" application_version=%u minimum_application_version=%u\n",
141 s->application_version,
s->minimum_application_version);
142 printf(
" has_custom_hdr_reference_white_flag=%u",
143 s->has_custom_hdr_reference_white_flag);
144 if (
s->has_custom_hdr_reference_white_flag)
145 printf(
" hdr_reference_white=0x%04x",
s->hdr_reference_white);
146 printf(
"\n has_adaptive_tone_map_flag=%u\n",
147 s->has_adaptive_tone_map_flag);
148 if (!
s->has_adaptive_tone_map_flag)
151 printf(
" baseline_hdr_headroom=0x%04x"
152 " use_reference_white_tone_mapping_flag=%u\n",
153 s->baseline_hdr_headroom,
s->use_reference_white_tone_mapping_flag);
154 if (
s->use_reference_white_tone_mapping_flag)
157 printf(
" num_alternate_images=%u chromaticities_flag=%u"
158 " has_common_component_mix_params_flag=%u"
159 " has_common_curve_params_flag=%u\n",
160 s->num_alternate_images,
161 s->gain_application_space_chromaticities_flag,
162 s->has_common_component_mix_params_flag,
163 s->has_common_curve_params_flag);
164 if (
s->gain_application_space_chromaticities_flag == 3) {
165 printf(
" chromaticities:");
166 for (
int r = 0;
r < 8;
r++)
167 printf(
" 0x%04x",
s->gain_application_space_chromaticities[
r]);
171 for (
int a = 0;
a <
s->num_alternate_images;
a++) {
172 int n =
s->gain_curve_num_control_points_minus_1[
a] + 1;
173 printf(
" alternate %d: hdr_headroom=0x%04x component_mixing_type=%u\n",
174 a,
s->alternate_hdr_headrooms[
a],
s->component_mixing_type[
a]);
175 if (
s->component_mixing_type[
a] == 3) {
176 printf(
" mixing flag:coefficient:");
177 for (
int k = 0; k < 6; k++)
179 s->has_component_mixing_coefficient_flag[
a][k],
180 s->component_mixing_coefficient[
a][k]);
183 printf(
" curve: num_control_points=%d use_pchip_slope=%u\n", n,
184 s->gain_curve_use_pchip_slope_flag[
a]);
186 for (
int c = 0;
c < n;
c++)
187 printf(
" 0x%04x",
s->gain_curve_control_points_x[
a][
c]);
189 for (
int c = 0;
c < n;
c++)
190 printf(
" 0x%04x",
s->gain_curve_control_points_y[
a][
c]);
193 if (!
s->gain_curve_use_pchip_slope_flag[
a]) {
195 for (
int c = 0;
c < n;
c++)
196 printf(
" 0x%04x",
s->gain_curve_control_points_theta[
a][
c]);
216 memset(
out, 0,
sizeof(*
out));
233 memset(
out, 0,
sizeof(*
out));
256 static const uint8_t percentages[9] = { 1, 5, 10, 25, 50, 75, 90, 95, 99 };
257 static const int percentiles[9] = {
258 1000, 0, 255, 25000, 50000, 75000, 90000, 95000, 99000,
261 memset(
s, 0,
sizeof(*
s));
263 s->application_version = 1;
265 s->targeted_system_display_maximum_luminance =
267 s->targeted_system_display_actual_peak_luminance_flag = 0;
268 s->mastering_display_actual_peak_luminance_flag = 0;
275 s->params[0].num_distribution_maxrgb_percentiles = 9;
276 for (
int i = 0;
i < 9;
i++) {
277 s->params[0].distribution_maxrgb[
i].percentage = percentages[
i];
278 s->params[0].distribution_maxrgb[
i].percentile =
281 s->params[0].fraction_bright_pixels =
284 s->params[0].tone_mapping_flag = 1;
287 s->params[0].num_bezier_curve_anchors = 9;
288 for (
int i = 0;
i < 9;
i++)
289 s->params[0].bezier_curve_anchors[
i] =
292 s->params[0].color_saturation_mapping_flag = 0;
305 memset(
s, 0,
sizeof(*
s));
307 s->application_version = 1;
309 s->targeted_system_display_maximum_luminance =
312 s->params[1].window_upper_left_corner_x = (
AVRational){ 100, 1 };
313 s->params[1].window_upper_left_corner_y = (
AVRational){ 120, 1 };
314 s->params[1].window_lower_right_corner_x = (
AVRational){ 500, 1 };
315 s->params[1].window_lower_right_corner_y = (
AVRational){ 520, 1 };
316 s->params[1].center_of_ellipse_x = 300;
317 s->params[1].center_of_ellipse_y = 320;
318 s->params[1].rotation_angle = 45;
319 s->params[1].semimajor_axis_internal_ellipse = 50;
320 s->params[1].semimajor_axis_external_ellipse = 100;
321 s->params[1].semiminor_axis_external_ellipse = 80;
322 s->params[1].overlap_process_option = 1;
328 s->params[0].num_distribution_maxrgb_percentiles = 2;
329 s->params[0].distribution_maxrgb[0].percentage = 50;
330 s->params[0].distribution_maxrgb[0].percentile =
332 s->params[0].distribution_maxrgb[1].percentage = 99;
333 s->params[0].distribution_maxrgb[1].percentile =
335 s->params[0].fraction_bright_pixels =
342 s->params[1].num_distribution_maxrgb_percentiles = 1;
343 s->params[1].distribution_maxrgb[0].percentage = 25;
344 s->params[1].distribution_maxrgb[0].percentile =
346 s->params[1].fraction_bright_pixels =
349 s->targeted_system_display_actual_peak_luminance_flag = 1;
350 s->num_rows_targeted_system_display_actual_peak_luminance = 2;
351 s->num_cols_targeted_system_display_actual_peak_luminance = 3;
352 for (
int i = 0;
i < 2;
i++)
353 for (
int j = 0; j < 3; j++)
354 s->targeted_system_display_actual_peak_luminance[
i][j] =
357 s->mastering_display_actual_peak_luminance_flag = 1;
358 s->num_rows_mastering_display_actual_peak_luminance = 3;
359 s->num_cols_mastering_display_actual_peak_luminance = 2;
360 for (
int i = 0;
i < 3;
i++)
361 for (
int j = 0; j < 2; j++)
362 s->mastering_display_actual_peak_luminance[
i][j] =
365 for (
int w = 0;
w < 2;
w++) {
366 s->params[
w].tone_mapping_flag = 1;
369 s->params[
w].num_bezier_curve_anchors = 3;
370 s->params[
w].bezier_curve_anchors[0] =
372 s->params[
w].bezier_curve_anchors[1] =
374 s->params[
w].bezier_curve_anchors[2] =
376 s->params[
w].color_saturation_mapping_flag = 1;
377 s->params[
w].color_saturation_weight =
386 size_t size = 0, required = 0;
390 printf(
"=== AVDynamicHDRPlus ===\n");
392 printf(
"Testing av_dynamic_hdr_plus_alloc()\n");
394 printf(
"alloc: %s size>0=%s\n", hdr ?
"OK" :
"FAIL",
395 size > 0 ?
"yes" :
"no");
399 printf(
"alloc (no size): %s\n", hdr ?
"OK" :
"FAIL");
402 printf(
"\nTesting av_dynamic_hdr_plus_create_side_data()\n");
406 printf(
"create_side_data: %s\n", hdr ?
"OK" :
"FAIL");
412 if (!hdr || !hdr_rt) {
420 printf(
"\nTesting av_dynamic_hdr_plus_to_t35() size query\n");
423 printf(
"size query: ret=%d required>0=%s\n", ret,
424 required > 0 ?
"yes" :
"no");
427 printf(
"\nTesting av_dynamic_hdr_plus_to_t35() allocation\n");
431 printf(
"alloc mode: ret=%d size_match=%s\n", ret,
432 size == required ?
"yes" :
"no");
436 printf(
"\nTesting av_dynamic_hdr_plus_to_t35() existing buffer\n");
442 printf(
"existing buf: ret=%d same_pointer=%s size_match=%s\n", ret,
443 buf == orig ?
"yes" :
"no",
444 size == required ?
"yes" :
"no");
449 printf(
"\nTesting av_dynamic_hdr_plus_to_t35() buffer too small\n");
455 printf(
"too small: ret==AVERROR_BUFFER_TOO_SMALL=%s\n",
461 printf(
"\nTesting round trip, conforming ST 2094-40 Version 1 payload\n");
463 printf(
"round trip: ret=%d\n", ret);
469 printf(
"\nTesting that to_t35() overrides application_version\n");
472 printf(
"input=7 ret=%d decoded application_version=%u\n", ret,
476 printf(
"\nTesting round trip, synthetic payload (branch coverage only)\n");
479 printf(
"round trip: ret=%d\n", ret);
483 printf(
"\nTesting error paths\n");
487 printf(
"to_t35 NULL s: ret==AVERROR(EINVAL)=%s\n",
488 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
491 printf(
"to_t35 no data no size: ret==AVERROR(EINVAL)=%s\n",
492 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
495 printf(
"from_t35 NULL s: ret==AVERROR(EINVAL)=%s\n",
496 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
504 printf(
"from_t35 oversized: ret==AVERROR(EINVAL)=%s\n",
505 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
513 printf(
"\nTesting OOM path\n");
516 printf(
"alloc OOM: %s\n", hdr ?
"FAIL" :
"OK");
524 memset(
s, 0,
sizeof(*
s));
525 s->application_version = 1;
526 s->minimum_application_version = 0;
527 s->has_custom_hdr_reference_white_flag = 1;
528 s->hdr_reference_white = 0x0203;
529 s->has_adaptive_tone_map_flag = 0;
535 memset(
s, 0,
sizeof(*
s));
536 s->application_version = 2;
537 s->has_adaptive_tone_map_flag = 1;
538 s->baseline_hdr_headroom = 0x0abc;
539 s->use_reference_white_tone_mapping_flag = 1;
547 memset(
s, 0,
sizeof(*
s));
548 s->application_version = 1;
549 s->has_adaptive_tone_map_flag = 1;
550 s->baseline_hdr_headroom = 0x0abc;
551 s->num_alternate_images = 2;
552 s->gain_application_space_chromaticities_flag = 3;
553 for (
int r = 0;
r < 8;
r++)
554 s->gain_application_space_chromaticities[
r] = 100 * (
r + 1);
555 s->has_common_component_mix_params_flag = 0;
556 s->has_common_curve_params_flag = 0;
557 for (
int a = 0;
a < 2;
a++) {
558 s->alternate_hdr_headrooms[
a] = 0x0100 +
a;
559 s->component_mixing_type[
a] = 3;
560 for (
int k = 0; k < 6; k++) {
561 s->has_component_mixing_coefficient_flag[
a][k] = k & 1;
562 s->component_mixing_coefficient[
a][k] = 0x1000 + 0x10 *
a + k;
564 s->gain_curve_num_control_points_minus_1[
a] = 1;
565 s->gain_curve_use_pchip_slope_flag[
a] = 0;
566 for (
int c = 0;
c < 2;
c++) {
567 s->gain_curve_control_points_x[
a][
c] = 0x2000 + 0x10 *
a +
c;
568 s->gain_curve_control_points_y[
a][
c] = 0x3000 + 0x10 *
a +
c;
569 s->gain_curve_control_points_theta[
a][
c] = 0x4000 + 0x10 *
a +
c;
583 memset(
s, 0,
sizeof(*
s));
584 s->application_version = 1;
585 s->has_adaptive_tone_map_flag = 1;
586 s->baseline_hdr_headroom = 0x0def;
587 s->num_alternate_images = 3;
588 s->gain_application_space_chromaticities_flag = 0;
589 s->has_common_component_mix_params_flag = 1;
590 s->has_common_curve_params_flag = 1;
591 for (
int a = 0;
a < 3;
a++) {
592 s->alternate_hdr_headrooms[
a] = 0x0200 +
a;
593 s->component_mixing_type[
a] = 1;
594 s->gain_curve_num_control_points_minus_1[
a] = 2;
595 s->gain_curve_use_pchip_slope_flag[
a] = 1;
596 for (
int c = 0;
c < 3;
c++) {
597 s->gain_curve_control_points_x[
a][
c] = 0x5000 +
c;
598 s->gain_curve_control_points_y[
a][
c] = 0x6000 + 0x10 *
a +
c;
607 size_t size = 0, required = 0;
611 printf(
"\n=== AVDynamicHDRSmpte2094App5 ===\n");
612 printf(
"Testing av_dynamic_hdr_smpte2094_app5_alloc()\n");
614 printf(
"alloc: %s size>0=%s\n", app5 ?
"OK" :
"FAIL",
615 size > 0 ?
"yes" :
"no");
618 printf(
"\nTesting av_dynamic_hdr_smpte2094_app5_create_side_data()\n");
622 printf(
"create_side_data: %s\n", app5 ?
"OK" :
"FAIL");
628 if (!app5 || !app5_rt) {
635 printf(
"\nTesting av_dynamic_hdr_smpte2094_app5_to_t35()\n");
638 printf(
"size query: ret=%d required>0=%s\n", ret,
639 required > 0 ?
"yes" :
"no");
644 printf(
"alloc mode: ret=%d size_match=%s\n", ret,
645 size == required ?
"yes" :
"no");
648 printf(
"\nTesting round trip, no adaptive tone map\n");
650 printf(
"round trip: ret=%d\n", ret);
654 printf(
"\nTesting round trip, reference-white tone mapping\n");
657 printf(
"round trip: ret=%d\n", ret);
661 printf(
"\nTesting round trip, per-image mixing and curve parameters\n");
664 printf(
"round trip: ret=%d\n", ret);
668 printf(
"\nTesting round trip, common mixing and curve parameters\n");
671 printf(
"round trip: ret=%d\n", ret);
675 printf(
"\nTesting error paths\n");
679 printf(
"to_t35 NULL s: ret==AVERROR(EINVAL)=%s\n",
680 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
683 printf(
"from_t35 NULL s: ret==AVERROR(EINVAL)=%s\n",
684 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
689 printf(
"to_t35 invalid application_version: ret==AVERROR_INVALIDDATA=%s\n",
696 printf(
"to_t35 invalid minimum_application_version:"
697 " ret==AVERROR_INVALIDDATA=%s\n",
704 printf(
"to_t35 too many alternate images: ret==AVERROR_INVALIDDATA=%s\n",
710 printf(
"\nTesting OOM path\n");
713 printf(
"alloc OOM: %s\n", app5 ?
"FAIL" :
"OK");
#define i(width, name, range_min, range_max)
__device__ int printf(const char *,...)
reference-counted frame API
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
void av_max_alloc(size_t max)
Set the maximum size that may be allocated in one block.
Memory handling functions.
Utilities for rational number calculation.
This struct represents dynamic metadata for color volume transform - application 4 of SMPTE 2094-40:2...
uint8_t application_version
Application version in the application defining document in ST-2094 suite.
This struct represents dynamic metadata for color volume transform as specified in the SMPTE 2094-50 ...
uint8_t application_version
Section C.2.1.
uint8_t num_alternate_images
uint8_t minimum_application_version
This structure describes decoded (raw) audio or video data.
Rational number (pair of numerator and denominator).