Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPaintDeviceData Class Reference

#include <kis_paint_device_data.h>

Classes

struct  CacheInvalidator
 
class  ChangeColorSpaceCommand
 
class  ChangeProfileCommand
 

Public Member Functions

void assignColorSpace (const KoColorSpace *dstColorSpace, KUndo2Command *parentCommand)
 
ALWAYS_INLINE KisPaintDeviceCachecache ()
 
ALWAYS_INLINE KisIteratorCompleteListenercacheInvalidator ()
 
ALWAYS_INLINE const KoColorSpacecolorSpace () const
 
void convertDataColorSpace (const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags, KUndo2Command *parentCommand, KoUpdater *updater=nullptr)
 
ALWAYS_INLINE KUndo2CommandcreateChangeInterstrokeDataCommand (KisInterstrokeDataSP value)
 
ALWAYS_INLINE KisDataManagerSP dataManager () const
 
void init (const KoColorSpace *cs, KisDataManagerSP dataManager)
 
ALWAYS_INLINE KisInterstrokeDataSP interstrokeData () const
 
 KisPaintDeviceData (KisPaintDevice *paintDevice)
 
 KisPaintDeviceData (KisPaintDevice *paintDevice, const KisPaintDeviceData *rhs, bool cloneContent)
 
ALWAYS_INLINE qint32 levelOfDetail () const
 
void prepareClone (const KisPaintDeviceData *srcData, bool copyContent=false)
 
void reincarnateWithDetachedHistory (bool copyContent, KUndo2Command *parentCommand)
 
ALWAYS_INLINE void setLevelOfDetail (qint32 value)
 
ALWAYS_INLINE void setX (qint32 value)
 
ALWAYS_INLINE void setY (qint32 value)
 
ALWAYS_INLINE qint32 x () const
 
ALWAYS_INLINE qint32 y () const
 

Private Attributes

KisPaintDeviceCache m_cache
 
CacheInvalidator m_cacheInvalidator
 
const KoColorSpacem_colorSpace
 
KisDataManagerSP m_dataManager
 
KisInterstrokeDataSP m_interstrokeData
 
qint32 m_levelOfDetail
 
qint32 m_x
 
qint32 m_y
 

Detailed Description

Definition at line 45 of file kis_paint_device_data.h.

Constructor & Destructor Documentation

◆ KisPaintDeviceData() [1/2]

KisPaintDeviceData::KisPaintDeviceData ( KisPaintDevice * paintDevice)
inline

Definition at line 48 of file kis_paint_device_data.h.

49 : m_cache(paintDevice),
50 m_x(0), m_y(0),
51 m_colorSpace(0),
54 {
55 }
CacheInvalidator m_cacheInvalidator
KisPaintDeviceCache m_cache
const KoColorSpace * m_colorSpace

◆ KisPaintDeviceData() [2/2]

KisPaintDeviceData::KisPaintDeviceData ( KisPaintDevice * paintDevice,
const KisPaintDeviceData * rhs,
bool cloneContent )
inline

Definition at line 57 of file kis_paint_device_data.h.

58 : m_dataManager(cloneContent ?
59 new KisDataManager(*rhs->m_dataManager) :
60 new KisDataManager(rhs->m_dataManager->pixelSize(), rhs->m_dataManager->defaultPixel())),
61 m_cache(paintDevice),
62 m_x(rhs->m_x),
63 m_y(rhs->m_y),
67 {
69 // WARNING: interstroke data is **not** copied while cloning, that is expected behavior!
70 }
KisDataManagerSP m_dataManager

References m_cache, and KisPaintDeviceCache::setupCache().

Member Function Documentation

◆ assignColorSpace()

void KisPaintDeviceData::assignColorSpace ( const KoColorSpace * dstColorSpace,
KUndo2Command * parentCommand )
inline

Definition at line 142 of file kis_paint_device_data.h.

142 {
143 if (*m_colorSpace->profile() == *dstColorSpace->profile()) return;
144
146
147 ChangeProfileCommand *cmd =
148 new ChangeProfileCommand(this,
149 m_colorSpace, dstColorSpace,
150 parentCommand);
151
152 // NOTE: first redo is skipped on a higher level,
153 // at DeviceChangeColorSpaceCommand
154 cmd->redo();
155
156 if (!parentCommand) {
157 delete cmd;
158 }
159 }
virtual quint32 pixelSize() const =0
virtual const KoColorProfile * profile() const =0
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75

