diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-05-19 21:23:37 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-05-19 21:23:37 +0200 |
| commit | b38aa006143abd4f10b7ec32576f5ce2867fa975 (patch) | |
| tree | 80c9ff2e89cd4ef1a1ee764daa94e79fd3b09bcb | |
| parent | ba0d345e3a986ea07398c1a9abe8d5263a870318 (diff) | |
Basic support for colours in binary STL.v1.6.48
| -rw-r--r-- | src/stl_binary_reader.cc | 36 | ||||
| -rw-r--r-- | test/stl_binary_reader_test.cc | 39 |
2 files changed, 72 insertions, 3 deletions
diff --git a/src/stl_binary_reader.cc b/src/stl_binary_reader.cc index 35091f0..7b38065 100644 --- a/src/stl_binary_reader.cc +++ b/src/stl_binary_reader.cc @@ -248,14 +248,46 @@ void STLBinaryReader::read (shared_ptr<InputReader> reader) break; } - if (c >= 0x80 && c <= 0x83) { - /* Italic or underline control code */ + if (c <= 0x07 || (c >= 0x80 && c <= 0x83)) { + /* Colour, italic or underline control code */ sub.text = utf_to_utf<char> (iso6937_to_utf16 (text.c_str())); _subs.push_back (sub); text.clear (); } switch (c) { + case 0x0: + /* Black */ + sub.colour = Colour(0, 0, 0); + break; + case 0x1: + /* Red */ + sub.colour = Colour(1, 0, 0); + break; + case 0x2: + /* Lime */ + sub.colour = Colour(0, 1, 0); + break; + case 0x3: + /* Yellow */ + sub.colour = Colour(1, 1, 0); + break; + case 0x4: + /* Blue */ + sub.colour = Colour(0, 0, 1); + break; + case 0x5: + /* Magenta */ + sub.colour = Colour(1, 0, 1); + break; + case 0x6: + /* Cyan */ + sub.colour = Colour(0, 1, 1); + break; + case 0x7: + /* White */ + sub.colour = Colour(1, 1, 1); + break; case 0x80: italic = true; break; diff --git a/test/stl_binary_reader_test.cc b/test/stl_binary_reader_test.cc index 6566c5f..a0469d0 100644 --- a/test/stl_binary_reader_test.cc +++ b/test/stl_binary_reader_test.cc @@ -17,6 +17,7 @@ */ + #include "stl_binary_reader.h" #include "subtitle.h" #include "test.h" @@ -24,10 +25,13 @@ #include <boost/test/unit_test.hpp> #include <fstream> + using std::ifstream; +using std::make_shared; using std::ofstream; using std::shared_ptr; -using std::make_shared; +using std::vector; + /* Test reading of a binary STL file */ BOOST_AUTO_TEST_CASE (stl_binary_reader_test1) @@ -94,3 +98,36 @@ BOOST_AUTO_TEST_CASE (stl_binary_reader_test3) } } + +BOOST_AUTO_TEST_CASE(stl_binary_reader_with_colour) +{ + auto path = private_test / "at.stl"; + ifstream in(path.string().c_str()); + auto reader = make_shared<sub::STLBinaryReader>(in); + + vector<sub::Colour> reference = { + { 1, 1, 1 }, + { 1, 0, 1 }, + { 1, 1, 1 }, + { 1, 0, 1 }, + { 1, 1, 1 }, + { 1, 1, 0 }, + { 1, 1, 1 }, + { 1, 1, 0 }, + { 1, 1, 1 }, + { 1, 1, 0 }, + { 1, 1, 1 }, + { 1, 1, 0 }, + { 1, 1, 1 }, + { 1, 1, 0 } + }; + + /* Check the first few lines */ + auto subs = reader->subtitles(); + BOOST_REQUIRE(subs.size() >= reference.size()); + + for (size_t i = 0; i < reference.size(); ++i) { + BOOST_CHECK(subs[i].colour == reference[i]); + } +} + |
