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 /* MinGW seems to define 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 ()
73  : width (0)
74  , height (0)
75  {}
76 
77  Size (int w, int h)
78  : width (w)
79  , height (h)
80  {}
81 
82  float ratio () const {
83  return float (width) / height;
84  }
85 
86  int width;
87  int height;
88 };
89 
90 
91 extern bool operator== (Size const & a, Size const & b);
92 extern bool operator!= (Size const & a, Size const & b);
93 
94 
96 enum class Channel {
97  LEFT = 0,
98  RIGHT = 1,
99  CENTRE = 2,
100  LFE = 3,
101  LS = 4,
102  RS = 5,
103  HI = 6,
104  VI = 7,
105  /* 8 and 9 are not used */
106  BSL = 10,
107  BSR = 11,
108  MOTION_DATA = 12,
109  SYNC_SIGNAL = 13,
110  SIGN_LANGUAGE = 14,
111  /* 15 is not used */
112  CHANNEL_COUNT = 16
113 };
114 
115 
116 std::vector<dcp::Channel> used_audio_channels ();
117 
118 
119 enum class MCASoundField
120 {
121  FIVE_POINT_ONE,
122  SEVEN_POINT_ONE
123 };
124 
125 
126 extern std::string channel_to_mca_id (Channel c, MCASoundField field);
127 extern Channel mca_id_to_channel (std::string);
128 extern std::string channel_to_mca_name (Channel c, MCASoundField field);
129 extern ASDCP::UL channel_to_mca_universal_label (Channel c, MCASoundField field, ASDCP::Dictionary const* dict);
130 
131 
132 enum class ContentKind
133 {
134  FEATURE,
135  SHORT,
136  TRAILER,
137  TEST,
138  TRANSITIONAL,
139  RATING,
140  TEASER,
141  POLICY,
142  PUBLIC_SERVICE_ANNOUNCEMENT,
143  ADVERTISEMENT,
144  EPISODE,
145  PROMO
146 };
147 
148 
149 extern std::string content_kind_to_string (ContentKind kind);
150 extern ContentKind content_kind_from_string (std::string kind);
151 
152 
153 enum class Effect
154 {
155  NONE,
156  BORDER,
157  SHADOW
158 };
159 
160 
161 extern std::string effect_to_string (Effect e);
162 extern Effect string_to_effect (std::string s);
163 
164 
165 enum class HAlign
166 {
167  LEFT,
168  CENTER,
169  RIGHT,
170 };
171 
172 
173 extern std::string halign_to_string (HAlign a);
174 extern HAlign string_to_halign (std::string s);
175 
176 
177 enum class VAlign
178 {
179  TOP,
180  CENTER,
181  BOTTOM
182 };
183 
184 
185 extern std::string valign_to_string (VAlign a);
186 extern VAlign string_to_valign (std::string s);
187 
188 
190 enum class Direction
191 {
192  LTR,
193  RTL,
194  TTB,
195  BTT
196 };
197 
198 
199 extern std::string direction_to_string (Direction a);
200 extern Direction string_to_direction (std::string s);
201 
202 
203 enum class Eye
204 {
205  LEFT,
206  RIGHT
207 };
208 
209 
213 class Fraction
214 {
215 public:
217  Fraction () {}
218  explicit Fraction (std::string s);
223  Fraction (int n, int d) : numerator (n), denominator (d) {}
224 
225  float as_float () const {
226  return float (numerator) / denominator;
227  }
228 
229  std::string as_string () const;
230 
231  int numerator = 0;
232  int denominator = 0;
233 };
234 
235 
236 extern bool operator== (Fraction const & a, Fraction const & b);
237 extern bool operator!= (Fraction const & a, Fraction const & b);
238 
239 
249 {
252 
267  bool load_font_nodes_can_differ = false;
268  bool keep_going = false;
271 };
272 
273 
274 enum class NoteType {
275  PROGRESS,
276  ERROR,
277  NOTE
278 };
279 
280 
281 enum class Standard {
282  INTEROP,
283  SMPTE
284 };
285 
286 
287 enum class Formulation {
288  MODIFIED_TRANSITIONAL_1,
289  MULTIPLE_MODIFIED_TRANSITIONAL_1,
290  DCI_ANY,
291  DCI_SPECIFIC,
294 };
295 
296 
300 class Colour
301 {
302 public:
304  Colour ();
305 
309  Colour (int r_, int g_, int b_);
310 
315  explicit Colour (std::string argb_hex);
316 
317  int r = 0;
318  int g = 0;
319  int b = 0;
320 
324  std::string to_rgb_string () const;
325 
329  std::string to_argb_string () const;
330 };
331 
332 
333 extern bool operator== (Colour const & a, Colour const & b);
334 extern bool operator!= (Colour const & a, Colour const & b);
335 
336 
337 typedef boost::function<void (NoteType, std::string)> NoteHandler;
338 
339 
343 constexpr float ASPECT_ADJUST_EPSILON = 1e-3;
344 
345 
349 constexpr float ALIGN_EPSILON = 1e-3;
350 
351 
355 constexpr float SPACE_BEFORE_EPSILON = 1e-3;
356 
357 
358 enum class Marker {
359  FFOC,
360  LFOC,
361  FFTC,
362  LFTC,
363  FFOI,
364  LFOI,
365  FFEC,
366  LFEC,
367  FFMC,
368  LFMC
369 };
370 
371 
372 std::string marker_to_string (Marker);
373 Marker marker_from_string (std::string);
374 
375 
376 enum class Status
377 {
378  FINAL,
379  TEMP,
380  PRE
381 };
382 
383 
384 extern std::string status_to_string (Status s);
385 extern Status string_to_status (std::string s);
386 
387 
389 {
390 public:
391  ContentVersion ();
392 
393  explicit ContentVersion (cxml::ConstNodePtr node);
394 
395  explicit ContentVersion (std::string label_text_);
396 
397  ContentVersion (std::string id_, std::string label_text_)
398  : id (id_)
399  , label_text (label_text_)
400  {}
401 
402  void as_xml (xmlpp::Element* parent) const;
403 
404  std::string id;
405  std::string label_text;
406 };
407 
408 
410 {
411 public:
412  enum class Unit {
413  CANDELA_PER_SQUARE_METRE,
414  FOOT_LAMBERT
415  };
416 
417  Luminance (cxml::ConstNodePtr node);
418 
419  Luminance (float value, Unit unit);
420 
421  void set_value (float v);
422  void set_unit (Unit u) {
423  _unit = u;
424  }
425 
426  float value () const {
427  return _value;
428  }
429 
430  Unit unit () const {
431  return _unit;
432  }
433 
434  float value_in_foot_lamberts () const;
435 
436  void as_xml (xmlpp::Element* parent, std::string ns) const;
437 
438  static std::string unit_to_string (Unit u);
439  static Unit string_to_unit (std::string u);
440 
441 private:
442  float _value;
443  Unit _unit;
444 };
445 
446 
447 bool operator== (Luminance const& a, Luminance const& b);
448 
449 
451 {
452 public:
453  MainSoundConfiguration (std::string);
454  MainSoundConfiguration (MCASoundField field_, int channels);
455 
456  MCASoundField field () const {
457  return _field;
458  }
459 
460  int channels () const {
461  return _channels.size();
462  }
463 
464  boost::optional<Channel> mapping (int index) const;
465  void set_mapping (int index, Channel channel);
466 
467  std::string to_string () const;
468 
469 private:
470  MCASoundField _field;
471  std::vector<boost::optional<Channel>> _channels;
472 };
473 
474 
475 }
476 
477 
478 #endif
An RGB colour.
Definition: types.h:301
int g
green component, from 0 to 255
Definition: types.h:318
int b
blue component, from 0 to 255
Definition: types.h:319
int r
red component, from 0 to 255
Definition: types.h:317
std::string to_argb_string() const
Definition: types.cc:137
std::string to_rgb_string() const
Definition: types.cc:146
A fraction (i.e. a thing with an integer numerator and an integer denominator).
Definition: types.h:214
Fraction(int n, int d)
Definition: types.h:223
Namespace for everything in libdcp.
Definition: array_data.h:50
Marker
Definition: types.h:358
@ 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
@ LFEC
last frame of end credits
@ LFTC
last frame of title credits
Direction
Definition: types.h:191
@ LTR
left-to-right
@ BTT
bottom-to-top
@ RTL
right-to-left
@ TTB
top-to-bottom
HAlign
Definition: types.h:166
@ RIGHT
horizontal position is distance from right of screen to right of subtitle
@ LEFT
horizontal position is distance from left of screen to left of subtitle
@ CENTER
horizontal position is distance from centre of screen to centre of subtitle
std::string content_kind_to_string(ContentKind kind)
Definition: types.cc:302
constexpr float SPACE_BEFORE_EPSILON
Definition: types.h:355
VAlign
Definition: types.h:178
@ BOTTOM
vertical position is distance from bottom of screen to bottom of subtitle
@ TOP
vertical position is distance from top of screen to top of subtitle
@ CENTER
vertical position is distance from centre of screen to centre of subtitle
ContentKind content_kind_from_string(std::string kind)
Definition: types.cc:341
Channel
Definition: types.h:96
@ LFE
low-frequency effects (sub)
@ CENTRE
centre
@ RS
right surround
@ LS
left surround
constexpr float ASPECT_ADJUST_EPSILON
Definition: types.h:343
Formulation
Definition: types.h:287
constexpr float ALIGN_EPSILON
Definition: types.h:349
Status
Definition: types.h:377
@ FINAL
final version
@ TEMP
temporary version (picture/sound unfinished)
@ PRE
pre-release (picture/sound finished)
A class to describe what "equality" means for a particular test.
Definition: types.h:249
bool reel_hashes_can_differ
Definition: types.h:264
double max_mean_pixel_error
Definition: types.h:254
double max_std_dev_pixel_error
Definition: types.h:256
int max_audio_sample_error
Definition: types.h:258
bool cpl_annotation_texts_can_differ
Definition: types.h:260
bool reel_annotation_texts_can_differ
Definition: types.h:262
bool issue_dates_can_differ
Definition: types.h:266
bool export_differing_subtitles
Definition: types.h:270
The integer, two-dimensional size of something.
Definition: types.h:71