a7dd9c5cee61c1f2e935705681f574a2a847ce17
[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 extern "C" {
26 #include <libavfilter/avfilter.h>
27 }
28
29 #include "i18n.h"
30
31 using namespace std;
32
33 vector<Filter const *> Filter::_filters;
34
35 /** @param i Our id.
36  *  @param n User-visible name.
37  *  @param c User-visible category.
38  *  @param v String for a FFmpeg video filter descriptor.
39  */
40 Filter::Filter (string i, string n, string c, string v)
41         : _id (i)
42         , _name (n)
43         , _category (c)
44         , _vf (v)
45 {
46
47 }
48
49 /** @return All available filters */
50 vector<Filter const *>
51 Filter::all ()
52 {
53         return _filters;
54 }
55
56
57 /** Set up the static _filters vector; must be called before from_*
58  *  methods are used.
59  */
60 void
61 Filter::setup_filters ()
62 {
63         /* Note: "none" is a magic id name, so don't use it here */
64            
65         maybe_add (N_("mcdeint"),   _("Motion compensating deinterlacer"),            _("De-interlacing"),  N_("mcdeint"));
66         maybe_add (N_("kerndeint"), _("Kernel deinterlacer"),                         _("De-interlacing"),  N_("kerndeint"));
67         maybe_add (N_("yadif"),     _("Yet Another Deinterlacing Filter"),            _("De-interlacing"),  N_("yadif"));
68         maybe_add (N_("gradfun"),   _("Gradient debander"),                           _("Misc"),            N_("gradfun"));
69         maybe_add (N_("unsharp"),   _("Unsharp mask and Gaussian blur"),              _("Misc"),            N_("unsharp"));
70         maybe_add (N_("denoise3d"), _("3D denoiser"),                                 _("Noise reduction"), N_("denoise3d"));
71         maybe_add (N_("hqdn3d"),    _("High quality 3D denoiser"),                    _("Noise reduction"), N_("hqdn3d"));
72         maybe_add (N_("telecine"),  _("Telecine filter"),                             _("Misc"),            N_("telecine"));
73         maybe_add (N_("ow"),        _("Overcomplete wavelet denoiser"),               _("Noise reduction"), N_("mp=ow"));
74 }
75
76 void
77 Filter::maybe_add (string i, string n, string c, string v)
78 {
79         if (avfilter_get_by_name (i.c_str())) {
80                 _filters.push_back (new Filter (i, n, c, v));
81         }
82 }
83
84 /** @param filters Set of filters.
85  *  @return String to pass to FFmpeg for the video filters.
86  */
87 string
88 Filter::ffmpeg_string (vector<Filter const *> const & filters)
89 {
90         string vf;
91
92         for (vector<Filter const *>::const_iterator i = filters.begin(); i != filters.end(); ++i) {
93                 if (!vf.empty ()) {
94                         vf += N_(",");
95                 }
96                 vf += (*i)->vf ();
97         }
98
99         return vf;
100 }
101
102 /** @param d Our id.
103  *  @return Corresponding Filter, or 0.
104  */
105 Filter const *
106 Filter::from_id (string d)
107 {
108         vector<Filter const *>::iterator i = _filters.begin ();
109         while (i != _filters.end() && (*i)->id() != d) {
110                 ++i;
111         }
112
113         if (i == _filters.end ()) {
114                 return 0;
115         }
116
117         return *i;
118 }
119