1313#include < qnumeric.h>
1414#include < qobject.h>
1515#include < qqmllist.h>
16+ #include < qrect.h>
1617#include < qrgb.h>
1718#include < qthreadpool.h>
1819#include < qtmetamacros.h>
@@ -24,9 +25,15 @@ namespace {
2425QS_LOGGING_CATEGORY (logColorQuantizer, " quickshell.colorquantizer" , QtWarningMsg);
2526}
2627
27- ColorQuantizerOperation::ColorQuantizerOperation (QUrl* source, qreal depth, qreal rescaleSize)
28+ ColorQuantizerOperation::ColorQuantizerOperation (
29+ QUrl* source,
30+ qreal depth,
31+ QRect imageRect,
32+ qreal rescaleSize
33+ )
2834 : source(source)
2935 , maxDepth(depth)
36+ , imageRect(imageRect)
3037 , rescaleSize(rescaleSize) {
3138 setAutoDelete (false );
3239}
@@ -37,6 +44,11 @@ void ColorQuantizerOperation::quantizeImage(const QAtomicInteger<bool>& shouldCa
3744 colors.clear ();
3845
3946 auto image = QImage (source->toLocalFile ());
47+
48+ if (imageRect.isValid ()) {
49+ image = image.copy (imageRect);
50+ }
51+
4052 if ((image.width () > rescaleSize || image.height () > rescaleSize) && rescaleSize > 0 ) {
4153 image = image.scaled (
4254 static_cast <int >(rescaleSize),
@@ -209,6 +221,15 @@ void ColorQuantizer::setRescaleSize(int rescaleSize) {
209221 }
210222}
211223
224+ void ColorQuantizer::setImageRect (QRect imageRect) {
225+ if (imageRect != mImageRect ) {
226+ mImageRect = imageRect;
227+ emit this ->imageRectChanged ();
228+
229+ if (this ->componentCompleted ) quantizeAsync ();
230+ }
231+ }
232+
212233void ColorQuantizer::operationFinished (const QList<QColor>& result) {
213234 bColors = result;
214235 this ->liveOperation = nullptr ;
@@ -219,7 +240,7 @@ void ColorQuantizer::quantizeAsync() {
219240 if (this ->liveOperation ) this ->cancelAsync ();
220241
221242 qCDebug (logColorQuantizer) << " Starting color quantization asynchronously" ;
222- this ->liveOperation = new ColorQuantizerOperation (&mSource , mDepth , mRescaleSize );
243+ this ->liveOperation = new ColorQuantizerOperation (&mSource , mDepth , mImageRect , mRescaleSize );
223244
224245 QObject::connect (
225246 this ->liveOperation ,
0 commit comments