2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2019-11-08 16:39:45 +03:00
|
|
|
#include "ColorImageProvider.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
QPixmap
|
|
|
|
ColorImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
auto args = id.split('?');
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QPixmap source(args[0]);
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
if (size)
|
|
|
|
*size = QSize(source.width(), source.height());
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
if (args.size() < 2)
|
|
|
|
return source;
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QColor color(args[1]);
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QPixmap colorized = source;
|
|
|
|
QPainter painter(&colorized);
|
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
|
|
|
painter.fillRect(colorized.rect(), color);
|
|
|
|
painter.end();
|
2019-11-08 16:39:45 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
return colorized;
|
2019-11-08 16:39:45 +03:00
|
|
|
}
|