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
36 using std::setprecision;
37 using std::stringstream;
39 using boost::shared_ptr;
42 vector<Format const *> Format::_formats;
44 /** @return A name to be presented to the user */
46 FixedFormat::name () const
49 if (!_nickname.empty ()) {
50 s << _nickname << N_(" (");
53 s << setprecision(3) << (_ratio / 100.0) << N_(":1");
55 if (!_nickname.empty ()) {
62 /** @return Identifier for this format as metadata for a Film's metadata file */
64 Format::as_metadata () const
69 /** Fill our _formats vector with all available formats */
71 Format::setup_formats ()
73 /// TRANSLATORS: these are film picture aspect ratios; "Academy" means 1.37, "Flat" 1.85 and "Scope" 2.39.
75 new FixedFormat (119, libdcp::Size (1285, 1080), N_("119"), _("1.19"), N_("F"),
76 _("Source scaled to 1.19:1")
80 new FixedFormat (133, libdcp::Size (1436, 1080), N_("133"), _("1.33"), N_("F"),
81 _("Source scaled to 1.33:1")
85 new FixedFormat (138, libdcp::Size (1485, 1080), N_("138"), _("1.375"), N_("F"),
86 _("Source scaled to 1.375:1")
90 new FixedFormat (133, libdcp::Size (1998, 1080), N_("133-in-flat"), _("4:3 within Flat"), N_("F"),
91 _("Source scaled to 1.33:1 then pillarboxed to Flat")
95 new FixedFormat (137, libdcp::Size (1480, 1080), N_("137"), _("Academy"), N_("F"),
96 _("Source scaled to 1.37:1 (Academy ratio)")
100 new FixedFormat (166, libdcp::Size (1793, 1080), N_("166"), _("1.66"), N_("F"),
101 _("Source scaled to 1.66:1")
105 new FixedFormat (166, libdcp::Size (1998, 1080), N_("166-in-flat"), _("1.66 within Flat"), N_("F"),
106 _("Source scaled to 1.66:1 then pillarboxed to Flat")
110 new FixedFormat (178, libdcp::Size (1998, 1080), N_("178-in-flat"), _("16:9 within Flat"), N_("F"),
111 _("Source scaled to 1.78:1 then pillarboxed to Flat")
115 new FixedFormat (178, libdcp::Size (1920, 1080), N_("178"), _("16:9"), N_("F"),
116 _("Source scaled to 1.78:1")
120 new FixedFormat (185, libdcp::Size (1998, 1080), N_("185"), _("Flat"), N_("F"),
121 _("Source scaled to Flat (1.85:1)")
125 new FixedFormat (239, libdcp::Size (2048, 858), N_("239"), _("Scope"), N_("S"),
126 _("Source scaled to Scope (2.39:1)")
130 new VariableFormat (libdcp::Size (1998, 1080), N_("var-185"), _("Flat without stretch"), N_("F"),
131 _("Source scaled to fit Flat preserving its aspect ratio")
135 new VariableFormat (libdcp::Size (2048, 858), N_("var-239"), _("Scope without stretch"), N_("S"),
136 _("Source scaled to fit Scope preserving its aspect ratio")
140 /** @param n Nickname.
141 * @return Matching Format, or 0.
144 Format::from_nickname (string n)
146 vector<Format const *>::iterator i = _formats.begin ();
147 while (i != _formats.end() && (*i)->nickname() != n) {
151 if (i == _formats.end ()) {
159 * @return Matching Format, or 0.
162 Format::from_id (string i)
164 vector<Format const *>::iterator j = _formats.begin ();
165 while (j != _formats.end() && (*j)->id() != i) {
169 if (j == _formats.end ()) {
177 /** @param m Metadata, as returned from as_metadata().
178 * @return Matching Format, or 0.
181 Format::from_metadata (string m)
186 /** @return All available formats */
187 vector<Format const *>
193 /** @param r Ratio multiplied by 100 (e.g. 185)
194 * @param dcp Size (in pixels) of the images that we should put in a DCP.
195 * @param id ID (e.g. 185)
196 * @param n Nick name (e.g. Flat)
198 FixedFormat::FixedFormat (int r, libdcp::Size dcp, string id, string n, string d, string e)
199 : Format (dcp, id, n, d, e)
205 /** @return Number of pixels (int the DCP image) to pad either side of the film
206 * (so there are dcp_padding() pixels on the left and dcp_padding() on the right)
209 Format::dcp_padding (shared_ptr<const Film> f) const
211 int p = rint ((_dcp_size.width - (_dcp_size.height * ratio_as_integer(f) / 100.0)) / 2.0);
213 /* This comes out -ve for Scope; bodge it */
222 Format::container_ratio_as_float () const
224 return static_cast<float> (_dcp_size.width) / _dcp_size.height;
227 VariableFormat::VariableFormat (libdcp::Size dcp, string id, string n, string d, string e)
228 : Format (dcp, id, n, d, e)
234 VariableFormat::ratio_as_integer (shared_ptr<const Film> f) const
236 return rint (ratio_as_float (f) * 100);
240 VariableFormat::ratio_as_float (shared_ptr<const Film> f) const
242 return float (f->size().width) / f->size().height;
245 /** @return A name to be presented to the user */
247 VariableFormat::name () const