Remove DCP-specialism from Container and add tests for it.
authorCarl Hetherington <cth@carlh.net>
Tue, 28 May 2013 15:12:44 +0000 (16:12 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 28 May 2013 15:12:44 +0000 (16:12 +0100)
src/lib/container.cc
src/lib/container.h
src/lib/encoder.cc
src/lib/film.cc
src/lib/film.h
src/lib/writer.cc
test/container_test.cc [new file with mode: 0644]
test/test.cc

index 6eaea7300572bf7de47e5ca6bc17336527e694bd..d679e4848fbbfcde36f0948f9872eea76104a833 100644 (file)
@@ -32,33 +32,22 @@ vector<Container const *> Container::_containers;
 void
 Container::setup_containers ()
 {
-       _containers.push_back (new Container (libdcp::Size (1285, 1080), "119", _("1.19"), "F"));
-       _containers.push_back (new Container (libdcp::Size (1436, 1080), "133", _("4:3"), "F"));
-       _containers.push_back (new Container (libdcp::Size (1480, 1080), "137", _("Academy"), "F"));
-       _containers.push_back (new Container (libdcp::Size (1485, 1080), "138", _("1.375"), "F"));
-       _containers.push_back (new Container (libdcp::Size (1793, 1080), "166", _("1.66"), "F"));
-       _containers.push_back (new Container (libdcp::Size (1920, 1080), "178", _("16:9"), "F"));
-       _containers.push_back (new Container (libdcp::Size (1998, 1080), "185", _("Flat"), "F"));
-       _containers.push_back (new Container (libdcp::Size (2048, 858), "239", _("Scope"), "S"));
-       _containers.push_back (new Container (libdcp::Size (2048, 1080), "full-frame", _("Full frame"), "C"));
+       _containers.push_back (new Container (float(1285) / 1080, "119", _("1.19"), "F"));
+       _containers.push_back (new Container (float(1436) / 1080, "133", _("4:3"), "F"));
+       _containers.push_back (new Container (float(1480) / 1080, "137", _("Academy"), "F"));
+       _containers.push_back (new Container (float(1485) / 1080, "138", _("1.375"), "F"));
+       _containers.push_back (new Container (float(1793) / 1080, "166", _("1.66"), "F"));
+       _containers.push_back (new Container (float(1920) / 1080, "178", _("16:9"), "F"));
+       _containers.push_back (new Container (float(1998) / 1080, "185", _("Flat"), "F"));
+       _containers.push_back (new Container (float(2048) /  858, "239", _("Scope"), "S"));
+       _containers.push_back (new Container (float(2048) / 1080, "full-frame", _("Full frame"), "C"));
 }
 
 /** @return A name to be presented to the user */
 string
 Container::name () const
 {
-       stringstream s;
-       if (!_nickname.empty ()) {
-               s << _nickname << " (";
-       }
-
-       s << _dcp_size.width << "x" << _dcp_size.height;
-
-       if (!_nickname.empty ()) {
-               s << ")";
-       }
-
-       return s.str ();
+       return _nickname;
 }
 
 Container const *
@@ -76,8 +65,14 @@ Container::from_id (string i)
        return *j;
 }
 
-float
-Container::ratio () const
+libdcp::Size
+Container::size (libdcp::Size full_frame) const
 {
-       return static_cast<float> (_dcp_size.width) / _dcp_size.height;
+       if (_ratio < static_cast<float>(full_frame.width) / full_frame.height) {
+               return libdcp::Size (full_frame.height * _ratio, full_frame.height);
+       } else {
+               return libdcp::Size (full_frame.width, full_frame.width / _ratio);
+       }
+
+       return libdcp::Size ();
 }
index fc3c72792e0920472c6442e4458f978484d7f39b..4bf03a3f1131f7728eeecc4e5b6a49658728a1cd 100644 (file)
 class Container
 {
 public:
-       Container (libdcp::Size dcp, std::string id, std::string n, std::string d)
-               : _dcp_size (dcp)
+       Container (float ratio, std::string id, std::string n, std::string d)
+               : _ratio (ratio)
                , _id (id)
                , _nickname (n)
                , _dci_name (d)
        {}
 
-       /** @return size in pixels of the images that we should
-        *  put in a DCP for this ratio.  This size will not correspond
-        *  to the ratio when we are doing things like 16:9 in a Flat frame.
-        */
-       libdcp::Size dcp_size () const {
-               return _dcp_size;
-       }
+       libdcp::Size size (libdcp::Size) const;
 
        std::string id () const {
                return _id;
        }
 
-       /** @return Full name to present to the user */
        std::string name () const;
 
        /** @return Nickname (e.g. Flat, Scope) */
@@ -54,7 +47,9 @@ public:
                return _dci_name;
        }
 
-       float ratio () const;
+       float ratio () const {
+               return _ratio;
+       }
        
        static void setup_containers ();
        static Container const * from_id (std::string i);
@@ -63,10 +58,7 @@ public:
        }
 
 private:
