summaryrefslogtreecommitdiffstats
path: root/src/gui/effects/qgraphicseffect.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2009-10-13 16:18:56 (GMT)
committerSamuel Rødal <sroedal@trolltech.com>2009-10-14 11:46:00 (GMT)
commit111558d709d7d55318bdf3de99442f26e246fcdc (patch)
tree1ea881731d66824475111b1f23af63b8434ef8fd /src/gui/effects/qgraphicseffect.cpp
parentebe1ff6107cf26ae262961e12ab1eb2917648c1b (diff)
downloadQt-111558d709d7d55318bdf3de99442f26e246fcdc.zip
Qt-111558d709d7d55318bdf3de99442f26e246fcdc.tar.gz
Qt-111558d709d7d55318bdf3de99442f26e246fcdc.tar.bz2
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
Diffstat (limited to 'src/gui/effects/qgraphicseffect.cpp')
-rw-r--r--src/gui/effects/qgraphicseffect.cpp22
1 files 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 <QtGui/qpainter.h>
#include <QtCore/qrect.h>
#include <QtCore/qdebug.h>
+#include <private/qdrawhelper_p.h>
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<QRgb *>(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);
}