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