working on subfilter

This commit is contained in:
lostjared
2018-09-17 14:45:53 -07:00
parent be3f751cb1
commit 4b59f261d7
5 changed files with 100 additions and 66 deletions

View File

@@ -10,7 +10,7 @@
#include"plugin.h" #include"plugin.h"
#include<sys/stat.h> #include<sys/stat.h>
std::unordered_map<std::string, std::pair<int, int>> filter_map; std::unordered_map<std::string, FilterValue> filter_map;
void custom_filter(cv::Mat &); void custom_filter(cv::Mat &);
const char *filter_names[] = { "AC Self AlphaBlend", "Reverse Self AlphaBlend", const char *filter_names[] = { "AC Self AlphaBlend", "Reverse Self AlphaBlend",
@@ -25,18 +25,18 @@ const char *filter_names[] = { "AC Self AlphaBlend", "Reverse Self AlphaBlend",
void generate_map() { void generate_map() {
for(int i = 0; i < ac::draw_max; ++i ) for(int i = 0; i < ac::draw_max; ++i )
filter_map[ac::draw_strings[i]] = std::make_pair(0, i); filter_map[ac::draw_strings[i]] = FilterValue(0, i, -1);
int index = 0; int index = 0;
while(filter_names[index] != 0) { while(filter_names[index] != 0) {
std::string filter_n = "AF_"; std::string filter_n = "AF_";
filter_n += filter_names[index]; filter_n += filter_names[index];
filter_map[filter_n] = std::make_pair(1, index); filter_map[filter_n] = FilterValue(1, index, -1);
++index; ++index;
} }
for(unsigned int j = 0; j < plugins.plugin_list.size(); ++j) { for(unsigned int j = 0; j < plugins.plugin_list.size(); ++j) {
std::string name = "plugin " + plugins.plugin_list[j]->name(); std::string name = "plugin " + plugins.plugin_list[j]->name();
filter_map[name] = std::make_pair(2, j); filter_map[name] = FilterValue(2, j, -1);
} }
} }
@@ -423,8 +423,19 @@ void AC_MainWindow::resetIndex() {
} }
void AC_MainWindow::clear_subfilter() { void AC_MainWindow::clear_subfilter() {
int crow = custom_filters->currentRow();
if(crow >= 0) {
QListWidgetItem *item = custom_filters->item(crow);
std::string text = item->text().toStdString();
if(text.find(":") == std::string::npos)
return;
std::string val = text.substr(0, text.find(":"));
item->setText(val.c_str());
std::vector<FilterValue> v;
buildVector(v);
Log(tr("Cleared SubFilter"));
}
ac::setSubFilter(-1); ac::setSubFilter(-1);
Log(tr("Cleared SubFilter"));
} }
void AC_MainWindow::clear_img() { void AC_MainWindow::clear_img() {
@@ -632,25 +643,21 @@ void AC_MainWindow::addClicked() {
int row = filters->currentIndex(); int row = filters->currentIndex();
if(row != -1) { if(row != -1) {
//QListWidgetItem *item = filters->item(row); //QListWidgetItem *item = filters->item(row);
std::string sub_str = filters->currentText().toStdString();
custom_filters->addItem(filters->currentText()); custom_filters->addItem(filters->currentText());
//custom_filters->addItem(sub_str.c_str());
QString qs; QString qs;
QTextStream stream(&qs); QTextStream stream(&qs);
stream << "Added Filter: " << filters->currentText() << "\n"; stream << "Added Filter: " << filters->currentText() << "\n";
Log(qs); Log(qs);
std::string text = filters->currentText().toStdString(); std::vector<FilterValue> v;
if(blend_set == false && text.find("Image") != std::string::npos)
Log(tr("Set an Image to use this filter\n"));
else if(ac::subfilter != -1 && text.find("SubFilter") != std::string::npos)
Log(tr("Set a SubFilter to use this filter\n"));
std::vector<std::pair<int, int>> v;
buildVector(v); buildVector(v);
playback->setVector(v); playback->setVector(v);
} }
} }
void AC_MainWindow::updateList() { void AC_MainWindow::updateList() {
std::vector<std::pair<int, int>> v; std::vector<FilterValue> v;
buildVector(v); buildVector(v);
playback->setVector(v); playback->setVector(v);
} }
@@ -663,7 +670,7 @@ void AC_MainWindow::rmvClicked() {
QTextStream stream(&qs); QTextStream stream(&qs);
stream << "Removed Filter: " << i->text() << "\n"; stream << "Removed Filter: " << i->text() << "\n";
Log(qs); Log(qs);
std::vector<std::pair<int, int>> v; std::vector<FilterValue> v;
buildVector(v); buildVector(v);
playback->setVector(v); playback->setVector(v);
} }
@@ -675,7 +682,7 @@ void AC_MainWindow::upClicked() {
QListWidgetItem *i = custom_filters->takeItem(item); QListWidgetItem *i = custom_filters->takeItem(item);
custom_filters->insertItem(item-1, i->text()); custom_filters->insertItem(item-1, i->text());
custom_filters->setCurrentRow(item-1); custom_filters->setCurrentRow(item-1);
std::vector<std::pair<int, int>> v; std::vector<FilterValue> v;
buildVector(v); buildVector(v);
playback->setVector(v); playback->setVector(v);
} }
@@ -687,44 +694,41 @@ void AC_MainWindow::downClicked() {
QListWidgetItem *i = custom_filters->takeItem(item); QListWidgetItem *i = custom_filters->takeItem(item);
custom_filters->insertItem(item+1, i->text()); custom_filters->insertItem(item+1, i->text());
custom_filters->setCurrentRow(item+1); custom_filters->setCurrentRow(item+1);
std::vector<std::pair<int, int>> v; std::vector<FilterValue> v;
buildVector(v); buildVector(v);
playback->setVector(v); playback->setVector(v);
} }
} }
void AC_MainWindow::setSub() { void AC_MainWindow::setSub() {
int row = filters->currentIndex(); int row = filters->currentIndex();
if(row != -1) { int crow = custom_filters->currentRow();
if(row != -1 && crow != -1) {
std::ostringstream stream; std::ostringstream stream;
//QListWidgetItem *item = filters->item(row); QListWidgetItem *item = custom_filters->item(crow);
QString filter_num = filters->currentText(); QString filter_num = filters->currentText();
std::string text = filter_num.toStdString(); int value_index = filter_map[filter_num.toStdString()].index;
if(text.find("SubFilter") != std::string::npos) { int filter_index = filter_map[filter_num.toStdString()].filter;
std::ostringstream stream;
stream << "SubFilter function: " << filter_num.toStdString() << " cannot be set to a SubFilter function.\n";
Log(stream.str().c_str());
return;
}
int value_index = filter_map[filter_num.toStdString()].first;
int filter_index = filter_map[filter_num.toStdString()].second;
if(value_index == 0) { if(value_index == 0) {
std::string filter_val = item->text().toStdString();
if(filter_val.find("SubFilter") == std::string::npos) {
stream << filter_val << " does not support a subfilter.\n";
Log(stream.str().c_str());
return;
}
stream << "SubFilter set to: " << filter_num.toStdString() << "\n"; stream << "SubFilter set to: " << filter_num.toStdString() << "\n";
stream << "SubFilter index: " << filter_index << "\n"; stream << "SubFilter index: " << filter_index << "\n";
playback->setSubFilter(filter_index); std::ostringstream stream1;
stream1 << filter_num.toStdString() << ":" << item->text().toStdString();
item->setText(stream1.str().c_str());
std::vector<FilterValue> v;
buildVector(v);
playback->setVector(v);
QString l = stream.str().c_str(); QString l = stream.str().c_str();
Log(l); Log(l);
} else {
QString txt;
QTextStream stream(&txt);
stream << "Only Regular Filters can be used as a SubFilter not AF\n";
Log(txt);
} }
} }
} }
void AC_MainWindow::Log(const QString &s) { void AC_MainWindow::Log(const QString &s) {
QString text; QString text;
text = log_text->toPlainText(); text = log_text->toPlainText();
@@ -1035,16 +1039,25 @@ void AC_MainWindow::controls_Step() {
step_frame = true; step_frame = true;
} }
void AC_MainWindow::buildVector(std::vector<std::pair<int,int>> &v) { void AC_MainWindow::buildVector(std::vector<FilterValue> &v) {
if(!v.empty()) v.erase(v.begin(), v.end()); if(!v.empty()) v.erase(v.begin(), v.end());
for(int i = 0; i < custom_filters->count(); ++i) { for(int i = 0; i < custom_filters->count(); ++i) {
QListWidgetItem *val = custom_filters->item(i); QListWidgetItem *val = custom_filters->item(i);
QString name = val->text(); QString name = val->text();
v.push_back(filter_map[name.toStdString()]); std::string n = name.toStdString();
if(n.find(":") == std::string::npos)
v.push_back(filter_map[name.toStdString()]);
else {
std::string namev = name.toStdString();
std::string left_str = namev.substr(0, namev.find(":"));
std::string right_str = namev.substr(namev.find(":")+1,namev.length()-left_str.length()-1);
int index_val = filter_map[right_str].filter;
FilterValue fv(filter_map[left_str].index, filter_map[left_str].filter, index_val);
v.push_back(fv);
}
} }
} }
cv::Mat QImage2Mat(QImage const& src) cv::Mat QImage2Mat(QImage const& src)
{ {
cv::Mat tmp(src.height(),src.width(),CV_8UC3,(uchar*)src.bits(),src.bytesPerLine()); cv::Mat tmp(src.height(),src.width(),CV_8UC3,(uchar*)src.bits(),src.bytesPerLine());
@@ -1121,10 +1134,12 @@ void AC_MainWindow::stopRecording() {
progress_bar->hide(); progress_bar->hide();
} }
void AC_MainWindow::setSubFilter(const QString &filter_num) { void AC_MainWindow::setSubFilter(const QString &filter_num) {
int value_index = filter_map[filter_num.toStdString()].first; int value_index = filter_map[filter_num.toStdString()].index;
int filter_index = filter_map[filter_num.toStdString()].second; int filter_index = filter_map[filter_num.toStdString()].filter;
if(value_index == 0) { int crow = custom_filters->currentRow();
if(value_index == 0 && crow >= 0) {
std::string text = filter_num.toStdString(); std::string text = filter_num.toStdString();
if(text.find("SubFilter") != std::string::npos) { if(text.find("SubFilter") != std::string::npos) {
std::ostringstream stream; std::ostringstream stream;
@@ -1132,10 +1147,15 @@ void AC_MainWindow::setSubFilter(const QString &filter_num) {
Log(stream.str().c_str()); Log(stream.str().c_str());
return; return;
} }
QListWidgetItem *item = custom_filters->item(crow);
std::ostringstream stream; std::ostringstream stream;
stream << "SubFilter set to: " << filter_num.toStdString() << "\n"; stream << "SubFilter set to: " << filter_num.toStdString() << "\n";
stream << "SubFilter index: " << filter_index << "\n"; stream << "SubFilter index: " << filter_index << "\n";
playback->setSubFilter(filter_index); std::ostringstream stream1;
stream1 << filter_num.toStdString() << ":" << item->text().toStdString();
item->setText(stream1.str().c_str());
std::vector<FilterValue> v;
buildVector(v);
QString l = stream.str().c_str(); QString l = stream.str().c_str();
Log(l); Log(l);
} else { } else {

View File

@@ -35,7 +35,7 @@ public:
QComboBox *color_maps, *filters; QComboBox *color_maps, *filters;
QMenu *file_menu, *controls_menu, *help_menu, *options, *movement, *speed_menu; QMenu *file_menu, *controls_menu, *help_menu, *options, *movement, *speed_menu;
QAction *file_exit, *file_new_capture, *file_new_video; QAction *file_exit, *file_new_capture, *file_new_video;
QAction *controls_snapshot, *controls_pause, *controls_step, *controls_stop, *controls_setimage,*controls_setkey,*controls_showvideo, *reset_filters; QAction *controls_snapshot, *controls_pause, *controls_step, *controls_stop, *controls_setimage,*controls_setkey,*controls_showvideo, *clear_images, *reset_filters;
QAction *help_about; QAction *help_about;
QAction *open_search; QAction *open_search;
QAction *in_out_increase; QAction *in_out_increase;
@@ -119,11 +119,11 @@ private:
unsigned long file_pos, frame_index; unsigned long file_pos, frame_index;
Playback *playback; Playback *playback;
VideoMode programMode; VideoMode programMode;
void buildVector(std::vector<std::pair<int,int>> &v); void buildVector(std::vector<FilterValue> &v);
}; };
extern const char *filer_names[]; extern const char *filer_names[];
extern std::unordered_map<std::string, std::pair<int, int>> filter_map; extern std::unordered_map<std::string, FilterValue> filter_map;
void generate_map(); void generate_map();
#endif #endif

View File

@@ -14,7 +14,7 @@ Playback::Playback(QObject *parent) : QThread(parent) {
bright_ = gamma_ = saturation_ = 0; bright_ = gamma_ = saturation_ = 0;
single_mode = true; single_mode = true;
alpha = 0; alpha = 0;
prev_filter = std::pair<int, int>(0, 0); prev_filter = FilterValue(0, 0, -1);
flip_frame1 = false; flip_frame1 = false;
flip_frame2 = false; flip_frame2 = false;
repeat_video = false; repeat_video = false;
@@ -92,7 +92,7 @@ bool Playback::setVideoCamera(int device, int res, cv::VideoWriter wr, bool reco
return true; return true;
} }
void Playback::setVector(std::vector<std::pair<int, int>> v) { void Playback::setVector(std::vector<FilterValue> v) {
mutex_add.lock(); mutex_add.lock();
current = v; current = v;
mutex_add.unlock(); mutex_add.unlock();
@@ -187,14 +187,16 @@ void Playback::drawEffects(cv::Mat &frame) {
} }
} }
void Playback::drawFilter(cv::Mat &frame, std::pair<int, int> &filter) { void Playback::drawFilter(cv::Mat &frame, FilterValue &f) {
if(filter.first == 0) { if(f.index == 0) {
ac::draw_func[filter.second](frame); ac::setSubFilter(f.subfilter);
} else if(current_filter.first == 1) { ac::draw_func[f.filter](frame);
current_filterx = filter.second; ac::setSubFilter(-1);
} else if(current_filter.index == 1) {
current_filterx = f.filter;
ac::alphaFlame(frame); ac::alphaFlame(frame);
} else if(filter.first == 2) { } else if(f.index == 2) {
draw_plugin(frame, filter.second); draw_plugin(frame, f.filter);
} }
} }
@@ -227,7 +229,7 @@ void Playback::run() {
} }
mutex.unlock(); mutex.unlock();
static std::vector<std::pair<int, int>> cur; static std::vector<FilterValue> cur;
mutex_shown.lock(); mutex_shown.lock();
cur = current; cur = current;
mutex_shown.unlock(); mutex_shown.unlock();
@@ -334,7 +336,7 @@ void Playback::Clear() {
void Playback::Stop() { void Playback::Stop() {
stop = true; stop = true;
alpha = 0; alpha = 0;
prev_filter = std::pair<int, int>(0, 0); prev_filter = FilterValue(0, 0, -1);
} }
void Playback::Release() { void Playback::Release() {
@@ -373,7 +375,7 @@ void Playback::setColorKey(const cv::Mat &image) {
mutex.unlock(); mutex.unlock();
} }
void Playback::filterFade(cv::Mat &frame, std::pair<int, int> &filter1, std::pair<int, int> &filter2, double alpha) { void Playback::filterFade(cv::Mat &frame, FilterValue &filter1, FilterValue &filter2, double alpha) {
unsigned int h = frame.rows; // frame height unsigned int h = frame.rows; // frame height
unsigned int w = frame.cols;// framew idth unsigned int w = frame.cols;// framew idth
// make copies of original frame // make copies of original frame

View File

@@ -27,7 +27,7 @@ private:
cv::VideoWriter writer; cv::VideoWriter writer;
cv::Mat rgb_frame; cv::Mat rgb_frame;
QImage img; QImage img;
std::vector<std::pair<int, int>> current; std::vector<FilterValue> current;
bool isPaused, isStep; bool isPaused, isStep;
VideoMode mode; VideoMode mode;
int device_num; int device_num;
@@ -35,7 +35,7 @@ private:
unsigned int red, green, blue; unsigned int red, green, blue;
unsigned int bright_, gamma_, saturation_; unsigned int bright_, gamma_, saturation_;
bool single_mode; bool single_mode;
std::pair<int, int> current_filter, prev_filter; FilterValue current_filter, prev_filter;
double alpha; double alpha;
bool flip_frame1, flip_frame2; bool flip_frame1, flip_frame2;
bool repeat_video; bool repeat_video;
@@ -57,7 +57,7 @@ public:
void run(); void run();
void Clear(); void Clear();
void msleep(int ms); void msleep(int ms);
void setVector(std::vector<std::pair<int, int>> s); void setVector(std::vector<FilterValue> s);
void setOptions(bool n, int c); void setOptions(bool n, int c);
void setImage(const cv::Mat &image); void setImage(const cv::Mat &image);
void setColorKey(const cv::Mat &image); void setColorKey(const cv::Mat &image);
@@ -65,9 +65,9 @@ public:
void setDisplayed(bool shown); void setDisplayed(bool shown);
void setIndexChanged(std::string name); void setIndexChanged(std::string name);
void setSingleMode(bool val); void setSingleMode(bool val);
void drawFilter(cv::Mat &frame, std::pair<int, int> &filter); void drawFilter(cv::Mat &frame, FilterValue &filter);
void drawEffects(cv::Mat &frame); void drawEffects(cv::Mat &frame);
void filterFade(cv::Mat &frame, std::pair<int, int> &filter1, std::pair<int, int> &filter2, double alpha); void filterFade(cv::Mat &frame, FilterValue &filter1, FilterValue &filter2, double alpha);
void reset_filters(); void reset_filters();
void setSubFilter(int index); void setSubFilter(int index);
void enableRepeat(bool re); void enableRepeat(bool re);

View File

@@ -6,7 +6,7 @@
#ifndef _QT_HEADERS__ #ifndef _QT_HEADERS__
#define _QT_HEADERS__ #define _QT_HEADERS__
#define ac_version "v1.18.0" #define ac_version "v1.19.0"
#include<QApplication> #include<QApplication>
#include<QMainWindow> #include<QMainWindow>
#include<QDialog> #include<QDialog>
@@ -44,7 +44,19 @@
#include<vector> #include<vector>
#include<algorithm> #include<algorithm>
struct FilterValue {
int index, filter, subfilter;
FilterValue() : index(0), filter(0), subfilter(-1) {}
FilterValue(int i, int f, int s) : index(i), filter(f), subfilter(s) {}
FilterValue &operator=(const FilterValue &v) {
index = v.index;
filter = v.filter;
subfilter = v.subfilter;
return *this;
}
};
void init_plugins(); void init_plugins();
void draw_plugin(cv::Mat &frame, int filter); void draw_plugin(cv::Mat &frame, int filter);
extern std::unordered_map<std::string, std::pair<int, int>> filter_map; extern std::unordered_map<std::string, FilterValue> filter_map;
#endif #endif