[graphics/krita] libs/ui/tool/strokes: Clean up the preview stroke job data API a bit

Emmet O'Neill <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 516d8e0ed65429e10fa7568ce86b61e2ff23a2db by Emmet O'Neill, on behalf of Dat Le.
Committed on 13/08/2026 at 23:16.
Pushed by emmetoneill into branch 'master'.

Clean up the preview stroke job data API a bit

M  +3    -6    libs/ui/tool/strokes/kis_color_sampler_stroke_strategy.cpp
M  +6    -8    libs/ui/tool/strokes/kis_color_sampler_stroke_strategy.h

https://invent.kde.org/graphics/krita/-/commit/516d8e0ed65429e10fa7568ce86b61e2ff23a2db

diff --git a/libs/ui/tool/strokes/kis_color_sampler_stroke_strategy.cpp b/libs/ui/tool/strokes/kis_color_sampler_stroke_strategy.cpp
index 095b25b0708..f711aa6988a 100644
--- a/libs/ui/tool/strokes/kis_color_sampler_stroke_strategy.cpp
+++ b/libs/ui/tool/strokes/kis_color_sampler_stroke_strategy.cpp
@@ -69,13 +69,10 @@ void KisColorSamplerStrokeStrategy::doStrokeCallback(KisStrokeJobData *data)
 
         QImage image = previewData->colorConverter->convertImageToDisplayColorSpace(tmpDev, effectiveRect, true);
 
-        // In case of instant preview, scale the sample back up to fit the original requested rect
-        if (previewData->levelOfDetail > 0) {
-            if (!previewData->originalRect.isValid()) return;
+        if (previewData->outputSize.isValid()) {
+            image = image.scaled(previewData->outputSize);
 
-            image = image.scaled(previewData->originalRect.size());
-
-            effectiveRect = QRect(QPoint(0,0), previewData->originalRect.size());
+            effectiveRect = QRect(QPoint(0,0), previewData->outputSize);
         }
 
         Q_EMIT sigCanvasZoomPreviewUpdated(image, effectiveRect);
diff --git a/libs/ui/tool/strokes/kis_color_sampler_stroke_strategy.h b/libs/ui/tool/strokes/kis_color_sampler_stroke_strategy.h
index 4990ed8c0e9..d329ae03d83 100644
--- a/libs/ui/tool/strokes/kis_color_sampler_stroke_strategy.h
+++ b/libs/ui/tool/strokes/kis_color_sampler_stroke_strategy.h
@@ -50,14 +50,13 @@ public:
     class GenerateCanvasZoomPreviewData : public KisStrokeJobData {
     public:
         GenerateCanvasZoomPreviewData(KisPaintDeviceSP _canvasDev, const QRect &_canvasPixelRect, KisDisplayColorConverter *_colorConverter,
-                                      int _levelOfDetail = 0, QSharedPointer<boost::none_t> _cookie = nullptr)
+                                      QSize _outputSize = QSize(), QSharedPointer<boost::none_t> _cookie = nullptr)
             : canvasDev(_canvasDev), canvasPixelRect(_canvasPixelRect), colorConverter(_colorConverter),
-            levelOfDetail(_levelOfDetail), strokeCookie(_cookie), originalRect()
+            outputSize(_outputSize), strokeCookie(_cookie)
         {}
 
         KisStrokeJobData* createLodClone(int levelOfDetail) override {
             KisLodTransform transform(levelOfDetail);
-
             QRect lodPixelRect = transform.map(canvasPixelRect);
 
             // The LOD pixel rect size should be odd so that the pixel sampled is in the center
@@ -69,15 +68,15 @@ public:
             }
             lodPixelRect.moveCenter(transform.map(canvasPixelRect.center()));
 
+            // When instant preview mode is on, canvas is scaled down. Therefore, sample the canvas with the scaled LOD rect
+            // But the data returned needs to be the original requested size
             GenerateCanvasZoomPreviewData *newData =
-                new GenerateCanvasZoomPreviewData(canvasDev, lodPixelRect, colorConverter, levelOfDetail);
+                new GenerateCanvasZoomPreviewData(canvasDev, lodPixelRect, colorConverter, canvasPixelRect.size());
 
             // When Lod is involved, swap the cookie to the new Lod clone to track execution
             // The original object seems to leaks
             newData->swapCookie(strokeCookie);
 
-            newData->originalRect = canvasPixelRect;
-
             return newData;
         }
 
@@ -93,9 +92,8 @@ public:
         KisPaintDeviceSP canvasDev;
         QRect canvasPixelRect;
         KisDisplayColorConverter *colorConverter;
-        int levelOfDetail;
+        QSize outputSize; // Useful for LOD
         QSharedPointer<boost::none_t> strokeCookie;
-        QRect originalRect;
     };
 public:
     KisColorSamplerStrokeStrategy(int radius, int blend, int lod = 0);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.