Missed update to private test repo version.
[dcpomatic.git] / src / lib / filter.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 /** @file src/filter.cc
22  *  @brief A class to describe one of FFmpeg's video or audio filters.
23  */
24
25 #include "filter.h"
26 extern "C" {
27 #include <libavfilter/avfilter.h>
28 }
29 #include <boost/foreach.hpp>
30 #include <iostream>
31
32 #include "i18n.h"
33
34 using namespace std;
35
36 vector<Filter const *> Filter::_filters;
37
38 /** @param i Our id.
39  *  @param n User-visible name.
40  *  @param c User-visible category.
41  *  @param f String for a FFmpeg filter descriptor.
42  */
43 Filter::Filter (string i, string n, string c, string f)
44         : _id (i)
45         , _name (n)
46         , _category (c)
47         , _ffmpeg (f)
48 {
49
50 }
51
52 /** @return All available filters */
53 vector<Filter const *>
54 Filter::all ()
55 {
56         return _filters;
57 }
58
59 /** Set up the static _filters vector; must be called before from_*
60  *  methods are used.
61  */
62 void
63 Filter::setup_filters ()
64 {
65         /* Note: "none" is a magic id name, so don't use it here */
66
67         maybe_add (N_("vflip"),       _("Vertical flip"),                    _("Orientation"),     N_("vflip"));
68         maybe_add (N_("hflip"),       _("Horizontal flip"),                  _("Orientation"),     N_("hflip"));
69         maybe_add (N_("90clock"),     _("Rotate 90 degrees clockwise"),      _("Orientation"),     N_("transpose=dir=clock"));
70         maybe_add (N_("90anticlock"), _("Rotate 90 degrees anti-clockwise"), _("Orientation"),     N_("transpose=dir=cclock"));
71         maybe_add (N_("mcdeint"),     _("Motion compensating deinterlacer"), _("De-interlacing"),  N_("mcdeint"));
72         maybe_add (N_("kerndeint"),   _("Kernel deinterlacer"),              _("De-interlacing"),  N_("kerndeint"));
73         maybe_add (N_("yadif"),       _("Yet Another Deinterlacing Filter"), _("De-interlacing"),  N_("yadif"));
74         maybe_add (N_("weave"),       _("Weave filter"),                     _("De-interlacing"),  N_("weave"));
75         maybe_add (N_("gradfun"),     _("Gradient debander"),                _("Misc"),            N_("gradfun"));
76         maybe_add (N_("unsharp"),     _("Unsharp mask and Gaussian blur"),   _("Misc"),            N_("unsharp"));
77         maybe_add (N_("denoise3d"),   _("3D denoiser"),                      _("Noise reduction"), N_("denoise3d"));
78         maybe_add (N_("hqdn3d"),      _("High quality 3D denoiser"),         _("Noise reduction"), N_("hqdn3d"));
79         maybe_add (N_("telecine"),    _("Telecine filter"),                  _("Misc"),            N_("telecine"));
80         maybe_add (N_("ow"),          _("Overcomplete wavelet denoiser"),    _("Noise reduction"), N_("mp=ow"));
81 }
82
83 void
84 Filter::maybe_add (string i, string n, string c, string f)
85 {
86         string check_name = f;
87         size_t end = check_name.find("=");
88         if (end != string::npos) {
89                 check_name = check_name.substr (0, end);
90         }
91
92         if (avfilter_get_by_name (check_name.c_str())) {
93                 _filters.push_back (new Filter (i, n, c, f));
94         }
95 }
96
97 /** @param filters Set of filters.
98  *  @return String to pass to FFmpeg for the video filters.
99  */
100 string
101 Filter::ffmpeg_string (vector<Filter const *> const & filters)
102 {
103         string ff;
104
105         BOOST_FOREACH (Filter const * i, filters) {
106                 if (!ff.empty ()) {
107                         ff += N_(",");
108                 }
109                 ff += i->ffmpeg ();
110         }
111
112         return ff;
113 }
114
115 /** @param d Our id.
116  *  @return Corresponding Filter, or 0.
117  */
118 Filter const *
119 Filter::from_id (string d)
120 {
121         vector<Filter const *>::iterator i = _filters.begin ();
122         while (i != _filters.end() && (*i)->id() != d) {
123                 ++i;
124         }
125
126         if (i == _filters.end ()) {
127                 return 0;
128         }
129
130         return *i;
131 }