JPEG: Fix reading of EXIF orientation.

The orientation is unsigned short, read it as such. In
JPEG-files created by Ricoh/Pentax cameras, the data is saved in
Motorola format. Reading the wrong data size will produce invalid
values when converting the byte order.

Change-Id: I8f7c5dc5bfc10c02e090d3654aaefa047229a962
Task-number: QTBUG-43563
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2014-12-27 20:36:37 +01:00 committed by Rainer Keller
parent 38a3158d2f
commit 16c32c6dfb
3 changed files with 27 additions and 12 deletions

View File

@ -826,10 +826,10 @@ static int getExifOrientation(QByteArray &exifData)
quint16 tag;
quint16 type;
quint32 components;
quint32 value;
stream >> tag >> type >> components >> value;
quint16 value;
quint16 dummy;
stream >> tag >> type >> components >> value >> dummy;
if (tag == 0x0112) { // Tag Exif.Image.Orientation
if (components !=1)
return -1;

Binary file not shown.

After

Width:  |  Height:  |  Size: 911 B

View File

@ -173,6 +173,7 @@ private slots:
void invertPixelsRGB_data();
void invertPixelsRGB();
void exifOrientation_data();
void exifOrientation();
void cleanupFunctions();
@ -2626,20 +2627,34 @@ void tst_QImage::invertPixelsRGB()
QCOMPARE(qBlue(pixel) >> 4, (255 - 96) >> 4);
}
void tst_QImage::exifOrientation_data()
{
QTest::addColumn<QString>("fileName");
QTest::newRow("Orientation 1, Intel format") << m_prefix + "jpeg_exif_orientation_value_1.jpg";
QTest::newRow("Orientation 2, Intel format") << m_prefix + "jpeg_exif_orientation_value_2.jpg";
QTest::newRow("Orientation 3, Intel format") << m_prefix + "jpeg_exif_orientation_value_3.jpg";
QTest::newRow("Orientation 4, Intel format") << m_prefix + "jpeg_exif_orientation_value_4.jpg";
QTest::newRow("Orientation 5, Intel format") << m_prefix + "jpeg_exif_orientation_value_5.jpg";
QTest::newRow("Orientation 6, Intel format") << m_prefix + "jpeg_exif_orientation_value_6.jpg";
QTest::newRow("Orientation 6, Motorola format") << m_prefix + "jpeg_exif_orientation_value_6_motorola.jpg";
QTest::newRow("Orientation 7, Intel format") << m_prefix + "jpeg_exif_orientation_value_7.jpg";
QTest::newRow("Orientation 8, Intel format") << m_prefix + "jpeg_exif_orientation_value_8.jpg";
}
void tst_QImage::exifOrientation()
{
for (unsigned int i = 1; i <= 8; ++i) {
QImage img;
QRgb px;
QFETCH(QString, fileName);
QVERIFY(img.load(m_prefix + QString::fromLatin1("jpeg_exif_orientation_value_%1.jpg").arg(i)));
QImage img;
QRgb px;
px = img.pixel(0, 0);
QVERIFY(qRed(px) > 250 && qGreen(px) < 5 && qBlue(px) < 5);
QVERIFY(img.load(fileName));
px = img.pixel(img.width() - 1, 0);
QVERIFY(qRed(px) < 5 && qGreen(px) < 5 && qBlue(px) > 250);
}
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);
}
static void cleanupFunction(void* info)