*/
+#include "dcpomatic_assert.h"
#include "filter.h"
#include <dcp/warnings.h>
LIBDCP_DISABLE_WARNINGS
#include <libavfilter/avfilter.h>
}
LIBDCP_ENABLE_WARNINGS
+#include <algorithm>
#include "i18n.h"
using namespace std;
+using boost::optional;
-vector<Filter const *> Filter::_filters;
+vector<Filter> Filter::_filters;
-/** @param i Our id.
- * @param n User-visible name.
- * @param c User-visible category.
- * @param f String for a FFmpeg filter descriptor.
+/** @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 f)
- : _id (i)
- , _name (n)
- , _category (c)
- , _ffmpeg (f)
+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;
{
/* Note: "none" is a magic id name, so don't use it here */
+ 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);
+ }
+
+ 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_("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"));
-}
-
-
-void
-Filter::maybe_add (string i, string n, string c, string f)
-{
- string check_name = f;
- size_t end = check_name.find("=");
- if (end != string::npos) {
- 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));
- }
+ maybe_add (N_("premultiply"), _("Premultiply alpha channel"), _("Misc"), N_("premultiply=inplace=1"));
}
* @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;
- for (auto 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)
{
- auto 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 nullptr;
+ if (a.category() != b.category()) {
+ return a.category() < b.category();
}
- return *i;
+ return a.ffmpeg() < b.ffmpeg();
}