Allow any ratio to appear in the ISDCF name as an interior aspect ratio (#2030).
authorCarl Hetherington <cth@carlh.net>
Sun, 30 May 2021 22:25:25 +0000 (00:25 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 30 May 2021 22:25:25 +0000 (00:25 +0200)
src/lib/film.cc
test/isdcf_name_test.cc

index 0b717738d09bfacd7198b870003869123dd7edb7..62cbf0e5095458699f79f1697c5917ad7d1487ac 100644 (file)
@@ -911,19 +911,15 @@ Film::isdcf_name (bool if_created_now) const
 
        /* Interior aspect ratio.  The standard says we don't do this for trailers, for some strange reason */
        if (dcp_content_type() && dcp_content_type()->libdcp_kind() != dcp::ContentKind::TRAILER) {
-               Ratio const* content_ratio = nullptr;
-               for (auto i: content ()) {
-                       if (i->video) {
-                               /* Here's the first piece of video content */
-                               content_ratio = Ratio::nearest_from_ratio(i->video->scaled_size(frame_size()).ratio());
-                               break;
+               auto cl = content();
+               auto first_video = std::find_if(cl.begin(), cl.end(), [](shared_ptr<Content> c) { return static_cast<bool>(c->video); });
+               if (first_video != cl.end()) {
+                       auto first_ratio = lrintf((*first_video)->video->scaled_size(frame_size()).ratio() * 100);
+                       auto container_ratio = lrintf(container()->ratio() * 100);
+                       if (first_ratio != container_ratio) {
+                               d += "-" + dcp::raw_convert<string>(first_ratio);
                        }
                }
-
-               if (content_ratio && content_ratio != container()) {
-                       /* This needs to be the numeric version of the ratio, and ::id() is close enough */
-                       d += "-" + content_ratio->id();
-               }
        }
 
        auto audio_langs = audio_languages();
index a41bf84b369703f47a1d70897508268253c58869..8fc2c8f643e9c4fbff692001c834e87439d82632 100644 (file)
@@ -126,6 +126,13 @@ BOOST_AUTO_TEST_CASE (isdcf_name_test)
 
        content->video->set_custom_ratio (1.9);
        BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-190_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
+
+       /* And it should be possible to set any 'strange' ratio, not just the ones we know about */
+       content->video->set_custom_ratio (2.2);
+       BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-220_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
+       content->video->set_custom_ratio (1.95);
+       BOOST_CHECK_EQUAL (film->isdcf_name(false), "MyNiceFilmWith_XSN-2_F-195_DE-fr_US-R_MOS_4K_DI_20140704_PPF_SMPTE_OV");
+
        content->video->set_custom_ratio (1.33);
 
        /* Test 3D */