From 9c0dae47cad1923fbc6abfc2aa5ba0969828b64d Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Fri, 8 Jan 2016 13:31:48 +1300 Subject: [PATCH] Normalize aspect ratio calculations to 4:3 Video Interface simply isn't aware about widescreen. Instead, the render class can multiply by 1.3333333 to get the 16:9 aspect ratio. --- Source/Core/Core/HW/VideoInterface.cpp | 29 +++----------------- Source/Core/Core/HW/VideoInterface.h | 2 +- Source/Core/VideoCommon/RenderBase.cpp | 38 +++++++++----------------- 3 files changed, 18 insertions(+), 51 deletions(-) diff --git a/Source/Core/Core/HW/VideoInterface.cpp b/Source/Core/Core/HW/VideoInterface.cpp index 3dd8e065e3..ed094030fa 100644 --- a/Source/Core/Core/HW/VideoInterface.cpp +++ b/Source/Core/Core/HW/VideoInterface.cpp @@ -472,7 +472,7 @@ static u32 GetTicksPerOddField() return GetTicksPerHalfLine() * GetHalfLinesPerOddField(); } -float GetAspectRatio(bool wide) +float GetAspectRatio() { u32 multiplier = static_cast(m_PictureConfiguration.STD / m_PictureConfiguration.WPL); int height = (multiplier * m_VerticalTimingRegister.ACV); @@ -485,14 +485,7 @@ float GetAspectRatio(bool wide) //In square pixels, 1024*576 is 16:9, and 768*576 is 4:3 //Therefore a 16:9 TV would have a "pixel" aspect ratio of 1024/702 //Similarly a 4:3 TV would have a ratio of 768/702 - if (wide) - { - pixelAR = 1024.0f / 702.0f; - } - else - { - pixelAR = 768.0f / 702.0f; - } + pixelAR = 768.0f / 702.0f; } else { @@ -500,25 +493,11 @@ float GetAspectRatio(bool wide) //In square pixels, 864*486 is 16:9, and 648*486 is 4:3 //Therefore a 16:9 TV would have a "pixel" aspect ratio of 864/710.85 //Similarly a 4:3 TV would have a ratio of 648/710.85 - if (wide) - { - pixelAR = 864.0f / 710.85f; - } - else - { - pixelAR = 648.0f / 710.85f; - } + pixelAR = 648.0f / 710.85f; } if (width == 0 || height == 0) { - if (wide) - { - return 16.0f / 9.0f; - } - else - { - return 4.0f / 3.0f; - } + return 4.0f / 3.0f; } return ((float)width / (float)height) * pixelAR; } diff --git a/Source/Core/Core/HW/VideoInterface.h b/Source/Core/Core/HW/VideoInterface.h index 45942e04f7..3f3cae80ea 100644 --- a/Source/Core/Core/HW/VideoInterface.h +++ b/Source/Core/Core/HW/VideoInterface.h @@ -334,5 +334,5 @@ union UVIHorizontalStepping u32 GetTicksPerField(); //For VI Scaling and Aspect Ratio Correction - float GetAspectRatio(bool); + float GetAspectRatio(); } diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index c52263843f..be1b774d3f 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -80,6 +80,7 @@ unsigned int Renderer::efb_scale_numeratorY = 1; unsigned int Renderer::efb_scale_denominatorX = 1; unsigned int Renderer::efb_scale_denominatorY = 1; +static float AspectToWidescreen(float aspect) { return aspect * ((16.0f / 9.0f) / (4.0f / 3.0f)); } Renderer::Renderer() : frame_data() @@ -431,7 +432,9 @@ void Renderer::UpdateDrawRectangle(int backbuffer_width, int backbuffer_height) // Don't know if there is a better place for this code so there isn't a 1 frame delay if (g_ActiveConfig.bWidescreenHack) { - float source_aspect = VideoInterface::GetAspectRatio(Core::g_aspect_wide); + float source_aspect = VideoInterface::GetAspectRatio(); + if (Core::g_aspect_wide) + source_aspect = AspectToWidescreen(source_aspect); float target_aspect; switch (g_ActiveConfig.iAspectRatio) @@ -440,10 +443,10 @@ void Renderer::UpdateDrawRectangle(int backbuffer_width, int backbuffer_height) target_aspect = WinWidth / WinHeight; break; case ASPECT_ANALOG: - target_aspect = VideoInterface::GetAspectRatio(false); + target_aspect = VideoInterface::GetAspectRatio(); break; case ASPECT_ANALOG_WIDE: - target_aspect = VideoInterface::GetAspectRatio(true); + target_aspect = AspectToWidescreen(VideoInterface::GetAspectRatio()); break; default: // ASPECT_AUTO @@ -476,17 +479,13 @@ void Renderer::UpdateDrawRectangle(int backbuffer_width, int backbuffer_height) // The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio float Ratio; - switch (g_ActiveConfig.iAspectRatio) + if (g_ActiveConfig.iAspectRatio == ASPECT_ANALOG_WIDE || (g_ActiveConfig.iAspectRatio != ASPECT_ANALOG && Core::g_aspect_wide)) { - case ASPECT_ANALOG_WIDE: - Ratio = (WinWidth / WinHeight) / VideoInterface::GetAspectRatio(true); - break; - case ASPECT_ANALOG: - Ratio = (WinWidth / WinHeight) / VideoInterface::GetAspectRatio(false); - break; - default: - Ratio = (WinWidth / WinHeight) / VideoInterface::GetAspectRatio(Core::g_aspect_wide); - break; + Ratio = (WinWidth / WinHeight) / AspectToWidescreen(VideoInterface::GetAspectRatio()); + } + else + { + Ratio = (WinWidth / WinHeight) / VideoInterface::GetAspectRatio(); } if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH) @@ -512,18 +511,7 @@ void Renderer::UpdateDrawRectangle(int backbuffer_width, int backbuffer_height) // ------------------ if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH && g_ActiveConfig.bCrop) { - switch (g_ActiveConfig.iAspectRatio) - { - case ASPECT_ANALOG_WIDE: - Ratio = (16.0f / 9.0f) / VideoInterface::GetAspectRatio(true); - break; - case ASPECT_ANALOG: - Ratio = (4.0f / 3.0f) / VideoInterface::GetAspectRatio(false); - break; - default: - Ratio = (!Core::g_aspect_wide ? (4.0f / 3.0f) : (16.0f / 9.0f)) / VideoInterface::GetAspectRatio(Core::g_aspect_wide); - break; - } + Ratio = (4.0f / 3.0f) / VideoInterface::GetAspectRatio(); if (Ratio <= 1.0f) { Ratio = 1.0f / Ratio;