Files
neochat/src/app/blurhashimageprovider.cpp
James Graham b6791485c4 Move remaining code to app module
There's still some stuff that could potentially go elsewhere but I think it's enough for now.
2025-04-18 09:26:17 +00:00

31 lines
888 B
C++

// SPDX-FileCopyrightText: 2021 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "blurhashimageprovider.h"
#include <QImage>
#include <QString>
#include "blurhash.h"
BlurhashImageProvider::BlurhashImageProvider()
: QQuickImageProvider(QQuickImageProvider::Image)
{
}
QImage BlurhashImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
if (id.isEmpty()) {
return QImage();
}
*size = requestedSize;
if (size->width() == -1) {
size->setWidth(256);
}
if (size->height() == -1) {
size->setHeight(256);
}
auto data = decode(QUrl::fromPercentEncoding(id.toLatin1()).toLatin1().data(), size->width(), size->height(), 1, 3);
QImage image(data, size->width(), size->height(), size->width() * 3, QImage::Format_RGB888, free, data);
return image;
}