Updated cs_CZ translation from Tomáš Begeni.
[dcpomatic.git] / src / lib / filter.cc
index 640a531e8aeb7185471c472542af2fed8e3fdbb0..9a14795eccf70c9ebe26427ff35c058da262c4d2 100644 (file)
@@ -1,56 +1,66 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
+    DCP-o-matic is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
+
 /** @file src/filter.cc
- *  @brief A class to describe one of FFmpeg's video or post-processing filters.
+ *  @brief A class to describe one of FFmpeg's video or audio filters.
  */
 
+
+#include "dcpomatic_assert.h"
 #include "filter.h"
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 extern "C" {
 #include <libavfilter/avfilter.h>
-#include <libpostproc/postprocess.h>
 }
+LIBDCP_ENABLE_WARNINGS
+#include <algorithm>
 
 #include "i18n.h"
 
+
 using namespace std;
+using boost::optional;
 
-vector<Filter const *> Filter::_filters;
 
-/** @param i Our id.
- *  @param n User-visible name.
- *  @param c User-visible category.
- *  @param v String for a FFmpeg video filter descriptor, or "".
- *  @param p String for a FFmpeg post-processing descriptor, or "".
+vector<Filter> Filter::_filters;
+
+
+/** @param id Our id.
+ *  @param name User-visible name.
+ *  @param category User-visible category.
+ *  @param ffmpeg_string String for a FFmpeg filter descriptor.
  */
-Filter::Filter (string i, string n, string c, string v, string p)
-       : _id (i)
-       , _name (n)
-       , _category (c)
-       , _vf (v)
-       , _pp (p)
+Filter::Filter(string id, string name, string category, string ffmpeg_string)
+       : _id(id)
+       , _name(name)
+       , _category(category)
+       , _ffmpeg(ffmpeg_string)
 {
 
 }
 
+
 /** @return All available filters */
