Raw ↗
+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
1 /*
2 * SPDX-License-Identifier: AGPL-3.0-or-later WITH Classpath-exception-2.0
3 * Copyright (c) 2026 Saif Mukhtar
4 *
5 * OpenAVX - Open Audio-Video eXchange
6 * include/avx_hdr.h - HDR and color primaries metadata
7 */
8  
9 #ifndef AVX_HDR_H
10 #define AVX_HDR_H
11  
12 #include "openavx.h"
13 #include <stdbool.h>
14 #include <stdint.h>
15 #include <stddef.h>
16  
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20  
21 /**
22 * Electro-Optical Transfer Function (EOTF) / Transfer Characteristics.
23 */
24 typedef enum avx_color_transfer_e {
25 AVX_COLOR_TRANSFER_SDR = 0, /* Standard Dynamic Range (BT.709 / BT.601) */
26 AVX_COLOR_TRANSFER_BT2100_HLG = 1, /* Hybrid Log-Gamma (ITU-R BT.2100 / ARIB STD-B67) */
27 AVX_COLOR_TRANSFER_BT2100_PQ = 2, /* Perceptual Quantizer (ITU-R BT.2100 / SMPTE ST 2084 / HDR10) */
28 } avx_color_transfer_e;
29  
30 /**
31 * Matrix Coefficients for YCbCr to RGB mapping.
32 */
33 typedef enum avx_color_matrix_e {
34 AVX_COLOR_MATRIX_BT709 = 0, /* ITU-R BT.709 (HD / SDR) */
35 AVX_COLOR_MATRIX_BT2020 = 1, /* ITU-R BT.2020 (UHD / HDR non-constant luminance) */
36 } avx_color_matrix_e;
37  
38 /**
39 * Color Primaries (Gamut).
40 */
41 typedef enum avx_color_primaries_e {
42 AVX_COLOR_PRIMARIES_BT709 = 0, /* ITU-R BT.709 (Standard sRGB / Rec.709 gamut) */
43 AVX_COLOR_PRIMARIES_BT2020 = 1, /* ITU-R BT.2020 (Wide color gamut) */
44 AVX_COLOR_PRIMARIES_DCI_P3 = 2, /* DCI-P3 (Digital Cinema gamut) */
45 } avx_color_primaries_e;
46  
47 /**
48 * Color and HDR Metadata Structure.
49 */
50 typedef struct avx_color_info_t {
51 avx_color_transfer_e transfer;
52 avx_color_matrix_e matrix;
53 avx_color_primaries_e primaries;
54 uint32_t max_cll; /* Max Content Light Level (nits, e.g. 1000). 0 if unspecified */
55 uint32_t max_fall; /* Max Frame-Average Light Level (nits, e.g. 400). 0 if unspecified */
56 } avx_color_info_t;
57  
58 /**
59 * Formats a color metadata XML string.
60 *
61 * @param p_info Pointer to the color info structure.
62 * @param out_xml Output buffer to store formatted null-terminated XML string.
63 * @param max_len Size in bytes of out_xml buffer.
64 * @return true on success, false if parameters or buffer length are insufficient.
65 */
66 OPENAVX_API bool avx_hdr_format_color_info(const avx_color_info_t* p_info, char* out_xml, size_t max_len);
67  
68 /**
69 * Parses a color metadata XML string.
70 *
71 * @param xml Null-terminated XML string.
72 * @param p_info Pointer to destination color info structure.
73 * @return true if valid <oavx_color_info> or color tag was parsed, false otherwise.
74 */
75 OPENAVX_API bool avx_hdr_parse_color_info(const char* xml, avx_color_info_t* p_info);
76  
77 /**
78 * Convenience helper to format color metadata and assign it to an openavx video frame's metadata.
79 *
80 * @param p_frame Video frame to modify.
81 * @param p_info Color info specification.
82 * @param xml_buf Persistent buffer owned by caller to hold formatted XML.
83 * @param xml_buf_len Capacity of xml_buf.
84 * @return true on success, false on error.
85 */
86 OPENAVX_API bool avx_hdr_frame_set_color_info(oavx_video_frame_t* p_frame,
87 const avx_color_info_t* p_info,
88 char* xml_buf, size_t xml_buf_len);
89  
90 /**
91 * Extracts and parses HDR / color info metadata from an openavx video frame's metadata.
92 *
93 * @param p_frame Video frame to query.
94 * @param p_info Destination color info structure.
95 * @return true if HDR/color metadata was detected and parsed, false if absent or invalid.
96 */
97 OPENAVX_API bool avx_hdr_frame_get_color_info(const oavx_video_frame_t* p_frame, avx_color_info_t* p_info);
98  
99 /**
100 * Returns true if color info represents an HDR stream (HLG or PQ).
101 */
102 OPENAVX_API bool avx_hdr_is_hdr(const avx_color_info_t* p_info);
103  
104 #ifdef __cplusplus
105 }
106 #endif
107  
108 #endif /* AVX_HDR_H */