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 * It also contains some settings for how the comparison should be done.
221 struct EqualityOptions
223 /** Construct an EqualityOptions where nothing at all can differ */
225 : max_mean_pixel_error (0)
226 , max_std_dev_pixel_error (0)
227 , max_audio_sample_error (0)
228 , cpl_annotation_texts_can_differ (false)
229 , reel_annotation_texts_can_differ (false)
230 , reel_hashes_can_differ (false)
231 , issue_dates_can_differ (false)
232 , load_font_nodes_can_differ (false)
234 , export_differing_subtitles (false)
237 /** The maximum allowable mean difference in pixel value between two images */
238 double max_mean_pixel_error;
239 /** The maximum standard deviation of the differences in pixel value between two images */
240 double max_std_dev_pixel_error;
241 /** The maximum difference in audio sample value between two soundtracks */
242 int max_audio_sample_error;
243 /** true if the <AnnotationText> nodes of CPLs are allowed to differ */
244 bool cpl_annotation_texts_can_differ;
245 /** true if the <AnnotationText> nodes of Reels are allowed to differ */
246 bool reel_annotation_texts_can_differ;
247 /** true if <Hash>es in Reels can differ */
248 bool reel_hashes_can_differ;
249 /** true if IssueDate nodes can differ */
250 bool issue_dates_can_differ;
251 bool load_font_nodes_can_differ;
253 /** true to save the first pair of differeng image subtitles to the current working directory */
254 bool export_differing_subtitles;
257 /* I've been unable to make mingw happy with ERROR as a symbol, so
258 I'm using a DCP_ prefix here.
272 MODIFIED_TRANSITIONAL_1,
273 MULTIPLE_MODIFIED_TRANSITIONAL_1,
276 /** For testing: adds no AuthorizedDeviceInfo tag */
277 MODIFIED_TRANSITIONAL_TEST
281 * @brief An RGB colour.
287 Colour (int r_, int g_, int b_);
288 explicit Colour (std::string argb_hex);
290 int r; ///< red component, from 0 to 255
291 int g; ///< green component, from 0 to 255
292 int b; ///< blue component, from 0 to 255
294 std::string to_rgb_string () const;
295 std::string to_argb_string () const;
298 extern bool operator== (Colour const & a, Colour const & b);
299 extern bool operator!= (Colour const & a, Colour const & b);
300 extern std::ostream & operator<< (std::ostream & s, Colour const & c);
302 typedef boost::function<void (NoteType, std::string)> NoteHandler;
304 /** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
305 * are considered equal.
307 const float ASPECT_ADJUST_EPSILON = 1e-3;
309 /** Maximum absolute difference between dcp::SubtitleString alignment values that
310 * are considered equal.
312 const float ALIGN_EPSILON = 1e-3;
315 FFOC, ///< first frame of composition
316 LFOC, ///< last frame of composition
317 FFTC, ///< first frame of title credits
318 LFTC, ///< last frame of title credits
319 FFOI, ///< first frame of intermission
320 LFOI, ///< last frame of intermission
321 FFEC, ///< first frame of end credits
322 LFEC, ///< last frame of end credits
323 FFMC, ///< first frame of moving credits
324 LFMC ///< last frame of moving credits
327 std::string marker_to_string (Marker);
328 Marker marker_from_string (std::string);
333 Rating (std::string agency_, std::string label_)
338 explicit Rating (cxml::ConstNodePtr node);
340 void as_xml (xmlpp::Element* parent) const;
342 /** URI of the agency issuing the rating */
344 /** Rating (e.g. PG, PG-13, 12A etc) */
348 extern bool operator== (Rating const & a, Rating const & b);
349 extern std::ostream& operator<< (std::ostream& s, Rating const & r);
354 FINAL, ///< final version
355 TEMP, ///< temporary version (picture/sound unfinished)
356 PRE ///< pre-release (picture/sound finished)
360 extern std::string status_to_string (Status s);
361 extern Status string_to_status (std::string s);
369 explicit ContentVersion (cxml::ConstNodePtr node);
371 explicit ContentVersion (std::string label_text_);
373 ContentVersion (std::string id_, std::string label_text_)
375 , label_text (label_text_)
378 void as_xml (xmlpp::Element* parent) const;
381 std::string label_text;
389 CANDELA_PER_SQUARE_METRE,
393 Luminance (cxml::ConstNodePtr node);
395 Luminance (float value, Unit unit);
397 void set_value (float v);
398 void set_unit (Unit u) {
402 float value () const {
410 void as_xml (xmlpp::Element* parent, std::string ns) const;
412 static std::string unit_to_string (Unit u);
413 static Unit string_to_unit (std::string u);
420 bool operator== (Luminance const& a, Luminance const& b);
423 class MainSoundConfiguration
426 MainSoundConfiguration (std::string);
427 MainSoundConfiguration (MCASoundField field_, int channels);
429 MCASoundField field () const {
433 int channels () const {
434 return _channels.size();
437 boost::optional<Channel> mapping (int index) const;
438 void set_mapping (int index, Channel channel);
440 std::string to_string () const;
443 MCASoundField _field;
444 std::vector<boost::optional<Channel> > _channels;