summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-02-07 21:38:01 +0000
committerCarl Hetherington <cth@carlh.net>2018-02-07 21:38:01 +0000
commitf964e99d63f5f5999ae4f245e6b25ced014d8383 (patch)
tree31262a83652d5e4b1b6d9460843873287208ad7c
parentf19fba719f1da6850ae320534c669196ea9d854c (diff)
db8af2f changed rebase() to round down when rebasing times, but
did not say why. This rounding down produces some unexpected results, e.g. taking 41 at a TCR of 1000 to a TCR of 24 gives 0, which upsets those who use DCP-o-matic and put in a SRT subtitle ending at ,041 --- the sub time is rounded down to 0 for a SMPTE DCP. This commit restores round-to-nearest behaviour.
-rw-r--r--src/dcp_time.cc2
-rw-r--r--test/dcp_time_test.cc9
-rw-r--r--test/write_subtitle_test.cc4
3 files changed, 7 insertions, 8 deletions
diff --git a/src/dcp_time.cc b/src/dcp_time.cc
index 50946f4c..f0b7e231 100644
--- a/src/dcp_time.cc
+++ b/src/dcp_time.cc
@@ -356,5 +356,5 @@ Time::as_seconds () const
Time
Time::rebase (int tcr_) const
{
- return Time (h, m, s, floor (float (e) * tcr_ / tcr), tcr_);
+ return Time (h, m, s, lrintf (float (e) * tcr_ / tcr), tcr_);
}
diff --git a/test/dcp_time_test.cc b/test/dcp_time_test.cc
index 099892b1..48a35b5a 100644
--- a/test/dcp_time_test.cc
+++ b/test/dcp_time_test.cc
@@ -96,14 +96,13 @@ BOOST_AUTO_TEST_CASE (dcp_time)
/* Check rounding on conversion from seconds */
BOOST_CHECK_EQUAL (dcp::Time (80.990, 1000), dcp::Time (0, 1, 20, 990, 1000));
- /* Check rebase() */
+ /* Check rebase */
a = dcp::Time (1, 58, 56, 2, 25);
- BOOST_CHECK_EQUAL (a.rebase (250), dcp::Time (1, 58, 56, 20, 250));
+ BOOST_CHECK_EQUAL (a.rebase(250), dcp::Time(1, 58, 56, 20, 250));
b = dcp::Time (9, 12, 41, 17, 99);
- BOOST_CHECK_EQUAL (b.rebase (250), dcp::Time (9, 12, 41, 42, 250));
- /* We must round down in rebase() */
+ BOOST_CHECK_EQUAL (b.rebase(250), dcp::Time(9, 12, 41, 43, 250));
a = dcp::Time (0, 2, 57, 999, 1000);
- BOOST_CHECK_EQUAL (a.rebase (250), dcp::Time (0, 2, 57, 249, 250));
+ BOOST_CHECK_EQUAL (a.rebase(250), dcp::Time(0, 2, 57, 250, 250));
/* Check some allowed constructions from string */
diff --git a/test/write_subtitle_test.cc b/test/write_subtitle_test.cc
index bb5a77c4..d9240a30 100644
--- a/test/write_subtitle_test.cc
+++ b/test/write_subtitle_test.cc
@@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE (write_interop_subtitle_test)
"</Subtitle>"
"</Font>"
"<Font AspectAdjust=\"1.0\" Color=\"FF800040\" Effect=\"border\" EffectColor=\"FF010203\" Italic=\"yes\" Script=\"normal\" Size=\"91\" Underlined=\"yes\" Weight=\"bold\">"
- "<Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:218\" TimeOut=\"06:12:15:218\" FadeUpTime=\"930792\" FadeDownTime=\"4591834\">"
+ "<Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:219\" TimeOut=\"06:12:15:219\" FadeUpTime=\"930792\" FadeDownTime=\"4591834\">"
"<Text VAlign=\"bottom\" VPosition=\"40\">What's going on</Text>"
"</Subtitle>"
"</Font>"
@@ -289,7 +289,7 @@ BOOST_AUTO_TEST_CASE (write_interop_subtitle_test2)
"</Subtitle>"
"</Font>"
"<Font AspectAdjust=\"1.0\" Color=\"FF800040\" Effect=\"border\" EffectColor=\"FF010203\" Italic=\"yes\" Script=\"normal\" Size=\"91\" Underlined=\"yes\" Weight=\"bold\">"
- "<Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:218\" TimeOut=\"06:12:15:218\" FadeUpTime=\"930792\" FadeDownTime=\"4591834\">"
+ "<Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:219\" TimeOut=\"06:12:15:219\" FadeUpTime=\"930792\" FadeDownTime=\"4591834\">"
"<Text HPosition=\"-20\" VAlign=\"bottom\" VPosition=\"40\">What's going on</Text>"
"</Subtitle>"
"</Font>"