diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 626004cce8..49fd08a07b 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -636,7 +636,10 @@ Image *DocumentData::goodThumbnail() const { } void DocumentData::validateGoodThumbnail() { - if (!isVideoFile() && !isAnimation() && !isWallPaper()) { + if (!isVideoFile() + && !isAnimation() + && !isWallPaper() + && (!sticker() || !sticker()->animated)) { _goodThumbnail = nullptr; } else if (!_goodThumbnail && hasRemoteLocation()) { _goodThumbnail = std::make_unique( @@ -665,7 +668,10 @@ void DocumentData::setGoodThumbnailOnUpload( } _goodThumbnail = std::make_unique( std::make_unique( - QString(), std::move(bytes), "JPG", std::move(image))); + QString(), + std::move(bytes), + sticker() ? "WEBP" : "JPG", + std::move(image))); } auto DocumentData::bigFileBaseCacheKey() const diff --git a/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp b/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp index 67ec4560ce..b89dc487e1 100644 --- a/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp +++ b/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document.h" #include "data/data_file_origin.h" #include "media/clip/media_clip_reader.h" +#include "lottie/lottie_animation.h" #include "auth_session.h" namespace Data { @@ -19,12 +20,20 @@ namespace { constexpr auto kGoodThumbQuality = 87; constexpr auto kWallPaperSize = 960; +enum class FileType { + Video, + AnimatedSticker, + WallPaper, +}; + QImage Prepare( const QString &path, QByteArray data, - bool isWallPaper) { - if (!isWallPaper) { + FileType type) { + if (type == FileType::Video) { return Media::Clip::PrepareForSending(path, data).thumbnail; + } else if (type == FileType::AnimatedSticker) { + return Lottie::ReadThumbnail(Lottie::ReadContent(data, path)); } const auto validateSize = [](QSize size) { return (size.width() + size.height()) < 10'000; @@ -64,7 +73,11 @@ void GoodThumbSource::generate(base::binary_guard &&guard) { return; } const auto data = _document->data(); - const auto isWallPaper = _document->isWallPaper(); + const auto type = _document->isWallPaper() + ? FileType::WallPaper + : _document->sticker() + ? FileType::AnimatedSticker + : FileType::Video; auto location = _document->location().isEmpty() ? nullptr : std::make_unique(_document->location()); @@ -80,11 +93,13 @@ void GoodThumbSource::generate(base::binary_guard &&guard) { const auto filepath = (location && location->accessEnable()) ? location->name() : QString(); - auto result = Prepare(filepath, data, isWallPaper); + auto result = Prepare(filepath, data, type); auto bytes = QByteArray(); if (!result.isNull()) { auto buffer = QBuffer(&bytes); - const auto format = (isWallPaper && result.hasAlphaChannel()) + const auto format = (type == FileType::AnimatedSticker) + ? "WEBP" + : (type == FileType::WallPaper && result.hasAlphaChannel()) ? "PNG" : "JPG"; result.save(&buffer, format, kGoodThumbQuality); diff --git a/Telegram/SourceFiles/history/media/history_media_sticker.cpp b/Telegram/SourceFiles/history/media/history_media_sticker.cpp index e41b3362bd..d9b1f731c1 100644 --- a/Telegram/SourceFiles/history/media/history_media_sticker.cpp +++ b/Telegram/SourceFiles/history/media/history_media_sticker.cpp @@ -156,6 +156,10 @@ void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, c const auto w = _pixw; const auto h = _pixh; const auto &c = st::msgStickerOverlay; + const auto good = _data->goodThumbnail(); + if (!lottieReady && good && !good->loaded()) { + good->load({}); + } static QPixmap empty; if (lottieReady) { return empty; @@ -170,6 +174,10 @@ void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, c // return selected // ? blurred->pixBlurredColored(o, c, w, h) // : blurred->pixBlurred(o, w, h); + } else if (good && good->loaded()) { + return selected + ? good->pixColored(o, c, w, h) + : good->pix(o, w, h); } else if (const auto thumbnail = _data->thumbnail()) { return selected ? thumbnail->pixBlurredColored(o, c, w, h) diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index 539f48ab9b..0ec49b5f84 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -894,6 +894,13 @@ void FileLoadTask::process() { MTP_string(QString()), MTP_inputStickerSetEmpty(), MTPMaskCoords())); + if (isAnimation) { + goodThumbnail = fullimage; + { + QBuffer buffer(&goodThumbnailBytes); + goodThumbnail.save(&buffer, "WEBP", kThumbnailQuality); + } + } } else if (isAnimation) { attributes.push_back(MTP_documentAttributeAnimated()); } else if (_type != SendMediaType::File) {