-vector<Filter const *>
+vector<Filter>
 Filter::all ()
 {
        return _filters;
@@ -64,93 +74,100 @@ void
 Filter::setup_filters ()
 {
        /* Note: "none" is a magic id name, so don't use it here */
-          
-       maybe_add (N_("pphb"),      _("Horizontal deblocking filter"),                _("De-blocking"),     N_(""),          N_("hb"));
-       maybe_add (N_("ppvb"),      _("Vertical deblocking filter"),                  _("De-blocking"),     N_(""),          N_("vb"));
-       maybe_add (N_("ppha"),      _("Horizontal deblocking filter A"),              _("De-blocking"),     N_(""),          N_("ha"));
-       maybe_add (N_("ppva"),      _("Vertical deblocking filter A"),                _("De-blocking"),     N_(""),          N_("va"));
-       maybe_add (N_("pph1"),      _("Experimental horizontal deblocking filter 1"), _("De-blocking"),     N_(""),          N_("h1"));
-       maybe_add (N_("pphv"),      _("Experimental vertical deblocking filter 1"),   _("De-blocking"),     N_(""),          N_("v1"));
-       maybe_add (N_("ppdr"),      _("Deringing filter"),                            _("Misc"),            N_(""),          N_("dr"));
-       maybe_add (N_("pplb"),      _("Linear blend deinterlacer"),                   _("De-interlacing"),  N_(""),          N_("lb"));
-       maybe_add (N_("ppli"),      _("Linear interpolating deinterlacer"),           _("De-interlacing"),  N_(""),          N_("li"));
-       maybe_add (N_("ppci"),      _("Cubic interpolating deinterlacer"),            _("De-interlacing"),  N_(""),          N_("ci"));
-       maybe_add (N_("ppmd"),      _("Median deinterlacer"),                         _("De-interlacing"),  N_(""),          N_("md"));
-       maybe_add (N_("ppfd"),      _("FFMPEG deinterlacer"),                         _("De-interlacing"),  N_(""),          N_("fd"));
-       maybe_add (N_("ppl5"),      _("FIR low-pass deinterlacer"),                   _("De-interlacing"),  N_(""),          N_("l5"));
-       maybe_add (N_("mcdeint"),   _("Motion compensating deinterlacer"),            _("De-interlacing"),  N_("mcdeint"),   N_(""));
-       maybe_add (N_("kerndeint"), _("Kernel deinterlacer"),                         _("De-interlacing"),  N_("kerndeint"), N_(""));
-       maybe_add (N_("yadif"),     _("Yet Another Deinterlacing Filter"),            _("De-interlacing"),  N_("yadif"),     N_(""));
-       maybe_add (N_("pptn"),      _("Temporal noise reducer"),                      _("Noise reduction"), N_(""),          N_("tn"));
-       maybe_add (N_("ppfq"),      _("Force quantizer"),                             _("Misc"),            N_(""),          N_("fq"));
-       maybe_add (N_("gradfun"),   _("Gradient debander"),                           _("Misc"),            N_("gradfun"),   N_(""));
-       maybe_add (N_("unsharp"),   _("Unsharp mask and Gaussian blur"),              _("Misc"),            N_("unsharp"),   N_(""));
-       maybe_add (N_("denoise3d"), _("3D denoiser"),                                 _("Noise reduction"), N_("denoise3d"), N_(""));
-       maybe_add (N_("hqdn3d"),    _("High quality 3D denoiser"),                    _("Noise reduction"), N_("hqdn3d"),    N_(""));
-       maybe_add (N_("telecine"),  _("Telecine filter"),                             _("Misc"),            N_("telecine"),  N_(""));
-       maybe_add (N_("ow"),        _("Overcomplete wavelet denoiser"),               _("Noise reduction"), N_("mp=ow"),     N_(""));
-}
 
-void
-Filter::maybe_add (string i, string n, string c, string v, string p)
-{
-       if (!v.empty ()) {
-               if (avfilter_get_by_name (i.c_str())) {
-                       _filters.push_back (new Filter (i, n, c, v, p));
+       auto maybe_add = [](string id, string name, string category, string ffmpeg)
+       {
+               string check_name = ffmpeg;
+               size_t end = check_name.find("=");
+               if (end != string::npos) {
+                       check_name = check_name.substr(0, end);
                }
-       } else if (!p.empty ()) {
-               pp_mode* m = pp_get_mode_by_name_and_quality (p.c_str(), PP_QUALITY_MAX);
-               if (m) {
-                       _filters.push_back (new Filter (i, n, c, v, p));
-                       pp_free_mode (m);
+
+               if (avfilter_get_by_name(check_name.c_str())) {
+                       _filters.push_back(Filter(id, name, category, ffmpeg));
                }
-       }
+       };
+
+       maybe_add (N_("vflip"),       _("Vertical flip"),                    _("Orientation"),     N_("vflip"));
+       maybe_add (N_("hflip"),       _("Horizontal flip"),                  _("Orientation"),     N_("hflip"));
+       maybe_add (N_("90clock"),     _("Rotate 90 degrees clockwise"),      _("Orientation"),     N_("transpose=dir=clock"));
+       maybe_add (N_("90anticlock"), _("Rotate 90 degrees anti-clockwise"), _("Orientation"),     N_("transpose=dir=cclock"));
+       maybe_add (N_("mcdeint"),     _("Motion compensating deinterlacer"), _("De-interlacing"),  N_("mcdeint"));
+       maybe_add (N_("kerndeint"),   _("Kernel deinterlacer"),              _("De-interlacing"),  N_("kerndeint"));
+       maybe_add (N_("yadif"),       _("Yet Another Deinterlacing Filter"), _("De-interlacing"),  N_("yadif"));
+       maybe_add (N_("bwdif"),       _("Bob Weaver Deinterlacing Filter"),  _("De-interlacing"),  N_("bwdif"));
+       maybe_add (N_("weave"),       _("Weave filter"),                     _("De-interlacing"),  N_("weave"));
+       maybe_add (N_("gradfun"),     _("Gradient debander"),                _("Misc"),            N_("gradfun"));
+       maybe_add (N_("unsharp"),     _("Unsharp mask and Gaussian blur"),   _("Misc"),            N_("unsharp"));
+       maybe_add (N_("denoise3d"),   _("3D denoiser"),                      _("Noise reduction"), N_("denoise3d"));
+       maybe_add (N_("hqdn3d"),      _("High quality 3D denoiser"),         _("Noise reduction"), N_("hqdn3d"));
+       maybe_add (N_("telecine"),    _("Telecine filter"),                  _("Misc"),            N_("telecine"));
+       maybe_add (N_("ow"),          _("Overcomplete wavelet denoiser"),    _("Noise reduction"), N_("mp=ow"));
+       maybe_add (N_("premultiply"), _("Premultiply alpha channel"),        _("Misc"),            N_("premultiply=inplace=1"));
 }
 
+
 /** @param filters Set of filters.
- *  @return A pair; .first is a string to pass to FFmpeg for the video filters,
- *  .second is a string to pass for the post-processors.
+ *  @return String to pass to FFmpeg for the video filters.
  */
-pair<string, string>
-Filter::ffmpeg_strings (vector<Filter const *> const & filters)
+string
+Filter::ffmpeg_string(vector<Filter> const& filters)
 {
-       string vf;
-       string pp;
-
-       for (vector<Filter const *>::const_iterator i = filters.begin(); i != filters.end(); ++i) {
-               if (!(*i)->vf().empty ()) {
-                       if (!vf.empty ()) {
-                               vf += N_(",");
-                       }
-                       vf += (*i)->vf ();
-               }
-               
-               if (!(*i)->pp().empty ()) {
-                       if (!pp.empty()) {
-                               pp += N_(",");
-                       }
-                       pp += (*i)->pp ();
+       string ff;
+
+       for (auto const& i: filters) {
+               if (!ff.empty ()) {
+                       ff += N_(",");
                }
+               ff += i.ffmpeg();
        }
 
-       return make_pair (vf, pp);
+       return ff;
 }
 
+
 /** @param d Our id.
- *  @return Corresponding Filter, or 0.
+ *  @return Corresponding Filter, if found.
  */
-Filter const *
-Filter::from_id (string d)
+optional<Filter>
+Filter::from_id(string id)
 {
-       vector<Filter const *>::iterator i = _filters.begin ();
-       while (i != _filters.end() && (*i)->id() != d) {
-               ++i;
+       auto iter = std::find_if(_filters.begin(), _filters.end(), [id](Filter const& filter) { return filter.id() == id; });
+       if (iter == _filters.end()) {
+               return {};
        }
+       return *iter;
+}
+
+
+bool
+operator==(Filter const& a, Filter const& b)
+{
+       return a.id() == b.id() && a.name() == b.name() && a.category() == b.category() && a.ffmpeg() == b.ffmpeg();
+}
 
-       if (i == _filters.end ()) {
-               return 0;
-       }
 
-       return *i;
+bool
+operator!=(Filter const& a, Filter const& b)
+{
+       return a.id() != b.id() || a.name() != b.name() || a.category() != b.category() || a.ffmpeg() != b.ffmpeg();
 }
 
+
+bool
+operator<(Filter const& a, Filter const& b)
+{
+       if (a.id() != b.id()) {
+               return a.id() < b.id();
+       }
+
+       if (a.name() != b.name()) {
+               return a.name() < b.name();
+       }
+
+       if (a.category() != b.category()) {
+               return a.category() < b.category();
+       }
+
+       return a.ffmpeg() < b.ffmpeg();
+}