From 111558d709d7d55318bdf3de99442f26e246fcdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 13 Oct 2009 18:18:56 +0200 Subject: Optimized bloom graphics effect implementation. Avoid doing so many conversions by operating on raster pixmaps, and by using INV_PREMUL/PREMUL instead of converting to ARGB32. Reviewed-by: Gunnar Sletta --- src/gui/effects/qgraphicseffect.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp index 01df46d..42845cc 100644 --- a/src/gui/effects/qgraphicseffect.cpp +++ b/src/gui/effects/qgraphicseffect.cpp @@ -105,6 +105,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -1461,6 +1462,8 @@ void QGraphicsBloomEffect::setStrength(qreal strength) The \a strength parameter holds the effect's new strength. */ +extern QPixmap qt_toRasterPixmap(const QPixmap &pixmap); + /*! \reimp */ @@ -1473,26 +1476,27 @@ void QGraphicsBloomEffect::draw(QPainter *painter, QGraphicsEffectSource *source } QPoint offset; - QPixmap pixmap = source->pixmap(Qt::DeviceCoordinates, &offset); - QImage result = pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); + QPixmap pixmap = qt_toRasterPixmap(source->pixmap(Qt::DeviceCoordinates, &offset)); // Blur. - QPainter blurPainter(&pixmap); + QImage overlay(pixmap.size(), QImage::Format_ARGB32_Premultiplied); + overlay.fill(0); + + QPainter blurPainter(&overlay); d->blurFilter.draw(&blurPainter, QPointF(), pixmap); blurPainter.end(); // Brighten. - QImage overlay = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); const int numBits = overlay.width() * overlay.height(); QRgb *bits = reinterpret_cast(overlay.bits()); for (int i = 0; i < numBits; ++i) { - const QRgb bit = bits[i]; - bits[i] = qRgba(d->colorTable[qRed(bit)], d->colorTable[qGreen(bit)], - d->colorTable[qBlue(bit)], qAlpha(bit)); + const QRgb pixel = INV_PREMUL(bits[i]); + bits[i] = PREMUL(qRgba(d->colorTable[qRed(pixel)], d->colorTable[qGreen(pixel)], + d->colorTable[qBlue(pixel)], qAlpha(pixel))); } // Composite. - QPainter compPainter(&result); + QPainter compPainter(&pixmap); compPainter.setCompositionMode(QPainter::CompositionMode_Overlay); compPainter.setOpacity(d->strength); compPainter.drawImage(0, 0, overlay); @@ -1500,7 +1504,7 @@ void QGraphicsBloomEffect::draw(QPainter *painter, QGraphicsEffectSource *source QTransform restoreTransform = painter->worldTransform(); painter->setWorldTransform(QTransform()); - painter->drawImage(offset, result); + painter->drawImage(offset, pixmap); painter->setWorldTransform(restoreTransform); } -- cgit v0.12