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
src/main.cpp
src/utils/LinphoneUtils.cpp
src/utils/Utils.cpp
src/utils/QExifImageHeader.cpp
)
set(HEADERS
......@@ -201,6 +202,7 @@ set(HEADERS
src/components/url-handlers/UrlHandlers.hpp
src/utils/LinphoneUtils.hpp
src/utils/Utils.hpp
src/utils/QExifImageHeader.h
)
if(APPLE)
......
......@@ -32,6 +32,7 @@
#include "../../app/paths/Paths.hpp"
#include "../../app/providers/ThumbnailProvider.hpp"
#include "../../utils/Utils.hpp"
#include "../../utils/QExifImageHeader.h"
#include "../core/CoreManager.hpp"
#include "ChatModel.hpp"
......@@ -71,15 +72,35 @@ inline void createThumbnail (const shared_ptr<linphone::ChatMessage> &message) {
return;
QString thumbnailPath = ::Utils::coreStringToAppString(message->getFileTransferFilepath());
QImage image(thumbnailPath);
if (image.isNull())
return;
int rotation = 0;
QExifImageHeader exifImageHeader;
if (exifImageHeader.loadFromJpeg(thumbnailPath)) {
rotation = (int) exifImageHeader.value(QExifImageHeader::ImageTag::Orientation).toShort();
}
QImage thumbnail = image.scaled(
THUMBNAIL_IMAGE_FILE_WIDTH, THUMBNAIL_IMAGE_FILE_HEIGHT,
Qt::KeepAspectRatio, Qt::SmoothTransformation
);
THUMBNAIL_IMAGE_FILE_WIDTH, THUMBNAIL_IMAGE_FILE_HEIGHT,
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 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