From 0991e7d8a4a0b94a9199a93a5aea9bf8c7ed1b08 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 25 Oct 2024 21:01:44 +0400 Subject: [PATCH] Mirror recorded round message. --- Telegram/Resources/art/round_placeholder.jpg | Bin 0 -> 787 bytes Telegram/Resources/qrc/telegram/telegram.qrc | 1 + .../ui/controls/round_video_recorder.cpp | 46 ++++++++++-------- 3 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 Telegram/Resources/art/round_placeholder.jpg diff --git a/Telegram/Resources/art/round_placeholder.jpg b/Telegram/Resources/art/round_placeholder.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cbdc9aee39c6eceacebf68a0459a84a54118502e GIT binary patch literal 787 zcmex=3Pz(s)!W)?;!R)+t#7!sDXq~`kxb$Jo_=aZ#w-c7&0o%iZad|6AV=|`oA{w0UiRT-GhJGq-`CnCa_{2Q zu1r0*>Hfk!mp0C<*SL^WDjB(M(Uh0R7d%N5Sr+frvuxjt4EcEa=qH-^{IVzf-!z-(5&{(bbEm z=NaARIPdk{>%xMddE(BGiXUB0J^M0jTQK{@*z}d5nM$|*>3kBcozwB8tL~gttiZvk zk&F8l&kgr^7CtFO&g1coNy=HaUml&^qa7_gSH9b(Jt$?(NzqTmU)E3Gztp^1CQrIe zuziicqE5HXoPR;O+a>?a`K$f(+ir`Rx#!LUJt8B>01RU!Z!j=0G6^yZDF_RI{lLTs z^uwQ=k}{LazS3Il?umiRW(7-sTsF(hKL7CNrpXH)6eV7HrJ=?@<44ycErXyEHP4BT zpS63Q^wI7*y@qFPW9Y&6hPdxq!2n$wNTO`VnoJy{kwt0>IZIL2DfOLdB} z>9cE6UOS#ke(YHkuDj!+pK(H4@2!../../art/logo_256.png ../../art/logo_256_no_margin.png ../../art/themeimage.jpg + ../../art/round_placeholder.jpg ../../day-blue.tdesktop-theme ../../night.tdesktop-theme ../../night-green.tdesktop-theme diff --git a/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp b/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp index 0009f6214..f01df2165 100644 --- a/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp +++ b/Telegram/SourceFiles/ui/controls/round_video_recorder.cpp @@ -143,6 +143,7 @@ private: void updateMaxLevel(const Media::Capture::Chunk &chunk); void updateResultDuration(int64 pts, AVRational timeBase); + void mirrorYUV420P(not_null frame); void cutCircleFromYUV420P(not_null frame); [[nodiscard]] RoundVideoResult appendToPrevious(RoundVideoResult video); @@ -752,6 +753,7 @@ void RoundVideoRecorder::Private::encodeVideoFrame( _videoFrame->data, _videoFrame->linesize); + mirrorYUV420P(_videoFrame.get()); cutCircleFromYUV420P(_videoFrame.get()); _videoFrame->pts = mcstimestamp - _videoFirstTimestamp; @@ -836,6 +838,21 @@ void RoundVideoRecorder::Private::initMinithumbsCanvas() { _minithumbs = QImage(width, height, QImage::Format_ARGB32_Premultiplied); } +void RoundVideoRecorder::Private::mirrorYUV420P(not_null frame) { + for (auto p = 0; p < 3; ++p) { + const auto size = p ? (kSide / 2) : kSide; + const auto linesize = _videoFrame->linesize[p]; + auto data = _videoFrame->data[p]; + for (auto y = 0; y != size; ++y) { + auto left = data + y * linesize; + auto right = left + size - 1; + while (left < right) { + std::swap(*left++, *right--); + } + } + } +} + void RoundVideoRecorder::Private::cutCircleFromYUV420P( not_null frame) { const auto width = frame->width; @@ -1104,26 +1121,14 @@ void RoundVideoRecorder::progressTo(float64 progress) { void RoundVideoRecorder::preparePlaceholder(const QImage &placeholder) { const auto ratio = style::DevicePixelRatio(); const auto full = QSize(_side, _side) * ratio; - if (!placeholder.isNull()) { - _framePlaceholder = Images::Circle( - placeholder.scaled( + _framePlaceholder = Images::Circle( + (placeholder.isNull() + ? QImage(u":/gui/art/round_placeholder.jpg"_q) + : placeholder).scaled( full, Qt::KeepAspectRatio, Qt::SmoothTransformation)); - _framePlaceholder.setDevicePixelRatio(ratio); - } else { - _framePlaceholder = QImage( - full, - QImage::Format_ARGB32_Premultiplied); - _framePlaceholder.fill(Qt::transparent); - _framePlaceholder.setDevicePixelRatio(ratio); - - auto p = QPainter(&_framePlaceholder); - auto hq = PainterHighQualityEnabler(p); - p.setPen(Qt::NoPen); - p.setBrush(Qt::black); - p.drawEllipse(0, 0, _side, _side); - } + _framePlaceholder.setDevicePixelRatio(ratio); } void RoundVideoRecorder::prepareFrame(bool blurred) { @@ -1159,14 +1164,15 @@ void RoundVideoRecorder::prepareFrame(bool blurred) { QSize(kBlurredSize, kBlurredSize), Qt::KeepAspectRatio, Qt::FastTransformation), - kRadius); + kRadius).mirrored(true, false); preparePlaceholder(image); _placeholderUpdates.fire(std::move(image)); } else { - _framePrepared = Images::Circle(copy.scaled( + auto scaled = copy.scaled( QSize(_side, _side) * ratio, Qt::KeepAspectRatio, - Qt::SmoothTransformation)); + Qt::SmoothTransformation).mirrored(true, false); + _framePrepared = Images::Circle(std::move(scaled)); _framePrepared.setDevicePixelRatio(ratio); } }