aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCastagnaIT <gottardo.stefano.83@gmail.com>2022-04-11 09:23:28 +0200
committerCastagnaIT <gottardo.stefano.83@gmail.com>2022-04-11 09:23:28 +0200
commita44b67ff4d9439b1838181a6066cdafa39c790e8 (patch)
tree8c1eb407c5dc55871d297ebc774e1170f020ce75
parent7bfc3183739042b1f3cd1904a0e4c12eb7ded096 (diff)
[subtitles] Improved align to video condition based on ratio
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/OverlayRenderer.h8
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererDX.cpp14
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp14
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;