summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-03-04 01:30:43 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2020-03-04 01:30:43 +0100
commit5ac18f1f5f758c28316791dc9aed8e216291dd38 (patch)
tree2c78f8c45b5da9b35cb91b01069b053593527769 /src
parentExperimental blurhash implementation (MXC2448) (diff)
downloadnheko-5ac18f1f5f758c28316791dc9aed8e216291dd38.tar.xz
Speed up blurhash code
Diffstat (limited to 'src')
-rw-r--r--src/BlurhashProvider.cpp19
-rw-r--r--src/ChatPage.cpp2
2 files changed, 5 insertions, 16 deletions
diff --git a/src/BlurhashProvider.cpp b/src/BlurhashProvider.cpp

index a5530a98..87d1f51b 100644 --- a/src/BlurhashProvider.cpp +++ b/src/BlurhashProvider.cpp
@@ -17,26 +17,13 @@ BlurhashProvider::requestImage(const QString &id, QSize *size, const QSize &requ *size = sz; auto decoded = blurhash::decode( - QUrl::fromPercentEncoding(id.toUtf8()).toStdString(), sz.width(), sz.height()); + QUrl::fromPercentEncoding(id.toUtf8()).toStdString(), sz.width(), sz.height(), 4); if (decoded.image.empty()) { *size = QSize(); return QImage(); } - QImage image(sz, QImage::Format_RGB888); + QImage image(decoded.image.data(), decoded.width, decoded.height, QImage::Format_RGB32); - for (int y = 0; y < sz.height(); y++) { - for (int x = 0; x < sz.width(); x++) { - int base = (y * sz.width() + x) * 3; - image.setPixel(x, - y, - qRgb(decoded.image[base], - decoded.image[base + 1], - decoded.image[base + 2])); - } - } - - // std::copy(decoded.image.begin(), decoded.image.end(), image.bits()); - - return image; + return image.copy(); } diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index 6a7d984c..698a4ae2 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp
@@ -332,6 +332,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) QImage img; img.loadFromData(bin); + if (img.height() > 200 && img.width() > 360) + img = img.scaled(360, 200, Qt::KeepAspectRatioByExpanding); std::vector<unsigned char> data; for (int y = 0; y < img.height(); y++) { for (int x = 0; x < img.width(); x++) {