diff options
author | Andreas Kling <andreas.kling@nokia.com> | 2010-11-30 13:39:44 +0100 |
---|---|---|
committer | Andreas Kling <andreas.kling@nokia.com> | 2010-11-30 14:56:51 +0100 |
commit | 0211631bb8af96dfe2f6edc2d6c419f496ba89da (patch) | |
tree | 08fbe2a608d7b4cb1827350c63d71d40e80e4161 /src/gui/image/qimage.cpp | |
parent | b498d78ce5cb62dce740fb366bbd76e3c66c7a85 (diff) | |
download | qt4-tools-0211631bb8af96dfe2f6edc2d6c419f496ba89da.tar.gz |
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.cpp')
-rw-r--r-- | src/gui/image/qimage.cpp | 42 |
1 files changed, 3 insertions, 39 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index d86021cb9a..747dd2f372 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -139,42 +139,6 @@ QImageData::QImageData() { } -static int 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; -} - /*! \fn QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors) \internal @@ -195,7 +159,7 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format, int nu uint width = size.width(); uint height = size.height(); - uint depth = depthForFormat(format); + uint depth = qt_depthForFormat(format); switch (format) { case QImage::Format_Mono: @@ -871,7 +835,7 @@ QImageData *QImageData::create(uchar *data, int width, int height, int bpl, QIm return 0; } - const int depth = depthForFormat(format); + const int depth = qt_depthForFormat(format); const int calc_bytes_per_line = ((width * depth + 31)/32) * 4; const int min_bytes_per_line = (width * depth + 7)/8; @@ -6321,7 +6285,7 @@ int QImage::bitPlaneCount() const bpc = 12; break; default: - bpc = depthForFormat(d->format); + bpc = qt_depthForFormat(d->format); break; } return bpc; |