Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_color_sampler_stroke_strategy.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef __KIS_COLOR_SAMPLER_STROKE_STRATEGY_H
8#define __KIS_COLOR_SAMPLER_STROKE_STRATEGY_H
9
10#include <QObject>
12#include "kis_lod_transform.h"
13#include "KoColor.h"
14
16
18{
19 Q_OBJECT
20public:
21 class Data : public KisStrokeJobData {
22 public:
23 Data(KisPaintDeviceSP _dev, const QPoint _pt, KoColor _currentColor)
24 : dev(_dev), pt(_pt), currentColor(_currentColor)
25 {}
26
27 KisStrokeJobData* createLodClone(int levelOfDetail) override {
28 KisLodTransform t(levelOfDetail);
29 const QPoint realPoint = t.map(pt);
30
31 return new Data(dev, realPoint, currentColor);
32 }
33
35 QPoint pt;
36 KoColor currentColor; // Used for color sampler blending.
37 };
38
40 public:
42 {}
43
44 KisStrokeJobData* createLodClone(int levelOfDetail) override {
45 Q_UNUSED(levelOfDetail);
46 return new FinalizeData();
47 }
48 };
49
51 public:
52 GenerateCanvasZoomPreviewData(KisPaintDeviceSP _canvasDev, const QRect &_canvasPixelRect, KisDisplayColorConverter *_colorConverter,
53 QSize _outputSize = QSize(), QSharedPointer<boost::none_t> _cookie = nullptr)
54 : canvasDev(_canvasDev), canvasPixelRect(_canvasPixelRect), colorConverter(_colorConverter),
55 outputSize(_outputSize), strokeCookie(_cookie)
56 {}
57
58 KisStrokeJobData* createLodClone(int levelOfDetail) override {
59 KisLodTransform transform(levelOfDetail);
60 QRect lodPixelRect = transform.map(canvasPixelRect);
61
62 // The LOD pixel rect size should be odd so that the pixel sampled is in the center
63 // Otherwise, even after scaling back, it will be wrong
64 if (lodPixelRect.width() % 2 == 0) {
65 int oddSize = lodPixelRect.width() - 1;
66 if (oddSize < 3) oddSize = 3;
67 lodPixelRect.setSize(QSize(oddSize, oddSize));
68 }
69 lodPixelRect.moveCenter(transform.map(canvasPixelRect.center()));
70
71 // When instant preview mode is on, canvas is scaled down. Therefore, sample the canvas with the scaled LOD rect
72 // But the data returned needs to be the original requested size
75
76 // When Lod is involved, swap the cookie to the new Lod clone to track execution
77 // The original object seems to leaks
78 newData->swapCookie(strokeCookie);
79
80 return newData;
81 }
82
84 strokeCookie.reset(new boost::none_t(boost::none));
85 return strokeCookie;
86 }
87
89 strokeCookie.swap(newCookie);
90 }
91
95 QSize outputSize; // Useful for LOD
97 };
98public:
99 KisColorSamplerStrokeStrategy(int radius, int blend, int lod = 0);
101
102 void doStrokeCallback(KisStrokeJobData *data) override;
103 KisStrokeStrategy* createLodClone(int levelOfDetail) override;
104
105Q_SIGNALS:
106 void sigColorUpdated(const KoColor &color);
107 void sigFinalColorSelected(const KoColor &color);
108 void sigCanvasZoomPreviewUpdated(const QImage &canvasImage, const QRect &canvasRect);
109
110private:
111 struct Private;
112 const QScopedPointer<Private> m_d;
113};
114
115#endif /* __KIS_COLOR_SAMPLER_STROKE_STRATEGY_H */
KisStrokeJobData * createLodClone(int levelOfDetail) override
Data(KisPaintDeviceSP _dev, const QPoint _pt, KoColor _currentColor)
KisStrokeJobData * createLodClone(int levelOfDetail) override
GenerateCanvasZoomPreviewData(KisPaintDeviceSP _canvasDev, const QRect &_canvasPixelRect, KisDisplayColorConverter *_colorConverter, QSize _outputSize=QSize(), QSharedPointer< boost::none_t > _cookie=nullptr)
void doStrokeCallback(KisStrokeJobData *data) override
void sigCanvasZoomPreviewUpdated(const QImage &canvasImage, const QRect &canvasRect)
KisStrokeStrategy * createLodClone(int levelOfDetail) override
KisColorSamplerStrokeStrategy(int radius, int blend, int lod=0)
void sigFinalColorSelected(const KoColor &color)
void sigColorUpdated(const KoColor &color)
KisPaintInformation map(KisPaintInformation pi) const