diff options
| -rw-r--r-- | src/subtitle_asset.cc | 8 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 7 | ||||
| -rw-r--r-- | src/types.cc | 39 | ||||
| -rw-r--r-- | src/types.h | 16 | ||||
| -rw-r--r-- | src/xml.cc | 11 | ||||
| -rw-r--r-- | src/xml.h | 1 | ||||
| -rw-r--r-- | test/tests.cc | 6 |
7 files changed, 86 insertions, 2 deletions
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<FontNode> font_node, list<shared_pt new Subtitle ( font_id_to_name (effective.id), effective.italic.get(), + effective.color.get(), effective.size, (*j)->in, (*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<SubtitleNode> ("Subtitle"); font_nodes = sub_nodes<FontNode> ("Font"); } @@ -91,6 +93,7 @@ FontNode::FontNode (xmlpp::Node const * node) FontNode::FontNode (list<shared_ptr<FontNode> > const & font_nodes) : size (0) , italic (false) + , color ("FFFFFFFF") { for (list<shared_ptr<FontNode> >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) { if (!(*i)->id.empty ()) { @@ -102,6 +105,9 @@ FontNode::FontNode (list<shared_ptr<FontNode> > 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<bool> italic; + boost::optional<Color> color; std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes; std::list<boost::shared_ptr<FontNode> > 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 <vector> +#include <cstdio> #include <boost/lexical_cast.hpp> #include <boost/algorithm/string.hpp> #include "types.h" @@ -18,3 +19,41 @@ Fraction::Fraction (string s) numerator = lexical_cast<int> (b[0]); denominator = lexical_cast<int> (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); } @@ -189,6 +189,17 @@ XMLNode::optional_bool_attribute (string name) return optional<bool> (false); } +optional<Color> +XMLNode::optional_color_attribute (string name) +{ + string const s = string_attribute (name); + if (s.empty ()) { + return optional<Color> (); + } + + return optional<Color> (Color (s)); +} + void XMLNode::done () { @@ -41,6 +41,7 @@ protected: int64_t int64_attribute (std::string); int64_t optional_int64_attribute (std::string); boost::optional<bool> optional_bool_attribute (std::string); + boost::optional<Color> optional_color_attribute (std::string); std::string content (); diff --git a/test/tests.cc b/test/tests.cc index d717faf4..61573f93 100644 --- a/test/tests.cc +++ b/test/tests.cc @@ -124,6 +124,7 @@ BOOST_AUTO_TEST_CASE (subtitles) BOOST_CHECK_EQUAL (s.front()->out(), libdcp::Time (0, 0, 7, 115)); BOOST_CHECK_EQUAL (s.front()->font(), "Arial"); BOOST_CHECK_EQUAL (s.front()->italic(), false); + BOOST_CHECK_EQUAL (s.front()->color(), libdcp::Color(255, 255, 255)); BOOST_CHECK_EQUAL (s.front()->size_in_pixels(1080), 53); s = subs.subtitles_at (libdcp::Time (0, 0, 7, 190)); @@ -140,7 +141,8 @@ BOOST_AUTO_TEST_CASE (subtitles) BOOST_CHECK_EQUAL (s.back()->in(), libdcp::Time (0, 0, 7, 177)); BOOST_CHECK_EQUAL (s.back()->out(), libdcp::Time (0, 0, 11, 31)); BOOST_CHECK_EQUAL (s.back()->font(), "Arial"); - BOOST_CHECK_EQUAL (s.front()->italic(), true); + BOOST_CHECK_EQUAL (s.back()->italic(), true); + BOOST_CHECK_EQUAL (s.back()->color(), libdcp::Color(255, 255, 255)); BOOST_CHECK_EQUAL (s.back()->size_in_pixels(1080), 53); s = subs.subtitles_at (libdcp::Time (0, 0, 11, 95)); @@ -151,6 +153,7 @@ BOOST_AUTO_TEST_CASE (subtitles) BOOST_CHECK_EQUAL (s.front()->out(), libdcp::Time (0, 0, 13, 63)); BOOST_CHECK_EQUAL (s.front()->font(), "Arial"); BOOST_CHECK_EQUAL (s.front()->italic(), false); + BOOST_CHECK_EQUAL (s.front()->color(), libdcp::Color(255, 255, 255)); BOOST_CHECK_EQUAL (s.front()->size_in_pixels(1080), 53); s = subs.subtitles_at (libdcp::Time (0, 0, 14, 42)); @@ -161,6 +164,7 @@ BOOST_AUTO_TEST_CASE (subtitles) BOOST_CHECK_EQUAL (s.front()->out(), libdcp::Time (0, 0, 15, 177)); BOOST_CHECK_EQUAL (s.front()->font(), "Arial"); BOOST_CHECK_EQUAL (s.front()->italic(), false); + BOOST_CHECK_EQUAL (s.front()->color(), libdcp::Color(255, 255, 255)); BOOST_CHECK_EQUAL (s.front()->size_in_pixels(1080), 53); } |
