mirror of
https://github.com/lostjared/Acid.Cam.v2.Qt.git
synced 2025-12-14 10:50:01 +01:00
working on plugin support, first doing Linux
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "main_window.h"
|
||||
#include<mutex>
|
||||
#include"plugin.h"
|
||||
|
||||
|
||||
std::unordered_map<std::string, std::pair<int, int>> 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() {
|
||||
|
||||
125
src/plugin.cpp
125
src/plugin.cpp
@@ -1,5 +1,128 @@
|
||||
#include "plugin.h"
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
#include<dirent.h>
|
||||
#include<sys/stat.h>
|
||||
#else
|
||||
|
||||
void ac::plugin(cv::Mat &/*frame*/) {
|
||||
#endif
|
||||
|
||||
PluginList plugins;
|
||||
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
void add_directory(std::string path, std::vector<std::string> &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<std::string> &files) {
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_plugins() {
|
||||
std::vector<std::string> 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<cv::Vec3b>(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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
25
src/plugin.h
25
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*> plugin_list;
|
||||
};
|
||||
|
||||
extern PluginList plugins;
|
||||
#endif
|
||||
|
||||
9
src/plugins/basic/Makefile
Normal file
9
src/plugins/basic/Makefile
Normal file
@@ -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
|
||||
|
||||
14
src/plugins/basic/basic.cpp
Normal file
14
src/plugins/basic/basic.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include<iostream>
|
||||
|
||||
|
||||
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() {
|
||||
|
||||
}
|
||||
BIN
src/plugins/basic/basic.so
Executable file
BIN
src/plugins/basic/basic.so
Executable file
Binary file not shown.
@@ -25,9 +25,12 @@
|
||||
#include<QImage>
|
||||
#include<QPainter>
|
||||
#include<QWaitCondition>
|
||||
#include<QLibrary>
|
||||
#include"ac.h"
|
||||
#include"fractal.h"
|
||||
#include<unordered_map>
|
||||
#include<utility>
|
||||
|
||||
void init_plugins();
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user