55#include < qproperty.h>
66#include < qqmlintegration.h>
77#include < qqmlparserstatus.h>
8+ #include < qrect.h>
89#include < qrunnable.h>
910#include < qtmetamacros.h>
1011#include < qtypes.h>
@@ -16,7 +17,7 @@ class ColorQuantizerOperation
1617 Q_OBJECT;
1718
1819public:
19- explicit ColorQuantizerOperation (QUrl* source, qreal depth, qreal rescaleSize);
20+ explicit ColorQuantizerOperation (QUrl* source, qreal depth, QRect imageRect, qreal rescaleSize);
2021
2122 void run () override ;
2223 void tryCancel ();
@@ -44,6 +45,7 @@ private slots:
4445 QList<QColor> colors;
4546 QUrl* source;
4647 qreal maxDepth;
48+ QRect imageRect;
4749 qreal rescaleSize;
4850};
4951
@@ -78,6 +80,9 @@ class ColorQuantizer
7880 // / binary split of the color space
7981 Q_PROPERTY (qreal depth READ depth WRITE setDepth NOTIFY depthChanged);
8082
83+ // / Rectangle that the source image is cropped to.
84+ Q_PROPERTY (QRect imageRect READ imageRect WRITE setImageRect NOTIFY imageRectChanged);
85+
8186 // / The size to rescale the image to, when rescaleSize is 0 then no scaling will be done.
8287 // / > [!NOTE] Results from color quantization doesn't suffer much when rescaling, it's
8388 // / > reccommended to rescale, otherwise the quantization process will take much longer.
@@ -97,13 +102,17 @@ class ColorQuantizer
97102 [[nodiscard]] qreal depth () const { return mDepth ; }
98103 void setDepth (qreal depth);
99104
105+ [[nodiscard]] QRect imageRect () const { return mImageRect ; }
106+ void setImageRect (QRect imageRect);
107+
100108 [[nodiscard]] qreal rescaleSize () const { return mRescaleSize ; }
101109 void setRescaleSize (int rescaleSize);
102110
103111signals:
104112 void colorsChanged ();
105113 void sourceChanged ();
106114 void depthChanged ();
115+ void imageRectChanged ();
107116 void rescaleSizeChanged ();
108117
109118public slots:
@@ -117,6 +126,7 @@ public slots:
117126 ColorQuantizerOperation* liveOperation = nullptr ;
118127 QUrl mSource ;
119128 qreal mDepth = 0 ;
129+ QRect mImageRect = QRect();
120130 qreal mRescaleSize = 0 ;
121131
122132 Q_OBJECT_BINDABLE_PROPERTY (
0 commit comments