db8af2f changed rebase() to round down when rebasing times, but
authorCarl Hetherington <cth@carlh.net>
Wed, 7 Feb 2018 21:38:01 +0000 (21:38 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 7 Feb 2018 21:38:01 +0000 (21:38 +0000)
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.

src/dcp_time.cc
test/dcp_time_test.cc
test/write_subtitle_test.cc

index 50946f4c9425ef4083b703688d2a787b06874880..f0b7e231c6935669d6942467f75b6c25380e06bb 100644 (file)
@@ -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_);
 }
index 099892b1bee6e777cac7046470fdacfba4b1614f..48a35b5a3c079185673a61dd21a21aefd935b65e 100644 (file)
@@ -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 */
 
index bb5a77c4163c8a7e572f9117dc3ed538a8a45206..d9240a3062af33c19c684028daba8a4e27200f23 100644 (file)
@@ -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>"