Krita Source Code Documentation
Loading...
Searching...
No Matches
Acs::PixelCacheRenderer Class Reference

#include <kis_acs_pixel_cache_renderer.h>

Static Public Member Functions

template<class Sampler >
static void render (Sampler *sampler, const KisDisplayColorConverter *converter, const QRect &sampleRect, KisPaintDeviceSP &realPixelCache, QImage &pixelCache, QPoint &pixelCacheOffset, qreal devicePixelRatioF)
 

Detailed Description

Definition at line 18 of file kis_acs_pixel_cache_renderer.h.

Member Function Documentation

◆ render()

template<class Sampler >
static void Acs::PixelCacheRenderer::render ( Sampler * sampler,
const KisDisplayColorConverter * converter,
const QRect & sampleRect,
KisPaintDeviceSP & realPixelCache,
QImage & pixelCache,
QPoint & pixelCacheOffset,
qreal devicePixelRatioF )
inlinestatic

Sampler class must provide one method:

  • KoColor Sampler::colorAt(float x, float y);

How to handle High DPI:

  • sampleRect - is in device independent pixels coordinates space (amount of space on the widget)
  • devicePixelRatioF - the amount of UI scaling
  • pixelCache and realPixelCache gets the size of sampleRect.size()*devicePixelRatioF and sets the device pixel ratio, and color samplers need to take it into account. That way you can paint on the cache the same way you'd paint on a low dpi display and then just use painter->drawImage() and it works.

Definition at line 36 of file kis_acs_pixel_cache_renderer.h.

43 {
44 const KoColorSpace *cacheColorSpace = converter->paintingColorSpace();
45 const int pixelSize = cacheColorSpace->pixelSize();
46
47 if (!realPixelCache || realPixelCache->colorSpace() != cacheColorSpace) {
48 realPixelCache = new KisPaintDevice(cacheColorSpace);
49 }
50
51 KoColor color;
52
53 QRect sampleRectHighDPI = QRect(sampleRect.topLeft(), sampleRect.size()*devicePixelRatioF);
54 KisSequentialIterator it(realPixelCache, sampleRectHighDPI);
55
56 while (it.nextPixel()) {
57 color = sampler->colorAt(it.x()/devicePixelRatioF, it.y()/devicePixelRatioF);
58 memcpy(it.rawData(), color.data(), pixelSize);
59 }
60
61
62 // NOTE: toQImage() function of the converter copies exactBounds() only!
63 pixelCache = converter->toQImage(realPixelCache);
64 pixelCache.setDevicePixelRatio(devicePixelRatioF);
65 pixelCacheOffset = realPixelCache->exactBounds().topLeft()/devicePixelRatioF - sampleRect.topLeft();
66 }
const KoColorSpace * paintingColorSpace() const
QImage toQImage(KisPaintDeviceSP srcDevice, bool proofPaintColors=false) const
QRect exactBounds() const
const KoColorSpace * colorSpace() const
virtual quint32 pixelSize() const =0
quint8 * data()
Definition KoColor.h:144

References KisPaintDevice::colorSpace(), KoColor::data(), KisPaintDevice::exactBounds(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisDisplayColorConverter::paintingColorSpace(), KoColorSpace::pixelSize(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), KisDisplayColorConverter::toQImage(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::x(), and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::y().


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