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 vector<Format const *> Format::_formats;
36 /** @param r Ratio multiplied by 100 (e.g. 185)
37 * @param dcp Size (in pixels) of the images that we should put in a DCP.
38 * @param id ID (e.g. 185)
39 * @param n Nick name (e.g. Flat)
41 Format::Format (int r, Size dcp, string id, string n)
50 /** @return A name to be presented to the user */
55 if (!_nickname.empty ()) {
56 s << _nickname << " (";
59 s << setprecision(3) << (_ratio / 100.0) << ":1";
61 if (!_nickname.empty ()) {
68 /** @return Identifier for this format as metadata for a Film's metadata file */
70 Format::as_metadata () const
75 /** Fill our _formats vector with all available formats */
77 Format::setup_formats ()
79 _formats.push_back (new Format (133, Size (1998, 1080), "133-in-flat", "4:3 within Flat"));
80 _formats.push_back (new Format (137, Size (1480, 1080), "137", "Academy"));
81 _formats.push_back (new Format (178, Size (1998, 1080), "178-in-flat", "16:9 within Flat"));
82 _formats.push_back (new Format (185, Size (1998, 1080), "185", "Flat"));
83 _formats.push_back (new Format (239, Size (2048, 858), "239", "Scope"));
86 /** @param r Ratio multiplied by 100.
87 * @return Matching Format, or 0.
90 Format::from_ratio (int r)
92 vector<Format const *>::iterator i = _formats.begin ();
93 while (i != _formats.end() && (*i)->ratio_as_integer() != r) {
97 if (i == _formats.end ()) {
104 /** @param n Nickname.
105 * @return Matching Format, or 0.
108 Format::from_nickname (string n)
110 vector<Format const *>::iterator i = _formats.begin ();
111 while (i != _formats.end() && (*i)->nickname() != n) {
115 if (i == _formats.end ()) {
123 * @return Matching Format, or 0.
126 Format::from_id (string i)
128 vector<Format const *>::iterator j = _formats.begin ();
129 while (j != _formats.end() && (*j)->id() != i) {
133 if (j == _formats.end ()) {
141 /** @param m Metadata, as returned from as_metadata().
142 * @return Matching Format, or 0.
145 Format::from_metadata (string m)
150 /** @param f A Format.
151 * @return Index of f within our static list, or -1.
154 Format::as_index (Format const * f)
156 vector<Format*>::size_type i = 0;
157 while (i < _formats.size() && _formats[i] != f) {
161 if (i == _formats.size ()) {
168 /** @param i An index returned from as_index().
169 * @return Corresponding Format.
172 Format::from_index (int i)
174 assert (i >= 0 && i < int(_formats.size ()));
178 /** @return All available formats */
179 vector<Format const *>
186 Format::dcp_padding () const
188 int p = rint ((_dcp_size.width - (_dcp_size.height * _ratio / 100.0)) / 2.0);
190 /* This comes out -ve for Scope; bodge it */