mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 14:18:49 +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 "Cache.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
static QPixmapCache avatar_cache;
|
static QPixmapCache avatar_cache;
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ resolve(const QString &avatarUrl, int size, QObject *receiver, AvatarCallback ca
|
||||||
|
|
||||||
auto data = cache::image(cacheKey);
|
auto data = cache::image(cacheKey);
|
||||||
if (!data.isNull()) {
|
if (!data.isNull()) {
|
||||||
pixmap.loadFromData(data);
|
pixmap = QPixmap::fromImage(utils::readImage(&data));
|
||||||
avatar_cache.insert(cacheKey, pixmap);
|
avatar_cache.insert(cacheKey, pixmap);
|
||||||
callback(pixmap);
|
callback(pixmap);
|
||||||
return;
|
return;
|
||||||
|
@ -54,9 +55,8 @@ resolve(const QString &avatarUrl, int size, QObject *receiver, AvatarCallback ca
|
||||||
QObject::connect(proxy.get(),
|
QObject::connect(proxy.get(),
|
||||||
&AvatarProxy::avatarDownloaded,
|
&AvatarProxy::avatarDownloaded,
|
||||||
receiver,
|
receiver,
|
||||||
[callback, cacheKey](const QByteArray &data) {
|
[callback, cacheKey](QByteArray data) {
|
||||||
QPixmap pm;
|
QPixmap pm = QPixmap::fromImage(utils::readImage(&data));
|
||||||
pm.loadFromData(data);
|
|
||||||
avatar_cache.insert(cacheKey, pm);
|
avatar_cache.insert(cacheKey, pm);
|
||||||
callback(pm);
|
callback(pm);
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
MxcImageResponse::run()
|
MxcImageResponse::run()
|
||||||
|
@ -14,12 +15,16 @@ MxcImageResponse::run()
|
||||||
.arg(m_requestedSize.height());
|
.arg(m_requestedSize.height());
|
||||||
|
|
||||||
auto data = cache::image(fileName);
|
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 = m_image.scaled(m_requestedSize, Qt::KeepAspectRatio);
|
||||||
m_image.setText("mxc url", "mxc://" + m_id);
|
m_image.setText("mxc url", "mxc://" + m_id);
|
||||||
|
|
||||||
|
if (!m_image.isNull()) {
|
||||||
emit finished();
|
emit finished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mtx::http::ThumbOpts opts;
|
mtx::http::ThumbOpts opts;
|
||||||
opts.mxc_url = "mxc://" + m_id.toStdString();
|
opts.mxc_url = "mxc://" + m_id.toStdString();
|
||||||
|
@ -39,18 +44,23 @@ MxcImageResponse::run()
|
||||||
|
|
||||||
auto data = QByteArray(res.data(), res.size());
|
auto data = QByteArray(res.data(), res.size());
|
||||||
cache::saveImage(fileName, data);
|
cache::saveImage(fileName, data);
|
||||||
m_image.loadFromData(data);
|
m_image = utils::readImage(&data);
|
||||||
m_image.setText("mxc url", "mxc://" + m_id);
|
m_image.setText("mxc url", "mxc://" + m_id);
|
||||||
|
|
||||||
emit finished();
|
emit finished();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
auto data = cache::image(m_id);
|
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);
|
m_image.setText("mxc url", "mxc://" + m_id);
|
||||||
|
|
||||||
|
if (!m_image.isNull()) {
|
||||||
emit finished();
|
emit finished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
http::client()->download(
|
http::client()->download(
|
||||||
"mxc://" + m_id.toStdString(),
|
"mxc://" + m_id.toStdString(),
|
||||||
|
@ -73,11 +83,11 @@ MxcImageResponse::run()
|
||||||
mtx::crypto::decrypt_file(temp, m_encryptionInfo.value()));
|
mtx::crypto::decrypt_file(temp, m_encryptionInfo.value()));
|
||||||
|
|
||||||
auto data = QByteArray(temp.data(), temp.size());
|
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",
|
m_image.setText("original filename",
|
||||||
QString::fromStdString(originalFilename));
|
QString::fromStdString(originalFilename));
|
||||||
m_image.setText("mxc url", "mxc://" + m_id);
|
m_image.setText("mxc url", "mxc://" + m_id);
|
||||||
cache::saveImage(m_id, data);
|
|
||||||
|
|
||||||
emit finished();
|
emit finished();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QBuffer>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
#include <QImageReader>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QSettings>
|
#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
|
void
|
||||||
restoreCombobox(QComboBox *combo, const QString &value);
|
restoreCombobox(QComboBox *combo, const QString &value);
|
||||||
|
|
||||||
|
//! Read image respecting exif orientation
|
||||||
|
QImage
|
||||||
|
readImage(QByteArray *data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue