File indexing completed on 2024-10-06 12:53:58
0001 // SPDX-FileCopyrightText: 2021 Tobias Fella <tobias.fella@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 #include "blurhashimageprovider.h" 0005 0006 #include <QImage> 0007 #include <QString> 0008 0009 #include "blurhash.h" 0010 0011 BlurhashImageProvider::BlurhashImageProvider() 0012 : QQuickImageProvider(QQuickImageProvider::Image) 0013 { 0014 } 0015 0016 QImage BlurhashImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) 0017 { 0018 if (id.isEmpty()) { 0019 return QImage(); 0020 } 0021 *size = requestedSize; 0022 if (size->width() == -1) { 0023 size->setWidth(256); 0024 } 0025 if (size->height() == -1) { 0026 size->setHeight(256); 0027 } 0028 auto data = decode(QUrl::fromPercentEncoding(id.toLatin1()).toLatin1().data(), size->width(), size->height(), 1, 3); 0029 QImage image(data, size->width(), size->height(), size->width() * 3, QImage::Format_RGB888, free, data); 0030 return image; 0031 }