hdr_dynamic_metadata.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. #ifndef AVUTIL_HDR_DYNAMIC_METADATA_H
  21. #define AVUTIL_HDR_DYNAMIC_METADATA_H
  22. #include "frame.h"
  23. #include "rational.h"
  24. /**
  25. * Option for overlapping elliptical pixel selectors in an image.
  26. */
  27. enum AVHDRPlusOverlapProcessOption {
  28. AV_HDR_PLUS_OVERLAP_PROCESS_WEIGHTED_AVERAGING = 0,
  29. AV_HDR_PLUS_OVERLAP_PROCESS_LAYERING = 1,
  30. };
  31. /**
  32. * Represents the percentile at a specific percentage in
  33. * a distribution.
  34. */
  35. typedef struct AVHDRPlusPercentile {
  36. /**
  37. * The percentage value corresponding to a specific percentile linearized
  38. * RGB value in the processing window in the scene. The value shall be in
  39. * the range of 0 to100, inclusive.
  40. */
  41. uint8_t percentage;
  42. /**
  43. * The linearized maxRGB value at a specific percentile in the processing
  44. * window in the scene. The value shall be in the range of 0 to 1, inclusive
  45. * and in multiples of 0.00001.
  46. */
  47. AVRational percentile;
  48. } AVHDRPlusPercentile;
  49. /**
  50. * Color transform parameters at a processing window in a dynamic metadata for
  51. * SMPTE 2094-40.
  52. */
  53. typedef struct AVHDRPlusColorTransformParams {
  54. /**
  55. * The relative x coordinate of the top left pixel of the processing
  56. * window. The value shall be in the range of 0 and 1, inclusive and
  57. * in multiples of 1/(width of Picture - 1). The value 1 corresponds
  58. * to the absolute coordinate of width of Picture - 1. The value for
  59. * first processing window shall be 0.
  60. */
  61. AVRational window_upper_left_corner_x;
  62. /**
  63. * The relative y coordinate of the top left pixel of the processing
  64. * window. The value shall be in the range of 0 and 1, inclusive and
  65. * in multiples of 1/(height of Picture - 1). The value 1 corresponds
  66. * to the absolute coordinate of height of Picture - 1. The value for
  67. * first processing window shall be 0.
  68. */
  69. AVRational window_upper_left_corner_y;
  70. /**
  71. * The relative x coordinate of the bottom right pixel of the processing
  72. * window. The value shall be in the range of 0 and 1, inclusive and
  73. * in multiples of 1/(width of Picture - 1). The value 1 corresponds
  74. * to the absolute coordinate of width of Picture - 1. The value for
  75. * first processing window shall be 1.
  76. */
  77. AVRational window_lower_right_corner_x;
  78. /**
  79. * The relative y coordinate of the bottom right pixel of the processing
  80. * window. The value shall be in the range of 0 and 1, inclusive and
  81. * in multiples of 1/(height of Picture - 1). The value 1 corresponds
  82. * to the absolute coordinate of height of Picture - 1. The value for
  83. * first processing window shall be 1.
  84. */
  85. AVRational window_lower_right_corner_y;
  86. /**
  87. * The x coordinate of the center position of the concentric internal and
  88. * external ellipses of the elliptical pixel selector in the processing
  89. * window. The value shall be in the range of 0 to (width of Picture - 1),
  90. * inclusive and in multiples of 1 pixel.
  91. */
  92. uint16_t center_of_ellipse_x;
  93. /**
  94. * The y coordinate of the center position of the concentric internal and
  95. * external ellipses of the elliptical pixel selector in the processing
  96. * window. The value shall be in the range of 0 to (height of Picture - 1),
  97. * inclusive and in multiples of 1 pixel.
  98. */
  99. uint16_t center_of_ellipse_y;
  100. /**
  101. * The clockwise rotation angle in degree of arc with respect to the
  102. * positive direction of the x-axis of the concentric internal and external
  103. * ellipses of the elliptical pixel selector in the processing window. The
  104. * value shall be in the range of 0 to 180, inclusive and in multiples of 1.
  105. */
  106. uint8_t rotation_angle;
  107. /**
  108. * The semi-major axis value of the internal ellipse of the elliptical pixel
  109. * selector in amount of pixels in the processing window. The value shall be
  110. * in the range of 1 to 65535, inclusive and in multiples of 1 pixel.
  111. */
  112. uint16_t semimajor_axis_internal_ellipse;
  113. /**
  114. * The semi-major axis value of the external ellipse of the elliptical pixel
  115. * selector in amount of pixels in the processing window. The value
  116. * shall not be less than semimajor_axis_internal_ellipse of the current
  117. * processing window. The value shall be in the range of 1 to 65535,
  118. * inclusive and in multiples of 1 pixel.
  119. */
  120. uint16_t semimajor_axis_external_ellipse;
  121. /**
  122. * The semi-minor axis value of the external ellipse of the elliptical pixel
  123. * selector in amount of pixels in the processing window. The value shall be
  124. * in the range of 1 to 65535, inclusive and in multiples of 1 pixel.
  125. */
  126. uint16_t semiminor_axis_external_ellipse;
  127. /**
  128. * Overlap process option indicates one of the two methods of combining
  129. * rendered pixels in the processing window in an image with at least one
  130. * elliptical pixel selector. For overlapping elliptical pixel selectors
  131. * in an image, overlap_process_option shall have the same value.
  132. */
  133. enum AVHDRPlusOverlapProcessOption overlap_process_option;
  134. /**
  135. * The maximum of the color components of linearized RGB values in the
  136. * processing window in the scene. The values should be in the range of 0 to
  137. * 1, inclusive and in multiples of 0.00001. maxscl[ 0 ], maxscl[ 1 ], and
  138. * maxscl[ 2 ] are corresponding to R, G, B color components respectively.
  139. */
  140. AVRational maxscl[3];
  141. /**
  142. * The average of linearized maxRGB values in the processing window in the
  143. * scene. The value should be in the range of 0 to 1, inclusive and in
  144. * multiples of 0.00001.
  145. */
  146. AVRational average_maxrgb;
  147. /**
  148. * The number of linearized maxRGB values at given percentiles in the
  149. * processing window in the scene. The maximum value shall be 15.
  150. */
  151. uint8_t num_distribution_maxrgb_percentiles;
  152. /**
  153. * The linearized maxRGB values at given percentiles in the
  154. * processing window in the scene.
  155. */
  156. AVHDRPlusPercentile distribution_maxrgb[15];
  157. /**
  158. * The fraction of selected pixels in the image that contains the brightest
  159. * pixel in the scene. The value shall be in the range of 0 to 1, inclusive
  160. * and in multiples of 0.001.
  161. */
  162. AVRational fraction_bright_pixels;
  163. /**
  164. * This flag indicates that the metadata for the tone mapping function in
  165. * the processing window is present (for value of 1).
  166. */
  167. uint8_t tone_mapping_flag;
  168. /**
  169. * The x coordinate of the separation point between the linear part and the
  170. * curved part of the tone mapping function. The value shall be in the range
  171. * of 0 to 1, excluding 0 and in multiples of 1/4095.
  172. */
  173. AVRational knee_point_x;
  174. /**
  175. * The y coordinate of the separation point between the linear part and the
  176. * curved part of the tone mapping function. The value shall be in the range
  177. * of 0 to 1, excluding 0 and in multiples of 1/4095.
  178. */
  179. AVRational knee_point_y;
  180. /**
  181. * The number of the intermediate anchor parameters of the tone mapping
  182. * function in the processing window. The maximum value shall be 15.
  183. */
  184. uint8_t num_bezier_curve_anchors;
  185. /**
  186. * The intermediate anchor parameters of the tone mapping function in the
  187. * processing window in the scene. The values should be in the range of 0
  188. * to 1, inclusive and in multiples of 1/1023.
  189. */
  190. AVRational bezier_curve_anchors[15];
  191. /**
  192. * This flag shall be equal to 0 in bitstreams conforming to this version of
  193. * this Specification. Other values are reserved for future use.
  194. */
  195. uint8_t color_saturation_mapping_flag;
  196. /**
  197. * The color saturation gain in the processing window in the scene. The
  198. * value shall be in the range of 0 to 63/8, inclusive and in multiples of
  199. * 1/8. The default value shall be 1.
  200. */
  201. AVRational color_saturation_weight;
  202. } AVHDRPlusColorTransformParams;
  203. /**
  204. * This struct represents dynamic metadata for color volume transform -
  205. * application 4 of SMPTE 2094-40:2016 standard.
  206. *
  207. * To be used as payload of a AVFrameSideData or AVPacketSideData with the
  208. * appropriate type.
  209. *
  210. * @note The struct should be allocated with
  211. * av_dynamic_hdr_plus_alloc() and its size is not a part of
  212. * the public ABI.
  213. */
  214. typedef struct AVDynamicHDRPlus {
  215. /**
  216. * Country code by Rec. ITU-T T.35 Annex A. The value shall be 0xB5.
  217. */
  218. uint8_t itu_t_t35_country_code;
  219. /**
  220. * Application version in the application defining document in ST-2094
  221. * suite. The value shall be set to 0.
  222. */
  223. uint8_t application_version;
  224. /**
  225. * The number of processing windows. The value shall be in the range
  226. * of 1 to 3, inclusive.
  227. */
  228. uint8_t num_windows;
  229. /**
  230. * The color transform parameters for every processing window.
  231. */
  232. AVHDRPlusColorTransformParams params[3];
  233. /**
  234. * The nominal maximum display luminance of the targeted system display,
  235. * in units of 0.0001 candelas per square metre. The value shall be in
  236. * the range of 0 to 10000, inclusive.
  237. */
  238. AVRational targeted_system_display_maximum_luminance;
  239. /**
  240. * This flag shall be equal to 0 in bit streams conforming to this version
  241. * of this Specification. The value 1 is reserved for future use.
  242. */
  243. uint8_t targeted_system_display_actual_peak_luminance_flag;
  244. /**
  245. * The number of rows in the targeted system_display_actual_peak_luminance
  246. * array. The value shall be in the range of 2 to 25, inclusive.
  247. */
  248. uint8_t num_rows_targeted_system_display_actual_peak_luminance;
  249. /**
  250. * The number of columns in the
  251. * targeted_system_display_actual_peak_luminance array. The value shall be
  252. * in the range of 2 to 25, inclusive.
  253. */
  254. uint8_t num_cols_targeted_system_display_actual_peak_luminance;
  255. /**
  256. * The normalized actual peak luminance of the targeted system display. The
  257. * values should be in the range of 0 to 1, inclusive and in multiples of
  258. * 1/15.
  259. */
  260. AVRational targeted_system_display_actual_peak_luminance[25][25];
  261. /**
  262. * This flag shall be equal to 0 in bitstreams conforming to this version of
  263. * this Specification. The value 1 is reserved for future use.
  264. */
  265. uint8_t mastering_display_actual_peak_luminance_flag;
  266. /**
  267. * The number of rows in the mastering_display_actual_peak_luminance array.
  268. * The value shall be in the range of 2 to 25, inclusive.
  269. */
  270. uint8_t num_rows_mastering_display_actual_peak_luminance;
  271. /**
  272. * The number of columns in the mastering_display_actual_peak_luminance
  273. * array. The value shall be in the range of 2 to 25, inclusive.
  274. */
  275. uint8_t num_cols_mastering_display_actual_peak_luminance;
  276. /**
  277. * The normalized actual peak luminance of the mastering display used for
  278. * mastering the image essence. The values should be in the range of 0 to 1,
  279. * inclusive and in multiples of 1/15.
  280. */
  281. AVRational mastering_display_actual_peak_luminance[25][25];
  282. } AVDynamicHDRPlus;
  283. /**
  284. * Allocate an AVDynamicHDRPlus structure and set its fields to
  285. * default values. The resulting struct can be freed using av_freep().
  286. *
  287. * @return An AVDynamicHDRPlus filled with default values or NULL
  288. * on failure.
  289. */
  290. AVDynamicHDRPlus *av_dynamic_hdr_plus_alloc(size_t *size);
  291. /**
  292. * Allocate a complete AVDynamicHDRPlus and add it to the frame.
  293. * @param frame The frame which side data is added to.
  294. *
  295. * @return The AVDynamicHDRPlus structure to be filled by caller or NULL
  296. * on failure.
  297. */
  298. AVDynamicHDRPlus *av_dynamic_hdr_plus_create_side_data(AVFrame *frame);
  299. /**
  300. * Parse the user data registered ITU-T T.35 to AVbuffer (AVDynamicHDRPlus).
  301. * The T.35 buffer must begin with the application mode, skipping the
  302. * country code, terminal provider codes, and application identifier.
  303. * @param s A pointer containing the decoded AVDynamicHDRPlus structure.
  304. * @param data The byte array containing the raw ITU-T T.35 data.
  305. * @param size Size of the data array in bytes.
  306. *
  307. * @return >= 0 on success. Otherwise, returns the appropriate AVERROR.
  308. */
  309. int av_dynamic_hdr_plus_from_t35(AVDynamicHDRPlus *s, const uint8_t *data,
  310. size_t size);
  311. #define AV_HDR_PLUS_MAX_PAYLOAD_SIZE 907
  312. /**
  313. * Serialize dynamic HDR10+ metadata to a user data registered ITU-T T.35 buffer,
  314. * excluding the first 48 bytes of the header, and beginning with the application mode.
  315. * @param s A pointer containing the decoded AVDynamicHDRPlus structure.
  316. * @param[in,out] data A pointer to pointer to a byte buffer to be filled with the
  317. * serialized metadata.
  318. * If *data is NULL, a buffer be will be allocated and a pointer to
  319. * it stored in its place. The caller assumes ownership of the buffer.
  320. * May be NULL, in which case the function will only store the
  321. * required buffer size in *size.
  322. * @param[in,out] size A pointer to a size to be set to the returned buffer's size.
  323. * If *data is not NULL, *size must contain the size of the input
  324. * buffer. May be NULL only if *data is NULL.
  325. *
  326. * @return >= 0 on success. Otherwise, returns the appropriate AVERROR.
  327. */
  328. int av_dynamic_hdr_plus_to_t35(const AVDynamicHDRPlus *s, uint8_t **data, size_t *size);
  329. #endif /* AVUTIL_HDR_DYNAMIC_METADATA_H */