From a6621233d02848e47d45a4ec90967157d5fa0930 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 25 Jan 2022 14:26:19 +0300 Subject: [PATCH] Show first frame of webm in photo editor. --- .../editor/scene/scene_item_sticker.cpp | 28 +++++++++++++++++-- .../editor/scene/scene_item_sticker.h | 2 ++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp b/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp index 16497ccb9..d7128c731 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp +++ b/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp @@ -34,9 +34,9 @@ ItemSticker::ItemSticker( } const auto updateThumbnail = [=] { const auto guard = gsl::finally([&] { - setAspectRatio(_pixmap.isNull() - ? 1.0 - : (_pixmap.height() / float64(_pixmap.width()))); + if (_pixmap.isNull()) { + setAspectRatio(1.); + } }); if (stickerData->isLottie()) { _lottie.player = ChatHelpers::LottiePlayerFromDocument( @@ -54,6 +54,25 @@ ItemSticker::ItemSticker( update(); }, _lottie.lifetime); return true; + } else if (stickerData->isWebm() + && !_document->dimensions.isEmpty()) { + const auto callback = [=](::Media::Clip::Notification) { + const auto size = _document->dimensions; + if (_webm && _webm->ready() && !_webm->started()) { + _webm->start({ .frame = size, .keepAlpha = true }); + } + if (_webm && _webm->started()) { + updatePixmap(_webm->current( + { .frame = size, .keepAlpha = true }, + 0)); + _webm = nullptr; + } + }; + _webm = ::Media::Clip::MakeReader( + _mediaView->owner()->location(), + _mediaView->bytes(), + callback); + return true; } const auto sticker = _mediaView->getStickerLarge(); if (!sticker) { @@ -83,6 +102,9 @@ void ItemSticker::updatePixmap(QPixmap &&pixmap) { } else { update(); } + if (!_pixmap.isNull()) { + setAspectRatio(_pixmap.height() / float64(_pixmap.width())); + } } void ItemSticker::paint( diff --git a/Telegram/SourceFiles/editor/scene/scene_item_sticker.h b/Telegram/SourceFiles/editor/scene/scene_item_sticker.h index 201aeb2a5..bbd0a758a 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_sticker.h +++ b/Telegram/SourceFiles/editor/scene/scene_item_sticker.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "editor/scene/scene_item_base.h" +#include "media/clip/media_clip_reader.h" namespace Data { class DocumentMedia; @@ -47,6 +48,7 @@ private: std::unique_ptr player; rpl::lifetime lifetime; } _lottie; + ::Media::Clip::ReaderPointer _webm; QPixmap _pixmap; rpl::lifetime _loadingLifetime;