Commit 0c816c17 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Implement simple progress reporting for the Colorize Mask

The progress bar is shown in the layer box only
parent 70d2bd39
......@@ -22,6 +22,7 @@
#include <KoColorSpace.h>
#include <KoColor.h>
#include <KoAlwaysInline.h>
#include <KoUpdater.h>
#include "kis_lazy_fill_tools.h"
......@@ -226,6 +227,11 @@ struct KisWatershedWorker::Private
int backgroundGroupColor = -1;
bool recolorMode = false;
quint64 totalPixelsToFill = 0;
quint64 numFilledPixels = 0;
KoUpdater *progressUpdater = 0;
void initializeQueueFromGroupMap(const QRect &rc);
ALWAYS_INLINE void visitNeighbour(const QPoint &currPt, const QPoint &prevPt, quint8 fromDirection, int prevDistance, quint8 prevLevel, qint32 prevGroupId, FillGroup &prevGroup, FillGroup::LevelData &prevLevelData, qint32 prevPrevGroupId, FillGroup &prevPrevGroup, bool statsOnly = false);
......@@ -253,11 +259,12 @@ struct KisWatershedWorker::Private
KisWatershedWorker::KisWatershedWorker(KisPaintDeviceSP heightMap, KisPaintDeviceSP dst, const QRect &boundingRect)
KisWatershedWorker::KisWatershedWorker(KisPaintDeviceSP heightMap, KisPaintDeviceSP dst, const QRect &boundingRect, KoUpdater *progress)
: m_d(new Private)
{
KIS_SAFE_ASSERT_RECOVER_RETURN(heightMap->colorSpace()->pixelSize() == 1);
m_d->progressUpdater = progress;
m_d->heightMap = heightMap;
m_d->dstDevice = dst;
m_d->boundingRect = boundingRect;
......@@ -635,6 +642,11 @@ void KisWatershedWorker::Private::processQueue(qint32 _backgroundGroupId)
backgroundGroupColor = groups[backgroundGroupId].colorIndex;
recolorMode = backgroundGroupId > 1;
totalPixelsToFill = boundingRect.width() * boundingRect.height();
numFilledPixels = 0;
const int progressReportingMask = (1 << 18) - 1; // report every 512x512 patch
if (recolorMode) {
updateNarrowRegionMetrics();
}
......@@ -660,6 +672,8 @@ void KisWatershedWorker::Private::processQueue(qint32 _backgroundGroupId)
if (prevGroupId > 0) {
FillGroup::LevelData &prevLevelData = prevGroup.levels[pt.level];
prevLevelData.numFilledPixels--;
} else {
numFilledPixels++;
}
const NeighbourStaticOffset *offsets = staticOffsets[pt.prevDirection];
......@@ -678,6 +692,12 @@ void KisWatershedWorker::Private::processQueue(qint32 _backgroundGroupId)
*groupPtr = pt.group;
if (progressUpdater && !(numFilledPixels & progressReportingMask)) {
const int progressPercent =
qBound(0, qRound(100.0 * numFilledPixels / totalPixelsToFill), 100);
progressUpdater->setProgress(progressPercent);
}
} else {
// nothing to do?
}
......
......@@ -42,7 +42,8 @@ public:
*/
KisWatershedWorker(KisPaintDeviceSP heightMap,
KisPaintDeviceSP dst,
const QRect &boundingRect);
const QRect &boundingRect,
KoUpdater *progress = 0);
~KisWatershedWorker();
/**
......
......@@ -333,6 +333,7 @@ void KisColorizeMask::slotUpdateRegenerateFilling(bool prefilterOnly)
m_d->filteredSource,
filteredSourceValid,
image->bounds(),
this,
prefilterOnly);
strategy->setFilteringOptions(m_d->filteringOptions);
......
......@@ -30,6 +30,7 @@
#include "kis_node.h"
#include "kis_image_config.h"
#include "KisWatershedWorker.h"
#include "kis_processing_visitor.h"
#include "kis_transaction.h"
#include "krita_utils.h"
......@@ -44,7 +45,8 @@ struct KisColorizeStrokeStrategy::Private
{
Private() : filteredSourceValid(false) {}
Private(const Private &rhs)
: src(rhs.src),
: progressNode(rhs.progressNode),
src(rhs.src),
dst(rhs.dst),
filteredSource(rhs.filteredSource),
internalFilteredSource(rhs.internalFilteredSource),
......@@ -55,6 +57,7 @@ struct KisColorizeStrokeStrategy::Private
filteringOptions(rhs.filteringOptions)
{}
KisNodeSP progressNode;
KisPaintDeviceSP src;
KisPaintDeviceSP dst;
KisPaintDeviceSP filteredSource;
......@@ -76,10 +79,12 @@ KisColorizeStrokeStrategy::KisColorizeStrokeStrategy(KisPaintDeviceSP src,
KisPaintDeviceSP filteredSource,
bool filteredSourceValid,
const QRect &boundingRect,
KisNodeSP progressNode,
bool prefilterOnly)
: KisRunnableBasedStrokeStrategy("colorize-stroke", prefilterOnly ? kundo2_i18n("Prefilter Colorize Mask") : kundo2_i18n("Colorize")),
m_d(new Private)
{
m_d->progressNode = progressNode;
m_d->src = src;
m_d->dst = dst;
m_d->filteredSource = filteredSource;
......@@ -236,7 +241,9 @@ void KisColorizeStrokeStrategy::initStrokeCallback()
}
addJobSequential(jobs, [this] () {
KisWatershedWorker worker(m_d->heightMap, m_d->dst, m_d->boundingRect);
KisProcessingVisitor::ProgressHelper helper(m_d->progressNode);
KisWatershedWorker worker(m_d->heightMap, m_d->dst, m_d->boundingRect, helper.updater());
Q_FOREACH (const KeyStroke &stroke, m_d->keyStrokes) {
KoColor color =
!stroke.isTransparent ?
......
......@@ -41,7 +41,7 @@ public:
KisPaintDeviceSP dst,
KisPaintDeviceSP filteredSource,
bool filteredSourceValid,
const QRect &boundingRect,
const QRect &boundingRect, KisNodeSP progressNode,
bool prefilterOnly = false);
KisColorizeStrokeStrategy(const KisColorizeStrokeStrategy &rhs, int levelOfDetail);
~KisColorizeStrokeStrategy() override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment