From 7ef166e2bdf4d666ab9a0ef5f6094b7283124d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Mon, 16 Jul 2012 01:39:26 +0200 Subject: [PATCH] Proper parsing of the CLI, adding filter according to it; catch some CLI error (unknown filter, no output file given, ...) --- TODO | 1 - configure.ac | 1 + src/configuration.cc | 27 +++++++++++++++++++++++++++ src/configuration.hh | 7 ++++++- src/configuration.hxx | 10 ++++++++++ src/main.cc | 43 +++++++++++++++++++++++++------------------ src/pipeline.cc | 12 ++++++++++-- 7 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 src/configuration.hxx diff --git a/TODO b/TODO index c83e8ef..0ac40f8 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,2 @@ -- Proper parsing of the CLI, adding filter according to it. - Moar filters ! - Kikoo stuff. diff --git a/configure.ac b/configure.ac index bef510b..5ef9492 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,7 @@ AC_CONFIG_MACRO_DIR([m4]) AC_PROG_CXX AC_PROG_RANLIB CXXFLAGS="$CXXFLAGS_save -std=c++11 -g -O0" +AM_SILENT_RULES([yes]) AC_ARG_ENABLE(debug, [ --enable-debug compile with debugging support], diff --git a/src/configuration.cc b/src/configuration.cc index a9234d0..aa4528c 100644 --- a/src/configuration.cc +++ b/src/configuration.cc @@ -1 +1,28 @@ #include "configuration.hh" +#include +#include + +void +Configuration::add_filter(const std::string param) +{ + std::pair > pair; + + boost::char_separator sep(",-;|. ="); + boost::tokenizer > tokens(param, sep); + + for (auto tok : tokens) + { + if (pair.first.empty()) + pair.first = tok; + else + { + int p = -1; + std::stringstream ss (tok); + + ss >> p; + pair.second.push_back(p); + } + } + + filters_.push_back (pair); +} diff --git a/src/configuration.hh b/src/configuration.hh index de7efdb..120caa2 100644 --- a/src/configuration.hh +++ b/src/configuration.hh @@ -3,6 +3,7 @@ # include # include +# include class Configuration { @@ -10,8 +11,12 @@ class Configuration std::list input; std::string output; std::string codec; - std::list filters; + void add_filter(std::string param); + inline std::list > > filters_get(); private: + std::list > > filters_; }; +# include "configuration.hxx" + #endif /* !CONFIGURATION_HH_ */ diff --git a/src/configuration.hxx b/src/configuration.hxx new file mode 100644 index 0000000..f5c688e --- /dev/null +++ b/src/configuration.hxx @@ -0,0 +1,10 @@ +#ifndef CONFIGURATION_HXX_ +# define CONFIGURATION_HXX_ + +std::list > > +Configuration::filters_get() +{ + return filters_; +} + +#endif /* !CONFIGURATION_HXX_ */ diff --git a/src/main.cc b/src/main.cc index 754ea5b..f2bbdf5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -49,24 +49,18 @@ bool parse_cli(Configuration& conf, int argc, char** argv) return false; } - // GO! - std::cout << "Given filters: "; - if (vm.count("filter")) - std::cout << vm["filter"].as > ().size() - << std::endl; - else - std::cout << 0 << std::endl; - - std::cout << "Given files: "; - if (vm.count("input-file")) - std::cout << vm["input-file"].as > ().size() - << std::endl; - else - std::cout << 0 << std::endl; - /* Store configuration */ - conf.output = std::string(vm["output"].as()); - conf.codec = std::string(vm["codec"].as()); + if (vm.count("output")) + conf.output = std::string(vm["output"].as()); + else + { + std::cerr << "Please provide an output file" << std::endl; + return false; + } + if (vm.count("codec")) + conf.codec = std::string(vm["codec"].as()); + else + conf.codec = "MP42"; std::vector vs; if (vm.count("input-file")) @@ -80,7 +74,7 @@ bool parse_cli(Configuration& conf, int argc, char** argv) { vs = vm["filter"].as> (); for (auto it = vs.begin(); it != vs.end(); ++it) - conf.filters.push_back(std::string(*it)); + conf.add_filter(std::string(*it)); } return true; @@ -102,6 +96,18 @@ int main (int argc, char** argv) input_vr.front().width_get(), input_vr.front().height_get()); Pipeline pipe(input_vr, vw); + + // Add filters to pipeline + for (auto filter : conf.filters_get()) + { + if (!pipe.add_filter(filter.first, filter.second)) + { + std::cerr << argv[0] << ": Unknown filter `" + << filter.first << "'" << std::endl; + return 2; + } + } + // add filters here //pipe.add_filter("grey", std::vector()); //pipe.add_filter("count", std::vector()); @@ -111,6 +117,7 @@ int main (int argc, char** argv) //pipe.add_filter("interlace", std::vector()); //pipe.add_filter("merge", std::vector()); //pipe.add_filter("inlay", std::vector { 0, 0, 255 }); + pipe.run(); return 0; diff --git a/src/pipeline.cc b/src/pipeline.cc index 697e51f..140b8cd 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -58,7 +58,11 @@ bool Pipeline::add_filter(std::string filter, std::vector args) this->pipeline_.add_filter(*(new Compose(*this->input_it_))); this->input_it_++; this->pipeline_.add_filter( - *(new Inlay(cv::Vec3b { args[0], args[1], args[2] }, 0))); + *(new Inlay(cv::Vec3b { + (unsigned char) args[0], + (unsigned char) args[1], + (unsigned char) args[2] + }, 0))); } else if (filter == "strictinlay" && this->input_it_ != this->input_.end() && args.size() >= 3) @@ -66,7 +70,11 @@ bool Pipeline::add_filter(std::string filter, std::vector args) this->pipeline_.add_filter(*(new Compose(*this->input_it_))); this->input_it_++; this->pipeline_.add_filter( - *(new Inlay(cv::Vec3b { args[0], args[1], args[2] }, 1))); + *(new Inlay(cv::Vec3b { + (unsigned char) args[0], + (unsigned char) args[1], + (unsigned char) args[2] + }, 1))); } else return false;