| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef KIS_BRUSH_SCALAR_APPLICATOR_H |
| 10 |
#define KIS_BRUSH_SCALAR_APPLICATOR_H |
| 11 |
|
| 12 |
#include "kis_brush_mask_applicator_base.h" |
| 13 |
#include "kis_global.h" |
| 14 |
#include "kis_random_source.h" |
| 15 |
|
| 16 |
template<class MaskGenerator, typename impl> |
| 17 |
struct KisBrushMaskScalarApplicator : public KisBrushMaskApplicatorBase { |
| 18 |
KisBrushMaskScalarApplicator(MaskGenerator *maskGenerator) |
| 19 |
: m_maskGenerator(maskGenerator) |
| 20 |
{ |
| 21 |
} |
| 22 |
|
| 23 |
void process(const QRect &rect) override |
| 24 |
{ |
| 25 |
processScalar(rect); |
| 26 |
} |
| 27 |
|
| 28 |
protected: |
| 29 |
void processScalar(const QRect &rect) |
| 30 |
{ |
| 31 |
const MaskProcessingData *m_d = KisBrushMaskApplicatorBase::m_d; |
| 32 |
MaskGenerator *m_maskGenerator = KisBrushMaskScalarApplicator<MaskGenerator, impl>::m_maskGenerator; |
| 33 |
|
| 34 |
qreal random = 1.0; |
| 35 |
quint8 *dabPointer = m_d->device->data() + rect.y() * rect.width() * m_d->pixelSize; |
| 36 |
quint8 alphaValue = OPACITY_TRANSPARENT_U8; |
| 37 |
|
| 38 |
int offset = (m_d->device->bounds().width() - rect.width()) * m_d->pixelSize; |
| 39 |
int supersample = 1; |
| 40 |
if (m_maskGenerator->shouldSupersample()) { |
| 41 |
|
| 42 |
supersample = (m_maskGenerator->shouldSupersample6x6() ? 6 : 3); |
| 43 |
} |
| 44 |
double invss = 1.0 / supersample; |
| 45 |
int samplearea = pow2(supersample); |
| 46 |
for (int y = rect.y(); y < rect.y() + rect.height(); y++) { |
| 47 |
for (int x = rect.x(); x < rect.x() + rect.width(); x++) { |
| 48 |
int value = 0; |
| 49 |
for (int sy = 0; sy < supersample; sy++) { |
| 50 |
for (int sx = 0; sx < supersample; sx++) { |
| 51 |
double x_ = x + sx * invss - m_d->centerX; |
| 52 |
double y_ = y + sy * invss - m_d->centerY; |
| 53 |
double maskX = m_d->cosa * x_ - m_d->sina * y_; |
| 54 |
double maskY = m_d->sina * x_ + m_d->cosa * y_; |
| 55 |
value += m_maskGenerator->valueAt(maskX, maskY); |
| 56 |
} |
| 57 |
} |
| 58 |
if (supersample != 1) |
| 59 |
value /= samplearea; |
| 60 |
|
| 61 |
if (m_d->randomness != 0.0) { |
| 62 |
random = (1.0 - m_d->randomness) + m_d->randomness * m_randomSource.generateNormalized(); |
| 63 |
} |
| 64 |
|
| 65 |
alphaValue = quint8((OPACITY_OPAQUE_U8 - value) * random); |
| 66 |
|
| 67 |
|
| 68 |
if (m_d->density != 1.0) { |
| 69 |
|
| 70 |
if (alphaValue != OPACITY_TRANSPARENT_U8) { |
| 71 |
if (!(m_d->density >= m_randomSource.generateNormalized())) { |
| 72 |
alphaValue = OPACITY_TRANSPARENT_U8; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
if (m_d->color) { |
| 78 |
memcpy(dabPointer, m_d->color, static_cast<size_t>(m_d->pixelSize)); |
| 79 |
} |
| 80 |
|
| 81 |
m_d->colorSpace->applyAlphaU8Mask(dabPointer, &alphaValue, 1); |
| 82 |
dabPointer += m_d->pixelSize; |
| 83 |
} |
| 84 |
dabPointer += offset; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
protected: |
| 89 |
MaskGenerator *m_maskGenerator; |
| 90 |
KisRandomSource m_randomSource; |
| 91 |
}; |
| 92 |
|
| 93 |
#endif |