2020-03-01 21:55:43 +03:00
|
|
|
#include "BlurhashProvider.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
#include "blurhash.hpp"
|
|
|
|
|
|
|
|
QImage
|
|
|
|
BlurhashProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
|
|
|
|
{
|
|
|
|
QSize sz = requestedSize;
|
|
|
|
if (sz.width() < 1 || sz.height() < 1)
|
|
|
|
return QImage();
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
*size = sz;
|
|
|
|
|
|
|
|
auto decoded = blurhash::decode(
|
2020-03-04 03:30:43 +03:00
|
|
|
QUrl::fromPercentEncoding(id.toUtf8()).toStdString(), sz.width(), sz.height(), 4);
|
2020-03-01 21:55:43 +03:00
|
|
|
if (decoded.image.empty()) {
|
|
|
|
*size = QSize();
|
|
|
|
return QImage();
|
|
|
|
}
|
|
|
|
|
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:30:43 +03:00
|
|
|
return image.copy();
|
2020-03-01 21:55:43 +03:00
|
|
|
}
|