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