4 #include <boost/lexical_cast.hpp>
5 #include <boost/algorithm/string.hpp>
7 #include "exceptions.h"
10 using namespace libdcp;
11 using namespace boost;
13 Fraction::Fraction (string s)
16 split (b, s, is_any_of (" "));
18 throw XMLError ("malformed fraction " + s + " in XML node");
20 numerator = lexical_cast<int> (b[0]);
21 denominator = lexical_cast<int> (b[1]);
25 libdcp::operator== (Fraction const & a, Fraction const & b)
27 return (a.numerator == b.numerator && a.denominator == b.denominator);
31 libdcp::operator!= (Fraction const & a, Fraction const & b)
33 return (a.numerator != b.numerator || a.denominator != b.denominator);
44 Color::Color (int r_, int g_, int b_)
52 /** Construct a Color from an ARGB hex string; the alpha value is ignored.
53 * @param argb_hex A string of the form AARRGGBB, where e.g. RR is a two-character
56 Color::Color (string argb_hex)
59 if (sscanf (argb_hex.c_str(), "%2x%2x%2x%2x", &alpha, &r, &g, &b) < 4) {
60 throw XMLError ("could not parse colour string");
64 /** @return An ARGB string of the form AARRGGBB, where e.g. RR is a two-character
65 * hex value. The alpha value will always be FF (ie 255; maximum alpha).
68 Color::to_argb_string () const
73 << setw(2) << setfill('0') << r
74 << setw(2) << setfill('0') << g
75 << setw(2) << setfill('0') << b;
82 /** operator== for Colors.
83 * @param a First color to compare.
84 * @param b Second color to compare.
87 libdcp::operator== (Color const & a, Color const & b)
89 return (a.r == b.r && a.g == b.g && a.b == b.b);
92 /** operator!= for Colors.
93 * @param a First color to compare.
94 * @param b Second color to compare.
97 libdcp::operator!= (Color const & a, Color const & b)
103 libdcp::operator<< (ostream& s, Color const & c)
105 s << "(" << c.r << ", " << c.g << ", " << c.b << ")";
110 libdcp::effect_to_string (Effect e)
121 throw MiscError ("unknown effect type");
125 libdcp::string_to_effect (string s)
129 } else if (s == "border") {
131 } else if (s == "shadow") {
135 throw DCPReadError ("unknown subtitle effect type");
139 libdcp::valign_to_string (VAlign v)
150 throw MiscError ("unknown valign type");
154 libdcp::string_to_valign (string s)
158 } else if (s == "center") {
160 } else if (s == "bottom") {
164 throw DCPReadError ("unknown subtitle valign type");