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;
39 vector<Format const *> Format::_formats;
41 /** @return A name to be presented to the user */
43 FixedFormat::name () const
46 if (!_nickname.empty ()) {
47 s << _nickname << " (";
50 s << setprecision(3) << (_ratio / 100.0) << ":1";
52 if (!_nickname.empty ()) {
59 /** @return Identifier for this format as metadata for a Film's metadata file */
61 Format::as_metadata () const
66 /** Fill our _formats vector with all available formats */
68 Format::setup_formats ()
70 _formats.push_back (new FixedFormat (119, Size (1285, 1080), "119", "1.19", "F"));
71 _formats.push_back (new FixedFormat (133, Size (1436, 1080), "133", "1.33", "F"));
72 _formats.push_back (new FixedFormat (138, Size (1485, 1080), "138", "1.375", "F"));
73 _formats.push_back (new FixedFormat (133, Size (1998, 1080), "133-in-flat", "4:3 within Flat", "F"));
74 _formats.push_back (new FixedFormat (137, Size (1480, 1080), "137", "Academy", "F"));
75 _formats.push_back (new FixedFormat (166, Size (1793, 1080), "166", "1.66", "F"));
76 _formats.push_back (new FixedFormat (166, Size (1998, 1080), "166-in-flat", "1.66 within Flat", "F"));
77 _formats.push_back (new FixedFormat (178, Size (1998, 1080), "178-in-flat", "16:9 within Flat", "F"));
78 _formats.push_back (new FixedFormat (178, Size (1920, 1080), "178", "16:9", "F"));
79 _formats.push_back (new FixedFormat (185, Size (1998, 1080), "185", "Flat", "F"));
80 _formats.push_back (new FixedFormat (239, Size (2048, 858), "239", "Scope", "S"));
81 _formats.push_back (new VariableFormat (Size (1998, 1080), "var-185", "Flat", "F"));
82 _formats.push_back (new VariableFormat (Size (2048, 858), "var-239", "Scope", "S"));
85 /** @param n Nickname.
86 * @return Matching Format, or 0.
89 Format::from_nickname (string n)
91 vector<Format const *>::iterator i = _formats.begin ();
92 while (i != _formats.end() && (*i)->nickname() != n) {
96 if (i == _formats.end ()) {
104 * @return Matching Format, or 0.
107 Format::from_id (string i)
109 vector<Format const *>::iterator j = _formats.begin ();
110 while (j != _formats.end() && (*j)->id() != i) {
114 if (j == _formats.end ()) {
122 /** @param m Metadata, as returned from as_metadata().
123 * @return Matching Format, or 0.
126 Format::from_metadata (string m)
131 /** @return All available formats */
132 vector<Format const *>
138 /** @param r Ratio multiplied by 100 (e.g. 185)
139 * @param dcp Size (in pixels) of the images that we should put in a DCP.
140 * @param id ID (e.g. 185)
141 * @param n Nick name (e.g. Flat)
143 FixedFormat::FixedFormat (int r, Size dcp, string id, string n, string d)
144 : Format (dcp, id, n, d)
151 Format::dcp_padding (shared_ptr<const Film> f) const
153 int p = rint ((_dcp_size.width - (_dcp_size.height * ratio_as_integer(f) / 100.0)) / 2.0);
155 /* This comes out -ve for Scope; bodge it */
163 VariableFormat::VariableFormat (Size dcp, string id, string n, string d)
164 : Format (dcp, id, n, d)
170 VariableFormat::ratio_as_integer (shared_ptr<const Film> f) const
172 return rint (ratio_as_float (f) * 100);
176 VariableFormat::ratio_as_float (shared_ptr<const Film> f) const
178 return float (f->size().width) / f->size().height;
181 /** @return A name to be presented to the user */
183 VariableFormat::name () const