Skip to content

Commit 275072f

Browse files
authored
Merge pull request xbmc#24845 from CrystalP/fix-bookmarkthumbs
[bookmarks] Fix large and rotated thumbnail creation
2 parents 5d078e5 + 49a4167 commit 275072f

File tree

9 files changed

+103
-10
lines changed

9 files changed

+103
-10
lines changed

xbmc/application/ApplicationPlayer.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,27 @@ float CApplicationPlayer::GetRenderAspectRatio() const
865865
return 1.0;
866866
}
867867

868+
bool CApplicationPlayer::GetRects(CRect& source, CRect& dest, CRect& view) const
869+
{
870+
const std::shared_ptr<const IPlayer> player{GetInternal()};
871+
if (player)
872+
{
873+
player->GetRects(source, dest, view);
874+
return true;
875+
}
876+
else
877+
return false;
878+
}
879+
880+
unsigned int CApplicationPlayer::GetOrientation() const
881+
{
882+
const std::shared_ptr<const IPlayer> player{GetInternal()};
883+
if (player)
884+
return player->GetOrientation();
885+
else
886+
return 0;
887+
}
888+
868889
void CApplicationPlayer::TriggerUpdateResolution()
869890
{
870891
std::shared_ptr<IPlayer> player = GetInternal();

xbmc/application/ApplicationPlayer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class CApplicationPlayer : public IApplicationComponent
5555
void FlushRenderer();
5656
void SetRenderViewMode(int mode, float zoom, float par, float shift, bool stretch);
5757
float GetRenderAspectRatio() const;
58+
bool GetRects(CRect& source, CRect& dest, CRect& view) const;
59+
unsigned int GetOrientation() const;
5860
void TriggerUpdateResolution();
5961
bool IsRenderingVideo() const;
6062
bool IsRenderingGuiLayer() const;

xbmc/cores/IPlayer.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,13 @@ class IPlayer
231231
virtual float GetRenderAspectRatio() const { return 1.0; }
232232
virtual void TriggerUpdateResolution() {}
233233
virtual bool IsRenderingVideo() const { return false; }
234-
234+
virtual void GetRects(CRect& source, CRect& dest, CRect& view) const
235+
{
236+
source = {};
237+
dest = {};
238+
view = {};
239+
}
240+
virtual unsigned int GetOrientation() const { return 0; }
235241
virtual bool Supports(EINTERLACEMETHOD method) const { return false; }
236242
virtual EINTERLACEMETHOD GetDeinterlacingMethodDefault() const
237243
{

xbmc/cores/VideoPlayer/VideoPlayer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5034,6 +5034,16 @@ float CVideoPlayer::GetRenderAspectRatio() const
50345034
return m_renderManager.GetAspectRatio();
50355035
}
50365036

5037+
void CVideoPlayer::GetRects(CRect& source, CRect& dest, CRect& view) const
5038+
{
5039+
m_renderManager.GetVideoRect(source, dest, view);
5040+
}
5041+
5042+
unsigned int CVideoPlayer::GetOrientation() const
5043+
{
5044+
return m_renderManager.GetOrientation();
5045+
}
5046+
50375047
void CVideoPlayer::TriggerUpdateResolution()
50385048
{
50395049
std::string stereomode;

xbmc/cores/VideoPlayer/VideoPlayer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ class CVideoPlayer : public IPlayer, public CThread, public IVideoPlayer,
340340
void FlushRenderer() override;
341341
void SetRenderViewMode(int mode, float zoom, float par, float shift, bool stretch) override;
342342
float GetRenderAspectRatio() const override;
343+
void GetRects(CRect& source, CRect& dest, CRect& view) const override;
344+
unsigned int GetOrientation() const override;
343345
void TriggerUpdateResolution() override;
344346
bool IsRenderingVideo() const override;
345347
bool Supports(EINTERLACEMETHOD method) const override;

xbmc/cores/VideoPlayer/VideoRenderers/BaseRenderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class CBaseRenderer
8585
*/
8686
void GetVideoRect(CRect& source, CRect& dest, CRect& view) const;
8787
float GetAspectRatio() const;
88+
unsigned int GetOrientation() const { return m_renderOrientation; }
8889

8990
static void SettingOptionsRenderMethodsFiller(const std::shared_ptr<const CSetting>& setting,
9091
std::vector<IntegerSettingOption>& list,

xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ float CRenderManager::GetAspectRatio() const
7070
return 1.0f;
7171
}
7272

73+
unsigned int CRenderManager::GetOrientation() const
74+
{
75+
std::unique_lock<CCriticalSection> lock(m_statelock);
76+
if (m_pRenderer)
77+
return m_pRenderer->GetOrientation();
78+
else
79+
return 0;
80+
}
81+
7382
void CRenderManager::SetVideoSettings(const CVideoSettings& settings)
7483
{
7584
std::unique_lock<CCriticalSection> lock(m_statelock);

xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class CRenderManager
6060
// Functions called from render thread
6161
void GetVideoRect(CRect& source, CRect& dest, CRect& view) const;
6262
float GetAspectRatio() const;
63+
unsigned int GetOrientation() const;
6364
void FrameMove();
6465
void FrameWait(std::chrono::milliseconds duration);
6566
void Render(bool clear, DWORD flags = 0, DWORD alpha = 255, bool gui = true);

xbmc/video/dialogs/GUIDialogVideoBookmarks.cpp

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@
3737
#include "video/VideoDatabase.h"
3838
#include "view/ViewState.h"
3939

40+
#include <algorithm>
4041
#include <mutex>
4142
#include <string>
4243
#include <vector>
4344

44-
#define BOOKMARK_THUMB_WIDTH CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_imageRes
45-
4645
#define CONTROL_ADD_BOOKMARK 2
4746
#define CONTROL_CLEAR_BOOKMARKS 3
4847
#define CONTROL_ADD_EPISODE_BOOKMARK 4
@@ -380,16 +379,58 @@ bool CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag)
380379
bookmark.player = g_application.GetCurrentPlayer();
381380

382381
// create the thumbnail image
383-
float aspectRatio = appPlayer->GetRenderAspectRatio();
384-
int width = BOOKMARK_THUMB_WIDTH;
385-
int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio);
386-
if (height > (int)BOOKMARK_THUMB_WIDTH)
382+
const float aspectRatio{appPlayer->GetRenderAspectRatio()};
383+
CRect srcRect{}, renderRect{}, viewRect{};
384+
appPlayer->GetRects(srcRect, renderRect, viewRect);
385+
const unsigned int srcWidth{static_cast<unsigned int>(srcRect.Width())};
386+
const unsigned int srcHeight{static_cast<unsigned int>(srcRect.Height())};
387+
const unsigned int renderWidth{static_cast<unsigned int>(renderRect.Width())};
388+
const unsigned int renderHeight{static_cast<unsigned int>(renderRect.Height())};
389+
const unsigned int viewWidth{static_cast<unsigned int>(viewRect.Width())};
390+
const unsigned int viewHeight{static_cast<unsigned int>(viewRect.Height())};
391+
392+
if (!srcWidth || !srcHeight || !renderWidth || !renderHeight || !viewWidth || !viewHeight)
393+
return false;
394+
395+
const unsigned int orientation{appPlayer->GetOrientation()};
396+
const bool rotated{orientation == 90 || orientation == 270};
397+
398+
// FIXME: the renderer sets the scissors to the size of the screen (provided by graphiccontext),
399+
// limiting the max size of thumbs (for example 4k video played on 1024x768 screen)
400+
401+
// The advanced setting defines the max size of the largest dimension (depends on orientation)
402+
const unsigned int maxThumbDim{
403+
CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_imageRes};
404+
unsigned int width{}, height{};
405+
406+
if (!rotated)
407+
{
408+
if (aspectRatio >= 1.0f)
409+
{
410+
width = std::min({maxThumbDim, viewWidth, renderWidth, srcWidth});
411+
height = static_cast<unsigned int>(width / aspectRatio);
412+
}
413+
else
414+
{
415+
height = std::min({maxThumbDim, viewHeight, renderHeight, srcHeight});
416+
width = static_cast<unsigned int>(height * aspectRatio);
417+
}
418+
}
419+
else
387420
{
388-
height = BOOKMARK_THUMB_WIDTH;
389-
width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio);
421+
// rotation is applied during rendering, switching source width and height
422+
if (aspectRatio >= 1.0f)
423+
{
424+
height = std::min({maxThumbDim, viewHeight, renderHeight, srcWidth});
425+
width = static_cast<unsigned int>(height / aspectRatio);
426+
}
427+
else
428+
{
429+
width = std::min({maxThumbDim, viewWidth, renderWidth, srcHeight});
430+
height = static_cast<unsigned int>(width * aspectRatio);
431+
}
390432
}
391433

392-
393434
uint8_t *pixels = (uint8_t*)malloc(height * width * 4);
394435
unsigned int captureId = appPlayer->RenderCaptureAlloc();
395436

0 commit comments

Comments
 (0)