Commit 94d32341 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Ported ImageUtils::transformMatrix and use it to rotate the image in

LoadingDocumentImpl.

svn path=/trunk/playground/graphics/gwenview/; revision=664750
parent 3b5953ae
......@@ -6,6 +6,7 @@ set(gwenviewlib_SRCS
documentloadedimpl.cpp
emptydocumentimpl.cpp
imagescaler.cpp
imageutils.cpp
imageviewpart.cpp
jpegcontent.cpp
loadingdocumentimpl.cpp
......
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#include "imageutils.h"
// Qt
#include <QMatrix>
namespace Gwenview {
namespace ImageUtils {
QMatrix transformMatrix(Orientation orientation) {
QMatrix matrix;
switch (orientation) {
case NOT_AVAILABLE:
case NORMAL:
break;
case HFLIP:
matrix.scale(-1,1);
break;
case ROT_180:
matrix.rotate(180);
break;
case VFLIP:
matrix.scale(1,-1);
break;
case TRANSPOSE:
matrix.scale(-1,1);
matrix.rotate(90);
break;
case ROT_90:
matrix.rotate(90);
break;
case TRANSVERSE:
matrix.scale(1,-1);
matrix.rotate(90);
break;
case ROT_270:
matrix.rotate(270);
break;
}
return matrix;
}
} // namespace
} // namespace
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef IMAGEUTILS_H
#define IMAGEUTILS_H
#include "orientation.h"
class QMatrix;
namespace Gwenview {
namespace ImageUtils {
QMatrix transformMatrix(Orientation);
} // namespace
} // namespace
#endif /* IMAGEUTILS_H */
......@@ -22,7 +22,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include "loadingdocumentimpl.moc"
// Qt
#include <QByteArray>
#include <QImage>
#include <QImageReader>
#include <QThread>
// KDE
......@@ -31,6 +33,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
// Local
#include "document.h"
#include "documentloadedimpl.h"
#include "imageutils.h"
#include "jpegcontent.h"
namespace Gwenview {
......@@ -38,7 +42,21 @@ namespace Gwenview {
class LoadingThread : public QThread {
public:
virtual void run() {
mImage.load(mUrl.path());
QString path = mUrl.path();
QByteArray format = QImageReader::imageFormat(path);
bool ok = mImage.load(path, format.data());
if (!ok) {
return;
}
if (format == "jpeg") {
JpegContent content;
if (!content.load(path)) {
return;
}
Gwenview::Orientation orientation = content.orientation();
QMatrix matrix = ImageUtils::transformMatrix(orientation);
mImage = mImage.transformed(matrix);
}
}
KUrl mUrl;
......
......@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Local
#include "../lib/documentfactory.h"
#include "../lib/imageutils.h"
#include "documenttest.moc"
......@@ -58,3 +59,20 @@ void DocumentTest::testDeleteWhileLoading() {
// Wait two seconds. If the test fails we will get a segfault while waiting
QTest::qWait(2000);
}
void DocumentTest::testLoadRotated() {
KUrl url("orient6.jpg");
QImage image;
bool ok = image.load(url.path());
QVERIFY2(ok, "Could not load 'orient6.jpg'");
QMatrix matrix = ImageUtils::transformMatrix(ROT_90);
image = image.transformed(matrix);
image.save("expected.png", "PNG");
Document::Ptr doc = DocumentFactory::instance()->load(url);
while (!doc->isLoaded()) {
QTest::qWait(30);
}
doc->image().save("result.png", "PNG");
QCOMPARE(image, doc->image());
}
......@@ -26,4 +26,5 @@ class DocumentTest : public QObject {
private Q_SLOTS:
void testLoad();
void testDeleteWhileLoading();
void testLoadRotated();
};
Markdown is supported
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