diff options
author | Miguel Borges de Freitas <enen92@users.noreply.github.com> | 2022-04-12 13:18:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-12 13:18:22 +0100 |
commit | 9930b2522e6378675a5134edbe2698f3969a138a (patch) | |
tree | 01017f77afd610e7751d360152f9f6c699c40520 | |
parent | f1bdf1e789e9e205f03e2d853bcc5d8ad71ee9f8 (diff) | |
parent | a44b67ff4d9439b1838181a6066cdafa39c790e8 (diff) |
Merge pull request #21246 from CastagnaIT/subImageAlignFix
[subtitles] Improved align to video condition based on resolution ratio
3 files changed, 24 insertions, 12 deletions
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRenderer.h b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRenderer.h index 437f570003..0d82de9b6a 100644 --- a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRenderer.h +++ b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRenderer.h @@ -94,6 +94,14 @@ namespace OVERLAY { float m_height; float m_source_width{0}; // Video source width resolution used to calculate aspect ratio float m_source_height{0}; // Video source height resolution used to calculate aspect ratio + + protected: + /*! + * \brief Given the resolution ratio determines if it is a 4/3 resolution + * \param resRatio The resolution ratio (the results of width / height) + * \return True if the ratio refer to a 4/3 resolution, otherwise false + */ + bool IsSquareResolution(float resRatio) { return resRatio > 1.22f && resRatio < 1.34f; } }; class CRenderer : public Observer diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererDX.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererDX.cpp index 88e75108af..8d5f74685d 100644 --- a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererDX.cpp +++ b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererDX.cpp @@ -25,6 +25,8 @@ #define ASSERT(f) _ASSERTE((f)) #endif +#include <cmath> + using namespace OVERLAY; using namespace DirectX; @@ -219,14 +221,14 @@ COverlayImageDX::COverlayImageDX(CDVDOverlayImage* o, CRect& rSource) m_x = (0.5f * o->width + o->x) / o->source_width; m_y = (0.5f * o->height + o->y) / o->source_height; - int videoSourceH{static_cast<int>(rSource.Height())}; - int videoSourceW{static_cast<int>(rSource.Width())}; + const float subRatio{static_cast<float>(o->source_width) / o->source_height}; + const float vidRatio{rSource.Width() / rSource.Height()}; + + // We always consider aligning 4/3 subtitles to the video, + // for example SD DVB subtitles (4/3) must be stretched on fullhd video - if ((o->source_height == videoSourceH || videoSourceH % o->source_height == 0) && - (o->source_width == videoSourceW || videoSourceW % o->source_width == 0)) + if (std::fabs(subRatio - vidRatio) < 0.001f || IsSquareResolution(subRatio)) { - // We check also for multiple of source_height/source_width - // because for example 1080P subtitles can be used on 4K videos m_align = ALIGN_VIDEO; m_width = static_cast<float>(o->width) / o->source_width; m_height = static_cast<float>(o->height) / o->source_height; diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp index a37b0fc61f..6895f74944 100644 --- a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp +++ b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp @@ -28,6 +28,8 @@ #include "utils/log.h" #include "utils/GLUtils.h" +#include <cmath> + #if HAS_GLES >= 2 // GLES2.0 cant do CLAMP, but can do CLAMP_TO_EDGE. #define GL_CLAMP GL_CLAMP_TO_EDGE @@ -191,14 +193,14 @@ COverlayTextureGL::COverlayTextureGL(CDVDOverlayImage* o, CRect& rSource) m_x = (0.5f * o->width + o->x) / o->source_width; m_y = (0.5f * o->height + o->y) / o->source_height; - int videoSourceH{static_cast<int>(rSource.Height())}; - int videoSourceW{static_cast<int>(rSource.Width())}; + const float subRatio{static_cast<float>(o->source_width) / o->source_height}; + const float vidRatio{rSource.Width() / rSource.Height()}; + + // We always consider aligning 4/3 subtitles to the video, + // for example SD DVB subtitles (4/3) must be stretched on fullhd video - if ((o->source_height == videoSourceH || videoSourceH % o->source_height == 0) && - (o->source_width == videoSourceW || videoSourceW % o->source_width == 0)) + if (std::fabs(subRatio - vidRatio) < 0.001f || IsSquareResolution(subRatio)) { - // We check also for multiple of source_height/source_width - // because for example 1080P subtitles can be used on 4K videos m_align = ALIGN_VIDEO; m_width = static_cast<float>(o->width) / o->source_width; m_height = static_cast<float>(o->height) / o->source_height; |