-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransactionthread.cpp
More file actions
144 lines (117 loc) · 2.82 KB
/
transactionthread.cpp
File metadata and controls
144 lines (117 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "transactionthread.h"
#include "imgproc.h"
Transaction * const EndTransaction = nullptr;
QImage BlurTransaction::apply()
{
return ImgProc::blur(image, width, height);
}
QString BlurTransaction::message()
{
return QObject::tr("Blurring image...");
}
QImage MedianBlurTransaction::apply()
{
return ImgProc::medianBlur(image, size);
}
QString MedianBlurTransaction::message()
{
return QObject::tr("Median Blurring image...");
}
QImage GaussianBlurTransaction::apply()
{
return ImgProc::GaussianBlur(image, width, height, sigmaX, sigmaY);
}
QString GaussianBlurTransaction::message()
{
return QObject::tr("Gaussian Blurring image...");
}
QImage BilateralFilterTransaction::apply()
{
return ImgProc::bilateralFilter(image, diam, color, space);
}
QString BilateralFilterTransaction::message()
{
return QObject::tr("Median Blurring image...");
}
QImage ThresholdTransaction::apply()
{
return ImgProc::threshold(image, thresh, maxval, type);
}
QString ThresholdTransaction::message()
{
return QObject::tr("Thresholding image...");
}
QImage EqualizeHistTransaction::apply()
{
return ImgProc::equalizeHist(image);
}
QString EqualizeHistTransaction::message()
{
return QObject::tr("Equalizing image histogram... ");
}
QImage ErodeTransaction::apply()
{
return ImgProc::erode(image, kernel, size);
}
QString ErodeTransaction::message()
{
return QObject::tr("Eroding image...");
}
QImage DilateTransaction::apply()
{
return ImgProc::dilate(image, kernel, size);
}
QString DilateTransaction::message()
{
return QObject::tr("Dilating image...");
}
TransactionThread::TransactionThread()
{
start();
}
TransactionThread::~TransactionThread()
{
{
QMutexLocker locker(&mutex);
while (!transactions.isEmpty())
delete transactions.dequeue();
transactions.enqueue(EndTransaction);
transactionAdded.wakeOne();
}
wait();
}
void TransactionThread::addTransaction(Transaction *transact)
{
QMutexLocker locker(&mutex);
transactions.enqueue(transact);
transactionAdded.wakeOne();
}
void TransactionThread::run()
{
Transaction *transact = nullptr;
forever
{
{
QMutexLocker locker(&mutex);
if (transactions.isEmpty())
transactionAdded.wait(&mutex);
transact = transactions.dequeue();
if (transact == EndTransaction)
break;
}
emit transactionStarted(transact->message());
QImage newImage = transact->apply();
delete transact;
{
QMutexLocker locker(&mutex);
currentImage = newImage;
if (transactions.isEmpty())
emit allTransactionDone();
}
}
}
QImage TransactionThread::image()
{
QMutexLocker locker(&mutex);
return currentImage;
}