mirror of
https://github.com/lostjared/Acid.Cam.v2.Qt.git
synced 2025-12-18 12:50:07 +01:00
working on subfilter
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include"plugin.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 &);
|
||||
|
||||
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() {
|
||||
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;
|
||||
while(filter_names[index] != 0) {
|
||||
std::string filter_n = "AF_";
|
||||
filter_n += filter_names[index];
|
||||
filter_map[filter_n] = std::make_pair(1, index);
|
||||
filter_map[filter_n] = FilterValue(1, index, -1);
|
||||
++index;
|
||||
}
|
||||
for(unsigned int j = 0; j < plugins.plugin_list.size(); ++j) {
|
||||
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() {
|
||||
ac::setSubFilter(-1);
|
||||
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);
|
||||
}
|
||||
|
||||
void AC_MainWindow::clear_img() {
|
||||
@@ -632,25 +643,21 @@ void AC_MainWindow::addClicked() {
|
||||
int row = filters->currentIndex();
|
||||
if(row != -1) {
|
||||
//QListWidgetItem *item = filters->item(row);
|
||||
|
||||
std::string sub_str = filters->currentText().toStdString();
|
||||
custom_filters->addItem(filters->currentText());
|
||||
//custom_filters->addItem(sub_str.c_str());
|
||||
QString qs;
|
||||
QTextStream stream(&qs);
|
||||
stream << "Added Filter: " << filters->currentText() << "\n";
|
||||
Log(qs);
|
||||
std::string text = filters->currentText().toStdString();
|
||||
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;
|
||||
std::vector<FilterValue> v;
|
||||
buildVector(v);
|
||||
playback->setVector(v);
|
||||
}
|
||||
}
|
||||
|
||||
void AC_MainWindow::updateList() {
|
||||
std::vector<std::pair<int, int>> v;
|
||||
std::vector<FilterValue> v;
|
||||
buildVector(v);
|
||||
playback->setVector(v);
|
||||
}
|
||||
@@ -663,7 +670,7 @@ void AC_MainWindow::rmvClicked() {
|
||||
QTextStream stream(&qs);
|
||||
stream << "Removed Filter: " << i->text() << "\n";
|
||||
Log(qs);
|
||||
std::vector<std::pair<int, int>> v;
|
||||
std::vector<FilterValue> v;
|
||||
buildVector(v);
|
||||
playback->setVector(v);
|
||||
}
|
||||
@@ -675,7 +682,7 @@ void AC_MainWindow::upClicked() {
|
||||
QListWidgetItem *i = custom_filters->takeItem(item);
|
||||
custom_filters->insertItem(item-1, i->text());
|
||||
custom_filters->setCurrentRow(item-1);
|
||||
std::vector<std::pair<int, int>> v;
|
||||
std::vector<FilterValue> v;
|
||||
buildVector(v);
|
||||
playback->setVector(v);
|
||||
}
|
||||
@@ -687,44 +694,41 @@ void AC_MainWindow::downClicked() {
|
||||
QListWidgetItem *i = custom_filters->takeItem(item);
|
||||
custom_filters->insertItem(item+1, i->text());
|
||||
custom_filters->setCurrentRow(item+1);
|
||||
std::vector<std::pair<int, int>> v;
|
||||
std::vector<FilterValue> v;
|
||||
buildVector(v);
|
||||
playback->setVector(v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AC_MainWindow::setSub() {
|
||||
int row = filters->currentIndex();
|
||||
if(row != -1) {
|
||||
int crow = custom_filters->currentRow();
|
||||
if(row != -1 && crow != -1) {
|
||||
std::ostringstream stream;
|
||||
//QListWidgetItem *item = filters->item(row);
|
||||
QListWidgetItem *item = custom_filters->item(crow);
|
||||
QString filter_num = filters->currentText();
|
||||
std::string text = filter_num.toStdString();
|
||||
if(text.find("SubFilter") != std::string::npos) {
|
||||
std::ostringstream stream;
|
||||
stream << "SubFilter function: " << filter_num.toStdString() << " cannot be set to a SubFilter function.\n";
|
||||
int value_index = filter_map[filter_num.toStdString()].index;
|
||||
int filter_index = filter_map[filter_num.toStdString()].filter;
|
||||
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;
|
||||
}
|
||||
|
||||
int value_index = filter_map[filter_num.toStdString()].first;
|
||||
int filter_index = filter_map[filter_num.toStdString()].second;
|
||||
if(value_index == 0) {
|
||||
stream << "SubFilter set to: " << filter_num.toStdString() << "\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();
|
||||
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) {
|
||||
QString text;
|
||||
text = log_text->toPlainText();
|
||||
@@ -1035,16 +1039,25 @@ void AC_MainWindow::controls_Step() {
|
||||
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());
|
||||
for(int i = 0; i < custom_filters->count(); ++i) {
|
||||
QListWidgetItem *val = custom_filters->item(i);
|
||||
QString name = val->text();
|
||||
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 tmp(src.height(),src.width(),CV_8UC3,(uchar*)src.bits(),src.bytesPerLine());
|
||||
@@ -1121,10 +1134,12 @@ void AC_MainWindow::stopRecording() {
|
||||
progress_bar->hide();
|
||||
}
|
||||
|
||||
|
||||
void AC_MainWindow::setSubFilter(const QString &filter_num) {
|
||||
int value_index = filter_map[filter_num.toStdString()].first;
|
||||
int filter_index = filter_map[filter_num.toStdString()].second;
|
||||
if(value_index == 0) {
|
||||
int value_index = filter_map[filter_num.toStdString()].index;
|
||||
int filter_index = filter_map[filter_num.toStdString()].filter;
|
||||
int crow = custom_filters->currentRow();
|
||||
if(value_index == 0 && crow >= 0) {
|
||||
std::string text = filter_num.toStdString();
|
||||
if(text.find("SubFilter") != std::string::npos) {
|
||||
std::ostringstream stream;
|
||||
@@ -1132,10 +1147,15 @@ void AC_MainWindow::setSubFilter(const QString &filter_num) {
|
||||
Log(stream.str().c_str());
|
||||
return;
|
||||
}
|
||||
QListWidgetItem *item = custom_filters->item(crow);
|
||||
std::ostringstream stream;
|
||||
stream << "SubFilter set to: " << filter_num.toStdString() << "\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();
|
||||
Log(l);
|
||||
} else {
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
QComboBox *color_maps, *filters;
|
||||
QMenu *file_menu, *controls_menu, *help_menu, *options, *movement, *speed_menu;
|
||||
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 *open_search;
|
||||
QAction *in_out_increase;
|
||||
@@ -119,11 +119,11 @@ private:
|
||||
unsigned long file_pos, frame_index;
|
||||
Playback *playback;
|
||||
VideoMode programMode;
|
||||
void buildVector(std::vector<std::pair<int,int>> &v);
|
||||
void buildVector(std::vector<FilterValue> &v);
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,7 @@ Playback::Playback(QObject *parent) : QThread(parent) {
|
||||
bright_ = gamma_ = saturation_ = 0;
|
||||
single_mode = true;
|
||||
alpha = 0;
|
||||
prev_filter = std::pair<int, int>(0, 0);
|
||||
prev_filter = FilterValue(0, 0, -1);
|
||||
flip_frame1 = false;
|
||||
flip_frame2 = false;
|
||||
repeat_video = false;
|
||||
@@ -92,7 +92,7 @@ bool Playback::setVideoCamera(int device, int res, cv::VideoWriter wr, bool reco
|
||||
return true;
|
||||
}
|
||||
|
||||
void Playback::setVector(std::vector<std::pair<int, int>> v) {
|
||||
void Playback::setVector(std::vector<FilterValue> v) {
|
||||
mutex_add.lock();
|
||||
current = v;
|
||||
mutex_add.unlock();
|
||||
@@ -187,14 +187,16 @@ void Playback::drawEffects(cv::Mat &frame) {
|
||||
}
|
||||
}
|
||||
|
||||
void Playback::drawFilter(cv::Mat &frame, std::pair<int, int> &filter) {
|
||||
if(filter.first == 0) {
|
||||
ac::draw_func[filter.second](frame);
|
||||
} else if(current_filter.first == 1) {
|
||||
current_filterx = filter.second;
|
||||
void Playback::drawFilter(cv::Mat &frame, FilterValue &f) {
|
||||
if(f.index == 0) {
|
||||
ac::setSubFilter(f.subfilter);
|
||||
ac::draw_func[f.filter](frame);
|
||||
ac::setSubFilter(-1);
|
||||
} else if(current_filter.index == 1) {
|
||||
current_filterx = f.filter;
|
||||
ac::alphaFlame(frame);
|
||||
} else if(filter.first == 2) {
|
||||
draw_plugin(frame, filter.second);
|
||||
} else if(f.index == 2) {
|
||||
draw_plugin(frame, f.filter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +229,7 @@ void Playback::run() {
|
||||
}
|
||||
|
||||
mutex.unlock();
|
||||
static std::vector<std::pair<int, int>> cur;
|
||||
static std::vector<FilterValue> cur;
|
||||
mutex_shown.lock();
|
||||
cur = current;
|
||||
mutex_shown.unlock();
|
||||
@@ -334,7 +336,7 @@ void Playback::Clear() {
|
||||
void Playback::Stop() {
|
||||
stop = true;
|
||||
alpha = 0;
|
||||
prev_filter = std::pair<int, int>(0, 0);
|
||||
prev_filter = FilterValue(0, 0, -1);
|
||||
}
|
||||
|
||||
void Playback::Release() {
|
||||
@@ -373,7 +375,7 @@ void Playback::setColorKey(const cv::Mat &image) {
|
||||
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 w = frame.cols;// framew idth
|
||||
// make copies of original frame
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
cv::VideoWriter writer;
|
||||
cv::Mat rgb_frame;
|
||||
QImage img;
|
||||
std::vector<std::pair<int, int>> current;
|
||||
std::vector<FilterValue> current;
|
||||
bool isPaused, isStep;
|
||||
VideoMode mode;
|
||||
int device_num;
|
||||
@@ -35,7 +35,7 @@ private:
|
||||
unsigned int red, green, blue;
|
||||
unsigned int bright_, gamma_, saturation_;
|
||||
bool single_mode;
|
||||
std::pair<int, int> current_filter, prev_filter;
|
||||
FilterValue current_filter, prev_filter;
|
||||
double alpha;
|
||||
bool flip_frame1, flip_frame2;
|
||||
bool repeat_video;
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
void run();
|
||||
void Clear();
|
||||
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 setImage(const cv::Mat &image);
|
||||
void setColorKey(const cv::Mat &image);
|
||||
@@ -65,9 +65,9 @@ public:
|
||||
void setDisplayed(bool shown);
|
||||
void setIndexChanged(std::string name);
|
||||
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 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 setSubFilter(int index);
|
||||
void enableRepeat(bool re);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#ifndef _QT_HEADERS__
|
||||
#define _QT_HEADERS__
|
||||
#define ac_version "v1.18.0"
|
||||
#define ac_version "v1.19.0"
|
||||
#include<QApplication>
|
||||
#include<QMainWindow>
|
||||
#include<QDialog>
|
||||
@@ -44,7 +44,19 @@
|
||||
#include<vector>
|
||||
#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 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
|
||||
|
||||
Reference in New Issue
Block a user