mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Respect exif rotation of images
Sometimes thumbnails still have the wrong dimensions, as they are scaled to fit inside a rectange of the reported size in the image. Not sure, who is wrong there, the media repo or we.
This commit is contained in:
parent
d94ac86816
commit
28adc9dc9b
4 changed files with 38 additions and 13 deletions
|
@ -24,6 +24,7 @@
|
|||
#include "Cache.h"
|
||||
#include "Logging.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "Utils.h"
|
||||
|
||||
static QPixmapCache avatar_cache;
|
||||
|
||||
|
@ -44,7 +45,7 @@ resolve(const QString &avatarUrl, int size, QObject *receiver, AvatarCallback ca
|
|||
|
||||
auto data = cache::image(cacheKey);
|
||||
if (!data.isNull()) {
|
||||
pixmap.loadFromData(data);
|
||||
pixmap = QPixmap::fromImage(utils::readImage(&data));
|
||||
avatar_cache.insert(cacheKey, pixmap);
|
||||
callback(pixmap);
|
||||
return;
|
||||
|
@ -54,9 +55,8 @@ resolve(const QString &avatarUrl, int size, QObject *receiver, AvatarCallback ca
|
|||
QObject::connect(proxy.get(),
|
||||
&AvatarProxy::avatarDownloaded,
|
||||
receiver,
|
||||
[callback, cacheKey](const QByteArray &data) {
|
||||
QPixmap pm;
|
||||
pm.loadFromData(data);
|
||||
[callback, cacheKey](QByteArray data) {
|
||||
QPixmap pm = QPixmap::fromImage(utils::readImage(&data));
|
||||
avatar_cache.insert(cacheKey, pm);
|
||||
callback(pm);
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "Cache.h"
|
||||
#include "Logging.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "Utils.h"
|
||||
|
||||
void
|
||||
MxcImageResponse::run()
|
||||
|
@ -14,11 +15,15 @@ MxcImageResponse::run()
|
|||
.arg(m_requestedSize.height());
|
||||
|
||||
auto data = cache::image(fileName);
|
||||
if (!data.isNull() && m_image.loadFromData(data)) {
|
||||
if (!data.isNull()) {
|
||||
m_image = utils::readImage(&data);
|
||||
m_image = m_image.scaled(m_requestedSize, Qt::KeepAspectRatio);
|
||||
m_image.setText("mxc url", "mxc://" + m_id);
|
||||
emit finished();
|
||||
return;
|
||||
|
||||
if (!m_image.isNull()) {
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mtx::http::ThumbOpts opts;
|
||||
|
@ -39,17 +44,22 @@ MxcImageResponse::run()
|
|||
|
||||
auto data = QByteArray(res.data(), res.size());
|
||||
cache::saveImage(fileName, data);
|
||||
m_image.loadFromData(data);
|
||||
m_image = utils::readImage(&data);
|
||||
m_image.setText("mxc url", "mxc://" + m_id);
|
||||
|
||||
emit finished();
|
||||
});
|
||||
} else {
|
||||
auto data = cache::image(m_id);
|
||||
if (!data.isNull() && m_image.loadFromData(data)) {
|
||||
|
||||
if (!data.isNull()) {
|
||||
m_image = utils::readImage(&data);
|
||||
m_image.setText("mxc url", "mxc://" + m_id);
|
||||
emit finished();
|
||||
return;
|
||||
|
||||
if (!m_image.isNull()) {
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
http::client()->download(
|
||||
|
@ -73,11 +83,11 @@ MxcImageResponse::run()
|
|||
mtx::crypto::decrypt_file(temp, m_encryptionInfo.value()));
|
||||
|
||||
auto data = QByteArray(temp.data(), temp.size());
|
||||
m_image.loadFromData(data);
|
||||
cache::saveImage(m_id, data);
|
||||
m_image = utils::readImage(&data);
|
||||
m_image.setText("original filename",
|
||||
QString::fromStdString(originalFilename));
|
||||
m_image.setText("mxc url", "mxc://" + m_id);
|
||||
cache::saveImage(m_id, data);
|
||||
|
||||
emit finished();
|
||||
});
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include "Utils.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QBuffer>
|
||||
#include <QComboBox>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGuiApplication>
|
||||
#include <QImageReader>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QScreen>
|
||||
#include <QSettings>
|
||||
|
@ -657,3 +659,12 @@ utils::restoreCombobox(QComboBox *combo, const QString &value)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
QImage
|
||||
utils::readImage(QByteArray *data)
|
||||
{
|
||||
QBuffer buf(data);
|
||||
QImageReader reader(&buf);
|
||||
reader.setAutoTransform(true);
|
||||
return reader.read();
|
||||
}
|
||||
|
|
|
@ -306,4 +306,8 @@ centerWidget(QWidget *widget, QWidget *parent);
|
|||
|
||||
void
|
||||
restoreCombobox(QComboBox *combo, const QString &value);
|
||||
|
||||
//! Read image respecting exif orientation
|
||||
QImage
|
||||
readImage(QByteArray *data);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue