libdcp
types.h
Go to the documentation of this file.
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 
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 
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 
93 enum class Channel {
94  LEFT = 0,
95  RIGHT = 1,
96  CENTRE = 2,
97  LFE = 3,
98  LS = 4,
99  RS = 5,
100  HI = 6,
101  VI = 7,
102  LC = 8,
103  RC = 9,
104  BSL = 10,
105  BSR = 11,
106  MOTION_DATA = 12,
107  SYNC_SIGNAL = 13,
108  SIGN_LANGUAGE = 14,
109  /* 15 is not used */
110  CHANNEL_COUNT = 16
111 };
112 
113 
114 std::vector<dcp::Channel> used_audio_channels ();
115 
116 
117 enum class MCASoundField
118 {
119  FIVE_POINT_ONE,
120  SEVEN_POINT_ONE,
121  OTHER
122 };
123 
124 
125 extern std::string channel_to_mca_id (Channel c, MCASoundField field);
126 extern Channel mca_id_to_channel (std::string);
127 extern std::string channel_to_mca_name (Channel c, MCASoundField field);
128 extern ASDCP::UL channel_to_mca_universal_label (Channel c, MCASoundField field, ASDCP::Dictionary const* dict);
129 
130 
131 enum class Effect
132 {
133  NONE,
134  BORDER,
135  SHADOW
136 };
137 
138 
139 extern std::string effect_to_string (Effect e);
140 extern Effect string_to_effect (std::string s);
141 
142 
144 enum class Direction
145 {
146  LTR,
147  RTL,
148  TTB,
149  BTT
150 };
151 
152 
153 extern std::string direction_to_string (Direction a);
154 extern Direction string_to_direction (std::string s);
155 
156 
157 enum class Eye
158 {
159  LEFT,
160  RIGHT
161 };
162 
163 
167 class Fraction
168 {
169 public:
171  Fraction() = default;
172 
173  explicit Fraction (std::string s);
178  Fraction (int n, int d) : numerator (n), denominator (d) {}
179 
180  float as_float () const {
181  return float (numerator) / denominator;
182  }
183 
184  std::string as_string () const;
185 
186  int numerator = 0;
187  int denominator = 0;
188 };
189 
190 
191 extern bool operator== (Fraction const & a, Fraction const & b);
192 extern bool operator!= (Fraction const & a, Fraction const & b);
193 
194 
195 enum class NoteType {
196  PROGRESS,
197  ERROR,
198  NOTE
199 };
200 
201 
202 enum class Standard {
203  INTEROP,
204  SMPTE
205 };
206 
207 
208 enum class Formulation {
209  MODIFIED_TRANSITIONAL_1,
210  MULTIPLE_MODIFIED_TRANSITIONAL_1,
211  DCI_ANY,
212  DCI_SPECIFIC,
213 };
214 
215 
216 std::string formulation_to_string (dcp::Formulation formulation);
217 dcp::Formulation string_to_formulation (std::string forumulation);
218 
219 
223 class Colour
224 {
225 public:
227  Colour() = default;
228 
232  Colour (int r_, int g_, int b_);
233 
238  explicit Colour (std::string argb_hex);
239 
240  int r = 0;
241  int g = 0;
242  int b = 0;
243 
247  std::string to_rgb_string () const;
248 
252  std::string to_argb_string () const;
253 };
254 
255 
256 extern bool operator== (Colour const & a, Colour const & b);
257 extern bool operator!= (Colour const & a, Colour const & b);
258 
259 
260 typedef boost::function<void (NoteType, std::string)> NoteHandler;
261 
262 
266 constexpr float ASPECT_ADJUST_EPSILON = 1e-3;
267 
268 
272 constexpr float ALIGN_EPSILON = 1e-3;
273 
274 
278 constexpr float SPACE_BEFORE_EPSILON = 1e-3;
279 
280 
281 constexpr float SIZE_EPSILON = 1e-3;
282 constexpr float OFFSET_EPSILON = 1e-3;
283 constexpr float SPACING_EPSILON = 1e-3;
284 
285 
286 enum class Marker {
287  FFOC,
288  LFOC,
289  FFTC,
290  LFTC,
291  FFOI,
292  LFOI,
293  FFEC,
294  LFEC,
295  FFMC,
296  LFMC,
297  FFOB,
298  LFOB,
299 };
300 
301 
302 std::string marker_to_string (Marker);
303 Marker marker_from_string (std::string);
304 
305 
306 enum class Status
307 {
308  FINAL,
309  TEMP,
310  PRE
311 };
312 
313 
314 extern std::string status_to_string (Status s);
315 extern Status string_to_status (std::string s);
316 
317 
319 {
320 public:
321  ContentVersion ();
322 
323  explicit ContentVersion (cxml::ConstNodePtr node);
324 
325  explicit ContentVersion (std::string label_text_);
326 
327  ContentVersion (std::string id_, std::string label_text_)
328  : id (id_)
329  , label_text (label_text_)
330  {}
331 
332  void as_xml (xmlpp::Element* parent) const;
333 
334  std::string id;
335  std::string label_text;
336 };
337 
338 
340 {
341 public:
342  enum class Unit {
343  CANDELA_PER_SQUARE_METRE,
344  FOOT_LAMBERT
345  };
346 
347  Luminance (cxml::ConstNodePtr node);
348 
349  Luminance (float value, Unit unit);
350 
351  void set_value (float v);
352  void set_unit (Unit u) {
353  _unit = u;
354  }
355 
356  float value () const {
357  return _value;
358  }
359 
360  Unit unit () const {
361  return _unit;
362  }
363 
364  float value_in_foot_lamberts () const;
365 
366  void as_xml (xmlpp::Element* parent, std::string ns) const;
367 
368  static std::string unit_to_string (Unit u);
369  static Unit string_to_unit (std::string u);
370 
371 private:
372  float _value;
373  Unit _unit;
374 };
375 
376 
377 bool operator== (Luminance const& a, Luminance const& b);
378 
379 
381 {
382 public:
383  explicit MainSoundConfiguration(std::string);
384  MainSoundConfiguration (MCASoundField field_, int channels);
385 
386  MCASoundField field () const {
387  return _field;
388  }
389 
390  int channels () const {
391  return _channels.size();
392  }
393 
394  boost::optional<Channel> mapping (int index) const;
395  void set_mapping (int index, Channel channel);
396 
397  std::string to_string () const;
398 
399 private:
400  MCASoundField _field;
401  std::vector<boost::optional<Channel>> _channels;
402 };
403 
404 
405 }
406 
407 
408 #endif
An RGB colour.
Definition: types.h:224
int g
green component, from 0 to 255
Definition: types.h:241
Colour()=default
int b
blue component, from 0 to 255
Definition: types.h:242
int r
red component, from 0 to 255
Definition: types.h:240
std::string to_argb_string() const
Definition: types.cc:131
std::string to_rgb_string() const
Definition: types.cc:140
A fraction (i.e. a thing with an integer numerator and an integer denominator).
Definition: types.h:168
Fraction()=default
Fraction(int n, int d)
Definition: types.h:178
Namespace for everything in libdcp.
Definition: array_data.h:50
Marker
Definition: types.h:286
@ FFOB
first frame of ratings band
@ FFOI
first frame of intermission
@ FFEC
first frame of end credits
@ LFMC
last frame of moving credits
@ LFOI
last frame of intermission
@ FFMC
first frame of moving credits
@ FFTC
first frame of title credits
@ LFOC
last frame of composition
@ FFOC
first frame of composition
@ LFOB
last frame of ratings band
@ LFEC
last frame of end credits
@ LFTC
last frame of title credits
Direction
Definition: types.h:145
@ LTR
left-to-right
@ BTT
bottom-to-top
@ RTL
right-to-left
@ TTB
top-to-bottom
constexpr float SPACE_BEFORE_EPSILON
Definition: types.h:278
Channel
Definition: types.h:93
@ LFE
low-frequency effects (sub)
@ LC
not used, but referred to in MainSoundConfiguration in some CPLs
@ RC
not used, but referred to in MainSoundConfiguration in some CPLs
@ CENTRE
centre
@ RS
right surround
@ LS
left surround
constexpr float ASPECT_ADJUST_EPSILON
Definition: types.h:266
constexpr float ALIGN_EPSILON
Definition: types.h:272
Status
Definition: types.h:307
@ FINAL
final version
@ TEMP
temporary version (picture/sound unfinished)
@ PRE
pre-release (picture/sound finished)
The integer, two-dimensional size of something.
Definition: types.h:71