References KIS_ASSERT_RECOVER_RETURN, m_colorSpace, KoColorSpace::pixelSize(), KoColorSpace::profile(), and KisPaintDeviceData::ChangeProfileCommand::redo().

◆ cache()

ALWAYS_INLINE KisPaintDeviceCache * KisPaintDeviceData::cache ( )
inline

Definition at line 301 of file kis_paint_device_data.h.

301 {
302 return &m_cache;
303 }

References m_cache.

◆ cacheInvalidator()

ALWAYS_INLINE KisIteratorCompleteListener * KisPaintDeviceData::cacheInvalidator ( )
inline

Definition at line 330 of file kis_paint_device_data.h.

330 {
331 return &m_cacheInvalidator;
332 }

References m_cacheInvalidator.

◆ colorSpace()

ALWAYS_INLINE const KoColorSpace * KisPaintDeviceData::colorSpace ( ) const
inline

Definition at line 319 of file kis_paint_device_data.h.

319 {
320 return m_colorSpace;
321 }

References m_colorSpace.

◆ convertDataColorSpace()

void KisPaintDeviceData::convertDataColorSpace ( const KoColorSpace * dstColorSpace,
KoColorConversionTransformation::Intent renderingIntent,
KoColorConversionTransformation::ConversionFlags conversionFlags,
KUndo2Command * parentCommand,
KoUpdater * updater = nullptr )
inline

Definition at line 161 of file kis_paint_device_data.h.

