diff --git a/src/main_window.cpp b/src/main_window.cpp index 7b88ba0..87c9d10 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -1,5 +1,7 @@ #include "main_window.h" #include +#include"plugin.h" + std::unordered_map> filter_map; @@ -204,6 +206,7 @@ AC_MainWindow::~AC_MainWindow() { } AC_MainWindow::AC_MainWindow(QWidget *parent) : QMainWindow(parent) { generate_map(); + init_plugins(); setGeometry(100, 100, 800, 600); setFixedSize(800, 600); setWindowTitle(tr("Acid Cam v2 - Qt")); @@ -221,6 +224,13 @@ AC_MainWindow::AC_MainWindow(QWidget *parent) : QMainWindow(parent) { disp = new DisplayWindow(this); playback = new Playback(); QObject::connect(playback, SIGNAL(procImage(QImage)), this, SLOT(updateFrame(QImage))); + + for(unsigned int i = 0; i < plugins.plugin_list.size(); ++i) { + QString text; + QTextStream stream(&text); + stream << "Loaded Plugin: " << plugins.plugin_list[i]->name().c_str() << "\n"; + Log(text); + } } void AC_MainWindow::createControls() { diff --git a/src/plugin.cpp b/src/plugin.cpp index ee3391d..74459eb 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -1,5 +1,128 @@ #include "plugin.h" +#if defined(__linux__) || defined(__APPLE__) +#include +#include +#else -void ac::plugin(cv::Mat &/*frame*/) { +#endif + +PluginList plugins; + +#if defined(__linux__) || defined(__APPLE__) +void add_directory(std::string path, std::vector &files) { + DIR *dir = opendir(path.c_str()); + if(dir == NULL) { + std::cerr << "Error could not open directory: " << path << "\n"; + return; + } + dirent *file_info; + while( (file_info = readdir(dir)) != 0 ) { + std::string f_info = file_info->d_name; + if(f_info == "." || f_info == "..") continue; + std::string fullpath=path+"/"+f_info; + struct stat s; + + lstat(fullpath.c_str(), &s); + if(S_ISDIR(s.st_mode)) { + if(f_info.length()>0 && f_info[0] != '.') + add_directory(path+"/"+f_info, files); + + continue; + } + if(f_info.length()>0 && f_info[0] != '.' && fullpath.rfind(".so") != std::string::npos) { + files.push_back(fullpath); + std::cout << "found: " << fullpath << "\n"; + } + } + closedir(dir); +} +#else +void add_directory(std::string path, std::vector &files) { } +#endif + +void init_plugins() { + std::vector files; + add_directory("plugins", files); + if(files.size()>0) { + for(unsigned int i = 0; i < files.size(); ++i) { + Plugin *p = new Plugin(); + if(p->loadPlugin(files[i])) + plugins.plugin_list.push_back(p); + } + } +} + + +void ac::plugin(cv::Mat &frame) { + for(int z = 0; z < frame.rows; ++z) { + for(int i = 0; i < frame.cols; ++i) { + unsigned char rgb[3]; + cv::Vec3b &cpixel = frame.at(z, i); + rgb[0] = cpixel[0]; + rgb[1] = cpixel[1]; + rgb[2] = cpixel[2]; + //plugins.plugin_list[0]->call_Pixel(i, z, rgb); + cpixel[0] = rgb[0]; + cpixel[1] = rgb[1]; + cpixel[2] = rgb[2]; + } + } + //plugins.plugin_list[0]->call_Complete(); +} + +Plugin::Plugin() { + library = 0; +} + +Plugin::~Plugin() { + if(library) delete library; +} + +bool Plugin::loadPlugin(const std::string &text) { + library = new QLibrary(text.c_str()); + if(!library) { + QMessageBox::information(0, QObject::tr("Could not load Library"), text.c_str()); + return false; + } + + pixel_function = (pixel) library->resolve("pixel"); + if(!pixel_function) { + QMessageBox::information(0, "Could not find pixel function", text.c_str()); + return false; + } + + complete_function = (complete) library->resolve("complete"); + if(!complete_function) { + QMessageBox::information(0, "Could not find complete function", text.c_str()); + return false; + } + mod_name = text; + return true; +} + + +void Plugin::call_Pixel(int x, int y, unsigned char *rgb) { + + if(pixel_function) + pixel_function(x, y, rgb); + +} +void Plugin::call_Complete() { + if(complete_function) + complete_function(); +} + +PluginList::PluginList() { + +} + +PluginList::~PluginList() { + if(plugin_list.size() == 0) return; + + for(auto i = plugin_list.begin(); i != plugin_list.end(); ++i) + delete *i; +} + + diff --git a/src/plugin.h b/src/plugin.h index bb768cd..0616270 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -4,5 +4,30 @@ #include "qtheaders.h" +typedef void (*pixel)(int x, int y, unsigned char *buf); +typedef void (*complete)(); +class Plugin { +public: + Plugin(); + ~Plugin(); + bool loadPlugin(const std::string &text); + void call_Pixel(int x, int y, unsigned char *rgb); + void call_Complete(); + std::string name() const { return mod_name; } +private: + pixel pixel_function; + complete complete_function; + QLibrary *library; + std::string mod_name; +}; + +class PluginList { +public: + PluginList(); + ~PluginList(); + std::vector plugin_list; +}; + +extern PluginList plugins; #endif diff --git a/src/plugins/basic/Makefile b/src/plugins/basic/Makefile new file mode 100644 index 0000000..b3b549f --- /dev/null +++ b/src/plugins/basic/Makefile @@ -0,0 +1,9 @@ + +all: basic.so + +basic.so: + g++ -std=c++11 -shared -fPIC basic.cpp -o basic.so + +clean: + rm -f basic.so + diff --git a/src/plugins/basic/basic.cpp b/src/plugins/basic/basic.cpp new file mode 100644 index 0000000..dbc8097 --- /dev/null +++ b/src/plugins/basic/basic.cpp @@ -0,0 +1,14 @@ +#include + + +extern "C" void pixel(int x, int y, unsigned char *rgb); +extern "C" void complete(); + + +void pixel(int x, int y, unsigned char *rgb) { + rgb[0] = rgb[1] = rgb[2] = 0; +} + +void complete() { + +} diff --git a/src/plugins/basic/basic.so b/src/plugins/basic/basic.so new file mode 100755 index 0000000..c865125 Binary files /dev/null and b/src/plugins/basic/basic.so differ diff --git a/src/qtheaders.h b/src/qtheaders.h index dd505e4..cdfdf14 100644 --- a/src/qtheaders.h +++ b/src/qtheaders.h @@ -25,9 +25,12 @@ #include #include #include +#include #include"ac.h" #include"fractal.h" #include #include +void init_plugins(); + #endif