summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMihailNaydenov <garfieldhq@yahoo.com>2014-09-26 12:23:55 +0300
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2014-12-12 15:32:55 +0100
commitdc583a0576343cfcd5544a21b8625af61e299e6f (patch)
tree5463f3fdbc4a878009684baa5368a406caddacda /src
parentd47b9ace50d47a4472dc9fb029bbf6e8dd810c01 (diff)
Fix incorrect QImage transformation when its devicePixelRatio != 1
QImage::transformed compensates for unwanted translation. This compensation is performed in "pixel space". However, a possible code path to perform the transformation uses QPainter which is devicePixelRatio-aware and expects the transformation matrix to be in logical coordinates. For example, image.transformed(QTransform().rotate(45)) will result in cropped out image if devicePixelRatio == 2. Change-Id: I830ff3ffa25531d842dc9c77f1d0e8d4bd502c9d Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/image/qimage.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 4e10b4cb4b..ea23954a49 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -4480,7 +4480,6 @@ QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode
dImage.d->dpmx = dotsPerMeterX();
dImage.d->dpmy = dotsPerMeterY();
- dImage.d->devicePixelRatio = devicePixelRatio();
switch (bpp) {
// initizialize the data
@@ -4502,13 +4501,19 @@ QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode
}
if (target_format >= QImage::Format_RGB32) {
+ // Prevent QPainter from applying devicePixelRatio corrections
+ const QImage sImage = (devicePixelRatio() != 1) ? QImage(constBits(), width(), height(), format()) : *this;
+
+ Q_ASSERT(sImage.devicePixelRatio() == 1);
+ Q_ASSERT(sImage.devicePixelRatio() == dImage.devicePixelRatio());
+
QPainter p(&dImage);
if (mode == Qt::SmoothTransformation) {
p.setRenderHint(QPainter::Antialiasing);
p.setRenderHint(QPainter::SmoothPixmapTransform);
}
p.setTransform(mat);
- p.drawImage(QPoint(0, 0), *this);
+ p.drawImage(QPoint(0, 0), sImage);
} else {
bool invertible;
mat = mat.inverted(&invertible); // invert matrix
@@ -4520,6 +4525,8 @@ QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode
int dbpl = dImage.bytesPerLine();
qt_xForm_helper(mat, 0, type, bpp, dImage.bits(), dbpl, 0, hd, sptr, sbpl, ws, hs);
}
+
+ dImage.d->devicePixelRatio = devicePixelRatio();
return dImage;
}