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/>.
21 * @brief Miscellaneous types.
24 #ifndef LIBDCP_TYPES_H
25 #define LIBDCP_TYPES_H
27 #include <boost/shared_ptr.hpp>
28 #include <boost/function.hpp>
35 * @brief The integer, two-dimensional size of something.
49 float ratio () const {
50 return float (width) / height;
57 /** Identifier for a sound channel */
61 CENTRE = 2, ///< centre
62 LFE = 3, ///< low-frequency effects (sub)
63 LS = 4, ///< left surround
64 RS = 5, ///< right surround
83 PUBLIC_SERVICE_ANNOUNCEMENT,
94 extern std::string effect_to_string (Effect e);
95 extern Effect string_to_effect (std::string s);
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
104 extern std::string halign_to_string (HAlign a);
105 extern HAlign string_to_halign (std::string s);
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
114 extern std::string valign_to_string (VAlign a);
115 extern VAlign string_to_valign (std::string s);
117 /** Direction for subtitle test */
120 DIRECTION_LTR, ///< left-to-right
121 DIRECTION_RTL, ///< right-to-left
122 DIRECTION_TTB, ///< top-to-bottom
123 DIRECTION_BTT ///< bottom-to-top
126 extern std::string direction_to_string (Direction a);
127 extern Direction string_to_direction (std::string s);
136 * @brief A fraction (i.e. a thing with an integer numerator and an integer denominator).
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.
148 Fraction (int n, int d) : numerator (n), denominator (d) {}
150 float as_float () const {
151 return float (numerator) / denominator;
154 std::string as_string () const;
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);
164 /** @struct EqualityOptions
165 * @brief A class to describe what "equality" means for a particular test.
167 * When comparing things, we want to be able to ignore some differences;
168 * this class expresses those differences.
170 struct EqualityOptions
172 /** Construct an EqualityOptions where nothing at all can differ */
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)
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 <AnnotationText> nodes of CPLs are allowed to differ */
191 bool cpl_annotation_texts_can_differ;
192 /** true if the <AnnotationText> 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;
201 /* I've been unable to make mingw happy with ERROR as a symbol, so
202 I'm using a DCP_ prefix here.
216 MODIFIED_TRANSITIONAL_1,
222 * @brief An RGB colour.
228 Colour (int r_, int g_, int b_);
229 Colour (std::string argb_hex);
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
235 std::string to_argb_string () const;
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);
242 typedef boost::function<void (NoteType, std::string)> NoteHandler;
244 /** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
245 * are considered equal.
247 const float ASPECT_ADJUST_EPSILON = 1e-3;
249 /** Maximum absolute difference between dcp::SubtitleString alignment values that
250 * are considered equal.
252 const float ALIGN_EPSILON = 1e-3;