From e8bb753ea7f1dfe2dac761050f47ea1cb786f01b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 21 Aug 2012 18:32:11 +0100 Subject: Pick up subtitle color. --- src/subtitle_asset.cc | 8 ++++++++ src/subtitle_asset.h | 7 +++++++ src/types.cc | 39 +++++++++++++++++++++++++++++++++++++++ src/types.h | 16 +++++++++++++++- src/xml.cc | 11 +++++++++++ src/xml.h | 1 + 6 files changed, 81 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index c27fd2c0..a5c94b80 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -60,6 +60,7 @@ SubtitleAsset::examine_font_node (shared_ptr font_node, listin, (*j)->out, @@ -84,6 +85,7 @@ FontNode::FontNode (xmlpp::Node const * node) id = string_attribute ("Id"); size = optional_int64_attribute ("Size"); italic = optional_bool_attribute ("Italic"); + color = optional_color_attribute ("Color"); subtitle_nodes = sub_nodes ("Subtitle"); font_nodes = sub_nodes ("Font"); } @@ -91,6 +93,7 @@ FontNode::FontNode (xmlpp::Node const * node) FontNode::FontNode (list > const & font_nodes) : size (0) , italic (false) + , color ("FFFFFFFF") { for (list >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) { if (!(*i)->id.empty ()) { @@ -102,6 +105,9 @@ FontNode::FontNode (list > const & font_nodes) if ((*i)->italic) { italic = (*i)->italic.get (); } + if ((*i)->color) { + color = (*i)->color.get (); + } } } @@ -163,6 +169,7 @@ SubtitleAsset::font_id_to_name (string id) const Subtitle::Subtitle ( std::string font, bool italic, + Color color, int size, Time in, Time out, @@ -171,6 +178,7 @@ Subtitle::Subtitle ( ) : _font (font) , _italic (italic) + , _color (color) , _size (size) , _in (in) , _out (out) diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 3df30e62..02dea865 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -55,6 +55,7 @@ public: std::string id; int size; boost::optional italic; + boost::optional color; std::list > subtitle_nodes; std::list > font_nodes; @@ -76,6 +77,7 @@ public: Subtitle ( std::string font, bool italic, + Color color, int size, Time in, Time out, @@ -91,6 +93,10 @@ public: return _italic; } + Color color () const { + return _color; + } + Time in () const { return _in; } @@ -112,6 +118,7 @@ public: private: std::string _font; bool _italic; + Color _color; int _size; Time _in; Time _out; diff --git a/src/types.cc b/src/types.cc index 85c5fd6e..39d7fea5 100644 --- a/src/types.cc +++ b/src/types.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include "types.h" @@ -18,3 +19,41 @@ Fraction::Fraction (string s) numerator = lexical_cast (b[0]); denominator = lexical_cast (b[1]); } + +Color::Color () + : r (0) + , g (0) + , b (0) +{ + +} + +Color::Color (int r_, int g_, int b_) + : r (r_) + , g (g_) + , b (b_) +{ + +} + +Color::Color (string argb_hex) +{ + int alpha; + if (sscanf (argb_hex.c_str(), "%2x%2x%2x%2x", &alpha, &r, &g, &b) < 4) { + throw XMLError ("could not parse colour string"); + } +} + + +bool +libdcp::operator== (Color const & a, Color const & b) +{ + return (a.r == b.r && a.g == b.g && a.b == b.b); +} + +ostream & +libdcp::operator<< (ostream& s, Color const & c) +{ + s << "(" << c.r << ", " << c.g << ", " << c.b << ")"; + return s; +} diff --git a/src/types.h b/src/types.h index 8c584579..3a50c5d3 100644 --- a/src/types.h +++ b/src/types.h @@ -74,7 +74,21 @@ struct EqualityOptions { double max_mean_pixel_error; double max_std_dev_pixel_error; }; - + +class Color +{ +public: + Color (); + Color (int r_, int g_, int b_); + Color (std::string argb_hex); + + int r; + int g; + int b; +}; + +extern bool operator== (Color const & a, Color const & b); +extern std::ostream & operator<< (std::ostream & s, Color const & c); } diff --git a/src/xml.cc b/src/xml.cc index bc42ebce..1d524738 100644 --- a/src/xml.cc +++ b/src/xml.cc @@ -189,6 +189,17 @@ XMLNode::optional_bool_attribute (string name) return optional (false); } +optional +XMLNode::optional_color_attribute (string name) +{ + string const s = string_attribute (name); + if (s.empty ()) { + return optional (); + } + + return optional (Color (s)); +} + void XMLNode::done () { diff --git a/src/xml.h b/src/xml.h index f1e39b55..65eb7399 100644 --- a/src/xml.h +++ b/src/xml.h @@ -41,6 +41,7 @@ protected: int64_t int64_attribute (std::string); int64_t optional_int64_attribute (std::string); boost::optional optional_bool_attribute (std::string); + boost::optional optional_color_attribute (std::string); std::string content (); -- cgit v1.2.3