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
37 using std::setprecision;
38 using std::stringstream;
40 using boost::shared_ptr;
43 vector<Format const *> Format::_formats;
45 /** @return A name to be presented to the user */
47 FixedFormat::name () const
50 if (!_nickname.empty ()) {
51 s << _nickname << N_(" (");
54 s << setprecision(3) << (_ratio / 100.0) << N_(":1");
56 if (!_nickname.empty ()) {
63 /** @return Identifier for this format as metadata for a Film's metadata file */
65 Format::as_metadata () const
70 /** Fill our _formats vector with all available formats */
72 Format::setup_formats ()
74 /// TRANSLATORS: these are film picture aspect ratios; "Academy" means 1.37, "Flat" 1.85 and "Scope" 2.39.
76 new FixedFormat (119, libdcp::Size (1285, 1080), N_("119"), _("1.19"), N_("F"),
77 _("Source scaled to 1.19:1")
81 new FixedFormat (133, libdcp::Size (1436, 1080), N_("133"), _("1.33"), N_("F"),
82 _("Source scaled to 1.33:1")
86 new FixedFormat (138, libdcp::Size (1485, 1080), N_("138"), _("1.375"), N_("F"),
87 _("Source scaled to 1.375:1")
91 new FixedFormat (133, libdcp::Size (1998, 1080), N_("133-in-flat"), _("4:3 within Flat"), N_("F"),
92 _("Source scaled to 1.33:1 then pillarboxed to Flat")
96 new FixedFormat (137, libdcp::Size (1480, 1080), N_("137"), _("Academy"), N_("F"),
97 _("Source scaled to 1.37:1 (Academy ratio)")
101 new FixedFormat (166, libdcp::Size (1793, 1080), N_("166"), _("1.66"), N_("F"),
102 _("Source scaled to 1.66:1")
106 new FixedFormat (166, libdcp::Size (1998, 1080), N_("166-in-flat"), _("1.66 within Flat"), N_("F"),
107 _("Source scaled to 1.66:1 then pillarboxed to Flat")
111 new FixedFormat (178, libdcp::Size (1998, 1080), N_("178-in-flat"), _("16:9 within Flat"), N_("F"),
112 _("Source scaled to 1.78:1 then pillarboxed to Flat")
116 new FixedFormat (178, libdcp::Size (1920, 1080), N_("178"), _("16:9"), N_("F"),
117 _("Source scaled to 1.78:1")
121 new FixedFormat (185, libdcp::Size (1998, 1080), N_("185"), _("Flat"), N_("F"),
122 _("Source scaled to Flat (1.85:1)")
126 new FixedFormat (239, libdcp::Size (2048, 858), N_("239"), _("Scope"), N_("S"),
127 _("Source scaled to Scope (2.39:1)")
131 new VariableFormat (libdcp::Size (1998, 1080), N_("var-185"), _("Flat without stretch"), N_("F"),
132 _("Source scaled to fit Flat preserving its aspect ratio")
136 new VariableFormat (libdcp::Size (2048, 858), N_("var-239"), _("Scope without stretch"), N_("S"),
137 _("Source scaled to fit Scope preserving its aspect ratio")
141 /** @param n Nickname.
142 * @return Matching Format, or 0.
145 Format::from_nickname (string n)
147 vector<Format const *>::iterator i = _formats.begin ();
148 while (i != _formats.end() && (*i)->nickname() != n) {
152 if (i == _formats.end ()) {
160 * @return Matching Format, or 0.
163 Format::from_id (string i)
165 vector<Format const *>::iterator j = _formats.begin ();
166 while (j != _formats.end() && (*j)->id() != i) {
170 if (j == _formats.end ()) {
178 /** @param m Metadata, as returned from as_metadata().
179 * @return Matching Format, or 0.
182 Format::from_metadata (string m)
187 /** @return All available formats */
188 vector<Format const *>
194 /** @param r Ratio multiplied by 100 (e.g. 185)
195 * @param dcp Size (in pixels) of the images that we should put in a DCP.
196 * @param id ID (e.g. 185)
197 * @param n Nick name (e.g. Flat)
199 FixedFormat::FixedFormat (int r, libdcp::Size dcp, string id, string n, string d, string e)
200 : Format (dcp, id, n, d, e)
206 /** @return Number of pixels (int the DCP image) to pad either side of the film
207 * (so there are dcp_padding() pixels on the left and dcp_padding() on the right)
210 Format::dcp_padding (shared_ptr<const Film> f) const
212 int pad = rint ((_dcp_size.width - (_dcp_size.height * ratio_as_integer(f) / 100.0)) / 2.0);
214 /* This comes out -ve for Scope; bodge it */
223 Format::container_ratio_as_float () const
225 return static_cast<float> (_dcp_size.width) / _dcp_size.height;
228 VariableFormat::VariableFormat (libdcp::Size dcp, string id, string n, string d, string e)
229 : Format (dcp, id, n, d, e)
235 VariableFormat::ratio_as_integer (shared_ptr<const Film> f) const
237 return rint (ratio_as_float (f) * 100);
241 VariableFormat::ratio_as_float (shared_ptr<const Film> f) const
243 return float (f->video_size().width) / f->video_size().height;
246 /** @return A name to be presented to the user */
248 VariableFormat::name () const