Commit 26c25720 authored by Fabio D'Urso's avatar Fabio D'Urso
Browse files

kimgio generator: Apply transformations dictated by Exif metadata

BUG: 322920
FIXED-IN: 4.12.0
REVIEW: 111793
parent fb78b19e
......@@ -8,6 +8,9 @@ macro_log_feature(HAVE_POPPLER_0_12_1 "Poppler-Qt4" "A PDF rendering library" "h
macro_optional_find_package(LibSpectre)
macro_log_feature(LIBSPECTRE_FOUND "libspectre" "A PostScript rendering library" "http://libspectre.freedesktop.org/wiki/" FALSE "${LIBSPECTRE_MINIMUM_VERSION}" "Support for PS files in okular.")
macro_optional_find_package(Kexiv2)
macro_log_feature(KEXIV2_FOUND "LibKExiv2" "Wrapper around Exiv2 library" "http://www.digikam.org/sharedlibs" FALSE "" "Support for image files")
macro_optional_find_package(CHM)
macro_log_feature(CHM_FOUND "CHM" "A library for dealing with Microsoft ITSS/CHM format files" "http://www.jedrea.com/chmlib" FALSE "" "Support CHM files in okular.")
......@@ -38,7 +41,9 @@ if(LIBSPECTRE_FOUND)
add_subdirectory(spectre)
endif(LIBSPECTRE_FOUND)
add_subdirectory( kimgio )
if(KEXIV2_FOUND)
add_subdirectory( kimgio )
endif(KEXIV2_FOUND)
if(CHM_FOUND)
add_subdirectory( chm )
......
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../..
${CMAKE_BINARY_DIR}
${QIMAGEBLITZ_INCLUDES}
${KEXIV2_INCLUDE_DIR}
)
......@@ -9,11 +12,12 @@ set(okularGenerator_kimgio_PART_SRCS generator_kimgio.cpp )
kde4_add_plugin(okularGenerator_kimgio ${okularGenerator_kimgio_PART_SRCS})
target_link_libraries(okularGenerator_kimgio okularcore ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${QT_QTXML_LIBRARY} )
target_link_libraries(okularGenerator_kimgio okularcore ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${QT_QTXML_LIBRARY} ${KEXIV2_LIBRARIES} )
install(TARGETS okularGenerator_kimgio DESTINATION ${PLUGIN_INSTALL_DIR})
kde4_add_unit_test( kimgiotest tests/kimgiotest.cpp ../../ui/pagepainter.cpp ../../ui/guiutils.cpp ../../settings.cpp )
target_link_libraries( kimgiotest ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} ${QIMAGEBLITZ_LIBRARIES} okularcore )
########### install files ###############
......
......@@ -23,6 +23,8 @@
#include <kimageio.h>
#include <klocale.h>
#include <libkexiv2/kexiv2.h>
#include <core/page.h>
static KAboutData createAboutData()
......@@ -82,6 +84,12 @@ bool KIMGIOGenerator::loadDocument( const QString & fileName, QVector<Okular::Pa
}
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 );
......@@ -107,6 +115,12 @@ bool KIMGIOGenerator::loadDocumentFromData( const QByteArray & fileData, QVector
}
docInfo.set( Okular::DocumentInfo::MimeType, mime );
// Apply transformations dictated by Exif metadata
KExiv2Iface::KExiv2 exifMetadata;
if ( exifMetadata.loadFromData( fileData ) ) {
exifMetadata.rotateExifQImage( m_img, exifMetadata.getImageOrientation() );
}
pagesVector.resize( 1 );
Okular::Page * page = new Okular::Page( 0, m_img.width(), m_img.height(), Okular::Rotation0 );
......
/***************************************************************************
* Copyright (C) 2013 by Fabio D'Urso <fabiodurso@hotmail.it> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include <qtest_kde.h>
#include "../generator_kimgio.h"
#include "../../settings_core.h"
#include <core/observer.h>
#include <core/page.h>
#include <ui/pagepainter.h>
#include <KTempDir>
#include <QImage>
#include <QPainter>
#include <QTemporaryFile>
class KIMGIOTest
: public QObject
{
Q_OBJECT
private slots:
void testExifOrientation_data();
void testExifOrientation();
};
// The following images have different Exif orientation tags, but they all
// are a 3x2 rectangle whose top-left pixel is black, and whose other pixels are
// white. Note that, due to JPEG lossy compression, some pixels are not pure
// white. In testExifOrientation, we only check the top-left and bottom-right
// corners.
void KIMGIOTest::testExifOrientation_data()
{
QTest::addColumn<QString>( "imgPath" );
// No Exif metadata at all
QTest::newRow( "No Exif metadata" ) << KDESRCDIR "tests/data/testExifOrientation-noexif.jpg";
// No Exif orientation information
QTest::newRow( "Unspecified" ) << KDESRCDIR "tests/data/testExifOrientation-unspecified.jpg";
// Valid Orientation values
QTest::newRow( "Horizontal (normal)" ) << KDESRCDIR "tests/data/testExifOrientation-0.jpg";
QTest::newRow( "Mirror horizontal" ) << KDESRCDIR "tests/data/testExifOrientation-0mirror.jpg";
QTest::newRow( "Rotate 90 CW" ) << KDESRCDIR "tests/data/testExifOrientation-90.jpg";
QTest::newRow( "Mirror horizontal and rotate 90 CW" ) << KDESRCDIR "tests/data/testExifOrientation-90mirror.jpg";
QTest::newRow( "Rotate 180" ) << KDESRCDIR "tests/data/testExifOrientation-180.jpg";
QTest::newRow( "Mirror vertical" ) << KDESRCDIR "tests/data/testExifOrientation-180mirror.jpg";
QTest::newRow( "Rotate 270 CW" ) << KDESRCDIR "tests/data/testExifOrientation-270.jpg";
QTest::newRow( "Mirror horizontal and rotate 270 CW" ) << KDESRCDIR "tests/data/testExifOrientation-270mirror.jpg";
}
void KIMGIOTest::testExifOrientation()
{
QFETCH( QString, imgPath );
Okular::SettingsCore::instance( "kimgiotest" );
Okular::Document *m_document = new Okular::Document( 0 );
const KMimeType::Ptr mime = KMimeType::findByPath( imgPath );
Okular::DocumentObserver *dummyDocumentObserver = new Okular::DocumentObserver();
m_document->addObserver( dummyDocumentObserver );
// Load image
m_document->openDocument( imgPath, KUrl(), mime );
m_document->setRotation( 0 ); // Test the default rotation
QCOMPARE( m_document->pages(), 1u );
// Check size
QCOMPARE( m_document->page(0)->width(), double(3) );
QCOMPARE( m_document->page(0)->height(), double(2) );
// Generate pixmap
Okular::PixmapRequest *req = new Okular::PixmapRequest( dummyDocumentObserver, 0, 3, 2,
1, Okular::PixmapRequest::NoFeature );
m_document->requestPixmaps( QLinkedList<Okular::PixmapRequest*>() << req );
QVERIFY( m_document->page(0)->hasPixmap( dummyDocumentObserver, 3, 2 ) );
// Obtain image
QImage img( 3, 2, QImage::Format_ARGB32_Premultiplied );
QPainter p( &img );
PagePainter::paintPageOnPainter( &p, m_document->page(0), dummyDocumentObserver, 0, 3, 2, QRect(0, 0, 3, 2) );
// Verify pixel data
QCOMPARE( img.pixel(0, 0), qRgb(0, 0, 0) );
QCOMPARE( img.pixel(2, 1), qRgb(255, 255, 255) );
m_document->removeObserver( dummyDocumentObserver );
delete dummyDocumentObserver;
delete m_document;
}
QTEST_KDEMAIN( KIMGIOTest, GUI )
#include "kimgiotest.moc"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment