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 /* windows.h defines this but we want to use it */
68 * @brief The integer, two-dimensional size of something.
79 float ratio () const {
80 return float (width) / height;
88 extern bool operator== (Size const & a, Size const & b);
89 extern bool operator!= (Size const & a, Size const & b);
92 /** Identifier for a sound channel */
96 CENTRE = 2, ///< centre
97 LFE = 3, ///< low-frequency effects (sub)
98 LS = 4, ///< left surround
99 RS = 5, ///< right surround
102 /* 8 and 9 are not used */
113 std::vector<dcp::Channel> used_audio_channels ();
116 enum class MCASoundField
124 extern std::string channel_to_mca_id (Channel c, MCASoundField field);
125 extern Channel mca_id_to_channel (std::string);
126 extern std::string channel_to_mca_name (Channel c, MCASoundField field);
127 extern ASDCP::UL channel_to_mca_universal_label (Channel c, MCASoundField field, ASDCP::Dictionary const* dict);
138 extern std::string effect_to_string (Effect e);
139 extern Effect string_to_effect (std::string s);
144 LEFT, ///< horizontal position is distance from left of screen to left of subtitle
145 CENTER, ///< horizontal position is distance from centre of screen to centre of subtitle
146 RIGHT, ///< horizontal position is distance from right of screen to right of subtitle
150 extern std::string halign_to_string (HAlign a);
151 extern HAlign string_to_halign (std::string s);
154 /** Direction for subtitle test */
157 LTR, ///< left-to-right
158 RTL, ///< right-to-left
159 TTB, ///< top-to-bottom
160 BTT ///< bottom-to-top
164 extern std::string direction_to_string (Direction a);
165 extern Direction string_to_direction (std::string s);
176 * @brief A fraction (i.e. a thing with an integer numerator and an integer denominator).
181 /** Construct a fraction of 0/0 */
182 Fraction() = default;
184 explicit Fraction (std::string s);
185 /** Construct a fraction with a specified numerator and denominator.
186 * @param n Numerator.
187 * @param d Denominator.
189 Fraction (int n, int d) : numerator (n), denominator (d) {}
191 float as_float () const {
192 return float (numerator) / denominator;
195 std::string as_string () const;
202 extern bool operator== (Fraction const & a, Fraction const & b);
203 extern bool operator!= (Fraction const & a, Fraction const & b);
206 enum class NoteType {
213 enum class Standard {
219 enum class Formulation {
220 MODIFIED_TRANSITIONAL_1,
221 MULTIPLE_MODIFIED_TRANSITIONAL_1,
227 std::string formulation_to_string (dcp::Formulation formulation);
228 dcp::Formulation string_to_formulation (std::string forumulation);
232 * @brief An RGB colour
237 /** Construct a Colour, initialising it to black */
240 /** Construct a Colour from R, G and B. The values run between
243 Colour (int r_, int g_, int b_);
245 /** Construct a Colour from an ARGB hex string; the alpha value is ignored.
246 * @param argb_hex A string of the form AARRGGBB, where e.g. RR is a two-character
249 explicit Colour (std::string argb_hex);
251 int r = 0; ///< red component, from 0 to 255
252 int g = 0; ///< green component, from 0 to 255
253 int b = 0; ///< blue component, from 0 to 255
255 /** @return An RGB string of the form RRGGBB, where e.g. RR is a two-character
258 std::string to_rgb_string () const;
260 /** @return An ARGB string of the form AARRGGBB, where e.g. RR is a two-character
261 * hex value. The alpha value will always be FF (ie 255; maximum alpha).
263 std::string to_argb_string () const;
267 extern bool operator== (Colour const & a, Colour const & b);
268 extern bool operator!= (Colour const & a, Colour const & b);
271 typedef boost::function<void (NoteType, std::string)> NoteHandler;
274 /** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
275 * are considered equal
277 constexpr float ASPECT_ADJUST_EPSILON = 1e-3;
280 /** Maximum absolute difference between dcp::SubtitleString alignment values that
281 * are considered equal.
283 constexpr float ALIGN_EPSILON = 1e-3;
286 /** Maximum absolute difference between dcp::SubtitleString space_before values that
287 * are considered equal.
289 constexpr float SPACE_BEFORE_EPSILON = 1e-3;
293 FFOC, ///< first frame of composition
294 LFOC, ///< last frame of composition
295 FFTC, ///< first frame of title credits
296 LFTC, ///< last frame of title credits
297 FFOI, ///< first frame of intermission
298 LFOI, ///< last frame of intermission
299 FFEC, ///< first frame of end credits
300 LFEC, ///< last frame of end credits
301 FFMC, ///< first frame of moving credits
302 LFMC ///< last frame of moving credits
306 std::string marker_to_string (Marker);
307 Marker marker_from_string (std::string);
312 FINAL, ///< final version
313 TEMP, ///< temporary version (picture/sound unfinished)
314 PRE ///< pre-release (picture/sound finished)
318 extern std::string status_to_string (Status s);
319 extern Status string_to_status (std::string s);
327 explicit ContentVersion (cxml::ConstNodePtr node);
329 explicit ContentVersion (std::string label_text_);
331 ContentVersion (std::string id_, std::string label_text_)
333 , label_text (label_text_)
336 void as_xml (xmlpp::Element* parent) const;
339 std::string label_text;
347 CANDELA_PER_SQUARE_METRE,
351 Luminance (cxml::ConstNodePtr node);
353 Luminance (float value, Unit unit);
355 void set_value (float v);
356 void set_unit (Unit u) {
360 float value () const {
368 float value_in_foot_lamberts () const;
370 void as_xml (xmlpp::Element* parent, std::string ns) const;
372 static std::string unit_to_string (Unit u);
373 static Unit string_to_unit (std::string u);
381 bool operator== (Luminance const& a, Luminance const& b);
384 class MainSoundConfiguration
387 explicit MainSoundConfiguration(std::string);
388 MainSoundConfiguration (MCASoundField field_, int channels);
390 MCASoundField field () const {
394 int channels () const {
395 return _channels.size();
398 boost::optional<Channel> mapping (int index) const;
399 void set_mapping (int index, Channel channel);
401 std::string to_string () const;
404 MCASoundField _field;
405 std::vector<boost::optional<Channel>> _channels;