Cleanup: extract HAlign to its own files.
[libdcp.git] / src / types.h
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp 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
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34
35 /** @file  src/types.h
36  *  @brief Miscellaneous types
37  */
38
39
40 #ifndef LIBDCP_TYPES_H
41 #define LIBDCP_TYPES_H
42
43
44 #include "warnings.h"
45 #include <libcxml/cxml.h>
46 LIBDCP_DISABLE_WARNINGS
47 #include <asdcp/KLV.h>
48 LIBDCP_ENABLE_WARNINGS
49 #include <memory>
50 #include <boost/function.hpp>
51 #include <string>
52
53
54 /* windows.h defines this but we want to use it */
55 #undef ERROR
56
57
58 namespace xmlpp {
59         class Element;
60 }
61
62
63 namespace dcp
64 {
65
66
67 /** @struct Size
68  *  @brief The integer, two-dimensional size of something.
69  */
70 struct Size
71 {
72         Size() = default;
73
74         Size (int w, int h)
75                 : width (w)
76                 , height (h)
77         {}
78
79         float ratio () const {
80                 return float (width) / height;
81         }
82
83         int width = 0;
84         int height = 0;
85 };
86
87
88 extern bool operator== (Size const & a, Size const & b);
89 extern bool operator!= (Size const & a, Size const & b);
90
91
92 /** Identifier for a sound channel */
93 enum class Channel {
94         LEFT = 0,      ///< left
95         RIGHT = 1,     ///< right
96         CENTRE = 2,    ///< centre
97         LFE = 3,       ///< low-frequency effects (sub)
98         LS = 4,        ///< left surround
99         RS = 5,        ///< right surround
100         HI = 6,
101         VI = 7,
102         /* 8 and 9 are not used */
103         BSL = 10,
104         BSR = 11,
105         MOTION_DATA = 12,
106         SYNC_SIGNAL = 13,
107         SIGN_LANGUAGE = 14,
108         /* 15 is not used */
109         CHANNEL_COUNT = 16
110 };
111
112
113 std::vector<dcp::Channel> used_audio_channels ();
114
115
116 enum class MCASoundField
117 {
118         FIVE_POINT_ONE,
119         SEVEN_POINT_ONE,
120         OTHER
121 };
122
123
124 extern std::string channel_to_mca_id (Channel c, MCASoundField field);
125 extern Channel mca_id_to_channel (std::string);
126 extern std::string channel_to_mca_name (Channel c, MCASoundField field);
127 extern ASDCP::UL channel_to_mca_universal_label (Channel c, MCASoundField field, ASDCP::Dictionary const* dict);
128
129
130 enum class Effect
131 {
132         NONE,
133         BORDER,
134         SHADOW
135 };
136
137
138 extern std::string effect_to_string (Effect e);
139 extern Effect string_to_effect (std::string s);
140
141
142 /** Direction for subtitle test */
143 enum class Direction
144 {
145         LTR, ///< left-to-right
146         RTL, ///< right-to-left
147         TTB, ///< top-to-bottom
148         BTT  ///< bottom-to-top
149 };
150
151
152 extern std::string direction_to_string (Direction a);
153 extern Direction string_to_direction (std::string s);
154
155
156 enum class Eye
157 {
158         LEFT,
159         RIGHT
160 };
161
162
163 /** @class Fraction
164  *  @brief A fraction (i.e. a thing with an integer numerator and an integer denominator).
165  */
166 class Fraction
167 {
168 public:
169         /** Construct a fraction of 0/0 */
170         Fraction() = default;
171
172         explicit Fraction (std::string s);
173         /** Construct a fraction with a specified numerator and denominator.
174          *  @param n Numerator.
175          *  @param d Denominator.
176          */
177         Fraction (int n, int d) : numerator (n), denominator (d) {}
178
179         float as_float () const {
180                 return float (numerator) / denominator;
181         }
182
183         std::string as_string () const;
184
185         int numerator = 0;
186         int denominator = 0;
187 };
188
189
190 extern bool operator== (Fraction const & a, Fraction const & b);
191 extern bool operator!= (Fraction const & a, Fraction const & b);
192
193
194 enum class NoteType {
195         PROGRESS,
196         ERROR,
197         NOTE
198 };
199
200
201 enum class Standard {
202         INTEROP,
203         SMPTE
204 };
205
206
207 enum class Formulation {
208         MODIFIED_TRANSITIONAL_1,
209         MULTIPLE_MODIFIED_TRANSITIONAL_1,
210         DCI_ANY,
211         DCI_SPECIFIC,
212 };
213
214
215 std::string formulation_to_string (dcp::Formulation formulation);
216 dcp::Formulation string_to_formulation (std::string forumulation);
217
218
219 /** @class Colour
220  *  @brief An RGB colour
221  */
222 class Colour
223 {
224 public:
225         /** Construct a Colour, initialising it to black */
226         Colour() = default;
227
228         /** Construct a Colour from R, G and B.  The values run between
229          *  0 and 255.
230          */
231         Colour (int r_, int g_, int b_);
232
233         /** Construct a Colour from an ARGB hex string; the alpha value is ignored.
234          *  @param argb_hex A string of the form AARRGGBB, where e.g. RR is a two-character
235          *  hex value.
236          */
237         explicit Colour (std::string argb_hex);
238
239         int r = 0; ///< red component, from 0 to 255
240         int g = 0; ///< green component, from 0 to 255
241         int b = 0; ///< blue component, from 0 to 255
242
243         /** @return An RGB string of the form RRGGBB, where e.g. RR is a two-character
244          *  hex value.
245          */
246         std::string to_rgb_string () const;
247
248         /** @return An ARGB string of the form AARRGGBB, where e.g. RR is a two-character
249          *  hex value.  The alpha value will always be FF (ie 255; maximum alpha).
250          */
251         std::string to_argb_string () const;
252 };
253
254
255 extern bool operator== (Colour const & a, Colour const & b);
256 extern bool operator!= (Colour const & a, Colour const & b);
257
258
259 typedef boost::function<void (NoteType, std::string)> NoteHandler;
260
261
262 /** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
263  *  are considered equal
264  */
265 constexpr float ASPECT_ADJUST_EPSILON = 1e-3;
266
267
268 /** Maximum absolute difference between dcp::SubtitleString alignment values that
269  *  are considered equal.
270  */
271 constexpr float ALIGN_EPSILON = 1e-3;
272
273
274 /** Maximum absolute difference between dcp::SubtitleString space_before values that
275  *  are considered equal.
276  */
277 constexpr float SPACE_BEFORE_EPSILON = 1e-3;
278
279
280 enum class Marker {
281         FFOC, ///< first frame of composition
282         LFOC, ///< last frame of composition
283         FFTC, ///< first frame of title credits
284         LFTC, ///< last frame of title credits
285         FFOI, ///< first frame of intermission
286         LFOI, ///< last frame of intermission
287         FFEC, ///< first frame of end credits
288         LFEC, ///< last frame of end credits
289         FFMC, ///< first frame of moving credits
290         LFMC  ///< last frame of moving credits
291 };
292
293
294 std::string marker_to_string (Marker);
295 Marker marker_from_string (std::string);
296
297
298 enum class Status
299 {
300         FINAL, ///< final version
301         TEMP,  ///< temporary version (picture/sound unfinished)
302         PRE    ///< pre-release (picture/sound finished)
303 };
304
305
306 extern std::string status_to_string (Status s);
307 extern Status string_to_status (std::string s);
308
309
310 class ContentVersion
311 {
312 public:
313         ContentVersion ();
314
315         explicit ContentVersion (cxml::ConstNodePtr node);
316
317         explicit ContentVersion (std::string label_text_);
318
319         ContentVersion (std::string id_, std::string label_text_)
320                 : id (id_)
321                 , label_text (label_text_)
322         {}
323
324         void as_xml (xmlpp::Element* parent) const;
325
326         std::string id;
327         std::string label_text;
328 };
329
330
331 class Luminance
332 {
333 public:
334         enum class Unit {
335                 CANDELA_PER_SQUARE_METRE,
336                 FOOT_LAMBERT
337         };
338
339         Luminance (cxml::ConstNodePtr node);
340
341         Luminance (float value, Unit unit);
342
343         void set_value (float v);
344         void set_unit (Unit u) {
345                 _unit = u;
346         }
347
348         float value () const {
349                 return _value;
350         }
351
352         Unit unit () const {
353                 return _unit;
354         }
355
356         float value_in_foot_lamberts () const;
357
358         void as_xml (xmlpp::Element* parent, std::string ns) const;
359
360         static std::string unit_to_string (Unit u);
361         static Unit string_to_unit (std::string u);
362
363 private:
364         float _value;
365         Unit _unit;
366 };
367
368
369 bool operator== (Luminance const& a, Luminance const& b);
370
371
372 class MainSoundConfiguration
373 {
374 public:
375         explicit MainSoundConfiguration(std::string);
376         MainSoundConfiguration (MCASoundField field_, int channels);
377
378         MCASoundField field () const {
379                 return _field;
380         }
381
382         int channels () const {
383                 return _channels.size();
384         }
385
386         boost::optional<Channel> mapping (int index) const;
387         void set_mapping (int index, Channel channel);
388
389         std::string to_string () const;
390
391 private:
392         MCASoundField _field;
393         std::vector<boost::optional<Channel>> _channels;
394 };
395
396
397 }
398
399
400 #endif