Cache good thumbnail in Webp for Webm stickers.

This commit is contained in:
John Preston 2022-01-21 17:30:12 +03:00
parent 581b84afe0
commit d18e28978a
2 changed files with 11 additions and 6 deletions

View file

@ -37,6 +37,7 @@ constexpr auto kGoodThumbQuality = 87;
enum class FileType { enum class FileType {
Video, Video,
VideoSticker,
AnimatedSticker, AnimatedSticker,
WallPaper, WallPaper,
WallPatternPNG, WallPatternPNG,
@ -56,7 +57,7 @@ enum class FileType {
const QString &path, const QString &path,
QByteArray data, QByteArray data,
FileType type) { FileType type) {
if (type == FileType::Video) { if (type == FileType::Video || type == FileType::VideoSticker) {
return ::Media::Clip::PrepareForSending(path, data).thumbnail; return ::Media::Clip::PrepareForSending(path, data).thumbnail;
} else if (type == FileType::AnimatedSticker) { } else if (type == FileType::AnimatedSticker) {
return Lottie::ReadThumbnail(Lottie::ReadContent(data, path)); return Lottie::ReadThumbnail(Lottie::ReadContent(data, path));
@ -409,9 +410,11 @@ void DocumentMedia::GenerateGoodThumbnail(
? FileType::WallPaper ? FileType::WallPaper
: document->isTheme() : document->isTheme()
? FileType::Theme ? FileType::Theme
: (document->sticker() && document->sticker()->isLottie()) : !document->sticker()
? FileType::Video
: document->sticker()->isLottie()
? FileType::AnimatedSticker ? FileType::AnimatedSticker
: FileType::Video; : FileType::VideoSticker;
auto location = document->location().isEmpty() auto location = document->location().isEmpty()
? nullptr ? nullptr
: std::make_unique<Core::FileLocation>(document->location()); : std::make_unique<Core::FileLocation>(document->location());
@ -428,7 +431,8 @@ void DocumentMedia::GenerateGoodThumbnail(
auto bytes = QByteArray(); auto bytes = QByteArray();
if (!result.isNull()) { if (!result.isNull()) {
auto buffer = QBuffer(&bytes); auto buffer = QBuffer(&bytes);
const auto format = (type == FileType::AnimatedSticker) const auto format = (type == FileType::AnimatedSticker
|| type == FileType::VideoSticker)
? "WEBP" ? "WEBP"
: (type == FileType::WallPatternPNG : (type == FileType::WallPatternPNG
|| type == FileType::WallPatternSVG) || type == FileType::WallPatternSVG)

View file

@ -28,7 +28,7 @@ namespace {
constexpr auto kWaitingFastDuration = crl::time(200); constexpr auto kWaitingFastDuration = crl::time(200);
constexpr auto kWaitingShowDuration = crl::time(500); constexpr auto kWaitingShowDuration = crl::time(500);
constexpr auto kWaitingShowDelay = crl::time(500); constexpr auto kWaitingShowDelay = crl::time(500);
constexpr auto kGoodThumbnailQuality = 87; constexpr auto kGoodThumbQuality = 87;
} // namespace } // namespace
@ -217,6 +217,7 @@ void Document::validateGoodThumbnail() {
|| _document->goodThumbnailChecked()) { || _document->goodThumbnailChecked()) {
return; return;
} }
const auto sticker = (_document->sticker() != nullptr);
const auto document = _document; const auto document = _document;
const auto information = _info.video; const auto information = _info.video;
const auto key = document->goodThumbnailCacheKey(); const auto key = document->goodThumbnailCacheKey();
@ -243,7 +244,7 @@ void Document::validateGoodThumbnail() {
auto bytes = QByteArray(); auto bytes = QByteArray();
{ {
auto buffer = QBuffer(&bytes); auto buffer = QBuffer(&bytes);
image.save(&buffer, "JPG", kGoodThumbnailQuality); image.save(&buffer, sticker ? "WEBP" : "JPG", kGoodThumbQuality);
} }
const auto length = bytes.size(); const auto length = bytes.size();
if (!length || length > Storage::kMaxFileInMemory) { if (!length || length > Storage::kMaxFileInMemory) {