Move things round a bit.
[dcpomatic.git] / src / lib / filter.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/filter.cc
21  *  @brief A class to describe one of FFmpeg's video or post-processing filters.
22  */
23
24 #include "filter.h"
25
26 using namespace std;
27
28 vector<Filter const *> Filter::_filters;
29
30 /** @param i Our id.
31  *  @param n User-visible name.
32  *  @param v String for a FFmpeg video filter descriptor, or "".
33  *  @param p String for a FFmpeg post-processing descriptor, or "".
34  */
35 Filter::Filter (string i, string n, string v, string p)
36         : _id (i)
37         , _name (n)
38         , _vf (v)
39         , _pp (p)
40 {
41
42 }
43
44 /** @return All available filters */
45 vector<Filter const *>
46 Filter::all ()
47 {
48         return _filters;
49 }
50
51
52 /** Set up the static _filters vector; must be called before from_*
53  *  methods are used.
54  */
55 void
56 Filter::setup_filters ()
57 {
58         /* Note: "none" is a magic id name, so don't use it here */
59            
60         _filters.push_back (new Filter ("pphb", "Horizontal deblocking filter", "", "hb"));
61         _filters.push_back (new Filter ("ppvb", "Vertical deblocking filter", "", "vb"));
62         _filters.push_back (new Filter ("ppha", "Horizontal deblocking filter A", "", "ha"));
63         _filters.push_back (new Filter ("ppva", "Vertical deblocking filter A", "", "va"));
64         _filters.push_back (new Filter ("pph1", "Experimental horizontal deblocking filter 1", "", "h1"));
65         _filters.push_back (new Filter ("pphv", "Experimental vertical deblocking filter 1", "", "v1"));
66         _filters.push_back (new Filter ("ppdr", "Deringing filter", "", "dr"));
67         _filters.push_back (new Filter ("pplb", "Linear blend deinterlacer", "", "lb"));
68         _filters.push_back (new Filter ("ppli", "Linear interpolating deinterlacer", "", "li"));
69         _filters.push_back (new Filter ("ppci", "Cubic interpolating deinterlacer", "", "ci"));
70         _filters.push_back (new Filter ("ppmd", "Median deinterlacer", "", "md"));
71         _filters.push_back (new Filter ("ppfd", "FFMPEG deinterlacer", "", "fd"));
72         _filters.push_back (new Filter ("ppl5", "FIR low-pass deinterlacer", "", "l5"));
73         _filters.push_back (new Filter ("mcdeint", "Motion compensating deinterlacer", "mcdeint", ""));
74         _filters.push_back (new Filter ("kerndeint", "Kernel deinterlacer", "kerndeint", ""));
75         _filters.push_back (new Filter ("pptn", "Temporal noise reducer", "", "tn"));
76         _filters.push_back (new Filter ("ppfq", "Force quantizer", "", "fq"));
77         _filters.push_back (new Filter ("gradfun", "Gradient debander", "gradfun", ""));
78         _filters.push_back (new Filter ("unsharp", "Unsharp mask and Gaussian blur", "unsharp", ""));
79         _filters.push_back (new Filter ("denoise3d", "3D denoiser", "denoise3d", ""));
80         _filters.push_back (new Filter ("hqdn3d", "High quality 3D denoiser", "hqdn3d", ""));
81         _filters.push_back (new Filter ("telecine", "Telecine filter", "telecine", ""));
82         _filters.push_back (new Filter ("ow", "Overcomplete wavelet denoiser", "mp=ow", ""));
83 }
84
85 /** @param filters Set of filters.
86  *  @return A pair; .first is a string to pass to FFmpeg for the video filters,
87  *  .second is a string to pass for the post-processors.
88  */
89 pair<string, string>
90 Filter::ffmpeg_strings (vector<Filter const *> const & filters)
91 {
92         string vf;
93         string pp;
94
95         for (vector<Filter const *>::const_iterator i = filters.begin(); i != filters.end(); ++i) {
96                 if (!(*i)->vf().empty ()) {
97                         if (!vf.empty ()) {
98                                 vf += ",";
99                         }
100                         vf += (*i)->vf ();
101                 }
102                 
103                 if (!(*i)->pp().empty ()) {
104                         if (!pp.empty()) {
105                                 pp += ",";
106                         }
107                         pp += (*i)->pp ();
108                 }
109         }
110
111         return make_pair (vf, pp);
112 }
113
114 /** @param d Our id.
115  *  @return Corresponding Filter, or 0.
116  */
117 Filter const *
118 Filter::from_id (string d)
119 {
120         vector<Filter const *>::iterator i = _filters.begin ();
121         while (i != _filters.end() && (*i)->id() != d) {
122                 ++i;
123         }
124
125         if (i == _filters.end ()) {
126                 return 0;
127         }
128
129         return *i;
130 }
131