2 Copyright (C) 2012-2021 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.
36 * @brief Miscellaneous types
40 #ifndef LIBDCP_TYPES_H
41 #define LIBDCP_TYPES_H
45 #include <libcxml/cxml.h>
46 LIBDCP_DISABLE_WARNINGS
47 #include <asdcp/KLV.h>
48 LIBDCP_ENABLE_WARNINGS
50 #include <boost/function.hpp>
54 /* MinGW seems to define this, but we want to use it */
68 * @brief The integer, two-dimensional size of something.
82 float ratio () const {
83 return float (width) / height;
91 extern bool operator== (Size const & a, Size const & b);
92 extern bool operator!= (Size const & a, Size const & b);
95 /** Identifier for a sound channel */
99 CENTRE = 2, ///< centre
100 LFE = 3, ///< low-frequency effects (sub)
101 LS = 4, ///< left surround
102 RS = 5, ///< right surround
105 /* 8 and 9 are not used */
116 std::vector<dcp::Channel> used_audio_channels ();
119 enum class MCASoundField
127 extern std::string channel_to_mca_id (Channel c, MCASoundField field);
128 extern Channel mca_id_to_channel (std::string);
129 extern std::string channel_to_mca_name (Channel c, MCASoundField field);
130 extern ASDCP::UL channel_to_mca_universal_label (Channel c, MCASoundField field, ASDCP::Dictionary const* dict);
141 extern std::string effect_to_string (Effect e);
142 extern Effect string_to_effect (std::string s);
147 LEFT, ///< horizontal position is distance from left of screen to left of subtitle
148 CENTER, ///< horizontal position is distance from centre of screen to centre of subtitle
149 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);
159 /** vertical position is distance:
160 * from top of screen to top of subtitle (for SMPTE 428-7:{2007,2010} or
161 * from top of screen to subtitle baseline (for Interop or SMPTE 428-7:2014)
164 /** vertical position is distance:
165 * from centre of screen to centre of subtitle (for SMPTE 428-7:{2007,2010}) or
166 * from centre of screen to subtitle baseline (for Interop or SMPTE 428-7:2014)
169 /** vertical position is distance:
170 * from bottom of screen to bottom of subtitle (for SMPTE 428-7:{2007,2010}) or
171 * from bottom of screen to subtitle baseline (for Interop or SMPTE 428-7:2014)
177 extern std::string valign_to_string (VAlign a);
178 extern VAlign string_to_valign (std::string s);
181 /** Direction for subtitle test */
184 LTR, ///< left-to-right
185 RTL, ///< right-to-left
186 TTB, ///< top-to-bottom
187 BTT ///< bottom-to-top
191 extern std::string direction_to_string (Direction a);
192 extern Direction string_to_direction (std::string s);
203 * @brief A fraction (i.e. a thing with an integer numerator and an integer denominator).
208 /** Construct a fraction of 0/0 */
210 explicit Fraction (std::string s);
211 /** Construct a fraction with a specified numerator and denominator.
212 * @param n Numerator.
213 * @param d Denominator.
215 Fraction (int n, int d) : numerator (n), denominator (d) {}
217 float as_float () const {
218 return float (numerator) / denominator;
221 std::string as_string () const;
228 extern bool operator== (Fraction const & a, Fraction const & b);
229 extern bool operator!= (Fraction const & a, Fraction const & b);
232 /** @class EqualityOptions
233 * @brief A class to describe what "equality" means for a particular test.
235 * When comparing things, we want to be able to ignore some differences;
236 * this class expresses those differences.
238 * It also contains some settings for how the comparison should be done.
240 class EqualityOptions
243 /** Construct an EqualityOptions where nothing at all can differ */
244 EqualityOptions () {}
246 /** The maximum allowable mean difference in pixel value between two images */
247 double max_mean_pixel_error = 0;
248 /** The maximum standard deviation of the differences in pixel value between two images */
249 double max_std_dev_pixel_error = 0;
250 /** The maximum difference in audio sample value between two soundtracks */
251 int max_audio_sample_error = 0;
252 /** true if the <AnnotationText> nodes of CPLs are allowed to differ */
253 bool cpl_annotation_texts_can_differ = false;
254 /** true if the <AnnotationText> nodes of Reels are allowed to differ */
255 bool reel_annotation_texts_can_differ = false;
256 /** true if <Hash>es in Reels can differ */
257 bool reel_hashes_can_differ = false;
258 /** true if asset hashes can differ */
259 bool asset_hashes_can_differ = false;
260 /** true if IssueDate nodes can differ */
261 bool issue_dates_can_differ = false;
262 bool load_font_nodes_can_differ = false;
263 bool keep_going = false;
264 /** true to save the first pair of different image subtitles to the current working directory */
265 bool export_differing_subtitles = false;
266 /** The maximum allowable absolute difference between the vertical position of subtitles */
267 float max_subtitle_vertical_position_error = 0;
271 enum class NoteType {
278 enum class Standard {
284 enum class Formulation {
285 MODIFIED_TRANSITIONAL_1,
286 MULTIPLE_MODIFIED_TRANSITIONAL_1,
292 std::string formulation_to_string (dcp::Formulation formulation);
293 dcp::Formulation string_to_formulation (std::string forumulation);
297 * @brief An RGB colour
302 /** Construct a Colour, initialising it to black */
305 /** Construct a Colour from R, G and B. The values run between
308 Colour (int r_, int g_, int b_);
310 /** Construct a Colour from an ARGB hex string; the alpha value is ignored.
311 * @param argb_hex A string of the form AARRGGBB, where e.g. RR is a two-character
314 explicit Colour (std::string argb_hex);
316 int r = 0; ///< red component, from 0 to 255
317 int g = 0; ///< green component, from 0 to 255
318 int b = 0; ///< blue component, from 0 to 255
320 /** @return An RGB string of the form RRGGBB, where e.g. RR is a two-character
323 std::string to_rgb_string () const;
325 /** @return An ARGB string of the form AARRGGBB, where e.g. RR is a two-character
326 * hex value. The alpha value will always be FF (ie 255; maximum alpha).
328 std::string to_argb_string () const;
332 extern bool operator== (Colour const & a, Colour const & b);
333 extern bool operator!= (Colour const & a, Colour const & b);
336 typedef boost::function<void (NoteType, std::string)> NoteHandler;
339 /** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
340 * are considered equal
342 constexpr float ASPECT_ADJUST_EPSILON = 1e-3;
345 /** Maximum absolute difference between dcp::SubtitleString alignment values that
346 * are considered equal.
348 constexpr float ALIGN_EPSILON = 1e-3;
351 /** Maximum absolute difference between dcp::SubtitleString space_before values that
352 * are considered equal.
354 constexpr float SPACE_BEFORE_EPSILON = 1e-3;
358 FFOC, ///< first frame of composition
359 LFOC, ///< last frame of composition
360 FFTC, ///< first frame of title credits
361 LFTC, ///< last frame of title credits
362 FFOI, ///< first frame of intermission
363 LFOI, ///< last frame of intermission
364 FFEC, ///< first frame of end credits
365 LFEC, ///< last frame of end credits
366 FFMC, ///< first frame of moving credits
367 LFMC ///< last frame of moving credits
371 std::string marker_to_string (Marker);
372 Marker marker_from_string (std::string);
377 FINAL, ///< final version
378 TEMP, ///< temporary version (picture/sound unfinished)
379 PRE ///< pre-release (picture/sound finished)
383 extern std::string status_to_string (Status s);
384 extern Status string_to_status (std::string s);
392 explicit ContentVersion (cxml::ConstNodePtr node);
394 explicit ContentVersion (std::string label_text_);
396 ContentVersion (std::string id_, std::string label_text_)
398 , label_text (label_text_)
401 void as_xml (xmlpp::Element* parent) const;
404 std::string label_text;
412 CANDELA_PER_SQUARE_METRE,
416 Luminance (cxml::ConstNodePtr node);
418 Luminance (float value, Unit unit);
420 void set_value (float v);
421 void set_unit (Unit u) {
425 float value () const {
433 float value_in_foot_lamberts () const;
435 void as_xml (xmlpp::Element* parent, std::string ns) const;
437 static std::string unit_to_string (Unit u);
438 static Unit string_to_unit (std::string u);
446 bool operator== (Luminance const& a, Luminance const& b);
449 class MainSoundConfiguration
452 explicit MainSoundConfiguration(std::string);
453 MainSoundConfiguration (MCASoundField field_, int channels);
455 MCASoundField field () const {
459 int channels () const {
460 return _channels.size();
463 boost::optional<Channel> mapping (int index) const;
464 void set_mapping (int index, Channel channel);
466 std::string to_string () const;
469 MCASoundField _field;
470 std::vector<boost::optional<Channel>> _channels;