DShowTextures.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef _XBOX
  2. #include "DShowTextures.h"
  3. #include <d3d9caps.h>
  4. #include "wmvinterfaces.h"
  5. //-----------------------------------------------------------------------------
  6. // CTextureRenderer constructor
  7. //-----------------------------------------------------------------------------
  8. CTextureRenderer::CTextureRenderer( LPUNKNOWN pUnk, HRESULT *phr )
  9. : CBaseVideoRenderer(__uuidof(CLSID_TextureRenderer),
  10. NAME("Texture Renderer"), pUnk, phr),
  11. m_bUseDynamicTextures(FALSE)
  12. {
  13. m_pTexture = NULL;
  14. // Store and AddRef the texture for our use.
  15. ASSERT(phr);
  16. if (phr)
  17. *phr = S_OK;
  18. }
  19. //-----------------------------------------------------------------------------
  20. // CTextureRenderer destructor
  21. //-----------------------------------------------------------------------------
  22. CTextureRenderer::~CTextureRenderer()
  23. {
  24. if( m_pTexture )
  25. m_pTexture->Release();
  26. m_pTexture = NULL;
  27. }
  28. //-----------------------------------------------------------------------------
  29. // CheckMediaType: This method forces the graph to give us an R8G8B8 video
  30. // type, making our copy to texture memory trivial.
  31. //-----------------------------------------------------------------------------
  32. HRESULT CTextureRenderer::CheckMediaType(const CMediaType *pmt)
  33. {
  34. HRESULT hr = E_FAIL;
  35. VIDEOINFO *pvi=0;
  36. CheckPointer(pmt,E_POINTER);
  37. // Reject the connection if this is not a video type
  38. if( *pmt->FormatType() != FORMAT_VideoInfo ) {
  39. return E_INVALIDARG;
  40. }
  41. // Only accept RGB24 video
  42. pvi = (VIDEOINFO *)pmt->Format();
  43. if(IsEqualGUID( *pmt->Type(), MEDIATYPE_Video) &&
  44. IsEqualGUID( *pmt->Subtype(), MEDIASUBTYPE_YV12))
  45. {
  46. hr = S_OK;
  47. }
  48. return hr;
  49. }
  50. //-----------------------------------------------------------------------------
  51. // SetMediaType: Graph connection has been made.
  52. //-----------------------------------------------------------------------------
  53. HRESULT CTextureRenderer::SetMediaType(const CMediaType *pmt)
  54. {
  55. UINT uintWidth = 2;
  56. UINT uintHeight = 2;
  57. // Retrive the size of this media type
  58. VIDEOINFO *pviBmp; // Bitmap info header
  59. pviBmp = (VIDEOINFO *)pmt->Format();
  60. m_lVidWidth = pviBmp->bmiHeader.biWidth;
  61. m_lVidHeight = abs(pviBmp->bmiHeader.biHeight);
  62. uintWidth = m_lVidWidth;
  63. uintHeight = ((m_lVidHeight*3 + 1) >> 1); // summary height = 1.5 x height
  64. m_pTexture = IWMVTexture::Create(uintWidth, uintHeight);
  65. if( !m_pTexture )
  66. return E_FAIL;
  67. return S_OK;
  68. }
  69. //-----------------------------------------------------------------------------
  70. // DoRenderSample: A sample has been delivered. Copy it to the texture.
  71. //-----------------------------------------------------------------------------
  72. HRESULT CTextureRenderer::DoRenderSample( IMediaSample * pSample )
  73. {
  74. BYTE * pbS = NULL;
  75. DWORD * pdwS = NULL;
  76. DWORD * pdwD = NULL;
  77. UINT row, q;// col, dwordWidth;
  78. CheckPointer(pSample,E_POINTER);
  79. CheckPointer(m_pTexture,E_UNEXPECTED);
  80. // Get the video bitmap buffer
  81. BYTE *pBmpBuffer; // Bitmap buffer
  82. pSample->GetPointer( &pBmpBuffer );
  83. void* pBuff;
  84. int nPitch;
  85. if( m_pTexture->Lock(pBuff,nPitch) )
  86. {
  87. BYTE* pTxtBuffer = (BYTE*)pBuff;
  88. LONG lTxtPitch = nPitch;
  89. // fill Y texture
  90. LONG lVidPitch = m_lVidWidth;
  91. q = m_lVidHeight;
  92. for( row = 0; row < q; row++ )
  93. {
  94. memcpy(pTxtBuffer,pBmpBuffer,m_lVidWidth);
  95. pBmpBuffer += lVidPitch;
  96. pTxtBuffer += lTxtPitch;
  97. }
  98. // fill U,V texture
  99. lVidPitch = (m_lVidWidth >> 1);
  100. q = (m_lVidHeight >> 1);
  101. LONG lBmpOffsetV = lVidPitch * q;
  102. for( row = 0; row < q; row++)
  103. {
  104. // U
  105. memcpy(pTxtBuffer,pBmpBuffer,lVidPitch);
  106. // V
  107. memcpy(pTxtBuffer + lVidPitch, pBmpBuffer+lBmpOffsetV, lVidPitch);
  108. // next texture row
  109. pBmpBuffer += lVidPitch;
  110. pTxtBuffer += lTxtPitch;
  111. }
  112. m_pTexture->Unlock();
  113. }
  114. pSample->Release();
  115. return S_OK;
  116. }
  117. #endif