From 77beb3980152ab5ee24402b70d8399df05a0f8da Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 19 Feb 2022 20:31:54 +0100 Subject: [PATCH] Fixed an issue where videos would not get centered if pillarboxes were enabled. --- .../src/components/VideoFFmpegComponent.cpp | 23 ++++++++++++++----- es-core/src/components/VideoFFmpegComponent.h | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/es-core/src/components/VideoFFmpegComponent.cpp b/es-core/src/components/VideoFFmpegComponent.cpp index 752b291fe..ebf68d86c 100644 --- a/es-core/src/components/VideoFFmpegComponent.cpp +++ b/es-core/src/components/VideoFFmpegComponent.cpp @@ -24,7 +24,8 @@ std::vector VideoFFmpegComponent::sHWDecodedVideos; std::vector VideoFFmpegComponent::sSWDecodedVideos; VideoFFmpegComponent::VideoFFmpegComponent() - : mFrameProcessingThread {nullptr} + : mRectangleOffset {0.0f, 0.0f} + , mFrameProcessingThread {nullptr} , mFormatContext {nullptr} , mVideoStream {nullptr} , mAudioStream {nullptr} @@ -159,10 +160,10 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans) } // clang-format off - vertices[0] = {{0.0f, 0.0f }, {0.0f, 0.0f}, color}; - vertices[1] = {{0.0f, mSize.y}, {0.0f, 1.0f}, color}; - vertices[2] = {{mSize.x, 0.0f }, {1.0f, 0.0f}, color}; - vertices[3] = {{mSize.x, mSize.y}, {1.0f, 1.0f}, color}; + vertices[0] = {{0.0f + mRectangleOffset.x, 0.0f + mRectangleOffset.y }, {0.0f, 0.0f}, color}; + vertices[1] = {{0.0f + mRectangleOffset.x, mSize.y + mRectangleOffset.y }, {0.0f, 1.0f}, color}; + vertices[2] = {{mSize.x + mRectangleOffset.x, 0.0f + + mRectangleOffset.y }, {1.0f, 0.0f}, color}; + vertices[3] = {{mSize.x + mRectangleOffset.x, mSize.y + + mRectangleOffset.y}, {1.0f, 1.0f}, color}; // clang-format on // Round vertices. @@ -882,8 +883,9 @@ void VideoFFmpegComponent::calculateBlackRectangle() // otherwise it will exactly match the video size. The reason to add a black rectangle // behind videos in this second instance is that the scanline rendering will make the // video partially transparent so this may avoid some unforseen issues with some themes. - if (mVideoAreaPos != glm::vec2 {} && mVideoAreaSize != glm::vec2 {}) { + if (mVideoAreaPos != glm::vec2 {0.0f, 0.0f} && mVideoAreaSize != glm::vec2 {0.0f, 0.0f}) { mVideoRectangleCoords.clear(); + mRectangleOffset = {0.0f, 0.0f}; if ((mLegacyTheme && Settings::getInstance()->getBool("GamelistVideoPillarbox")) || (!mLegacyTheme && mDrawPillarboxes)) { @@ -919,6 +921,15 @@ void VideoFFmpegComponent::calculateBlackRectangle() std::round(mVideoAreaPos.y - rectHeight * mOrigin.y)); mVideoRectangleCoords.emplace_back(std::round(rectWidth)); mVideoRectangleCoords.emplace_back(std::round(rectHeight)); + + // If an origin value other than 0.5 is used, then create an offset for centering + // the video inside the rectangle. + if (mOrigin != glm::vec2 {0.5f, 0.5f}) { + if (rectWidth > mSize.x) + mRectangleOffset.x -= (rectWidth - mSize.x) * (mOrigin.x - 0.5f); + else if (rectHeight > mSize.y) + mRectangleOffset.y -= (rectHeight - mSize.y) * (mOrigin.y - 0.5f); + } } // If the option to display pillarboxes is disabled, then make the rectangle equivalent // to the size of the video. diff --git a/es-core/src/components/VideoFFmpegComponent.h b/es-core/src/components/VideoFFmpegComponent.h index ec3ef8459..f648276bd 100644 --- a/es-core/src/components/VideoFFmpegComponent.h +++ b/es-core/src/components/VideoFFmpegComponent.h @@ -90,6 +90,7 @@ private: std::shared_ptr mTexture; std::vector mVideoRectangleCoords; + glm::vec2 mRectangleOffset; std::unique_ptr mFrameProcessingThread; std::mutex mPictureMutex;