Yeah that would've blown up.

This commit is contained in:
ArsenArsen 2017-05-29 23:00:08 +02:00
parent 8def91b0a8
commit dd8683b9e8
2 changed files with 12 additions and 5 deletions

View File

@ -7,8 +7,10 @@ QMutex Worker::workerLock;
void Worker::queue(WorkerContext *context) { void Worker::queue(WorkerContext *context) {
QMutexLocker ml(&lock); QMutexLocker ml(&lock);
context->pixmap = context->pixmap.copy(); _WorkerContext *c = new _WorkerContext;
qqueue.enqueue(context); c->image = context->pixmap.toImage().convertToFormat(context->targetFormat);
c->consumer = context->consumer;
qqueue.enqueue(c);
} }
void Worker::init() { void Worker::init() {
@ -45,8 +47,8 @@ void Worker::process() {
while (!ended()) { while (!ended()) {
lock.lock(); lock.lock();
if (!qqueue.isEmpty()) { if (!qqueue.isEmpty()) {
WorkerContext *c = qqueue.dequeue(); _WorkerContext *c = qqueue.dequeue();
c->consumer(c->pixmap.toImage().convertToFormat(c->targetFormat)); c->consumer(c->image);
} }
lock.unlock(); lock.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // STL likes it's scopes std::this_thread::sleep_for(std::chrono::milliseconds(100)); // STL likes it's scopes

View File

@ -15,6 +15,11 @@ struct WorkerContext {
std::function<void(QImage)> consumer; std::function<void(QImage)> consumer;
}; };
struct _WorkerContext {
QImage image;
std::function<void(QImage)> consumer;
};
class Worker : public QObject { class Worker : public QObject {
Q_OBJECT Q_OBJECT
public: public:
@ -27,7 +32,7 @@ private:
QMutex lock; QMutex lock;
QMutex endLock; QMutex endLock;
QThread *thr; QThread *thr;
QQueue<WorkerContext *> qqueue; // Say that ten times as fast QQueue<_WorkerContext *> qqueue; // Say that ten times as fast
bool _ended; bool _ended;
void _queue(WorkerContext *context); void _queue(WorkerContext *context);