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
51 for (
int i = 0;
i < rows;
i++)
52 for (
int j = 0; j < cols; j++)
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;
301 memset(
s, 0,
sizeof(*
s));
303 s->application_version = 1;
305 s->targeted_system_display_maximum_luminance =
308 s->params[1].window_upper_left_corner_x = (
AVRational){ 100, 1 };
309 s->params[1].window_upper_left_corner_y = (
AVRational){ 120, 1 };
310 s->params[1].window_lower_right_corner_x = (
AVRational){ 500, 1 };
311 s->params[1].window_lower_right_corner_y = (
AVRational){ 520, 1 };
312 s->params[1].center_of_ellipse_x = 300;
313 s->params[1].center_of_ellipse_y = 320;
314 s->params[1].rotation_angle = 45;
315 s->params[1].semimajor_axis_internal_ellipse = 50;
316 s->params[1].semimajor_axis_external_ellipse = 100;
317 s->params[1].semiminor_axis_external_ellipse = 80;
318 s->params[1].overlap_process_option = 1;
324 s->params[0].num_distribution_maxrgb_percentiles = 2;
325 s->params[0].distribution_maxrgb[0].percentage = 50;
326 s->params[0].distribution_maxrgb[0].percentile =
328 s->params[0].distribution_maxrgb[1].percentage = 99;
329 s->params[0].distribution_maxrgb[1].percentile =
331 s->params[0].fraction_bright_pixels =
338 s->params[1].num_distribution_maxrgb_percentiles = 1;
339 s->params[1].distribution_maxrgb[0].percentage = 25;
340 s->params[1].distribution_maxrgb[0].percentile =
342 s->params[1].fraction_bright_pixels =
345 s->targeted_system_display_actual_peak_luminance_flag = 1;
346 s->num_rows_targeted_system_display_actual_peak_luminance = 2;
347 s->num_cols_targeted_system_display_actual_peak_luminance = 3;
348 for (
int i = 0;
i < 2;
i++)
349 for (
int j = 0; j < 3; j++)
350 s->targeted_system_display_actual_peak_luminance[
i][j] =
353 s->mastering_display_actual_peak_luminance_flag = 1;
354 s->num_rows_mastering_display_actual_peak_luminance = 3;
355 s->num_cols_mastering_display_actual_peak_luminance = 2;
356 for (
int i = 0;
i < 3;
i++)
357 for (
int j = 0; j < 2; j++)
358 s->mastering_display_actual_peak_luminance[
i][j] =
361 s->params[0].tone_mapping_flag = 1;
364 s->params[0].num_bezier_curve_anchors = 3;
368 s->params[1].tone_mapping_flag = 0;
370 for (
int w = 0;
w < 2;
w++) {
371 s->params[
w].color_saturation_mapping_flag = 1;
372 s->params[
w].color_saturation_weight =
381 size_t size = 0, required = 0;
385 printf(
"=== AVDynamicHDRPlus ===\n");
387 printf(
"Testing av_dynamic_hdr_plus_alloc()\n");
389 printf(
"alloc: %s size>0=%s\n", hdr ?
"OK" :
"FAIL",
390 size > 0 ?
"yes" :
"no");
394 printf(
"alloc (no size): %s\n", hdr ?
"OK" :
"FAIL");
397 printf(
"\nTesting av_dynamic_hdr_plus_create_side_data()\n");
401 printf(
"create_side_data: %s\n", hdr ?
"OK" :
"FAIL");
407 if (!hdr || !hdr_rt) {
415 printf(
"\nTesting av_dynamic_hdr_plus_to_t35() size query\n");
418 printf(
"size query: ret=%d required>0=%s\n", ret,
419 required > 0 ?
"yes" :
"no");
422 printf(
"\nTesting av_dynamic_hdr_plus_to_t35() allocation\n");
426 printf(
"alloc mode: ret=%d size_match=%s\n", ret,
427 size == required ?
"yes" :
"no");
431 printf(
"\nTesting av_dynamic_hdr_plus_to_t35() existing buffer\n");
437 printf(
"existing buf: ret=%d same_pointer=%s size_match=%s\n", ret,
438 buf == orig ?
"yes" :
"no",
439 size == required ?
"yes" :
"no");
444 printf(
"\nTesting av_dynamic_hdr_plus_to_t35() buffer too small\n");
450 printf(
"too small: ret==AVERROR_BUFFER_TOO_SMALL=%s\n",
456 printf(
"\nTesting round trip, conforming ST 2094-40 Version 1 payload\n");
458 printf(
"round trip: ret=%d\n", ret);
464 printf(
"\nTesting that to_t35() overrides application_version\n");
467 printf(
"input=7 ret=%d decoded application_version=%u\n", ret,
471 printf(
"\nTesting round trip, synthetic payload (branch coverage only)\n");
474 printf(
"round trip: ret=%d\n", ret);
478 printf(
"\nTesting error paths\n");
482 printf(
"to_t35 NULL s: ret==AVERROR(EINVAL)=%s\n",
483 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
486 printf(
"to_t35 no data no size: ret==AVERROR(EINVAL)=%s\n",
487 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
490 printf(
"from_t35 NULL s: ret==AVERROR(EINVAL)=%s\n",
491 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
499 printf(
"from_t35 oversized: ret==AVERROR(EINVAL)=%s\n",
500 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
508 printf(
"\nTesting OOM path\n");
511 printf(
"alloc OOM: %s\n", hdr ?
"FAIL" :
"OK");
519 memset(
s, 0,
sizeof(*
s));
520 s->application_version = 1;
521 s->minimum_application_version = 0;
522 s->has_custom_hdr_reference_white_flag = 1;
523 s->hdr_reference_white = 0x0203;
524 s->has_adaptive_tone_map_flag = 0;
530 memset(
s, 0,
sizeof(*
s));
531 s->application_version = 2;
532 s->has_adaptive_tone_map_flag = 1;
533 s->baseline_hdr_headroom = 0x0abc;
534 s->use_reference_white_tone_mapping_flag = 1;
542 memset(
s, 0,
sizeof(*
s));
543 s->application_version = 1;
544 s->has_adaptive_tone_map_flag = 1;
545 s->baseline_hdr_headroom = 0x0abc;
546 s->num_alternate_images = 2;
547 s->gain_application_space_chromaticities_flag = 3;
548 for (
int r = 0;
r < 8;
r++)
549 s->gain_application_space_chromaticities[
r] = 100 * (
r + 1);
550 s->has_common_component_mix_params_flag = 0;
551 s->has_common_curve_params_flag = 0;
552 for (
int a = 0;
a < 2;
a++) {
553 s->alternate_hdr_headrooms[
a] = 0x0100 +
a;
554 s->component_mixing_type[
a] = 3;
555 for (
int k = 0; k < 6; k++) {
556 s->has_component_mixing_coefficient_flag[
a][k] = k & 1;
557 s->component_mixing_coefficient[
a][k] = 0x1000 + 0x10 *
a + k;
559 s->gain_curve_num_control_points_minus_1[
a] = 1;
560 s->gain_curve_use_pchip_slope_flag[
a] = 0;
561 for (
int c = 0;
c < 2;
c++) {
562 s->gain_curve_control_points_x[
a][
c] = 0x2000 + 0x10 *
a +
c;
563 s->gain_curve_control_points_y[
a][
c] = 0x3000 + 0x10 *
a +
c;
564 s->gain_curve_control_points_theta[
a][
c] = 0x4000 + 0x10 *
a +
c;
578 memset(
s, 0,
sizeof(*
s));
579 s->application_version = 1;
580 s->has_adaptive_tone_map_flag = 1;
581 s->baseline_hdr_headroom = 0x0def;
582 s->num_alternate_images = 3;
583 s->gain_application_space_chromaticities_flag = 0;
584 s->has_common_component_mix_params_flag = 1;
585 s->has_common_curve_params_flag = 1;
586 for (
int a = 0;
a < 3;
a++) {
587 s->alternate_hdr_headrooms[
a] = 0x0200 +
a;
588 s->component_mixing_type[
a] = 1;
589 s->gain_curve_num_control_points_minus_1[
a] = 2;
590 s->gain_curve_use_pchip_slope_flag[
a] = 1;
591 for (
int c = 0;
c < 3;
c++) {
592 s->gain_curve_control_points_x[
a][
c] = 0x5000 +
c;
593 s->gain_curve_control_points_y[
a][
c] = 0x6000 + 0x10 *
a +
c;
602 size_t size = 0, required = 0;
606 printf(
"\n=== AVDynamicHDRSmpte2094App5 ===\n");
607 printf(
"Testing av_dynamic_hdr_smpte2094_app5_alloc()\n");
609 printf(
"alloc: %s size>0=%s\n", app5 ?
"OK" :
"FAIL",
610 size > 0 ?
"yes" :
"no");
613 printf(
"\nTesting av_dynamic_hdr_smpte2094_app5_create_side_data()\n");
617 printf(
"create_side_data: %s\n", app5 ?
"OK" :
"FAIL");
623 if (!app5 || !app5_rt) {
630 printf(
"\nTesting av_dynamic_hdr_smpte2094_app5_to_t35()\n");
633 printf(
"size query: ret=%d required>0=%s\n", ret,
634 required > 0 ?
"yes" :
"no");
639 printf(
"alloc mode: ret=%d size_match=%s\n", ret,
640 size == required ?
"yes" :
"no");
643 printf(
"\nTesting round trip, no adaptive tone map\n");
645 printf(
"round trip: ret=%d\n", ret);
649 printf(
"\nTesting round trip, reference-white tone mapping\n");
652 printf(
"round trip: ret=%d\n", ret);
656 printf(
"\nTesting round trip, per-image mixing and curve parameters\n");
659 printf(
"round trip: ret=%d\n", ret);
663 printf(
"\nTesting round trip, common mixing and curve parameters\n");
666 printf(
"round trip: ret=%d\n", ret);
670 printf(
"\nTesting error paths\n");
674 printf(
"to_t35 NULL s: ret==AVERROR(EINVAL)=%s\n",
675 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
678 printf(
"from_t35 NULL s: ret==AVERROR(EINVAL)=%s\n",
679 ret ==
AVERROR(EINVAL) ?
"yes" :
"no");
684 printf(
"to_t35 invalid application_version: ret==AVERROR_INVALIDDATA=%s\n",
691 printf(
"to_t35 invalid minimum_application_version:"
692 " ret==AVERROR_INVALIDDATA=%s\n",
699 printf(
"to_t35 too many alternate images: ret==AVERROR_INVALIDDATA=%s\n",
705 printf(
"\nTesting OOM path\n");
708 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).