diff --git a/src/configuration.cc b/src/configuration.cc index aa4528c..a5c3a1c 100644 --- a/src/configuration.cc +++ b/src/configuration.cc @@ -7,7 +7,7 @@ Configuration::add_filter(const std::string param) { std::pair > pair; - boost::char_separator sep(",-;|. ="); + boost::char_separator sep(",;:. ="); boost::tokenizer > tokens(param, sep); for (auto tok : tokens) diff --git a/src/filterSample/Makefile.am b/src/filterSample/Makefile.am index 154839f..0032175 100644 --- a/src/filterSample/Makefile.am +++ b/src/filterSample/Makefile.am @@ -7,4 +7,5 @@ AM_CXXFLAGS = \ $(DEBUG_CXXFLAGS) ______lib_libfilterSample_a_SOURCES = grey.cc reverse.cc merge.cc \ - interlace.cc inlay.cc blur.cc cartoon.cc count.cc color.cc + interlace.cc inlay.cc blur.cc cartoon.cc count.cc color.cc \ + rotate.cc diff --git a/src/filterSample/color.cc b/src/filterSample/color.cc index f34548e..47aa415 100644 --- a/src/filterSample/color.cc +++ b/src/filterSample/color.cc @@ -11,9 +11,14 @@ void* Color::operator()(void* para) for (size_t i = 0; i < mat->rows; ++i) for (size_t j = 0; j < mat->cols; ++j) { - mat->at(i, j)[0] = mat->at(i, j)[0] * this->ref_[0] / 255; - mat->at(i, j)[1] = mat->at(i, j)[1] * this->ref_[1] / 255; - mat->at(i, j)[2] = mat->at(i, j)[2] * this->ref_[2] / 255; + mat->at(i, j)[0] = mat->at(i, j)[0] + * this->ref_[0] / 255; + + mat->at(i, j)[1] = mat->at(i, j)[1] + * this->ref_[1] / 255; + + mat->at(i, j)[2] = mat->at(i, j)[2] + * this->ref_[2] / 255; } return mat; diff --git a/src/filterSample/rotate.cc b/src/filterSample/rotate.cc new file mode 100644 index 0000000..b6385d9 --- /dev/null +++ b/src/filterSample/rotate.cc @@ -0,0 +1,29 @@ +#include "rotate.hh" + +void* Rotate::operator()(void* para) +{ + cv::Mat* mat = (cv::Mat*)para; + + if (mat == nullptr) + return nullptr; + + if (direction_ == 0) // rotate-h + for (size_t i = 0; i < mat->rows; ++i) + for (size_t j = mat->cols / 2 + 1; j > 0; --j) + { + cv::Vec3b tmp = mat->at(i, j); + mat->at(i, j) = mat->at(i, mat->cols - j - 1); + mat->at(i, mat->cols - j - 1) = tmp; + } + + else if (direction_ == 2 || direction_ == -2) // rotate-v + for (size_t i = mat->rows / 2 + 1; i > 0; --i) + for (size_t j = 0; j < mat->cols; ++j) + { + cv::Vec3b tmp = mat->at(i, j); + mat->at(i, j) = mat->at(mat->rows - i - 1, j); + mat->at(mat->rows - i - 1, j) = tmp; + } + + return mat; +} diff --git a/src/filterSample/rotate.hh b/src/filterSample/rotate.hh new file mode 100644 index 0000000..5530d8a --- /dev/null +++ b/src/filterSample/rotate.hh @@ -0,0 +1,17 @@ +#ifndef ROTATE_HH_ +# define ROTATE_HH_ + +# include "tbb/pipeline.h" +# include "opencv2/opencv.hpp" + +class Rotate: public tbb::filter +{ + public: + Rotate(char direction) + : filter(tbb::filter::parallel), direction_(direction) {} + void* operator()(void*); + private: + char direction_; +}; + +#endif /* !ROTATE_HH_ */ diff --git a/src/main.cc b/src/main.cc index ad2c1cf..8f365c3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -18,7 +18,9 @@ bool parse_cli(Configuration& conf, int argc, char** argv) po::options_description desc("Allowed options"); desc.add_options() ("help,h", "produce help message") - ("filter,f", po::value>(), "apply a filter") + ("filter,f", po::value>(), "apply a filter; " + "choose between grey, reverse, cartoon, count, color=B,G,R, sepia, " + "blur[=X], merge, interlace, inlay=B,G,R, strictinlay=B,G,R") ("input-file,i", po::value>(), "file to treat") ("output,o", po::value(), "output file") ("codec,c", po::value(), "output codec") @@ -110,7 +112,7 @@ int main (int argc, char** argv) if (!pipe.add_filter(filter.first, filter.second)) { std::cerr << argv[0] << ": Unknown filter `" - << filter.first << "'" << filter.second.size() << std::endl; + << filter.first << "'" << std::endl; return 2; } } diff --git a/src/pipeline.cc b/src/pipeline.cc index 472d957..7fc61d1 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -15,6 +15,7 @@ #include "filterSample/inlay.hh" #include "filterSample/count.hh" #include "filterSample/color.hh" +#include "filterSample/rotate.hh" Pipeline::Pipeline(std::list input, VideoWriter output) : input_(input), output_(output) @@ -34,6 +35,10 @@ bool Pipeline::add_filter(std::string filter, std::vector args) this->pipeline_.add_filter(*(new Cartoon())); else if (filter == "count") this->pipeline_.add_filter(*(new Count())); + else if (filter == "rotate-h") + this->pipeline_.add_filter(*(new Rotate(0))); + else if (filter == "rotate-v") + this->pipeline_.add_filter(*(new Rotate(2))); else if (filter == "color" && args.size() >= 3) this->pipeline_.add_filter(*(new Color(cv::Vec3b { (unsigned char) args[0],