Pick up subtitle color.
[libdcp.git] / src / types.cc
1 #include <vector>
2 #include <cstdio>
3 #include <boost/lexical_cast.hpp>
4 #include <boost/algorithm/string.hpp>
5 #include "types.h"
6 #include "exceptions.h"
7
8 using namespace std;
9 using namespace libdcp;
10 using namespace boost;
11
12 Fraction::Fraction (string s)
13 {
14         vector<string> b;
15         split (b, s, is_any_of (" "));
16         if (b.size() != 2) {
17                 throw XMLError ("malformed fraction " + s + " in XML node");
18         }
19         numerator = lexical_cast<int> (b[0]);
20         denominator = lexical_cast<int> (b[1]);
21 }
22
23 Color::Color ()
24         : r (0)
25         , g (0)
26         , b (0)
27 {
28
29 }
30
31 Color::Color (int r_, int g_, int b_)
32         : r (r_)
33         , g (g_)
34         , b (b_)
35 {
36
37 }
38
39 Color::Color (string argb_hex)
40 {
41         int alpha;
42         if (sscanf (argb_hex.c_str(), "%2x%2x%2x%2x", &alpha, &r, &g, &b) < 4) {
43                 throw XMLError ("could not parse colour string");
44         }
45 }
46
47
48 bool
49 libdcp::operator== (Color const & a, Color const & b)
50 {
51         return (a.r == b.r && a.g == b.g && a.b == b.b);
52 }
53
54 ostream &
55 libdcp::operator<< (ostream& s, Color const & c)
56 {
57         s << "(" << c.r << ", " << c.g << ", " << c.b << ")";
58         return s;
59 }