Move things round a bit.
[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 m mplayer command line id.
37  *  @param i Our id.
38  *  @param n User-visible name.
39  */
40 Scaler::Scaler (int f, int m, string i, string n)
41         : _ffmpeg_id (f)
42         , _mplayer_id (m)
43         , _id (i)
44         , _name (n)
45 {
46
47 }
48
49 /** @return All available scalers */
50 vector<Scaler const *>
51 Scaler::all ()
52 {
53         return _scalers;
54 }
55
56 /** Set up the static _scalers vector; must be called before from_*
57  *  methods are used.
58  */
59 void
60 Scaler::setup_scalers ()
61 {
62         _scalers.push_back (new Scaler (SWS_BICUBIC, 2, "bicubic", "Bicubic"));
63         _scalers.push_back (new Scaler (SWS_X, 3, "x", "X"));
64         _scalers.push_back (new Scaler (SWS_AREA, 5, "area", "Area"));
65         _scalers.push_back (new Scaler (SWS_GAUSS, 7, "gauss", "Gaussian"));
66         _scalers.push_back (new Scaler (SWS_LANCZOS, 9, "lanczos", "Lanczos"));
67         _scalers.push_back (new Scaler (SWS_SINC, 8, "sinc", "Sinc"));
68         _scalers.push_back (new Scaler (SWS_SPLINE, 10, "spline", "Spline"));
69         _scalers.push_back (new Scaler (SWS_BILINEAR, 1, "bilinear", "Bilinear"));
70         _scalers.push_back (new Scaler (SWS_FAST_BILINEAR, 0, "fastbilinear", "Fast Bilinear"));
71 }
72
73 /** @param id One of our ids.
74  *  @return Corresponding scaler, or 0.
75  */
76 Scaler const *
77 Scaler::from_id (string id)
78 {
79         vector<Scaler const *>::iterator i = _scalers.begin ();
80         while (i != _scalers.end() && (*i)->id() != id) {
81                 ++i;
82         }
83
84         if (i == _scalers.end ()) {
85                 return 0;
86         }
87
88         return *i;
89 }
90
91 /** @param s A scaler from our static list.
92  *  @return Index of the scaler with the list, or -1.
93  */
94 int
95 Scaler::as_index (Scaler const * s)
96 {
97         vector<Scaler*>::size_type i = 0;
98         while (i < _scalers.size() && _scalers[i] != s) {
99                 ++i;
100         }
101
102         if (i == _scalers.size ()) {
103                 return -1;
104         }
105
106         return i;
107 }
108
109 /** @param i An index returned from as_index().
110  *  @return Corresponding scaler.
111  */
112 Scaler const *
113 Scaler::from_index (int i)
114 {
115         assert (i <= int(_scalers.size ()));
116         return _scalers[i];
117 }