mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-27 21:48:48 +03:00
Speed up blurhash code
This commit is contained in:
parent
0fc98b2692
commit
5ac18f1f5f
4 changed files with 10 additions and 18 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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++) {
|
||||
|
|
5
third_party/blurhash/blurhash.cpp
vendored
5
third_party/blurhash/blurhash.cpp
vendored
|
@ -251,7 +251,7 @@ multiplyBasisFunction(Components components, int width, int height, unsigned cha
|
|||
|
||||
namespace blurhash {
|
||||
Image
|
||||
decode(std::string_view blurhash, size_t width, size_t height)
|
||||
decode(std::string_view blurhash, size_t width, size_t height, size_t bytesPerPixel)
|
||||
{
|
||||
Image i{};
|
||||
|
||||
|
@ -295,6 +295,9 @@ decode(std::string_view blurhash, size_t width, size_t height)
|
|||
i.image.push_back(static_cast<unsigned char>(linearToSrgb(c.r)));
|
||||
i.image.push_back(static_cast<unsigned char>(linearToSrgb(c.g)));
|
||||
i.image.push_back(static_cast<unsigned char>(linearToSrgb(c.b)));
|
||||
|
||||
for (size_t p = 3; p < bytesPerPixel; p++)
|
||||
i.image.push_back(255);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
third_party/blurhash/blurhash.hpp
vendored
2
third_party/blurhash/blurhash.hpp
vendored
|
@ -13,7 +13,7 @@ struct Image
|
|||
|
||||
// Decode a blurhash to an image with size width*height
|
||||
Image
|
||||
decode(std::string_view blurhash, size_t width, size_t height);
|
||||
decode(std::string_view blurhash, size_t width, size_t height, size_t bytesPerPixel = 3);
|
||||
|
||||
// Encode an image of rgb pixels (without padding) with size width*height into a blurhash with x*y
|
||||
// components
|
||||
|
|
Loading…
Reference in a new issue