@@ -28,26 +28,28 @@ ColorQuantizerOperation::ColorQuantizerOperation(QUrl* source, qreal depth, qrea
28
28
: source(source)
29
29
, maxDepth(depth)
30
30
, rescaleSize(rescaleSize) {
31
- setAutoDelete (false );
31
+ this -> setAutoDelete (false );
32
32
}
33
33
34
34
void ColorQuantizerOperation::quantizeImage (const QAtomicInteger<bool >& shouldCancel) {
35
- if (shouldCancel.loadAcquire () || source->isEmpty ()) return ;
35
+ if (shouldCancel.loadAcquire () || this -> source ->isEmpty ()) return ;
36
36
37
- colors.clear ();
37
+ this -> colors .clear ();
38
38
39
- auto image = QImage (source->toLocalFile ());
40
- if ((image.width () > rescaleSize || image.height () > rescaleSize) && rescaleSize > 0 ) {
39
+ auto image = QImage (this ->source ->toLocalFile ());
40
+ if ((image.width () > this ->rescaleSize || image.height () > this ->rescaleSize )
41
+ && this ->rescaleSize > 0 )
42
+ {
41
43
image = image.scaled (
42
- static_cast <int >(rescaleSize),
43
- static_cast <int >(rescaleSize),
44
+ static_cast <int >(this -> rescaleSize ),
45
+ static_cast <int >(this -> rescaleSize ),
44
46
Qt::KeepAspectRatio,
45
47
Qt::SmoothTransformation
46
48
);
47
49
}
48
50
49
51
if (image.isNull ()) {
50
- qCWarning (logColorQuantizer) << " Failed to load image from" << source->toString ();
52
+ qCWarning (logColorQuantizer) << " Failed to load image from" << this -> source ->toString ();
51
53
return ;
52
54
}
53
55
@@ -63,7 +65,7 @@ void ColorQuantizerOperation::quantizeImage(const QAtomicInteger<bool>& shouldCa
63
65
64
66
auto startTime = QDateTime::currentDateTime ();
65
67
66
- colors = quantization (pixels, 0 );
68
+ this -> colors = this -> quantization (pixels, 0 );
67
69
68
70
auto endTime = QDateTime::currentDateTime ();
69
71
auto milliseconds = startTime.msecsTo (endTime);
@@ -77,7 +79,7 @@ QList<QColor> ColorQuantizerOperation::quantization(
77
79
) {
78
80
if (shouldCancel.loadAcquire ()) return QList<QColor>();
79
81
80
- if (depth >= maxDepth || rgbValues.isEmpty ()) {
82
+ if (depth >= this -> maxDepth || rgbValues.isEmpty ()) {
81
83
if (rgbValues.isEmpty ()) return QList<QColor>();
82
84
83
85
auto totalR = 0 ;
@@ -114,8 +116,8 @@ QList<QColor> ColorQuantizerOperation::quantization(
114
116
auto rightHalf = rgbValues.mid (mid);
115
117
116
118
QList<QColor> result;
117
- result.append (quantization (leftHalf, depth + 1 ));
118
- result.append (quantization (rightHalf, depth + 1 ));
119
+ result.append (this -> quantization (leftHalf, depth + 1 ));
120
+ result.append (this -> quantization (rightHalf, depth + 1 ));
119
121
120
122
return result;
121
123
}
@@ -159,7 +161,7 @@ void ColorQuantizerOperation::finishRun() {
159
161
}
160
162
161
163
void ColorQuantizerOperation::finished () {
162
- emit this ->done (colors);
164
+ emit this ->done (this -> colors );
163
165
delete this ;
164
166
}
165
167
@@ -178,39 +180,39 @@ void ColorQuantizerOperation::run() {
178
180
void ColorQuantizerOperation::tryCancel () { this ->shouldCancel .storeRelease (true ); }
179
181
180
182
void ColorQuantizer::componentComplete () {
181
- componentCompleted = true ;
182
- if (!mSource .isEmpty ()) quantizeAsync ();
183
+ this -> componentCompleted = true ;
184
+ if (!this -> mSource .isEmpty ()) this -> quantizeAsync ();
183
185
}
184
186
185
187
void ColorQuantizer::setSource (const QUrl& source) {
186
- if (mSource != source) {
187
- mSource = source;
188
+ if (this -> mSource != source) {
189
+ this -> mSource = source;
188
190
emit this ->sourceChanged ();
189
191
190
- if (this ->componentCompleted && !mSource .isEmpty ()) quantizeAsync ();
192
+ if (this ->componentCompleted && !this -> mSource .isEmpty ()) this -> quantizeAsync ();
191
193
}
192
194
}
193
195
194
196
void ColorQuantizer::setDepth (qreal depth) {
195
- if (mDepth != depth) {
196
- mDepth = depth;
197
+ if (this -> mDepth != depth) {
198
+ this -> mDepth = depth;
197
199
emit this ->depthChanged ();
198
200
199
- if (this ->componentCompleted ) quantizeAsync ();
201
+ if (this ->componentCompleted ) this -> quantizeAsync ();
200
202
}
201
203
}
202
204
203
205
void ColorQuantizer::setRescaleSize (int rescaleSize) {
204
- if (mRescaleSize != rescaleSize) {
205
- mRescaleSize = rescaleSize;
206
+ if (this -> mRescaleSize != rescaleSize) {
207
+ this -> mRescaleSize = rescaleSize;
206
208
emit this ->rescaleSizeChanged ();
207
209
208
- if (this ->componentCompleted ) quantizeAsync ();
210
+ if (this ->componentCompleted ) this -> quantizeAsync ();
209
211
}
210
212
}
211
213
212
214
void ColorQuantizer::operationFinished (const QList<QColor>& result) {
213
- bColors = result;
215
+ this -> bColors = result;
214
216
this ->liveOperation = nullptr ;
215
217
emit this ->colorsChanged ();
216
218
}
@@ -219,7 +221,8 @@ void ColorQuantizer::quantizeAsync() {
219
221
if (this ->liveOperation ) this ->cancelAsync ();
220
222
221
223
qCDebug (logColorQuantizer) << " Starting color quantization asynchronously" ;
222
- this ->liveOperation = new ColorQuantizerOperation (&mSource , mDepth , mRescaleSize );
224
+ this ->liveOperation =
225
+ new ColorQuantizerOperation (&this ->mSource , this ->mDepth , this ->mRescaleSize );
223
226
224
227
QObject::connect (
225
228
this ->liveOperation ,
0 commit comments