2020-03-01 21:55:43 +03:00
|
|
|
#include "BlurhashProvider.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
#include "blurhash.hpp"
|
|
|
|
|
2020-03-04 03:56:58 +03:00
|
|
|
void
|
|
|
|
BlurhashResponse::run()
|
2020-03-01 21:55:43 +03:00
|
|
|
{
|
2020-03-04 03:56:58 +03:00
|
|
|
if (m_requestedSize.width() < 0 || m_requestedSize.height() < 0) {
|
|
|
|
m_error = QStringLiteral("Blurhash needs size request");
|
|
|
|
emit finished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_requestedSize.width() == 0 || m_requestedSize.height() == 0) {
|
|
|
|
m_image = QImage(m_requestedSize, QImage::Format_RGB32);
|
|
|
|
m_image.fill(QColor(0, 0, 0));
|
|
|
|
emit finished();
|
|
|
|
return;
|
|
|
|
}
|
2020-03-01 21:55:43 +03:00
|
|
|
|
2020-03-04 03:56:58 +03:00
|
|
|
auto decoded = blurhash::decode(QUrl::fromPercentEncoding(m_id.toUtf8()).toStdString(),
|
|
|
|
m_requestedSize.width(),
|
|
|
|
m_requestedSize.height(),
|
|
|
|
4);
|
2020-03-01 21:55:43 +03:00
|
|
|
if (decoded.image.empty()) {
|
2020-03-04 03:56:58 +03:00
|
|
|
m_error = QStringLiteral("Failed decode!");
|
|
|
|
emit finished();
|
|
|
|
return;
|
2020-03-01 21:55:43 +03:00
|
|
|
}
|
|
|
|
|
2020-03-04 03:30:43 +03:00
|
|
|
QImage image(decoded.image.data(), decoded.width, decoded.height, QImage::Format_RGB32);
|
2020-03-01 21:55:43 +03:00
|
|
|
|
2020-03-04 03:56:58 +03:00
|
|
|
m_image = image.copy();
|
|
|
|
emit finished();
|
2020-03-01 21:55:43 +03:00
|
|
|
}
|