2 Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
25 #include <dcp/types.h>
33 using boost::optional;
36 vector<Ratio const *> Ratio::_ratios;
40 Ratio::setup_ratios ()
42 _ratios.push_back (new Ratio(float(1290) / 1080, "119", _("1.19"), optional<string>(), "119"));
43 _ratios.push_back (new Ratio(float(1440) / 1080, "133", _("1.33 (4:3)"), optional<string>(), "133"));
44 _ratios.push_back (new Ratio(float(1485) / 1080, "138", _("1.38 (Academy)"), optional<string>(), "137"));
45 _ratios.push_back (new Ratio(float(1544) / 1080, "143", _("1.43 (IMAX)"), optional<string>(), "143"));
46 _ratios.push_back (new Ratio(float(1800) / 1080, "166", _("1.66"), optional<string>(), "166"));
47 _ratios.push_back (new Ratio(float(1920) / 1080, "178", _("1.78 (16:9 or HD)"), optional<string>(), "178"));
48 _ratios.push_back (new Ratio(float(1998) / 1080, "185", _("1.85 (Flat)"), string(_("DCI Flat")), "F"));
49 _ratios.push_back (new Ratio(float(2048) / 872, "235", _("2.35 (35mm Scope)"), optional<string>(), "S"));
50 _ratios.push_back (new Ratio(float(2048) / 858, "239", _("2.39 (Scope)"), string(_("DCI Scope")), "S"));
51 _ratios.push_back (new Ratio(float(2048) / 1080, "190", _("1.90 (Full frame)"), string(_("Full frame")), "C"));
56 Ratio::from_id (string i)
58 /* We removed the ratio with id 137; replace it with 138 */
63 auto j = _ratios.begin ();
64 while (j != _ratios.end() && (*j)->id() != i) {
68 if (j == _ratios.end ()) {
76 /** @return Ratio corresponding to a given fractional ratio (+/- 0.01), or 0 */
78 Ratio::from_ratio (float r)
80 auto j = _ratios.begin ();
81 while (j != _ratios.end() && fabs((*j)->ratio() - r) > 0.01) {
85 if (j == _ratios.end ()) {
94 Ratio::nearest_from_ratio (float r)
96 Ratio const * nearest = nullptr;
97 float distance = FLT_MAX;
99 for (auto i = _ratios.begin(); i != _ratios.end(); ++i) {
100 float const d = fabs((*i)->ratio() - r);
110 vector<Ratio const *>
113 if (Config::instance()->allow_any_container()) {
117 vector<Ratio const *> r;
118 r.push_back (Ratio::from_id ("185"));
119 r.push_back (Ratio::from_id ("239"));
125 Ratio::container_nickname () const
127 if (!_container_nickname) {
128 /* Fall back to the image nickname; this just for when non-standard container
131 return _image_nickname;
134 return *_container_nickname;