diff options
author | Andreas Kling <andreas.kling@nokia.com> | 2010-11-30 12:39:44 (GMT) |
---|---|---|
committer | Andreas Kling <andreas.kling@nokia.com> | 2010-11-30 13:56:51 (GMT) |
commit | 0211631bb8af96dfe2f6edc2d6c419f496ba89da (patch) | |
tree | 08fbe2a608d7b4cb1827350c63d71d40e80e4161 /src/gui/image/qimage_p.h | |
parent | b498d78ce5cb62dce740fb366bbd76e3c66c7a85 (diff) | |
download | Qt-0211631bb8af96dfe2f6edc2d6c419f496ba89da.zip Qt-0211631bb8af96dfe2f6edc2d6c419f496ba89da.tar.gz Qt-0211631bb8af96dfe2f6edc2d6c419f496ba89da.tar.bz2 |
QRasterPixmapData: Reuse underlying QImage in fill() if possible.
When switching from a format without alpha channel to one that has it,
reuse the underlying QImage memory if the old & new color depths match.
This avoids one allocation when using the rather common pattern:
QPixmap pixmap(w, h);
pixmap.fill(Qt::transparent);
Reviewed-by: Samuel Rødal
Diffstat (limited to 'src/gui/image/qimage_p.h')
-rw-r--r-- | src/gui/image/qimage_p.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/gui/image/qimage_p.h b/src/gui/image/qimage_p.h index c687448..e054814 100644 --- a/src/gui/image/qimage_p.h +++ b/src/gui/image/qimage_p.h @@ -112,6 +112,42 @@ struct Q_GUI_EXPORT QImageData { // internal image data void qInitImageConversions(); +inline int qt_depthForFormat(QImage::Format format) +{ + int depth = 0; + switch(format) { + case QImage::Format_Invalid: + case QImage::NImageFormats: + Q_ASSERT(false); + case QImage::Format_Mono: + case QImage::Format_MonoLSB: + depth = 1; + break; + case QImage::Format_Indexed8: + depth = 8; + break; + case QImage::Format_RGB32: + case QImage::Format_ARGB32: + case QImage::Format_ARGB32_Premultiplied: + depth = 32; + break; + case QImage::Format_RGB555: + case QImage::Format_RGB16: + case QImage::Format_RGB444: + case QImage::Format_ARGB4444_Premultiplied: + depth = 16; + break; + case QImage::Format_RGB666: + case QImage::Format_ARGB6666_Premultiplied: + case QImage::Format_ARGB8565_Premultiplied: + case QImage::Format_ARGB8555_Premultiplied: + case QImage::Format_RGB888: + depth = 24; + break; + } + return depth; +} + QT_END_NAMESPACE #endif |