From 2e4089247c02f1f1bf43ab880594ce0218dfbc11 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 24 Jun 2019 12:31:56 +0100 Subject: Add support for \c in SSA. --- src/exceptions.h | 8 ++++++++ src/ssa_reader.cc | 11 +++++++++++ 2 files changed, 19 insertions(+) (limited to 'src') diff --git a/src/exceptions.h b/src/exceptions.h index 56b58aa..2bb7018 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -65,6 +65,14 @@ private: std::list _context; }; +class SSAError : public std::runtime_error +{ +public: + SSAError (std::string message) + : std::runtime_error(message) + {} +}; + class MXFError : public std::runtime_error { public: diff --git a/src/ssa_reader.cc b/src/ssa_reader.cc index f592b9e..111a4cb 100644 --- a/src/ssa_reader.cc +++ b/src/ssa_reader.cc @@ -22,6 +22,7 @@ #include "sub_assert.h" #include "raw_convert.h" #include "subtitle.h" +#include "compose.hpp" #include #include #include @@ -282,6 +283,16 @@ SSAReader::parse_line (RawSubtitle base, string line, int play_res_x, int play_r } else if (boost::starts_with(style, "\\fs")) { SUB_ASSERT (style.length() > 3); current.font_size.set_points (raw_convert(style.substr(3))); + } else if (boost::starts_with(style, "\\c")) { + /* \c&Hbbggrr& */ + if (style.length() != 11 || style[2] != '&' || style[3] != 'H' || style[10] != '&') { + throw SSAError(String::compose("Badly formatted colour tag %1", style)); + } + int ir, ig, ib; + if (sscanf(style.c_str() + 4, "%2x%2x%2x", &ib, &ig, &ir) < 3) { + throw SSAError(String::compose("Badly formatted colour tag %1", style)); + } + current.colour = sub::Colour(ir / 255.0, ig / 255.0, ib / 255.0); } style = ""; } -- cgit v1.2.3