Commit e0428071 authored by Sylvain Berfini's avatar Sylvain Berfini

Added EXIF orientation support for file transfer images' preview

parent 30a4054a
...@@ -147,6 +147,7 @@ set(SOURCES ...@@ -147,6 +147,7 @@ set(SOURCES
src/main.cpp src/main.cpp
src/utils/LinphoneUtils.cpp src/utils/LinphoneUtils.cpp
src/utils/Utils.cpp src/utils/Utils.cpp
src/utils/QExifImageHeader.cpp
) )
set(HEADERS set(HEADERS
...@@ -201,6 +202,7 @@ set(HEADERS ...@@ -201,6 +202,7 @@ set(HEADERS
src/components/url-handlers/UrlHandlers.hpp src/components/url-handlers/UrlHandlers.hpp
src/utils/LinphoneUtils.hpp src/utils/LinphoneUtils.hpp
src/utils/Utils.hpp src/utils/Utils.hpp
src/utils/QExifImageHeader.h
) )
if(APPLE) if(APPLE)
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "../../app/paths/Paths.hpp" #include "../../app/paths/Paths.hpp"
#include "../../app/providers/ThumbnailProvider.hpp" #include "../../app/providers/ThumbnailProvider.hpp"
#include "../../utils/Utils.hpp" #include "../../utils/Utils.hpp"
#include "../../utils/QExifImageHeader.h"
#include "../core/CoreManager.hpp" #include "../core/CoreManager.hpp"
#include "ChatModel.hpp" #include "ChatModel.hpp"
...@@ -71,15 +72,35 @@ inline void createThumbnail (const shared_ptr<linphone::ChatMessage> &message) { ...@@ -71,15 +72,35 @@ inline void createThumbnail (const shared_ptr<linphone::ChatMessage> &message) {
return; return;
QString thumbnailPath = ::Utils::coreStringToAppString(message->getFileTransferFilepath()); QString thumbnailPath = ::Utils::coreStringToAppString(message->getFileTransferFilepath());
QImage image(thumbnailPath); QImage image(thumbnailPath);
if (image.isNull()) if (image.isNull())
return; return;
int rotation = 0;
QExifImageHeader exifImageHeader;
if (exifImageHeader.loadFromJpeg(thumbnailPath)) {
rotation = (int) exifImageHeader.value(QExifImageHeader::ImageTag::Orientation).toShort();
}
QImage thumbnail = image.scaled( QImage thumbnail = image.scaled(
THUMBNAIL_IMAGE_FILE_WIDTH, THUMBNAIL_IMAGE_FILE_HEIGHT, THUMBNAIL_IMAGE_FILE_WIDTH, THUMBNAIL_IMAGE_FILE_HEIGHT,
Qt::KeepAspectRatio, Qt::SmoothTransformation Qt::KeepAspectRatio, Qt::SmoothTransformation
); );
if (rotation != 0) {
QTransform transform;
if (rotation == 3 || rotation == 4) {
transform.rotate(180);
} else if (rotation == 5 || rotation == 6) {
transform.rotate(90);
} else if (rotation == 7 || rotation == 8) {
transform.rotate(-90);
}
thumbnail = thumbnail.transformed(transform);
if (rotation == 2 || rotation == 4 || rotation == 5 || rotation == 7) {
thumbnail = thumbnail.mirrored(true, false);
}
}
QString uuid = QUuid::createUuid().toString(); QString uuid = QUuid::createUuid().toString();
QString fileId = QStringLiteral("%1.jpg").arg(uuid.mid(1, uuid.length() - 2)); QString fileId = QStringLiteral("%1.jpg").arg(uuid.mid(1, uuid.length() - 2));
......
This diff is collapsed.
This diff is collapsed.
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