Skip to content

Commit

Permalink
Decouple and generalize CropSource so that it can take any target rec…
Browse files Browse the repository at this point in the history
…tangle
  • Loading branch information
CrystalP authored and CrystalP committed Oct 5, 2011
1 parent bf883d0 commit 4f2c641
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
30 changes: 16 additions & 14 deletions xbmc/cores/VideoRenderers/WinRenderer.cpp
Expand Up @@ -634,35 +634,36 @@ void CWinRenderer::UpdateVideoFilter()
}
}

void CWinRenderer::CropSource(RECT& src, RECT& dst, const D3DSURFACE_DESC& desc)
// Adjust the src rectangle so that the dst is always contained in the target rectangle.
void CWinRenderer::CropSource(RECT& src, RECT& dst, RECT target)
{
if(dst.left < 0)
if(dst.left < target.left)
{
src.left -= dst.left
src.left -= (dst.left - target.left)
* (src.right - src.left)
/ (dst.right - dst.left);
dst.left = 0;
dst.left = target.left;
}
if(dst.top < 0)
if(dst.top < target.top)
{
src.top -= dst.top
src.top -= (dst.top - target.top)
* (src.bottom - src.top)
/ (dst.bottom - dst.top);
dst.top = 0;
dst.top = target.top;
}
if(dst.right > (LONG)desc.Width)
if(dst.right > target.right)
{
src.right -= (dst.right - desc.Width)
src.right -= (dst.right - target.right)
* (src.right - src.left)
/ (dst.right - dst.left);
dst.right = desc.Width;
dst.right = target.right;
}
if(dst.bottom > (LONG)desc.Height)
if(dst.bottom > target.bottom)
{
src.bottom -= (dst.bottom - desc.Height)
src.bottom -= (dst.bottom - target.bottom)
* (src.bottom - src.top)
/ (dst.bottom - dst.top);
dst.bottom = desc.Height;
dst.bottom = target.bottom;
}
}

Expand Down Expand Up @@ -782,9 +783,10 @@ void CWinRenderer::ScaleStretchRect()
D3DSURFACE_DESC desc;
if (FAILED(target->GetDesc(&desc)))
CLog::Log(LOGERROR, "CWinRenderer::Render - failed to get back buffer description");
RECT tgtRect = { 0, 0, desc.Width, desc.Height };
// Need to manipulate the coordinates since StretchRect doesn't accept off-screen coordinates.
CropSource(srcRect, dstRect, desc);
CropSource(srcRect, dstRect, tgtRect);
HRESULT hr;
LPDIRECT3DDEVICE9 pD3DDevice = g_Windowing.Get3DDevice();
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/VideoRenderers/WinRenderer.h
Expand Up @@ -192,7 +192,7 @@ class CWinRenderer : public CBaseRenderer

virtual unsigned int GetProcessorSize() { return m_processor.Size(); }

static void CropSource(RECT& src, RECT& dst, const D3DSURFACE_DESC& desc);
static void CropSource(RECT& src, RECT& dst, RECT target);

protected:
virtual void Render(DWORD flags);
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/DXVA.cpp
Expand Up @@ -1439,8 +1439,8 @@ bool CProcessor::Render(RECT src, RECT dst, IDirect3DSurface9* target, REFERENCE

D3DSURFACE_DESC desc;
CHECK(target->GetDesc(&desc));

CWinRenderer::CropSource(src, dst, desc);
RECT recttarget = { 0, 0, desc.Width, desc.Height };
CWinRenderer::CropSource(src, dst, recttarget);

// How to prepare the samples array for VideoProcessBlt
// - always provide current picture + the number of forward and backward references required by the current processor.
Expand Down

0 comments on commit 4f2c641

Please sign in to comment.