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