summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Richardson <arichardson.kde@gmail.com>2015-08-14 00:24:08 (GMT)
committerAlex Richardson <arichardson.kde@gmail.com>2015-08-15 18:28:06 (GMT)
commitbb22f7d3f1307ec8eff837a13bcaa930c38ab08a (patch)
treed373cc2b41db8a5ef6331dd62abe897fb1417323
parent824a35ced051842a1518b95146042d3567a89ba1 (diff)
Don't rotate images with Qt 5.4.0 and 5.4.1
There was behaviour change that automatically rotated jpeg images based on exif metadata that was reverted in 5.4.2. We now skip rotating with those two version to prevent rotating twice. Also shared some code so that the #ifdef does not need to be added to both methods REVIEW: 123895
-rw-r--r--generators/kimgio/generator_kimgio.cpp55
-rw-r--r--generators/kimgio/generator_kimgio.h3
2 files changed, 29 insertions, 29 deletions
diff --git a/generators/kimgio/generator_kimgio.cpp b/generators/kimgio/generator_kimgio.cpp
index 9be961f..84c155b 100644
--- a/generators/kimgio/generator_kimgio.cpp
+++ b/generators/kimgio/generator_kimgio.cpp
@@ -12,6 +12,7 @@
#include "generator_kimgio.h"
#include <QBuffer>
+#include <QFile>
#include <QImageReader>
#include <QPainter>
#include <QPrinter>
@@ -63,53 +64,49 @@ KIMGIOGenerator::~KIMGIOGenerator()
bool KIMGIOGenerator::loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector )
{
- QMimeDatabase db;
- const QString mime = db.mimeTypeForFile(fileName, QMimeDatabase::MatchContent).name();
- const QStringList types = KImageIO::typeForMime(mime);
- const QByteArray type = !types.isEmpty() ? types[0].toAscii() : QByteArray();
- QImageReader reader( fileName, type );
- if ( !reader.read( &m_img ) ) {
- emit error( i18n( "Unable to load document: %1", reader.errorString() ), -1 );
+ QFile f( fileName );
+ if ( !f.open(QFile::ReadOnly) ) {
+ emit error( i18n( "Unable to load document: %1", f.errorString() ), -1 );
return false;
}
- docInfo.set( Okular::DocumentInfo::MimeType, mime );
-
- // Apply transformations dictated by Exif metadata
- KExiv2Iface::KExiv2 exifMetadata;
- if ( exifMetadata.load( fileName ) ) {
- exifMetadata.rotateExifQImage( m_img, exifMetadata.getImageOrientation() );
- }
-
- pagesVector.resize( 1 );
-
- Okular::Page * page = new Okular::Page( 0, m_img.width(), m_img.height(), Okular::Rotation0 );
- pagesVector[0] = page;
-
- return true;
+ return loadDocumentInternal( f.readAll(), fileName, pagesVector );
}
bool KIMGIOGenerator::loadDocumentFromData( const QByteArray & fileData, QVector<Okular::Page*> & pagesVector )
{
- QMimeDatabase db;
- const QString mime = db.mimeTypeForData(fileData).name();
- const QStringList types = KImageIO::typeForMime(mime);
- const QByteArray type = !types.isEmpty() ? types[0].toAscii() : QByteArray();
-
+ return loadDocumentInternal( fileData, QString(), pagesVector );
+}
+
+bool KIMGIOGenerator::loadDocumentInternal(const QByteArray & fileData, const QString & fileName, QVector<Okular::Page*> & pagesVector )
+{
QBuffer buffer;
buffer.setData( fileData );
buffer.open( QIODevice::ReadOnly );
- QImageReader reader( &buffer, type );
+ QImageReader reader( &buffer, QImageReader::imageFormat( &buffer ) );
+ reader.setAutoDetectImageFormat( true );
if ( !reader.read( &m_img ) ) {
emit error( i18n( "Unable to load document: %1", reader.errorString() ), -1 );
return false;
}
- docInfo.set( Okular::DocumentInfo::MimeType, mime );
+ QMimeDatabase db;
+ auto mime = db.mimeTypeForFileNameAndData( fileName, fileData );
+ docInfo.set( Okular::DocumentInfo::MimeType, mime.name() );
// Apply transformations dictated by Exif metadata
KExiv2Iface::KExiv2 exifMetadata;
if ( exifMetadata.loadFromData( fileData ) ) {
- exifMetadata.rotateExifQImage( m_img, exifMetadata.getImageOrientation() );
+#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) && QT_VERSION < QT_VERSION_CHECK(5, 4, 2)
+ // Qt 5.4 (up to 5.4.1) rotates jpeg images automatically with no way of disabling it
+ // See https://bugreports.qt.io/browse/QTBUG-37946
+ // and https://codereview.qt-project.org/#/c/98013/
+ // and https://codereview.qt-project.org/#/c/110668/
+ if (reader.format() != QByteArrayLiteral("jpeg")) {
+ exifMetadata.rotateExifQImage( m_img, exifMetadata.getImageOrientation() );
+ }
+#else
+ exifMetadata.rotateExifQImage(m_img, exifMetadata.getImageOrientation());
+#endif
}
pagesVector.resize( 1 );
diff --git a/generators/kimgio/generator_kimgio.h b/generators/kimgio/generator_kimgio.h
index 139c230..1d7d89e 100644
--- a/generators/kimgio/generator_kimgio.h
+++ b/generators/kimgio/generator_kimgio.h
@@ -39,6 +39,9 @@ class KIMGIOGenerator : public Okular::Generator
QImage image( Okular::PixmapRequest * request );
private:
+ bool loadDocumentInternal(const QByteArray & fileData, const QString & fileName,
+ QVector<Okular::Page*> & pagesVector );
+ private:
QImage m_img;
Okular::DocumentInfo docInfo;
};