72 Q_UNUSED(progressUpdater);
73 Q_ASSERT(!device.
isNull());
76 const int level = (config && config->getProperty(
"level",
value)) ?
value.toInt() : 50;
77 const int opacity = (config && config->getProperty(
"opacity",
value)) ?
value.toInt() : 100;
78 const bool isGrayscale = (config && config->getProperty(
"grayscale",
value)) ?
value.toBool() :
false;
80 const double threshold = (100.0 - level) * 0.01;
82 const quint32 pixelSize = colorSpace->
pixelSize();
85 std::vector<quint8> scratchPixel(pixelSize);
87 constexpr quint32 numMixPixels = 2;
88 qint16 weights[numMixPixels];
89 weights[0] = (255 * opacity) / 100;
90 weights[1] = 255 - weights[0];
92 const quint8* pixels[numMixPixels];
93 pixels[0] = scratchPixel.data();
95 int seedThreshold = rand();
97 int seedGreen = rand();
98 int seedBlue = rand();
101 seedThreshold = config->getInt(
"seedThreshold", seedThreshold);
102 seedRed = config->getInt(
"seedRed", seedRed);
103 seedGreen = config->getInt(
"seedGreen", seedGreen);
104 seedBlue = config->getInt(
"seedBlue", seedBlue);
114 qint32 dstY_ =
rect.y();
115 qint32 rowsRemaining =
rect.height();
117 while (rowsRemaining > 0) {
118 qint32 dstX_ =
rect.x();
119 qint32 columnsRemaining =
rect.width();
121 qint32 rows = qMin(numContiguousDstRows, rowsRemaining);
123 while (columnsRemaining > 0) {
125 qint32 columns = qMin(numContiguousDstColumns, columnsRemaining);
127 qint32 dstRowStride = dstIt->
rowStride(dstX_, dstY_);
128 dstIt->
moveTo(dstX_, dstY_);
130 for (
int rowIndex = 0; rowIndex < rows; ++rowIndex) {
131 for (
int colIndex = 0; colIndex < columns; ++colIndex) {
132 const int px = dstX_ + colIndex;
133 const int py = dstY_ + rowIndex;
137 const int gray =
static_cast<int>(randr.
doubleRandomAt(px, py) * 255);
138 color = qRgb(gray, gray, gray);
140 color = qRgb(
static_cast<int>(randr.
doubleRandomAt(px, py) * 255),
144 const quint32 dataOffset = colIndex * pixelSize + rowIndex * dstRowStride;
145 if (opacity == 100) {
148 colorSpace->
fromQColor(color, scratchPixel.data());
150 mixOp->
mixColors(pixels, weights, numMixPixels, dstIt->
rawData() + dataOffset);
157 columnsRemaining -= columns;
161 rowsRemaining -= rows;
virtual void mixColors(const quint8 *const *colors, const qint16 *weights, int nColors, quint8 *dst, int weightSum=255) const =0