From 3dfcd0f4f4501dba5925d894b7f0fbc9414549c8 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 9 Sep 2018 17:33:11 +0900 Subject: Avatar: don't paint on null images; optimise initial placeholder generation --- lib/avatar.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/avatar.cpp b/lib/avatar.cpp index 7e6dc50b..be9b6a78 100644 --- a/lib/avatar.cpp +++ b/lib/avatar.cpp @@ -126,6 +126,14 @@ QImage Avatar::Private::get(Connection* connection, QSize size, if (callback) callbacks.emplace_back(move(callback)); _thumbnailRequest = connection->getThumbnail(_url, size); + if (_originalImage.isNull() && !_defaultIcon.isNull()) + { + _originalImage = QImage(_defaultIcon.actualSize(size), + QImage::Format_ARGB32_Premultiplied); + _originalImage.fill(Qt::transparent); + QPainter p { &_originalImage }; + _defaultIcon.paint(&p, { QPoint(), _defaultIcon.actualSize(size) }); + } QObject::connect( _thumbnailRequest, &MediaThumbnailJob::success, _thumbnailRequest, [this] { _fetched = true; @@ -138,15 +146,6 @@ QImage Avatar::Private::get(Connection* connection, QSize size, }); } - if( _originalImage.isNull() ) - { - if (_defaultIcon.isNull()) - return _originalImage; - - QPainter p { &_originalImage }; - _defaultIcon.paint(&p, { QPoint(), _defaultIcon.actualSize(size) }); - } - for (const auto& p: _scaledImages) if (p.first == size) return p.second; -- cgit v1.2.3