X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fsubrip_decoder.cc;h=2de27248111eb17eaddd8f93f2afcf095522224d;hp=dae2e4ab755d8085114b137a2ed83b7b0a9ba187;hb=aeb835a18c8df347e0ed68fb24631b320abeb611;hpb=7affca9f7b210c3137eb084cd393b534051a2647 diff --git a/src/lib/subrip_decoder.cc b/src/lib/subrip_decoder.cc index dae2e4ab7..2de272481 100644 --- a/src/lib/subrip_decoder.cc +++ b/src/lib/subrip_decoder.cc @@ -20,6 +20,7 @@ #include #include "subrip_decoder.h" #include "subrip_content.h" +#include using std::list; using std::vector; @@ -40,7 +41,7 @@ void SubRipDecoder::seek (ContentTime time, bool accurate) { SubtitleDecoder::seek (time, accurate); - + _next = 0; while (_next < _subtitles.size() && ContentTime::from_seconds (_subtitles[_next].from.all_as_seconds ()) < time) { ++_next; @@ -48,14 +49,14 @@ SubRipDecoder::seek (ContentTime time, bool accurate) } bool -SubRipDecoder::pass (PassReason) +SubRipDecoder::pass () { if (_next >= _subtitles.size ()) { return true; } /* XXX: we are ignoring positioning specified in the file */ - + list out; for (list::const_iterator i = _subtitles[_next].lines.begin(); i != _subtitles[_next].lines.end(); ++i) { for (list::const_iterator j = i->blocks.begin(); j != i->blocks.end(); ++j) { @@ -63,13 +64,15 @@ SubRipDecoder::pass (PassReason) dcp::SubtitleString ( SubRipContent::font_id, j->italic, - dcp::Colour (255, 255, 255), + dcp::Colour (j->colour.r * 255, j->colour.g * 255, j->colour.b * 255), j->font_size.points (72 * 11), 1.0, dcp::Time (_subtitles[_next].from.all_as_seconds()), dcp::Time (_subtitles[_next].to.all_as_seconds()), + 0, + dcp::HALIGN_CENTER, i->vertical_position.line.get() * (1.5 / 22) + 0.8, - dcp::TOP, + dcp::VALIGN_TOP, j->text, dcp::NONE, dcp::Colour (255, 255, 255), @@ -80,7 +83,8 @@ SubRipDecoder::pass (PassReason) } } - text_subtitle (out); + text_subtitle (content_time_period (_subtitles[_next]), out); + ++_next; return false; } @@ -99,12 +103,7 @@ SubRipDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const list d; for (vector::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { - - ContentTimePeriod t ( - ContentTime::from_seconds (i->from.all_as_seconds()), - ContentTime::from_seconds (i->to.all_as_seconds()) - ); - + ContentTimePeriod t = content_time_period (*i); if ((starting && p.contains (t.from)) || (!starting && p.overlaps (t))) { d.push_back (t); } @@ -112,3 +111,12 @@ SubRipDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const return d; } + +ContentTimePeriod +SubRipDecoder::content_time_period (sub::Subtitle s) const +{ + return ContentTimePeriod ( + ContentTime::from_seconds (s.from.all_as_seconds()), + ContentTime::from_seconds (s.to.all_as_seconds()) + ); +}