From 2f9c39fe53e5a52d20ac19465368277dd9bbd12a Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 21 Jan 2022 18:00:13 +0300 Subject: [PATCH] Support selecting Webm stickers. --- .../history/view/media/history_view_gif.cpp | 14 +++++++++++--- .../media/streaming/media_streaming_common.h | 7 ++++++- .../media/streaming/media_streaming_player.cpp | 1 + .../media/streaming/media_streaming_utility.cpp | 7 ++++++- .../streaming/media_streaming_video_track.cpp | 2 ++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 81c12f748..96e1fbaa4 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -391,7 +391,10 @@ void Gif::draw(Painter &p, const PaintContext &context) const { auto request = ::Media::Streaming::FrameRequest(); request.outer = QSize(usew, painth) * cIntRetinaFactor(); request.resize = QSize(_thumbw, _thumbh) * cIntRetinaFactor(); - request.keepAlpha = !isRound && unwrapped; + request.keepAlpha = (sticker != nullptr); + if (sticker && context.selected()) { + request.colored = context.st->msgStickerOverlay()->c; + } request.corners = roundCorners; request.radius = roundRadius; if (!activeRoundPlaying && activeOwnPlaying->instance.playerLocked()) { @@ -442,8 +445,13 @@ void Gif::draw(Painter &p, const PaintContext &context) const { ensureDataMediaCreated(); const auto size = QSize(_thumbw, _thumbh); const auto args = Images::PrepareArgs{ - .options = Images::RoundOptions(roundRadius, roundCorners), - .outer = QSize(usew, painth), + .colored = ((sticker && context.selected()) + ? &context.st->msgStickerOverlay() + : nullptr), + .options = (sticker + ? Images::Option::TransparentBackground + : Images::RoundOptions(roundRadius, roundCorners)), + .outer = sticker ? QSize() : QSize(usew, painth), }; if (const auto good = _dataMedia->goodThumbnail()) { p.drawPixmap(rthumb.topLeft(), good->pixSingle(size, args)); diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_common.h b/Telegram/SourceFiles/media/streaming/media_streaming_common.h index 8d42fa599..47bd097dd 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_common.h +++ b/Telegram/SourceFiles/media/streaming/media_streaming_common.h @@ -59,6 +59,7 @@ struct VideoInformation { QSize size; QImage cover; int rotation = 0; + bool alpha = false; }; struct AudioInformation { @@ -120,6 +121,7 @@ struct FrameRequest { QSize outer; ImageRoundRadius radius = ImageRoundRadius(); RectParts corners = RectPart::AllCorners; + QColor colored = QColor(0, 0, 0, 0); bool requireARGB32 = true; bool keepAlpha = false; bool strict = true; @@ -139,6 +141,7 @@ struct FrameRequest { && (outer == other.outer) && (radius == other.radius) && (corners == other.corners) + && (colored == other.colored) && (keepAlpha == other.keepAlpha) && (requireARGB32 == other.requireARGB32); } @@ -149,7 +152,8 @@ struct FrameRequest { [[nodiscard]] bool goodFor(const FrameRequest &other) const { return (requireARGB32 == other.requireARGB32) && (keepAlpha == other.keepAlpha) - && ((*this == other) || (strict && !other.strict)); + && (colored == other.colored) + && ((strict && !other.strict) || (*this == other)); } }; @@ -177,6 +181,7 @@ struct FrameWithInfo { FrameYUV420 *yuv420 = nullptr; FrameFormat format = FrameFormat::None; int index = -1; + bool alpha = false; }; } // namespace Streaming diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_player.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_player.cpp index 3cdab3da1..bdde638ef 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_player.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_player.cpp @@ -63,6 +63,7 @@ void SaveValidVideoInformation( to.size = from.size; to.cover = std::move(from.cover); to.rotation = from.rotation; + to.alpha = from.alpha; } void SaveValidStartInformation(Information &to, Information &&from) { diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_utility.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_utility.cpp index 172347efc..e33c4ffba 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_utility.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_utility.cpp @@ -92,7 +92,9 @@ bool GoodForRequest( bool hasAlpha, int rotation, const FrameRequest &request) { - if (image.isNull() || (hasAlpha && !request.keepAlpha)) { + if (image.isNull() + || (hasAlpha && !request.keepAlpha) + || request.colored.alpha() != 0) { return false; } else if (request.resize.isEmpty()) { return true; @@ -321,6 +323,9 @@ QImage PrepareByRequest( p.end(); ApplyFrameRounding(storage, request); + if (request.colored.alpha() != 0) { + storage = Images::Colored(std::move(storage), request.colored); + } return storage; } diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp index 13647a89e..c6ab1d97a 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp @@ -661,6 +661,7 @@ void VideoTrackObject::callReady() { } data.cover = frame->original; data.rotation = _stream.rotation; + data.alpha = frame->alpha; data.state.duration = _stream.duration; data.state.position = _syncTimePoint.trackTime; data.state.receivedTill = _readTillEnd @@ -1166,6 +1167,7 @@ FrameWithInfo VideoTrack::frameWithInfo(const Instance *instance) { .yuv420 = &data.frame->yuv420, .format = data.frame->format, .index = data.index, + .alpha = data.frame->alpha, }; }