Remove film player, DVD ripping, alignment, screen configs; never finished and not...
[dcpomatic.git] / src / lib / scaler.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file src/scaler.cc
21  *  @brief A class to describe one of FFmpeg's software scalers.
22  */
23
24 #include <iostream>
25 #include <cassert>
26 extern "C" {
27 #include <libswscale/swscale.h>
28 }
29 #include "scaler.h"
30
31 using namespace std;
32
33 vector<Scaler const *> Scaler::_scalers;
34
35 /** @param f FFmpeg id.
36  *  @param i Our id.
37  *  @param n User-visible name.
38  */
39 Scaler::Scaler (int f, string i, string n)
40         : _ffmpeg_id (f)
41         , _id (i)
42         , _name (n)
43 {
44
45 }
46
47 /** @return All available scalers */
48 vector<Scaler const *>
49 Scaler::all ()
50 {
51         return _scalers;
52 }
53
54 /** Set up the static _scalers vector; must be called before from_*
55  *  methods are used.
56  */
57 void
58 Scaler::setup_scalers ()
59 {
60         _scalers.push_back (new Scaler (SWS_BICUBIC, "bicubic", "Bicubic"));
61         _scalers.push_back (new Scaler (SWS_X, "x", "X"));
62         _scalers.push_back (new Scaler (SWS_AREA, "area", "Area"));
63         _scalers.push_back (new Scaler (SWS_GAUSS, "gauss", "Gaussian"));
64         _scalers.push_back (new Scaler (SWS_LANCZOS, "lanczos", "Lanczos"));
65         _scalers.push_back (new Scaler (SWS_SINC, "sinc", "Sinc"));
66         _scalers.push_back (new Scaler (SWS_SPLINE, "spline", "Spline"));
67         _scalers.push_back (new Scaler (SWS_BILINEAR, "bilinear", "Bilinear"));
68         _scalers.push_back (new Scaler (SWS_FAST_BILINEAR, "fastbilinear", "Fast Bilinear"));
69 }
70
71 /** @param id One of our ids.
72  *  @return Corresponding scaler, or 0.
73  */
74 Scaler const *
75 Scaler::from_id (string id)
76 {
77         vector<Scaler const *>::iterator i = _scalers.begin ();
78         while (i != _scalers.end() && (*i)->id() != id) {
79                 ++i;
80         }
81
82         if (i == _scalers.end ()) {
83                 return 0;
84         }
85
86         return *i;
87 }
88
89 /** @param s A scaler from our static list.
90  *  @return Index of the scaler with the list, or -1.
91  */
92 int
93 Scaler::as_index (Scaler const * s)
94 {
95         vector<Scaler*>::size_type i = 0;
96         while (i < _scalers.size() && _scalers[i] != s) {
97                 ++i;
98         }
99
100         if (i == _scalers.size ()) {
101                 return -1;
102         }
103
104         return i;
105 }
106
107 /** @param i An index returned from as_index().
108  *  @return Corresponding scaler.
109  */
110 Scaler const *
111 Scaler::from_index (int i)
112 {
113         assert (i <= int(_scalers.size ()));
114         return _scalers[i];
115 }