Add OpenSSL licence exception.
[libdcp.git] / src / types.h
1 /*
2     Copyright (C) 2012-2015 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 /** @file  src/types.h
35  *  @brief Miscellaneous types.
36  */
37
38 #ifndef LIBDCP_TYPES_H
39 #define LIBDCP_TYPES_H
40
41 #include <boost/shared_ptr.hpp>
42 #include <boost/function.hpp>
43 #include <string>
44
45 namespace dcp
46 {
47
48 /** @struct Size
49  *  @brief The integer, two-dimensional size of something.
50  */
51 struct Size
52 {
53         Size ()
54                 : width (0)
55                 , height (0)
56         {}
57
58         Size (int w, int h)
59                 : width (w)
60                 , height (h)
61         {}
62
63         float ratio () const {
64                 return float (width) / height;
65         }
66
67         int width;
68         int height;
69 };
70
71 /** Identifier for a sound channel */
72 enum Channel {
73         LEFT = 0,      ///< left
74         RIGHT = 1,     ///< right
75         CENTRE = 2,    ///< centre
76         LFE = 3,       ///< low-frequency effects (sub)
77         LS = 4,        ///< left surround
78         RS = 5,        ///< right surround
79         HI = 6,
80         VI = 7,
81         LC = 8,
82         RC = 9,
83         BSL = 10,
84         BSR = 11
85 };
86
87 enum ContentKind
88 {
89         FEATURE,
90         SHORT,
91         TRAILER,
92         TEST,
93         TRANSITIONAL,
94         RATING,
95         TEASER,
96         POLICY,
97         PUBLIC_SERVICE_ANNOUNCEMENT,
98         ADVERTISEMENT
99 };
100
101 enum Effect
102 {
103         NONE,
104         BORDER,
105         SHADOW
106 };
107
108 extern std::string effect_to_string (Effect e);
109 extern Effect string_to_effect (std::string s);
110
111 enum HAlign
112 {
113         HALIGN_LEFT,   ///< horizontal position is distance from left of screen to left of subtitle
114         HALIGN_CENTER, ///< horizontal position is distance from centre of screen to centre of subtitle
115         HALIGN_RIGHT,  ///< horizontal position is distance from right of screen to right of subtitle
116 };
117
118 extern std::string halign_to_string (HAlign a);
119 extern HAlign string_to_halign (std::string s);
120
121 enum VAlign
122 {
123         VALIGN_TOP,    ///< vertical position is distance from top of screen to top of subtitle
124         VALIGN_CENTER, ///< vertical position is distance from centre of screen to centre of subtitle
125         VALIGN_BOTTOM  ///< vertical position is distance from bottom of screen to bottom of subtitle
126 };
127
128 extern std::string valign_to_string (VAlign a);
129 extern VAlign string_to_valign (std::string s);
130
131 /** Direction for subtitle test */
132 enum Direction
133 {
134         DIRECTION_LTR, ///< left-to-right
135         DIRECTION_RTL, ///< right-to-left
136         DIRECTION_TTB, ///< top-to-bottom
137         DIRECTION_BTT  ///< bottom-to-top
138 };
139
140 extern std::string direction_to_string (Direction a);
141 extern Direction string_to_direction (std::string s);
142
143 enum Eye
144 {
145         EYE_LEFT,
146         EYE_RIGHT
147 };
148
149 /** @class Fraction
150  *  @brief A fraction (i.e. a thing with an integer numerator and an integer denominator).
151  */
152 class Fraction
153 {
154 public:
155         /** Construct a fraction of 0/0 */
156         Fraction () : numerator (0), denominator (0) {}
157         explicit Fraction (std::string s);
158         /** Construct a fraction with a specified numerator and denominator.
159          *  @param n Numerator.
160          *  @param d Denominator.
161          */
162         Fraction (int n, int d) : numerator (n), denominator (d) {}
163
164         float as_float () const {
165                 return float (numerator) / denominator;
166         }
167
168         std::string as_string () const;
169
170         int numerator;
171         int denominator;
172 };
173
174 extern bool operator== (Fraction const & a, Fraction const & b);
175 extern bool operator!= (Fraction const & a, Fraction const & b);
176 extern std::ostream& operator<< (std::ostream& s, Fraction const & f);
177
178 /** @struct EqualityOptions
179  *  @brief  A class to describe what "equality" means for a particular test.
180  *
181  *  When comparing things, we want to be able to ignore some differences;
182  *  this class expresses those differences.
183  */
184 struct EqualityOptions
185 {
186         /** Construct an EqualityOptions where nothing at all can differ */
187         EqualityOptions ()
188                 : max_mean_pixel_error (0)
189                 , max_std_dev_pixel_error (0)
190                 , max_audio_sample_error (0)
191                 , cpl_annotation_texts_can_differ (false)
192                 , reel_annotation_texts_can_differ (false)
193                 , reel_hashes_can_differ (false)
194                 , issue_dates_can_differ (false)
195                 , keep_going (false)
196         {}
197
198         /** The maximum allowable mean difference in pixel value between two images */
199         double max_mean_pixel_error;
200         /** The maximum standard deviation of the differences in pixel value between two images */
201         double max_std_dev_pixel_error;
202         /** The maximum difference in audio sample value between two soundtracks */
203         int max_audio_sample_error;
204         /** true if the &lt;AnnotationText&gt; nodes of CPLs are allowed to differ */
205         bool cpl_annotation_texts_can_differ;
206         /** true if the &lt;AnnotationText&gt; nodes of Reels are allowed to differ */
207         bool reel_annotation_texts_can_differ;
208         /** true if <Hash>es in Reels can differ */
209         bool reel_hashes_can_differ;
210         /** true if IssueDate nodes can differ */
211         bool issue_dates_can_differ;
212         bool keep_going;
213 };
214
215 /* I've been unable to make mingw happy with ERROR as a symbol, so
216    I'm using a DCP_ prefix here.
217 */
218 enum NoteType {
219         DCP_PROGRESS,
220         DCP_ERROR,
221         DCP_NOTE
222 };
223
224 enum Standard {
225         INTEROP,
226         SMPTE
227 };
228
229 enum Formulation {
230         MODIFIED_TRANSITIONAL_1,
231         DCI_ANY,
232         DCI_SPECIFIC
233 };
234
235 /** @class Colour
236  *  @brief An RGB colour.
237  */
238 class Colour
239 {
240 public:
241         Colour ();
242         Colour (int r_, int g_, int b_);
243         explicit Colour (std::string argb_hex);
244
245         int r; ///< red component, from 0 to 255
246         int g; ///< green component, from 0 to 255
247         int b; ///< blue component, from 0 to 255
248
249         std::string to_argb_string () const;
250 };
251
252 extern bool operator== (Colour const & a, Colour const & b);
253 extern bool operator!= (Colour const & a, Colour const & b);
254 extern std::ostream & operator<< (std::ostream & s, Colour const & c);
255
256 typedef boost::function<void (NoteType, std::string)> NoteHandler;
257
258 /** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
259  *  are considered equal.
260  */
261 const float ASPECT_ADJUST_EPSILON = 1e-3;
262
263 /** Maximum absolute difference between dcp::SubtitleString alignment values that
264  *  are considered equal.
265  */
266 const float ALIGN_EPSILON = 1e-3;
267
268 }
269
270 #endif