2 Copyright (C) 2012-2019 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 <libcxml/cxml.h>
42 #include <asdcp/KLV.h>
43 #include <boost/shared_ptr.hpp>
44 #include <boost/function.hpp>
55 * @brief The integer, two-dimensional size of something.
69 float ratio () const {
70 return float (width) / height;
77 extern bool operator== (Size const & a, Size const & b);
78 extern bool operator!= (Size const & a, Size const & b);
79 extern std::ostream& operator<< (std::ostream& s, Size const & a);
81 /** Identifier for a sound channel */
85 CENTRE = 2, ///< centre
86 LFE = 3, ///< low-frequency effects (sub)
87 LS = 4, ///< left surround
88 RS = 5, ///< right surround
91 /* 8 and 9 are not used */
101 std::vector<dcp::Channel> used_audio_channels ();
111 extern std::string channel_to_mca_id (Channel c, MCASoundField field);
112 extern Channel mca_id_to_channel (std::string);
113 extern std::string channel_to_mca_name (Channel c, MCASoundField field);
114 extern ASDCP::UL channel_to_mca_universal_label (Channel c, MCASoundField field, ASDCP::Dictionary const* dict);
127 PUBLIC_SERVICE_ANNOUNCEMENT,
133 extern std::string content_kind_to_string (ContentKind kind);
134 extern ContentKind content_kind_from_string (std::string kind);
143 extern std::string effect_to_string (Effect e);
144 extern Effect string_to_effect (std::string s);
148 HALIGN_LEFT, ///< horizontal position is distance from left of screen to left of subtitle
149 HALIGN_CENTER, ///< horizontal position is distance from centre of screen to centre of subtitle
150 HALIGN_RIGHT, ///< horizontal position is distance from right of screen to right of subtitle
153 extern std::string halign_to_string (HAlign a);
154 extern HAlign string_to_halign (std::string s);
158 VALIGN_TOP, ///< vertical position is distance from top of screen to top of subtitle
159 VALIGN_CENTER, ///< vertical position is distance from centre of screen to centre of subtitle
160 VALIGN_BOTTOM ///< vertical position is distance from bottom of screen to bottom of subtitle
163 extern std::string valign_to_string (VAlign a);
164 extern VAlign string_to_valign (std::string s);
166 /** Direction for subtitle test */
169 DIRECTION_LTR, ///< left-to-right
170 DIRECTION_RTL, ///< right-to-left
171 DIRECTION_TTB, ///< top-to-bottom
172 DIRECTION_BTT ///< bottom-to-top
175 extern std::string direction_to_string (Direction a);
176 extern Direction string_to_direction (std::string s);
185 * @brief A fraction (i.e. a thing with an integer numerator and an integer denominator).
190 /** Construct a fraction of 0/0 */
191 Fraction () : numerator (0), denominator (0) {}
192 explicit Fraction (std::string s);
193 /** Construct a fraction with a specified numerator and denominator.
194 * @param n Numerator.
195 * @param d Denominator.
197 Fraction (int n, int d) : numerator (n), denominator (d) {}
199 float as_float () const {
200 return float (numerator) / denominator;
203 std::string as_string () const;
209 extern bool operator== (Fraction const & a, Fraction const & b);
210 extern bool operator!= (Fraction const & a, Fraction const & b);
211 extern std::ostream& operator<< (std::ostream& s, Fraction const & f);
213 /** @struct EqualityOptions
214 * @brief A class to describe what "equality" means for a particular test.
216 * When comparing things, we want to be able to ignore some differences;
217 * this class expresses those differences.
219 struct EqualityOptions
221 /** Construct an EqualityOptions where nothing at all can differ */
223 : max_mean_pixel_error (0)
224 , max_std_dev_pixel_error (0)
225 , max_audio_sample_error (0)
226 , cpl_annotation_texts_can_differ (false)
227 , reel_annotation_texts_can_differ (false)
228 , reel_hashes_can_differ (false)
229 , issue_dates_can_differ (false)
230 , load_font_nodes_can_differ (false)
234 /** The maximum allowable mean difference in pixel value between two images */
235 double max_mean_pixel_error;
236 /** The maximum standard deviation of the differences in pixel value between two images */
237 double max_std_dev_pixel_error;
238 /** The maximum difference in audio sample value between two soundtracks */
239 int max_audio_sample_error;
240 /** true if the <AnnotationText> nodes of CPLs are allowed to differ */
241 bool cpl_annotation_texts_can_differ;
242 /** true if the <AnnotationText> nodes of Reels are allowed to differ */
243 bool reel_annotation_texts_can_differ;
244 /** true if <Hash>es in Reels can differ */
245 bool reel_hashes_can_differ;
246 /** true if IssueDate nodes can differ */
247 bool issue_dates_can_differ;
248 bool load_font_nodes_can_differ;
252 /* I've been unable to make mingw happy with ERROR as a symbol, so
253 I'm using a DCP_ prefix here.
267 MODIFIED_TRANSITIONAL_1,
268 MULTIPLE_MODIFIED_TRANSITIONAL_1,
271 /** For testing: adds no AuthorizedDeviceInfo tag */
272 MODIFIED_TRANSITIONAL_TEST
276 * @brief An RGB colour.
282 Colour (int r_, int g_, int b_);
283 explicit Colour (std::string argb_hex);
285 int r; ///< red component, from 0 to 255
286 int g; ///< green component, from 0 to 255
287 int b; ///< blue component, from 0 to 255
289 std::string to_rgb_string () const;
290 std::string to_argb_string () const;
293 extern bool operator== (Colour const & a, Colour const & b);
294 extern bool operator!= (Colour const & a, Colour const & b);
295 extern std::ostream & operator<< (std::ostream & s, Colour const & c);
297 typedef boost::function<void (NoteType, std::string)> NoteHandler;
299 /** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
300 * are considered equal.
302 const float ASPECT_ADJUST_EPSILON = 1e-3;
304 /** Maximum absolute difference between dcp::SubtitleString alignment values that
305 * are considered equal.
307 const float ALIGN_EPSILON = 1e-3;
310 FFOC, ///< first frame of composition
311 LFOC, ///< last frame of composition
312 FFTC, ///< first frame of title credits
313 LFTC, ///< last frame of title credits
314 FFOI, ///< first frame of intermission
315 LFOI, ///< last frame of intermission
316 FFEC, ///< first frame of end credits
317 LFEC, ///< last frame of end credits
318 FFMC, ///< first frame of moving credits
319 LFMC ///< last frame of moving credits
322 std::string marker_to_string (Marker);
323 Marker marker_from_string (std::string);
328 Rating (std::string agency_, std::string label_)
333 explicit Rating (cxml::ConstNodePtr node);
335 void as_xml (xmlpp::Element* parent) const;
337 /** URI of the agency issuing the rating */
339 /** Rating (e.g. PG, PG-13, 12A etc) */
343 extern bool operator== (Rating const & a, Rating const & b);
344 extern std::ostream& operator<< (std::ostream& s, Rating const & r);
349 FINAL, ///< final version
350 TEMP, ///< temporary version (picture/sound unfinished)
351 PRE ///< pre-release (picture/sound finished)
355 extern std::string status_to_string (Status s);
356 extern Status string_to_status (std::string s);
364 explicit ContentVersion (cxml::ConstNodePtr node);
366 explicit ContentVersion (std::string label_text_);
368 ContentVersion (std::string id_, std::string label_text_)
370 , label_text (label_text_)
373 void as_xml (xmlpp::Element* parent) const;
376 std::string label_text;
384 CANDELA_PER_SQUARE_METRE,
388 Luminance (cxml::ConstNodePtr node);
390 Luminance (float value, Unit unit);
392 void set_value (float v);
393 void set_unit (Unit u) {
397 float value () const {
405 void as_xml (xmlpp::Element* parent, std::string ns) const;
407 static std::string unit_to_string (Unit u);
408 static Unit string_to_unit (std::string u);
415 bool operator== (Luminance const& a, Luminance const& b);
418 class MainSoundConfiguration
421 MainSoundConfiguration (std::string);
422 MainSoundConfiguration (MCASoundField field_, int channels);
424 MCASoundField field () const {
428 int channels () const {
429 return _channels.size();
432 boost::optional<Channel> mapping (int index) const;
433 void set_mapping (int index, Channel channel);
435 std::string to_string () const;
438 MCASoundField _field;
439 std::vector<boost::optional<Channel> > _channels;