forked from quickshell/quickshell
fix: additional pr requests
This commit is contained in:
parent
b7eb562abc
commit
a84a6726cb
|
@ -17,18 +17,14 @@ ColorQuantizerOperation::ColorQuantizerOperation(QUrl* source, qreal depth, qrea
|
|||
, maxDepth(depth)
|
||||
, rescaleSize(rescaleSize) {
|
||||
setAutoDelete(false);
|
||||
colors = QList<QColor>();
|
||||
}
|
||||
|
||||
void ColorQuantizerOperation::quantizeImage(const QAtomicInteger<bool>& shouldCancel) {
|
||||
if (shouldCancel.loadAcquire()) return;
|
||||
if (shouldCancel.loadAcquire() || source->isEmpty()) return;
|
||||
|
||||
colors.clear();
|
||||
|
||||
if (source->isEmpty()) return;
|
||||
|
||||
auto image = QImage(source->toLocalFile());
|
||||
|
||||
if ((image.width() > rescaleSize || image.height() > rescaleSize) && rescaleSize > 0) {
|
||||
image = image.scaled(
|
||||
static_cast<int>(rescaleSize),
|
||||
|
@ -59,7 +55,7 @@ void ColorQuantizerOperation::quantizeImage(const QAtomicInteger<bool>& shouldCa
|
|||
|
||||
auto endTime = QDateTime::currentDateTime();
|
||||
auto milliseconds = startTime.msecsTo(endTime);
|
||||
qDebug() << "Color Quantization took: " << milliseconds << "ms";
|
||||
qCDebug(logColorQuantizer) << "Color Quantization took: " << milliseconds << "ms";
|
||||
}
|
||||
|
||||
QList<QColor> ColorQuantizerOperation::quantization(
|
||||
|
@ -95,8 +91,8 @@ QList<QColor> ColorQuantizerOperation::quantization(
|
|||
|
||||
auto dominantChannel = findBiggestColorRange(rgbValues);
|
||||
std::ranges::sort(rgbValues, [dominantChannel](const auto& a, const auto& b) {
|
||||
if (dominantChannel == "r") return a.red() < b.red();
|
||||
else if (dominantChannel == "g") return a.green() < b.green();
|
||||
if (dominantChannel == 'r') return a.red() < b.red();
|
||||
else if (dominantChannel == 'g') return a.green() < b.green();
|
||||
return a.blue() < b.blue();
|
||||
});
|
||||
|
||||
|
@ -112,7 +108,7 @@ QList<QColor> ColorQuantizerOperation::quantization(
|
|||
return result;
|
||||
}
|
||||
|
||||
QChar ColorQuantizerOperation::findBiggestColorRange(const QList<QColor>& rgbValues) {
|
||||
char ColorQuantizerOperation::findBiggestColorRange(const QList<QColor>& rgbValues) {
|
||||
if (rgbValues.isEmpty()) return 'r';
|
||||
|
||||
auto rMin = 255;
|
||||
|
@ -203,8 +199,8 @@ void ColorQuantizer::setRescaleSize(int rescaleSize) {
|
|||
|
||||
void ColorQuantizer::operationFinished(const QList<QColor>& result) {
|
||||
bColors = result;
|
||||
emit this->colorsChanged();
|
||||
this->liveOperation = nullptr;
|
||||
emit this->colorsChanged();
|
||||
}
|
||||
|
||||
void ColorQuantizer::quantizeAsync() {
|
||||
|
@ -212,12 +208,14 @@ void ColorQuantizer::quantizeAsync() {
|
|||
|
||||
qCDebug(logColorQuantizer) << "Starting color quantization asynchronously";
|
||||
this->liveOperation = new ColorQuantizerOperation(&mSource, mDepth, mRescaleSize);
|
||||
|
||||
QObject::connect(
|
||||
this->liveOperation,
|
||||
&ColorQuantizerOperation::done,
|
||||
this,
|
||||
&ColorQuantizer::operationFinished
|
||||
);
|
||||
|
||||
QThreadPool::globalInstance()->start(this->liveOperation);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ private slots:
|
|||
void finished();
|
||||
|
||||
private:
|
||||
static QChar findBiggestColorRange(const QList<QColor>& rgbValues);
|
||||
static char findBiggestColorRange(const QList<QColor>& rgbValues);
|
||||
|
||||
void quantizeImage(const QAtomicInteger<bool>& shouldCancel = false);
|
||||
QList<QColor> quantization(
|
||||
|
@ -67,7 +67,7 @@ class ColorQuantizer
|
|||
/// Access the colors resulting from the color quantization performed.
|
||||
/// > [!NOTE] The amount of colors returned from the quantization is determined by
|
||||
/// > the property depth, specifically 2ⁿ where n is the depth.
|
||||
Q_PROPERTY(QList<QColor> colors READ default BINDABLE bindableColors);
|
||||
Q_PROPERTY(QList<QColor> colors READ default NOTIFY colorsChanged BINDABLE bindableColors);
|
||||
|
||||
/// Path to the image you'd like to run the color quantization on.
|
||||
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged);
|
||||
|
|
Loading…
Reference in a new issue