2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
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.
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.
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/>.
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
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.
35 * @brief Miscellaneous types.
38 #ifndef LIBDCP_TYPES_H
39 #define LIBDCP_TYPES_H
41 #include <boost/shared_ptr.hpp>
42 #include <boost/function.hpp>
49 * @brief The integer, two-dimensional size of something.
63 float ratio () const {
64 return float (width) / height;
71 /** Identifier for a sound channel */
75 CENTRE = 2, ///< centre
76 LFE = 3, ///< low-frequency effects (sub)
77 LS = 4, ///< left surround
78 RS = 5, ///< right surround
97 PUBLIC_SERVICE_ANNOUNCEMENT,
108 extern std::string effect_to_string (Effect e);
109 extern Effect string_to_effect (std::string s);
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
118 extern std::string halign_to_string (HAlign a);
119 extern HAlign string_to_halign (std::string s);
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
128 extern std::string valign_to_string (VAlign a);
129 extern VAlign string_to_valign (std::string s);
131 /** Direction for subtitle test */
134 DIRECTION_LTR, ///< left-to-right
135 DIRECTION_RTL, ///< right-to-left
136 DIRECTION_TTB, ///< top-to-bottom
137 DIRECTION_BTT ///< bottom-to-top
140 extern std::string direction_to_string (Direction a);
141 extern Direction string_to_direction (std::string s);
150 * @brief A fraction (i.e. a thing with an integer numerator and an integer denominator).
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.
162 Fraction (int n, int d) : numerator (n), denominator (d) {}
164 float as_float () const {
165 return float (numerator) / denominator;
168 std::string as_string () const;
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);
178 /** @struct EqualityOptions
179 * @brief A class to describe what "equality" means for a particular test.
181 * When comparing things, we want to be able to ignore some differences;
182 * this class expresses those differences.
184 struct EqualityOptions
186 /** Construct an EqualityOptions where nothing at all can differ */
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)
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 <AnnotationText> nodes of CPLs are allowed to differ */
205 bool cpl_annotation_texts_can_differ;
206 /** true if the <AnnotationText> 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;
215 /* I've been unable to make mingw happy with ERROR as a symbol, so
216 I'm using a DCP_ prefix here.
230 MODIFIED_TRANSITIONAL_1,
236 * @brief An RGB colour.
242 Colour (int r_, int g_, int b_);
243 explicit Colour (std::string argb_hex);
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
249 std::string to_argb_string () const;
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);
256 typedef boost::function<void (NoteType, std::string)> NoteHandler;
258 /** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
259 * are considered equal.
261 const float ASPECT_ADJUST_EPSILON = 1e-3;
263 /** Maximum absolute difference between dcp::SubtitleString alignment values that
264 * are considered equal.
266 const float ALIGN_EPSILON = 1e-3;