166 {
167 using InternalSequentialConstIterator =
169 using InternalSequentialIterator =
171
172 if (m_colorSpace == dstColorSpace || *m_colorSpace == *dstColorSpace) {
173 return;
174 }
175
176 QRect rc = m_dataManager->region().boundingRect();
177
178 const int dstPixelSize = dstColorSpace->pixelSize();
179 QScopedArrayPointer<quint8> dstDefaultPixel(new quint8[dstPixelSize]);
180 memset(dstDefaultPixel.data(), 0, dstPixelSize);
181 m_colorSpace->convertPixelsTo(m_dataManager->defaultPixel(), dstDefaultPixel.data(), dstColorSpace, 1, renderingIntent, conversionFlags);
182
183 KisDataManagerSP dstDataManager = new KisDataManager(dstPixelSize, dstDefaultPixel.data());
184
185
186 if (!rc.isEmpty()) {
187 InternalSequentialConstIterator srcIt(DirectDataAccessPolicy(m_dataManager.data(), cacheInvalidator()), rc, updater);
188 InternalSequentialIterator dstIt(DirectDataAccessPolicy(dstDataManager.data(), cacheInvalidator()), rc, updater);
189
190 int nConseqPixels = srcIt.nConseqPixels();
191
192 // since we are accessing data managers directly, the columns are always aligned
193 KIS_SAFE_ASSERT_RECOVER_NOOP(srcIt.nConseqPixels() == dstIt.nConseqPixels());
194
195 while(srcIt.nextPixels(nConseqPixels) &&
196 dstIt.nextPixels(nConseqPixels)) {
197
198 nConseqPixels = srcIt.nConseqPixels();
199
200 const quint8 *srcData = srcIt.rawDataConst();
201 quint8 *dstData = dstIt.rawData();
202
203 m_colorSpace->convertPixelsTo(srcData, dstData,
204 dstColorSpace,
205 nConseqPixels,
206 renderingIntent, conversionFlags);
207 }
208 }
209
210 // becomes owned by the parent
211 ChangeColorSpaceCommand *cmd =
212 new ChangeColorSpaceCommand(this,
213 m_dataManager, dstDataManager,
214 m_colorSpace, dstColorSpace,
215 parentCommand);
216
217 // NOTE: first redo is skipped on a higher level,
218 // at DeviceChangeColorSpaceCommand
219 cmd->redo();
220
221 if (!parentCommand) {
222 delete cmd;
223 }
224 }
KisRegion region() const
const quint8 * defaultPixel() const
ALWAYS_INLINE KisIteratorCompleteListener * cacheInvalidator()
QRect boundingRect() const
virtual bool convertPixelsTo(const quint8 *src, quint8 *dst, const KoColorSpace *dstColorSpace, quint32 numPixels, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KisRegion::boundingRect(), cacheInvalidator(), KoColorSpace::convertPixelsTo(), KisSharedPtr< T >::data(), KisDataManager::defaultPixel(), KIS_SAFE_ASSERT_RECOVER_NOOP, m_colorSpace, m_dataManager, KoColorSpace::pixelSize(), KisPaintDeviceData::ChangeColorSpaceCommand::redo(), and KisDataManager::region().

◆ createChangeInterstrokeDataCommand()

ALWAYS_INLINE KUndo2Command * KisPaintDeviceData::createChangeInterstrokeDataCommand ( KisInterstrokeDataSP value)
inline

Definition at line 338 of file kis_paint_device_data.h.

338 {
339 struct SwapInterstrokeDataCommand : public KUndo2Command
340 {
341 SwapInterstrokeDataCommand(KisPaintDeviceData *q, KisInterstrokeDataSP data)
342 : m_q(q),
343 m_data(data)
344 {
345 }
346
347 void redo() override {
348 std::swap(m_data, m_q->m_interstrokeData);
349 }
350
351 void undo() override {
352 std::swap(m_data, m_q->m_interstrokeData);
353 }
354
355 private:
358 };
359
360 return new SwapInterstrokeDataCommand(this, value);
361 }
float value(const T *src, size_t ch)
QAction * redo(const QObject *recvr, const char *slot, QObject *parent)
QAction * undo(const QObject *recvr, const char *slot, QObject *parent)

References value().

◆ dataManager()

ALWAYS_INLINE KisDataManagerSP KisPaintDeviceData::dataManager ( ) const
inline

Definition at line 297 of file kis_paint_device_data.h.

297 {
298 return m_dataManager;
299 }

References m_dataManager.

◆ init()

void KisPaintDeviceData::init ( const KoColorSpace * cs,
KisDataManagerSP dataManager )
inline

Definition at line 72 of file kis_paint_device_data.h.

72 {
73 m_colorSpace = cs;
76 }
ALWAYS_INLINE KisDataManagerSP dataManager() const

References dataManager(), m_cache, m_colorSpace, m_dataManager, and KisPaintDeviceCache::setupCache().

◆ interstrokeData()

ALWAYS_INLINE KisInterstrokeDataSP KisPaintDeviceData::interstrokeData ( ) const
inline

Definition at line 334 of file kis_paint_device_data.h.

334 {
335 return m_interstrokeData;
336 }
KisInterstrokeDataSP m_interstrokeData

References m_interstrokeData.

◆ levelOfDetail()

ALWAYS_INLINE qint32 KisPaintDeviceData::levelOfDetail ( ) const
inline

Definition at line 323 of file kis_paint_device_data.h.

323 {
324 return m_levelOfDetail;
325 }

References m_levelOfDetail.

◆ prepareClone()

void KisPaintDeviceData::prepareClone ( const KisPaintDeviceData * srcData,
bool copyContent = false )
inline

Definition at line 265 of file kis_paint_device_data.h.

265 {
266 m_x = srcData->x();
267 m_y = srcData->y();
268
269 if (copyContent) {
270 m_dataManager = new KisDataManager(*srcData->dataManager());
271 } else if (m_dataManager->pixelSize() !=
272 srcData->dataManager()->pixelSize()) {
273 // NOTE: we don't check default pixel value! it is the task of
274 // the higher level!
275
276 m_dataManager = new KisDataManager(srcData->dataManager()->pixelSize(), srcData->dataManager()->defaultPixel());
278 } else {
280 const quint8 *srcDefPixel = srcData->dataManager()->defaultPixel();
281
282 const int cmp =
283 memcmp(srcDefPixel,
286
287 if (cmp != 0) {
288 m_dataManager->setDefaultPixel(srcDefPixel);
289 }
290 }
291
292 m_levelOfDetail = srcData->levelOfDetail();
293 m_colorSpace = srcData->colorSpace();
295 }
void clear(qint32 x, qint32 y, qint32 w, qint32 h, quint8 def)
void setDefaultPixel(const quint8 *defPixel)
quint32 pixelSize() const
ALWAYS_INLINE qint32 levelOfDetail() const
ALWAYS_INLINE qint32 y() const
ALWAYS_INLINE qint32 x() const
ALWAYS_INLINE const KoColorSpace * colorSpace() const

References KisDataManager::clear(), colorSpace(), dataManager(), KisDataManager::defaultPixel(), KisPaintDeviceCache::invalidate(), levelOfDetail(), m_cache, m_colorSpace, m_dataManager, m_levelOfDetail, m_x, m_y, KisDataManager::pixelSize(), KisDataManager::setDefaultPixel(), KisPaintDeviceCache::setupCache(), x(), and y().

◆ reincarnateWithDetachedHistory()

void KisPaintDeviceData::reincarnateWithDetachedHistory ( bool copyContent,
KUndo2Command * parentCommand )
inline

Definition at line 226 of file kis_paint_device_data.h.

226 {
227 struct SwitchDataManager : public KUndo2Command
228 {
229 SwitchDataManager(KisPaintDeviceData *data,
231 KUndo2Command *parent = 0)
233 m_data(data),
234 m_oldDm(oldDm),
235 m_newDm(newDm)
236 {
237 }
238
239 void redo() override {
240 m_data->m_dataManager = m_newDm;
241 m_data->cache()->invalidate();
242 }
243
244 void undo() override {
245 m_data->m_dataManager = m_oldDm;
246 m_data->cache()->invalidate();
247 }
248
249 private:
250 KisPaintDeviceData *m_data;
251 KisDataManagerSP m_oldDm;
252 KisDataManagerSP m_newDm;
253 };
254
255 new KisCommandUtils::LambdaCommand(parentCommand,
256 [this, copyContent] () {
257 KisDataManagerSP newDm =
258 copyContent ?
259 new KisDataManager(*this->dataManager()) :
260 new KisDataManager(this->dataManager()->pixelSize(), this->dataManager()->defaultPixel());
261 return new SwitchDataManager(this, this->dataManager(), newDm);
262 });
263 }
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327
The LambdaCommand struct is a shorthand for creation of AggregateCommand commands using C++ lambda fe...

References dataManager().

◆ setLevelOfDetail()

ALWAYS_INLINE void KisPaintDeviceData::setLevelOfDetail ( qint32 value)
inline

Definition at line 326 of file kis_paint_device_data.h.

326 {
328 }

References m_levelOfDetail, and value().

◆ setX()

ALWAYS_INLINE void KisPaintDeviceData::setX ( qint32 value)
inline

Definition at line 308 of file kis_paint_device_data.h.

308 {
309 m_x = value;
310 }

References m_x, and value().

◆ setY()

ALWAYS_INLINE void KisPaintDeviceData::setY ( qint32 value)
inline

Definition at line 315 of file kis_paint_device_data.h.

315 {
316 m_y = value;
317 }

References m_y, and value().

◆ x()

ALWAYS_INLINE qint32 KisPaintDeviceData::x ( ) const
inline

Definition at line 305 of file kis_paint_device_data.h.

305 {
306 return m_x;
307 }

References m_x.

◆ y()

ALWAYS_INLINE qint32 KisPaintDeviceData::y ( ) const
inline

Definition at line 312 of file kis_paint_device_data.h.

312 {
313 return m_y;
314 }

References m_y.

Member Data Documentation

◆ m_cache

KisPaintDeviceCache KisPaintDeviceData::m_cache
private

Definition at line 379 of file kis_paint_device_data.h.

◆ m_cacheInvalidator

CacheInvalidator KisPaintDeviceData::m_cacheInvalidator
private

Definition at line 384 of file kis_paint_device_data.h.

◆ m_colorSpace

const KoColorSpace* KisPaintDeviceData::m_colorSpace
private

Definition at line 382 of file kis_paint_device_data.h.

◆ m_dataManager

KisDataManagerSP KisPaintDeviceData::m_dataManager
private

Definition at line 378 of file kis_paint_device_data.h.

◆ m_interstrokeData

KisInterstrokeDataSP KisPaintDeviceData::m_interstrokeData
private

Definition at line 385 of file kis_paint_device_data.h.

◆ m_levelOfDetail

qint32 KisPaintDeviceData::m_levelOfDetail
private

Definition at line 383 of file kis_paint_device_data.h.

◆ m_x

qint32 KisPaintDeviceData::m_x
private

Definition at line 380 of file kis_paint_device_data.h.

◆ m_y

qint32 KisPaintDeviceData::m_y
private

Definition at line 381 of file kis_paint_device_data.h.


The documentation for this class was generated from the following file: