Put the right 'actual' ratio in DCP titles even with no-stretch and no-scale.
authorCarl Hetherington <cth@carlh.net>
Wed, 3 Sep 2014 22:34:32 +0000 (23:34 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 3 Sep 2014 22:34:32 +0000 (23:34 +0100)
src/lib/film.cc
src/lib/ratio.cc
src/lib/ratio.h

index 2701d81b8374f619c205aa63589933da63717f39..b4d12a062949ffe4a3ca2e49daed3c76a14b60bb 100644 (file)
@@ -580,18 +580,22 @@ Film::isdcf_name (bool if_created_now) const
                d << "_" << container()->isdcf_name();
        }
 
-       /* XXX: this only works for content which has been scaled to a given ratio,
-          and uses the first bit of content only.
-       */
+       /* XXX: this uses the first bit of content only */
 
        /* The standard says we don't do this for trailers, for some strange reason */
        if (dcp_content_type() && dcp_content_type()->libdcp_kind() != libdcp::TRAILER) {
-               ContentList cl = content ();
                Ratio const * content_ratio = 0;
-               for (ContentList::const_iterator i = cl.begin(); i != cl.end(); ++i) {
+               ContentList cl = content ();
+               for (ContentList::iterator i = cl.begin(); i != cl.end(); ++i) {
                        shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*i);
-                       if (vc && (content_ratio == 0 || vc->scale().ratio() != content_ratio)) {
-                               content_ratio = vc->scale().ratio();
+                       if (vc) {
+                               /* Here's the first piece of video content */
+                               if (vc->scale().ratio ()) {
+                                       content_ratio = vc->scale().ratio ();
+                               } else {
+                                       content_ratio = Ratio::from_ratio (vc->video_size().ratio ());
+                               }
+                               break;
                        }
                }
                
index 4a5b39a22f28b060ebf5ede3e7b27d197e7667d4..554d3c36c6c551f93e30b0d1305de5f94b9cdde4 100644 (file)
@@ -56,3 +56,20 @@ Ratio::from_id (string i)
 
        return *j;
 }
+
+/** @return Ratio corresponding to a given fractional ratio (+/- 0.01), or 0 */
+Ratio const *
+Ratio::from_ratio (float r)
+{
+       vector<Ratio const *>::iterator j = _ratios.begin ();
+       while (j != _ratios.end() && fabs ((*j)->ratio() - r) > 0.01) {
+               ++j;
+       }
+
+       if (j == _ratios.end ()) {
+               return 0;
+       }
+
+       return *j;
+}
+   
index 8b1a1fc716dc61d9175c6144e30f34ea27bdf39f..ab157a9bcb4a65404d1531973d02fbd61d39ec76 100644 (file)
@@ -52,6 +52,7 @@ public:
 
        static void setup_ratios ();
        static Ratio const * from_id (std::string i);
+       static Ratio const * from_ratio (float r);
        static std::vector<Ratio const *> all () {
                return _ratios;
        }