From c8d4818d225f495d8869cd4a5b82e7abfc6a2c88 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 21 Oct 2024 18:15:24 +0400 Subject: [PATCH] Blurred frame while paused. --- .../ui/controls/round_video_recorder.cpp | 61 ++++++++++++++----- .../ui/controls/round_video_recorder.h | 3 +- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp b/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp index ea8540fc4a..3851f0bf85 100644 --- a/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp +++ b/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp @@ -29,6 +29,7 @@ constexpr auto kVideoBitRate = 3 * 1024 * 1024; constexpr auto kMinDuration = crl::time(200); constexpr auto kMaxDuration = 60 * crl::time(1000); constexpr auto kInitTimeout = 5 * crl::time(1000); +constexpr auto kBlurredSize = 64; using namespace FFmpeg; @@ -978,16 +979,16 @@ void RoundVideoRecorder::hide(Fn done) { } void RoundVideoRecorder::progressTo(float64 progress) { - if (_progress == progress) { + if (_progress == progress || _paused) { return; - } else if (_progress > 0.001) { + } else if (_progressReceived) { _progressAnimation.start( [=] { _preview->update(); }, _progress, progress, kUpdateEach * 1.1); - } - if (!_progress) { + } else { + _progressReceived = true; _fadeContentAnimation.start( [=] { _preview->update(); }, 0., @@ -998,11 +999,15 @@ void RoundVideoRecorder::progressTo(float64 progress) { _preview->update(); } -void RoundVideoRecorder::prepareFrame() { - if (_frameOriginal.isNull() || _preparedIndex == _lastAddedIndex) { +void RoundVideoRecorder::prepareFrame(bool blurred) { + if (_frameOriginal.isNull()) { return; + } else if (!blurred) { + if (_preparedIndex == _lastAddedIndex) { + return; + } + _preparedIndex = _lastAddedIndex; } - _preparedIndex = _lastAddedIndex; const auto owidth = _frameOriginal.width(); const auto oheight = _frameOriginal.height(); @@ -1020,12 +1025,27 @@ void RoundVideoRecorder::prepareFrame() { _frameOriginal.format()); const auto ratio = style::DevicePixelRatio(); - _framePrepared = Images::Circle(copy.scaled( - _side * ratio, - _side * ratio, - Qt::KeepAspectRatio, - Qt::SmoothTransformation)); - _framePrepared.setDevicePixelRatio(ratio); + if (blurred) { + static constexpr auto kRadius = 16; + _framePlaceholder = Images::Circle( + Images::BlurLargeImage( + copy.scaled( + QSize(kBlurredSize, kBlurredSize), + Qt::KeepAspectRatio, + Qt::FastTransformation), + kRadius + ).scaled( + QSize(_side, _side) * ratio, + Qt::KeepAspectRatio, + Qt::SmoothTransformation)); + _framePlaceholder.setDevicePixelRatio(ratio); + } else { + _framePrepared = Images::Circle(copy.scaled( + QSize(_side, _side) * ratio, + Qt::KeepAspectRatio, + Qt::SmoothTransformation)); + _framePrepared.setDevicePixelRatio(ratio); + } } void RoundVideoRecorder::createImages() { @@ -1093,12 +1113,14 @@ void RoundVideoRecorder::setup() { } p.drawImage(raw->rect(), _shadow); const auto inner = QRect(_extent, _extent, _side, _side); - if (!_progress) { + const auto fading = _fadeContentAnimation.animating(); + if (!_progressReceived && !fading) { p.drawImage(inner, _framePlaceholder); } else { - if (_fadeContentAnimation.animating()) { + if (fading) { p.drawImage(inner, _framePlaceholder); - p.setOpacity(opacity * _fadeContentAnimation.value(1.)); + const auto to = _progressReceived ? 1. : 0.; + p.setOpacity(opacity * _fadeContentAnimation.value(to)); } p.drawImage(inner, _framePrepared); @@ -1162,6 +1184,13 @@ void RoundVideoRecorder::pause(Fn done) { }); } _paused = true; + prepareFrame(true); + _progressReceived = false; + _fadeContentAnimation.start( + [=] { _preview->update(); }, + 1., + 0., + crl::time(200)); _descriptor.track->setState(Webrtc::VideoState::Inactive); _preview->update(); } diff --git a/Telegram/SourceFiles/ui/controls/round_video_recorder.h b/Telegram/SourceFiles/ui/controls/round_video_recorder.h index 7c3832eeb1..914054435c 100644 --- a/Telegram/SourceFiles/ui/controls/round_video_recorder.h +++ b/Telegram/SourceFiles/ui/controls/round_video_recorder.h @@ -69,7 +69,7 @@ private: class Private; void setup(); - void prepareFrame(); + void prepareFrame(bool blurred = false); void createImages(); void progressTo(float64 progress); void fade(bool visible); @@ -90,6 +90,7 @@ private: int _side = 0; int _progressStroke = 0; int _extent = 0; + bool _progressReceived = false; bool _visible = false; bool _paused = false;