-       /** libdcp::Size in pixels of the images that we should
-        *  put in a DCP for this container.
-        */
-       libdcp::Size _dcp_size;
+       float _ratio;
        /** id for use in metadata */
        std::string _id;
        /** nickname (e.g. Flat, Scope) */
index 270bf3d43b736fe888f23a537cdf1c1c68d0dfa5..3152669ad46a0e083d7893781866ba9770f30a4f 100644 (file)
@@ -211,7 +211,7 @@ Encoder::process_video (shared_ptr<const Image> image, bool same, shared_ptr<Sub
                /* XXX: padding */
                _queue.push_back (shared_ptr<DCPVideoFrame> (
                                          new DCPVideoFrame (
-                                                 image, sub, _film->container()->dcp_size(), 0,
+                                                 image, sub, _film->container()->size (_film->full_frame()), 0,
                                                  _film->subtitle_offset(), _film->subtitle_scale(),
                                                  _film->scaler(), _video_frames_out, _film->dcp_video_frame_rate(),
                                                  _film->colour_lut(), _film->j2k_bandwidth(),
index 8eeb4fec5141ba1e936f49d2568277d1aee95e8c..e76d97b5950607d175da422bbda983f881923f37 100644 (file)
@@ -911,3 +911,9 @@ Film::set_sequence_video (bool s)
 {
        _playlist->set_sequence_video (s);
 }
+
+libdcp::Size
+Film::full_frame () const
+{
+       return libdcp::Size (2048, 1080);
+}
index cb970da4d0667f98f10cbec89d128697e750d982..31454c5a7c7c1a8d8a2b18973f09d2abc1c61755 100644 (file)
@@ -96,6 +96,8 @@ public:
                return _dirty;
        }
 
+       libdcp::Size full_frame () const;
+
        bool have_dcp () const;
 
        boost::shared_ptr<Player> player () const;
index 39b9b9304ff5a49a1d9b29f9f75d30fa38ca3eda..22aacb64033fcda2dbabdf80acd808179fe519f8 100644 (file)
@@ -76,7 +76,7 @@ Writer::Writer (shared_ptr<Film> f, shared_ptr<Job> j)
                        _film->internal_video_mxf_dir (),
                        _film->internal_video_mxf_filename (),
                        _film->dcp_video_frame_rate (),
-                       _film->container()->dcp_size ()
+                       _film->container()->size (_film->full_frame ())
                        )
                );
 
diff --git a/test/container_test.cc b/test/container_test.cc
new file mode 100644 (file)
index 0000000..825a8cd
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+using std::ostream;
+
+namespace libdcp {
+       
+ostream&
+operator<< (ostream& s, libdcp::Size const & t)
+{
+       s << t.width << "x" << t.height;
+       return s;
+}
+
+}
+
+BOOST_AUTO_TEST_CASE (container_test)
+{
+       Container::setup_containers ();
+
+       Container const * c = Container::from_id ("119");
+       BOOST_CHECK (c);
+       BOOST_CHECK_EQUAL (c->size(libdcp::Size (2048, 1080)), libdcp::Size (1285, 1080));
+
+       c = Container::from_id ("133");
+       BOOST_CHECK (c);
+       BOOST_CHECK_EQUAL (c->size(libdcp::Size (2048, 1080)), libdcp::Size (1436, 1080));
+
+       c = Container::from_id ("137");
+       BOOST_CHECK (c);
+       BOOST_CHECK_EQUAL (c->size(libdcp::Size (2048, 1080)), libdcp::Size (1480, 1080));
+
+       c = Container::from_id ("138");
+       BOOST_CHECK (c);
+       BOOST_CHECK_EQUAL (c->size(libdcp::Size (2048, 1080)), libdcp::Size (1485, 1080));
+
+       c = Container::from_id ("166");
+       BOOST_CHECK (c);
+       BOOST_CHECK_EQUAL (c->size(libdcp::Size (2048, 1080)), libdcp::Size (1793, 1080));
+
+       c = Container::from_id ("178");
+       BOOST_CHECK (c);
+       BOOST_CHECK_EQUAL (c->size(libdcp::Size (2048, 1080)), libdcp::Size (1920, 1080));
+
+       c = Container::from_id ("185");
+       BOOST_CHECK (c);
+       BOOST_CHECK_EQUAL (c->size(libdcp::Size (2048, 1080)), libdcp::Size (1998, 1080));
+
+       c = Container::from_id ("239");
+       BOOST_CHECK (c);
+       BOOST_CHECK_EQUAL (c->size(libdcp::Size (2048, 1080)), libdcp::Size (2048, 858));
+
+       c = Container::from_id ("full-frame");
+       BOOST_CHECK (c);
+       BOOST_CHECK_EQUAL (c->size(libdcp::Size (2048, 1080)), libdcp::Size (2048, 1080));
+}
+
index 7e2715a02169112f899feaf493de4888119db374..f7e2b2e82dc771562e633ab0c121cb12ee4a327e 100644 (file)
@@ -93,6 +93,7 @@ new_test_film (string name)
        return f;
 }
 
+#include "container_test.cc"
 #include "pixel_formats_test.cc"
 #include "make_black_test.cc"
 #include "film_metadata_test.cc"