diff --git a/src/plugins/imageformats/dds/qddshandler.cpp b/src/plugins/imageformats/dds/qddshandler.cpp
index 13bb9aafb77121e8fb56242bafdc658acdbf915b..d5c8793e64d6ee6c784a9b25063ddfd3c0fdc63e 100644
--- a/src/plugins/imageformats/dds/qddshandler.cpp
+++ b/src/plugins/imageformats/dds/qddshandler.cpp
@@ -1338,9 +1338,9 @@ bool QDDSHandler::write(const QImage &outImage)
     dds.pixelFormat.bBitMask = 0x000000ff;
 
     s << dds;
-    for (int width = 0; width < image.width(); width++) {
-        for (int height = 0; height < image.height(); height++) {
-            QRgb pixel = image.pixel(height, width);;
+    for (int height = 0; height < image.height(); height++) {
+        for (int width = 0; width < image.width(); width++) {
+            QRgb pixel = image.pixel(width, height);
             quint32 color;
             quint8 alpha = qAlpha(pixel);
             quint8 red = qRed(pixel);
diff --git a/tests/auto/dds/tst_qdds.cpp b/tests/auto/dds/tst_qdds.cpp
index eb2584975c79e88cb0d4f451839de2d4528b2afc..d41ea2570a6fdba37c068947814889a3ef6f6324 100644
--- a/tests/auto/dds/tst_qdds.cpp
+++ b/tests/auto/dds/tst_qdds.cpp
@@ -109,6 +109,7 @@ void tst_qdds::readImage_data()
     QTest::newRow("46") << QString("RXGB") << QSize(64, 64);
     QTest::newRow("47") << QString("ATI2") << QSize(64, 64);
     QTest::newRow("48") << QString("P4") << QSize(64, 64);
+    QTest::newRow("49") << QString("A8R8G8B8_2") << QSize(64, 32);
 }
 
 void tst_qdds::readImage()
@@ -158,6 +159,7 @@ void tst_qdds::testWriteImage_data()
     QTest::addColumn<QSize>("size");
 
     QTest::newRow("1") << QString("A8R8G8B8") << QSize(64, 64);
+    QTest::newRow("2") << QString("A8R8G8B8_2") << QSize(64, 32);
 }
 
 void tst_qdds::testWriteImage()
diff --git a/tests/shared/images/dds.qrc b/tests/shared/images/dds.qrc
index 128a38dee0068f552f38ec641f843a83032d9c44..c8f1bc09cb5b60444b572acdd7e786b6a884e950 100644
--- a/tests/shared/images/dds.qrc
+++ b/tests/shared/images/dds.qrc
@@ -49,5 +49,6 @@
         <file>dds/YUY2.dds</file>
         <file>dds/RXGB.dds</file>
         <file>dds/ATI2.dds</file>
+        <file>dds/A8R8G8B8_2.dds</file>
     </qresource>
 </RCC>
diff --git a/tests/shared/images/dds/A8R8G8B8_2.dds b/tests/shared/images/dds/A8R8G8B8_2.dds
new file mode 100644
index 0000000000000000000000000000000000000000..19fe92ca65e7e611d2d1aab5c3e747249a316c4c
Binary files /dev/null and b/tests/shared/images/dds/A8R8G8B8_2.dds differ