summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-04-20 16:53:25 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-04-23 10:14:48 +0000
commitf657ecdc5ddef611a503ce460dc81fe2f0bbc2d6 (patch)
tree8fc435147a8a409a58f9e9e7c4f96effae121957 /src/gui
parentc3737573ced4dc2217f31aac627fa8070e7512c8 (diff)
Fix inplace double mirroring on odd sized images
The QImage inplace mirroring method, failed to handle the middle line when mirroring both ways (rotate 180). In both other mirroring cases the middle can be left untouched, but in this case it needs to be mirrored half way. To make the logic simpler, double mirroring will now mirror half the lines instead of half of every line. Change-Id: Iaa1f1e1c3f7dedfb78891fc93207f6d0c64bcafe Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qimage.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index f20800440d..f09e73f214 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -2825,14 +2825,22 @@ template<class T> inline void do_mirror_data(QImageData *dst, QImageData *src,
if (dst == src) {
// When mirroring in-place, stop in the middle for one of the directions, since we
// are swapping the bytes instead of merely copying.
- const int srcXEnd = dstX0 ? w / 2 : w;
- const int srcYEnd = !dstX0 && dstY0 ? h / 2 : h;
+ const int srcXEnd = (dstX0 && !dstY0) ? w / 2 : w;
+ const int srcYEnd = dstY0 ? h / 2 : h;
for (int srcY = 0, dstY = dstY0; srcY < srcYEnd; ++srcY, dstY += dstYIncr) {
T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);
T *dstPtr = (T *) (dst->data + dstY * dst->bytes_per_line);
for (int srcX = 0, dstX = dstX0; srcX < srcXEnd; ++srcX, dstX += dstXIncr)
std::swap(srcPtr[srcX], dstPtr[dstX]);
}
+ // If mirroring both ways, the middle line needs to be mirrored horizontally only.
+ if (dstX0 && dstY0 && (h & 1)) {
+ int srcY = h / 2;
+ int srcXEnd2 = w / 2;
+ T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);
+ for (int srcX = 0, dstX = dstX0; srcX < srcXEnd2; ++srcX, dstX += dstXIncr)
+ std::swap(srcPtr[srcX], srcPtr[dstX]);
+ }
} else {
for (int srcY = 0, dstY = dstY0; srcY < h; ++srcY, dstY += dstYIncr) {
T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);