mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-23 19:38:48 +03:00
d424145ee4
Might fix #844 See https://code.qt.io/cgit/qt/qtdeclarative.git/commit/examples/quick/imageresponseprovider/imageresponseprovider.cpp?h=5.15&id=b1f238568214e6587b829d6695677e55a99b1d40 for context.
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include "BlurhashProvider.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <QUrl>
|
|
|
|
#include "blurhash.hpp"
|
|
|
|
void
|
|
BlurhashRunnable::run()
|
|
{
|
|
if (m_requestedSize.width() < 0 || m_requestedSize.height() < 0) {
|
|
emit error("Blurhash needs size request");
|
|
return;
|
|
}
|
|
if (m_requestedSize.width() == 0 || m_requestedSize.height() == 0) {
|
|
auto image = QImage(m_requestedSize, QImage::Format_RGB32);
|
|
image.fill(QColor(0, 0, 0));
|
|
emit done(image);
|
|
return;
|
|
}
|
|
|
|
auto decoded = blurhash::decode(QUrl::fromPercentEncoding(m_id.toUtf8()).toStdString(),
|
|
m_requestedSize.width(),
|
|
m_requestedSize.height());
|
|
if (decoded.image.empty()) {
|
|
emit error(QStringLiteral("Failed decode!"));
|
|
return;
|
|
}
|
|
|
|
QImage image(decoded.image.data(),
|
|
(int)decoded.width,
|
|
(int)decoded.height,
|
|
(int)decoded.width * 3,
|
|
QImage::Format_RGB888);
|
|
|
|
emit done(std::move(image));
|
|
}
|