| 1789 | } |
| 1790 | |
| 1791 | HRESULT CDX9VideoProcessor::GetDisplayedImage(BYTE **ppDib, unsigned *pSize) |
| 1792 | { |
| 1793 | if (!m_pD3DDevEx) { |
| 1794 | return E_ABORT; |
| 1795 | } |
| 1796 | |
| 1797 | HRESULT hr = S_OK; |
| 1798 | const UINT width = m_windowRect.Width(); |
| 1799 | const UINT height = m_windowRect.Height(); |
| 1800 | |
| 1801 | // use the back buffer, because the display profile is applied to the front buffer |
| 1802 | CComPtr<IDirect3DSurface9> pBackBuffer; |
| 1803 | CComPtr<IDirect3DSurface9> pDestSurface; |
| 1804 | |
| 1805 | hr = m_pD3DDevEx->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer); |
| 1806 | if (SUCCEEDED(hr)) { |
| 1807 | hr = m_pD3DDevEx->CreateRenderTarget(width, height, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &pDestSurface, nullptr); |
| 1808 | } |
| 1809 | if (SUCCEEDED(hr)) { |
| 1810 | hr = m_pD3DDevEx->StretchRect(pBackBuffer, m_windowRect, pDestSurface, nullptr, D3DTEXF_NONE); |
| 1811 | } |
| 1812 | if (FAILED(hr)) { |
| 1813 | DLog(L"CDX9VideoProcessor::GetDisplayedImage() failed with error {}", HR2Str(hr)); |
| 1814 | return hr; |
| 1815 | } |
| 1816 | |
| 1817 | const UINT dib_bitdepth = 32; |
| 1818 | const UINT dib_pitch = CalcDibRowPitch(width, dib_bitdepth); |
| 1819 | const UINT dib_size = dib_pitch * height; |
| 1820 | |
| 1821 | *pSize = sizeof(BITMAPINFOHEADER) + dib_size; |
| 1822 | BYTE* p = (BYTE*)LocalAlloc(LMEM_FIXED, *pSize); // only this allocator can be used |
| 1823 | if (!p) { |
| 1824 | return E_OUTOFMEMORY; |
| 1825 | } |
| 1826 | |
| 1827 | BITMAPINFOHEADER* pBIH = (BITMAPINFOHEADER*)p; |
| 1828 | ZeroMemory(pBIH, sizeof(BITMAPINFOHEADER)); |
| 1829 | pBIH->biSize = sizeof(BITMAPINFOHEADER); |
| 1830 | pBIH->biWidth = width; |
| 1831 | pBIH->biHeight = -(LONG)height; // top-down RGB bitmap |
| 1832 | pBIH->biBitCount = dib_bitdepth; |
| 1833 | pBIH->biPlanes = 1; |
| 1834 | pBIH->biSizeImage = dib_size; |
| 1835 | |
| 1836 | D3DLOCKED_RECT lr; |
| 1837 | hr = pDestSurface->LockRect(&lr, nullptr, D3DLOCK_READONLY); |
| 1838 | if (S_OK == hr) { |
| 1839 | CopyPlaneAsIs(height, (BYTE*)(pBIH + 1), dib_pitch, (BYTE*)lr.pBits, lr.Pitch); |
| 1840 | hr = pDestSurface->UnlockRect(); |
| 1841 | } |
| 1842 | |
| 1843 | if (FAILED(hr)) { |
| 1844 | DLog(L"CDX9VideoProcessor::GetDisplayedImage() failed with error {}", HR2Str(hr)); |
| 1845 | LocalFree(p); |
| 1846 | return hr; |
| 1847 | } |
| 1848 |
no test coverage detected