2017-05-29 22:42:10 +02:00
|
|
|
#ifndef WORKER_HPP
|
|
|
|
#define WORKER_HPP
|
|
|
|
|
|
|
|
#include <QImage>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QQueue>
|
|
|
|
#include <QThread>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
struct WorkerContext {
|
|
|
|
QPixmap pixmap;
|
|
|
|
QImage::Format targetFormat;
|
|
|
|
std::function<void(QImage)> consumer;
|
|
|
|
};
|
|
|
|
|
2017-05-29 23:00:08 +02:00
|
|
|
struct _WorkerContext {
|
|
|
|
QImage image;
|
2017-05-30 13:22:20 +02:00
|
|
|
QImage::Format targetFormat;
|
2017-05-29 23:00:08 +02:00
|
|
|
std::function<void(QImage)> consumer;
|
2017-06-06 01:26:26 +02:00
|
|
|
WorkerContext *underlyingThing;
|
2017-05-29 23:00:08 +02:00
|
|
|
};
|
|
|
|
|
2017-05-29 22:42:10 +02:00
|
|
|
class Worker : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2017-06-04 01:04:42 +02:00
|
|
|
static void queue(WorkerContext *context);
|
2017-05-29 22:42:10 +02:00
|
|
|
static void init();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Worker();
|
|
|
|
~Worker();
|
2017-06-04 01:04:42 +02:00
|
|
|
static QMutex lock;
|
2017-05-29 22:42:10 +02:00
|
|
|
QMutex endLock;
|
|
|
|
QThread *thr;
|
2017-05-29 23:00:08 +02:00
|
|
|
QQueue<_WorkerContext *> qqueue; // Say that ten times as fast
|
2017-05-29 22:42:10 +02:00
|
|
|
bool _ended;
|
2017-05-30 15:51:25 +02:00
|
|
|
void _end();
|
2017-05-29 22:42:10 +02:00
|
|
|
|
|
|
|
void _queue(WorkerContext *context);
|
|
|
|
bool ended();
|
|
|
|
|
|
|
|
static Worker *inst;
|
|
|
|
static QMutex workerLock;
|
|
|
|
signals:
|
|
|
|
void error(QString err);
|
|
|
|
void finished();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void process();
|
2017-05-30 15:51:25 +02:00
|
|
|
static void end();
|
2017-05-29 22:42:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // WORKER_HPP
|