/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
*/
+
/** @file src/filter.cc
* @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 <boost/foreach.hpp>
-#include <iostream>
+LIBDCP_ENABLE_WARNINGS
+#include <algorithm>
#include "i18n.h"
+
using namespace std;
+using boost::optional;
+
+
+vector<Filter> Filter::_filters;
-vector<Filter const *> Filter::_filters;
/** @param i Our id.
* @param n User-visible name.
}
+
/** @return All available filters */
-vector<Filter const *>
+vector<Filter>
Filter::all ()
{
return _filters;
}
+
/** Set up the static _filters vector; must be called before from_*
* methods are used.
*/
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_("ow"), _("Overcomplete wavelet denoiser"), _("Noise reduction"), N_("mp=ow"));
}
+
void
Filter::maybe_add (string i, string n, string c, string f)
{
check_name = check_name.substr (0, end);
}
- if (avfilter_get_by_name (check_name.c_str())) {
- _filters.push_back (new Filter (i, n, c, f));
+ if (avfilter_get_by_name(check_name.c_str())) {
+ _filters.push_back (Filter(i, n, c, f));
}
}
+
/** @param filters Set of filters.
* @return String to pass to FFmpeg for the video filters.
*/
string
-Filter::ffmpeg_string (vector<Filter const *> const & filters)
+Filter::ffmpeg_string(vector<Filter> const& filters)
{
string ff;
- BOOST_FOREACH (Filter const * i, filters) {
+ for (auto const& i: filters) {
if (!ff.empty ()) {
ff += N_(",");
}
- ff += i->ffmpeg ();
+ ff += i.ffmpeg();
}
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();
+}
+
+
+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 (i == _filters.end ()) {
- return 0;
+ if (a.category() != b.category()) {
+ return a.category() < b.category();
}
- return *i;
+ return a.ffmpeg() < b.ffmpeg();
}