void KisPixelizeFilter::process(KisPaintDeviceSP device, const QRect& applyRect, const KisFilterConfiguration* configuration, KoUpdater* progressUpdater ) const { QPoint srcTopLeft = applyRect.topLeft(); Q_ASSERT(device); Q_ASSERT(configuration); qint32 width = applyRect.width(); qint32 height = applyRect.height(); //read the filter configuration values from the KisFilterConfiguration object quint32 pixelWidth = configuration->getInt("pixelWidth", 10); quint32 pixelHeight = configuration->getInt("pixelHeight", 10); if (pixelWidth == 0) pixelWidth = 1; if (pixelHeight == 0) pixelHeight = 1; qint32 pixelSize = device->pixelSize(); QVector<qint32> average(pixelSize); qint32 count; if (progressUpdater) { progressUpdater->setRange(0, applyRect.width() * applyRect.height()); } qint32 numberOfPixelsProcessed = 0; for (qint32 y = 0; y < height; y += pixelHeight - (y % pixelHeight)) { qint32 h = pixelHeight; h = qMin(h, height - y); for (qint32 x = 0; x < width; x += pixelWidth - (x % pixelWidth)) { qint32 w = pixelWidth; w = qMin(w, width - x); for (qint32 i = 0; i < pixelSize; i++) { average[i] = 0; } count = 0; //read KisRectConstIteratorSP srcIt = device->createRectConstIteratorNG(srcTopLeft.x() + x, srcTopLeft.y() + y, w, h); do { for (qint32 i = 0; i < pixelSize; i++) { average[i] += srcIt->oldRawData()[i]; } count++; } while (srcIt->nextPixel()); //average if (count > 0) { for (qint32 i = 0; i < pixelSize; i++) average[i] /= count; } //write KisRectIteratorSP dstIt = device->createRectIteratorNG(srcTopLeft.x() + x, srcTopLeft.y() + y, w, h); do { for (int i = 0; i < pixelSize; i++) { dstIt->rawData()[i] = average[i]; } } while (dstIt->nextPixel()); if (progressUpdater) progressUpdater->setValue(++numberOfPixelsProcessed); } } }