From fae3aee9e0b6bc7f193bccf71a4c34a06237e4aa Mon Sep 17 00:00:00 2001 From: Filoppi Date: Tue, 27 Jun 2023 12:41:14 +0300 Subject: [PATCH] Video: The `% 4` that was done on the rendering resolution was only meant to be done when recording videos (due to encoding limitations) but one case was missed (this had no consequences really, as it was just in the code that automatically resizes the window). The hardcoded `4` has been replaced with `VIDEO_ENCODER_LMC` for clarity. --- Source/Core/VideoCommon/Present.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Source/Core/VideoCommon/Present.cpp b/Source/Core/VideoCommon/Present.cpp index b89c9fa32d..4d17a6519b 100644 --- a/Source/Core/VideoCommon/Present.cpp +++ b/Source/Core/VideoCommon/Present.cpp @@ -23,6 +23,9 @@ std::unique_ptr g_presenter; +// The video encoder needs the image to be a multiple of x samples. +static constexpr int VIDEO_ENCODER_LCM = 4; + namespace VideoCommon { static float AspectToWidescreen(float aspect) @@ -441,11 +444,14 @@ void Presenter::UpdateDrawRectangle() crop_width = win_width; } - // ensure divisibility by 4 to make it compatible with all the video encoders if (g_frame_dumper->IsFrameDumping()) { - draw_width = std::ceil(draw_width) - static_cast(std::ceil(draw_width)) % 4; - draw_height = std::ceil(draw_height) - static_cast(std::ceil(draw_height)) % 4; + // ensure divisibility by "VIDEO_ENCODER_LCM" to make it compatible with all the video encoders. + // Note that this is theoretically only necessary when recording videos and not screenshots. + draw_width = + std::ceil(draw_width) - static_cast(std::ceil(draw_width)) % VIDEO_ENCODER_LCM; + draw_height = + std::ceil(draw_height) - static_cast(std::ceil(draw_height)) % VIDEO_ENCODER_LCM; } m_target_rectangle.left = static_cast(std::round(win_width / 2.0 - draw_width / 2.0)); @@ -482,10 +488,13 @@ std::tuple Presenter::CalculateOutputDimensions(int width, int height) width = static_cast(std::ceil(scaled_width)); height = static_cast(std::ceil(scaled_height)); - // UpdateDrawRectangle() makes sure that the rendered image is divisible by four for video - // encoders, so do that here too to match it - width -= width % 4; - height -= height % 4; + if (g_frame_dumper->IsFrameDumping()) + { + // UpdateDrawRectangle() makes sure that the rendered image is divisible by "VIDEO_ENCODER_LCM" + // for video encoders, so do that here too to match it + width -= width % VIDEO_ENCODER_LCM; + height -= height % VIDEO_ENCODER_LCM; + } return std::make_tuple(width, height); }