2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/format.cc
21 * @brief Class to describe a format (aspect ratio) that a Film should
34 using std::setprecision;
35 using std::stringstream;
37 using boost::shared_ptr;
40 vector<Format const *> Format::_formats;
42 /** @return A name to be presented to the user */
44 FixedFormat::name () const
47 if (!_nickname.empty ()) {
48 s << _nickname << " (";
51 s << setprecision(3) << (_ratio / 100.0) << ":1";
53 if (!_nickname.empty ()) {
60 /** @return Identifier for this format as metadata for a Film's metadata file */
62 Format::as_metadata () const
67 /** Fill our _formats vector with all available formats */
69 Format::setup_formats ()
71 _formats.push_back (new FixedFormat (119, libdcp::Size (1285, 1080), "119", "1.19", "F"));
72 _formats.push_back (new FixedFormat (133, libdcp::Size (1436, 1080), "133", "1.33", "F"));
73 _formats.push_back (new FixedFormat (138, libdcp::Size (1485, 1080), "138", "1.375", "F"));
74 _formats.push_back (new FixedFormat (133, libdcp::Size (1998, 1080), "133-in-flat", "4:3 within Flat", "F"));
75 _formats.push_back (new FixedFormat (137, libdcp::Size (1480, 1080), "137", "Academy", "F"));
76 _formats.push_back (new FixedFormat (166, libdcp::Size (1793, 1080), "166", "1.66", "F"));
77 _formats.push_back (new FixedFormat (166, libdcp::Size (1998, 1080), "166-in-flat", "1.66 within Flat", "F"));
78 _formats.push_back (new FixedFormat (178, libdcp::Size (1998, 1080), "178-in-flat", "16:9 within Flat", "F"));
79 _formats.push_back (new FixedFormat (178, libdcp::Size (1920, 1080), "178", "16:9", "F"));
80 _formats.push_back (new FixedFormat (185, libdcp::Size (1998, 1080), "185", "Flat", "F"));
81 _formats.push_back (new FixedFormat (239, libdcp::Size (2048, 858), "239", "Scope", "S"));
82 _formats.push_back (new VariableFormat (libdcp::Size (1998, 1080), "var-185", "Flat", "F"));
83 _formats.push_back (new VariableFormat (libdcp::Size (2048, 858), "var-239", "Scope", "S"));
86 /** @param n Nickname.
87 * @return Matching Format, or 0.
90 Format::from_nickname (string n)
92 vector<Format const *>::iterator i = _formats.begin ();
93 while (i != _formats.end() && (*i)->nickname() != n) {
97 if (i == _formats.end ()) {
105 * @return Matching Format, or 0.
108 Format::from_id (string i)
110 vector<Format const *>::iterator j = _formats.begin ();
111 while (j != _formats.end() && (*j)->id() != i) {
115 if (j == _formats.end ()) {
123 /** @param m Metadata, as returned from as_metadata().
124 * @return Matching Format, or 0.
127 Format::from_metadata (string m)
132 /** @return All available formats */
133 vector<Format const *>
139 /** @param r Ratio multiplied by 100 (e.g. 185)
140 * @param dcp Size (in pixels) of the images that we should put in a DCP.
141 * @param id ID (e.g. 185)
142 * @param n Nick name (e.g. Flat)
144 FixedFormat::FixedFormat (int r, libdcp::Size dcp, string id, string n, string d)
145 : Format (dcp, id, n, d)
152 Format::dcp_padding (shared_ptr<const Film> f) const
154 int p = rint ((_dcp_size.width - (_dcp_size.height * ratio_as_integer(f) / 100.0)) / 2.0);
156 /* This comes out -ve for Scope; bodge it */
164 VariableFormat::VariableFormat (libdcp::Size dcp, string id, string n, string d)
165 : Format (dcp, id, n, d)
171 VariableFormat::ratio_as_integer (shared_ptr<const Film> f) const
173 return rint (ratio_as_float (f) * 100);
177 VariableFormat::ratio_as_float (shared_ptr<const Film> f) const
179 return float (f->size().width) / f->size().height;
182 /** @return A name to be presented to the user */
184 VariableFormat::name () const