X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Ftypes.cc;h=687e90f81fa21f3b9d56195e892bd63fbe4bd6fb;hb=a869c520e4c75ee16cc9c07b96bd4886aae39f8a;hp=0ecf7a16439c0b1bed10ee6f7d8f4e42c2bee202;hpb=ac265d3d008328b9bdaf00c39ebcd86f263605c7;p=libdcp.git diff --git a/src/types.cc b/src/types.cc index 0ecf7a16..687e90f8 100644 --- a/src/types.cc +++ b/src/types.cc @@ -17,9 +17,10 @@ */ +#include "raw_convert.h" #include "types.h" #include "exceptions.h" -#include +#include "compose.hpp" #include #include #include @@ -39,8 +40,14 @@ Fraction::Fraction (string s) if (b.size() != 2) { boost::throw_exception (XMLError ("malformed fraction " + s + " in XML node")); } - numerator = lexical_cast (b[0]); - denominator = lexical_cast (b[1]); + numerator = raw_convert (b[0]); + denominator = raw_convert (b[1]); +} + +string +Fraction::as_string () const +{ + return String::compose ("%1 %2", numerator, denominator); } bool @@ -55,8 +62,15 @@ dcp::operator!= (Fraction const & a, Fraction const & b) return (a.numerator != b.numerator || a.denominator != b.denominator); } -/** Construct a Color, initialising it to black. */ -Color::Color () +ostream& +dcp::operator<< (ostream& s, Fraction const & f) +{ + s << f.numerator << "/" << f.denominator; + return s; +} + +/** Construct a Colour, initialising it to black. */ +Colour::Colour () : r (0) , g (0) , b (0) @@ -64,10 +78,10 @@ Color::Color () } -/** Construct a Color from R, G and B. The values run between +/** Construct a Colour from R, G and B. The values run between * 0 and 255. */ -Color::Color (int r_, int g_, int b_) +Colour::Colour (int r_, int g_, int b_) : r (r_) , g (g_) , b (b_) @@ -75,14 +89,14 @@ Color::Color (int r_, int g_, int b_) } -/** Construct a Color from an ARGB hex string; the alpha value is ignored. +/** Construct a Colour from an ARGB hex string; the alpha value is ignored. * @param argb_hex A string of the form AARRGGBB, where e.g. RR is a two-character * hex value. */ -Color::Color (string argb_hex) +Colour::Colour (string argb_hex) { int alpha; - if (sscanf (argb_hex.c_str(), "%2x%2x%2x%2x", &alpha, &r, &g, &b) < 4) { + if (sscanf (argb_hex.c_str(), "%2x%2x%2x%2x", &alpha, &r, &g, &b) != 4) { boost::throw_exception (XMLError ("could not parse colour string")); } } @@ -91,7 +105,7 @@ Color::Color (string argb_hex) * hex value. The alpha value will always be FF (ie 255; maximum alpha). */ string -Color::to_argb_string () const +Colour::to_argb_string () const { stringstream s; s << "FF"; @@ -105,28 +119,28 @@ Color::to_argb_string () const return t; } -/** operator== for Colors. - * @param a First color to compare. - * @param b Second color to compare. +/** operator== for Colours. + * @param a First colour to compare. + * @param b Second colour to compare. */ bool -dcp::operator== (Color const & a, Color const & b) +dcp::operator== (Colour const & a, Colour const & b) { return (a.r == b.r && a.g == b.g && a.b == b.b); } -/** operator!= for Colors. - * @param a First color to compare. - * @param b Second color to compare. +/** operator!= for Colours. + * @param a First colour to compare. + * @param b Second colour to compare. */ bool -dcp::operator!= (Color const & a, Color const & b) +dcp::operator!= (Colour const & a, Colour const & b) { return !(a == b); } ostream & -dcp::operator<< (ostream& s, Color const & c) +dcp::operator<< (ostream& s, Colour const & c) { s << "(" << c.r << ", " << c.g << ", " << c.b << ")"; return s; @@ -161,33 +175,60 @@ dcp::string_to_effect (string s) boost::throw_exception (DCPReadError ("unknown subtitle effect type")); } +string +dcp::halign_to_string (HAlign h) +{ + switch (h) { + case HALIGN_LEFT: + return "left"; + case HALIGN_CENTER: + return "center"; + case HALIGN_RIGHT: + return "right"; + } + + boost::throw_exception (MiscError ("unknown subtitle halign type")); +} + +HAlign +dcp::string_to_halign (string s) +{ + if (s == "left") { + return HALIGN_LEFT; + } else if (s == "center") { + return HALIGN_CENTER; + } else if (s == "right") { + return HALIGN_RIGHT; + } + + boost::throw_exception (DCPReadError ("unknown subtitle halign type")); +} + string dcp::valign_to_string (VAlign v) { switch (v) { - case TOP: + case VALIGN_TOP: return "top"; - case CENTER: + case VALIGN_CENTER: return "center"; - case BOTTOM: + case VALIGN_BOTTOM: return "bottom"; } - boost::throw_exception (MiscError ("unknown valign type")); + boost::throw_exception (MiscError ("unknown subtitle valign type")); } VAlign dcp::string_to_valign (string s) { if (s == "top") { - return TOP; + return VALIGN_TOP; } else if (s == "center") { - return CENTER; + return VALIGN_CENTER; } else if (s == "bottom") { - return BOTTOM; + return VALIGN_BOTTOM; } - + boost::throw_exception (DCPReadError ("unknown subtitle valign type")); } - -