summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qpixmap_raster.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2010-06-22 11:24:26 (GMT)
committerSamuel Rødal <samuel.rodal@nokia.com>2010-06-23 08:45:11 (GMT)
commitfb76a872e20bd0df8e7bbe9c039b7f20423c6f12 (patch)
treec01d5f47cad65a056eb6edc1cab11c628b11e2f8 /src/gui/image/qpixmap_raster.cpp
parenteaf886318568bfbd9aa1722586264c8fdf90df12 (diff)
downloadQt-fb76a872e20bd0df8e7bbe9c039b7f20423c6f12.zip
Qt-fb76a872e20bd0df8e7bbe9c039b7f20423c6f12.tar.gz
Qt-fb76a872e20bd0df8e7bbe9c039b7f20423c6f12.tar.bz2
Optimized sub-rect copying / painting of QPixmaps.
Prevented downloading of the whole XImage by introducing new QPixmapData::toImage() overload taking a sub-rect. Also avoid an additional copy by simply taking ownership of the XImage data when the XImage format matches the QImage format. Reviewed-by: Trond
Diffstat (limited to 'src/gui/image/qpixmap_raster.cpp')
-rw-r--r--src/gui/image/qpixmap_raster.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp
index 13c03a1..13e95c7 100644
--- a/src/gui/image/qpixmap_raster.cpp
+++ b/src/gui/image/qpixmap_raster.cpp
@@ -289,6 +289,20 @@ QImage QRasterPixmapData::toImage() const
return image;
}
+QImage QRasterPixmapData::toImage(const QRect &rect) const
+{
+ if (rect.isNull())
+ return image;
+
+ QRect clipped = rect.intersected(QRect(0, 0, w, h));
+ if (d % 8 == 0)
+ return QImage(image.scanLine(clipped.y()) + clipped.x() * (d / 8),
+ clipped.width(), clipped.height(),
+ image.bytesPerLine(), image.format());
+ else
+ return image.copy(clipped);
+}
+
void QRasterPixmapData::setAlphaChannel(const QPixmap &alphaChannel)
{
image.setAlphaChannel(alphaChannel.toImage());