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 << N_(":1");
56 if (!_nickname.empty ()) {
63 /** Fill our _formats vector with all available formats */
65 Format::setup_formats ()
67 /// TRANSLATORS: these are film picture aspect ratios; "Academy" means 1.37, "Flat" 1.85 and "Scope" 2.39.
69 new FixedFormat (1.19, libdcp::Size (1285, 1080), N_("119"), _("1.19"), N_("F")
73 new FixedFormat (4.0 / 3.0, libdcp::Size (1436, 1080), N_("133"), _("4:3"), N_("F")
77 new FixedFormat (1.38, libdcp::Size (1485, 1080), N_("138"), _("1.375"), N_("F")
81 new FixedFormat (4.0 / 3.0, libdcp::Size (1998, 1080), N_("133-in-flat"), _("4:3 within Flat"), N_("F")
85 new FixedFormat (1.37, libdcp::Size (1480, 1080), N_("137"), _("Academy"), N_("F")
89 new FixedFormat (1.66, libdcp::Size (1793, 1080), N_("166"), _("1.66"), N_("F")
93 new FixedFormat (1.66, libdcp::Size (1998, 1080), N_("166-in-flat"), _("1.66 within Flat"), N_("F")
97 new FixedFormat (1.78, libdcp::Size (1998, 1080), N_("178-in-flat"), _("16:9 within Flat"), N_("F")
101 new FixedFormat (1.78, libdcp::Size (1920, 1080), N_("178"), _("16:9"), N_("F")
105 new FixedFormat (1.85, libdcp::Size (1998, 1080), N_("185"), _("Flat"), N_("F")
109 new FixedFormat (1.78, libdcp::Size (2048, 858), N_("178-in-scope"), _("16:9 within Scope"), N_("S")
113 new FixedFormat (2.39, libdcp::Size (2048, 858), N_("239"), _("Scope"), N_("S")
117 new VariableFormat (libdcp::Size (1998, 1080), N_("var-185"), _("Flat without stretch"), N_("F")
121 new VariableFormat (libdcp::Size (2048, 858), N_("var-239"), _("Scope without stretch"), N_("S")
125 /** @param n Nickname.
126 * @return Matching Format, or 0.
129 Format::from_nickname (string n)
131 vector<Format const *>::iterator i = _formats.begin ();
132 while (i != _formats.end() && (*i)->nickname() != n) {
136 if (i == _formats.end ()) {
144 * @return Matching Format, or 0.
147 Format::from_id (string i)
149 vector<Format const *>::iterator j = _formats.begin ();
150 while (j != _formats.end() && (*j)->id() != i) {
154 if (j == _formats.end ()) {
161 /** @return All available formats */
162 vector<Format const *>
169 * @param dcp Size (in pixels) of the images that we should put in a DCP.
170 * @param id ID (e.g. 185)
171 * @param n Nick name (e.g. Flat)
173 FixedFormat::FixedFormat (float r, libdcp::Size dcp, string id, string n, string d)
174 : Format (dcp, id, n, d)
180 /** @return Number of pixels (int the DCP image) to pad either side of the film
181 * (so there are dcp_padding() pixels on the left and dcp_padding() on the right)
184 Format::dcp_padding (shared_ptr<const Film> f) const
186 int p = rint ((_dcp_size.width - (_dcp_size.height * ratio(f))) / 2.0);
188 /* This comes out -ve for Scope; bodge it */
197 Format::container_ratio () const
199 return static_cast<float> (_dcp_size.width) / _dcp_size.height;
202 VariableFormat::VariableFormat (libdcp::Size dcp, string id, string n, string d)
203 : Format (dcp, id, n, d)
209 VariableFormat::ratio (shared_ptr<const Film> f) const
211 libdcp::Size const c = f->cropped_size (f->video_size ());
212 return float (c.width) / c.height;
215 /** @return A name to be presented to the user */
217 VariableFormat::name () const