summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-05-04 13:32:32 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-05-12 09:25:11 +0000
commitba323b04cd78fb43e9e63b891e973d24b08250af (patch)
tree8ad4da1eaf991f061d3e24159a3a5b4fdaf8fbfa /tests
parent12dd4ff7e7b4fae33fb74def603ce880eee0c16b (diff)
downloadqtbase-ba323b04cd78fb43e9e63b891e973d24b08250af.tar.gz
Optionally apply orientation on QImage read
Make it possible to read images with EXIF orientation automatically applied. This was originally implemented without opt-out in Qt 5.4, but reverted. Here it is implemented as opt-in for JPEG, and opt-out for TIFF to keep behavioral consistency. The EXIF support for JPEG was written by Rainer Keller. [ChangeLog][QtGui][Image plugins] An option has been added to QImageReader to enable automatic application of EXIF orientation. This behavior was default in Qt 5.4.1, but reverted in Qt 5.4.2. Task-number: QTBUG-37946 Task-number: QTBUG-43563 Task-number: QTBUG-45552 Task-number: QTBUG-45865 Change-Id: Iaafd2519b63ede66ecc1f8aa4c7118081312b8f5 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_QTBUG-45865.jpgbin0 -> 27540 bytes
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_1.jpgbin0 -> 910 bytes
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_2.jpgbin0 -> 910 bytes
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_3.jpgbin0 -> 988 bytes
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_4.jpgbin0 -> 995 bytes
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_5.jpgbin0 -> 912 bytes
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_6.jpgbin0 -> 911 bytes
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_6_motorola.jpgbin0 -> 911 bytes
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_7.jpgbin0 -> 987 bytes
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_8.jpgbin0 -> 991 bytes
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp60
11 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_QTBUG-45865.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_QTBUG-45865.jpg
new file mode 100644
index 0000000000..97deae3e25
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_QTBUG-45865.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_1.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_1.jpg
new file mode 100644
index 0000000000..aaa4ac4e10
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_1.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_2.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_2.jpg
new file mode 100644
index 0000000000..a61d2723d7
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_2.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_3.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_3.jpg
new file mode 100644
index 0000000000..43e56dcef7
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_3.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_4.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_4.jpg
new file mode 100644
index 0000000000..d5d06f7409
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_4.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_5.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_5.jpg
new file mode 100644
index 0000000000..1886f3775e
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_5.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_6.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_6.jpg
new file mode 100644
index 0000000000..5cec757354
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_6.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_6_motorola.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_6_motorola.jpg
new file mode 100644
index 0000000000..0aa164b78b
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_6_motorola.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_7.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_7.jpg
new file mode 100644
index 0000000000..b3dcc466a9
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_7.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_8.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_8.jpg
new file mode 100644
index 0000000000..8bc390e2b9
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_orientation_value_8.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 62a9f19f36..da29a57f98 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -181,6 +181,11 @@ private slots:
void invertPixelsRGB_data();
void invertPixelsRGB();
+ void exifOrientation_data();
+ void exifOrientation();
+
+ void exif_QTBUG45865();
+
void cleanupFunctions();
void devicePixelRatio();
@@ -2810,6 +2815,61 @@ void tst_QImage::invertPixelsRGB()
QCOMPARE(qBlue(pixel) >> 4, (255 - 96) >> 4);
}
+void tst_QImage::exifOrientation_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<int>("orientation");
+ QTest::newRow("Orientation 1, Intel format") << m_prefix + "jpeg_exif_orientation_value_1.jpg" << (int)QImageIOHandler::TransformationNone;
+ QTest::newRow("Orientation 2, Intel format") << m_prefix + "jpeg_exif_orientation_value_2.jpg" << (int)QImageIOHandler::TransformationMirror;
+ QTest::newRow("Orientation 3, Intel format") << m_prefix + "jpeg_exif_orientation_value_3.jpg" << (int)QImageIOHandler::TransformationRotate180;
+ QTest::newRow("Orientation 4, Intel format") << m_prefix + "jpeg_exif_orientation_value_4.jpg" << (int)QImageIOHandler::TransformationFlip;
+ QTest::newRow("Orientation 5, Intel format") << m_prefix + "jpeg_exif_orientation_value_5.jpg" << (int)QImageIOHandler::TransformationFlipAndRotate90;
+ QTest::newRow("Orientation 6, Intel format") << m_prefix + "jpeg_exif_orientation_value_6.jpg" << (int)QImageIOHandler::TransformationRotate90;
+ QTest::newRow("Orientation 6, Motorola format") << m_prefix + "jpeg_exif_orientation_value_6_motorola.jpg" << (int)QImageIOHandler::TransformationRotate90;
+ QTest::newRow("Orientation 7, Intel format") << m_prefix + "jpeg_exif_orientation_value_7.jpg" << (int)QImageIOHandler::TransformationMirrorAndRotate90;
+ QTest::newRow("Orientation 8, Intel format") << m_prefix + "jpeg_exif_orientation_value_8.jpg" << (int)QImageIOHandler::TransformationRotate270;
+}
+
+QT_BEGIN_NAMESPACE
+extern void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient);
+QT_END_NAMESPACE
+QT_USE_NAMESPACE
+
+void tst_QImage::exifOrientation()
+{
+ QFETCH(QString, fileName);
+ QFETCH(int, orientation);
+
+ QImageReader imageReader(fileName);
+ imageReader.setAutoTransform(true);
+ QCOMPARE(imageReader.transformation(), orientation);
+ QImage img = imageReader.read();
+ QRgb px;
+ QVERIFY(!img.isNull());
+
+ px = img.pixel(0, 0);
+ QVERIFY(qRed(px) > 250 && qGreen(px) < 5 && qBlue(px) < 5);
+
+ px = img.pixel(img.width() - 1, 0);
+ QVERIFY(qRed(px) < 5 && qGreen(px) < 5 && qBlue(px) > 250);
+
+ QImageReader imageReader2(fileName);
+ QCOMPARE(imageReader2.autoTransform(), false);
+ QCOMPARE(imageReader2.transformation(), orientation);
+ QImage img2 = imageReader2.read();
+ qt_imageTransform(img2, imageReader2.transformation());
+ QCOMPARE(img, img2);
+}
+
+void tst_QImage::exif_QTBUG45865()
+{
+ QFile file(m_prefix + "jpeg_exif_QTBUG-45865.jpg");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QByteArray byteArray = file.readAll();
+ QImage image = QImage::fromData(byteArray);
+ QCOMPARE(image.size(), QSize(5, 8));
+}
+
static void cleanupFunction(void* info)
{
bool *called = static_cast<bool*>(info);