Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
6.5 KiB

  1. #include "ddrawpr.h"
  2. #include <ImgUtil.H>
  3. //#include <ocmm.h>
  4. #include "decoder.h"
  5. #include <atlcom.h>
  6. #define Assert(x)
  7. #define ReleaseMemoryDC(x) DeleteObject(x)
  8. #define MulDivQuick MulDiv
  9. #define Verify(x) x
  10. extern HPALETTE hpalApp;
  11. void CImageDecodeEventSink::Init(FILTERINFO * pFilter)
  12. {
  13. m_nRefCount=0;
  14. m_pFilter=pFilter;
  15. m_pDDrawSurface=NULL;
  16. m_dwLastTick=0;
  17. ZeroMemory(&m_rcProg, sizeof(m_rcProg));
  18. }
  19. /*
  20. CImageDecodeEventSink::~CImageDecodeEventSink()
  21. {
  22. }
  23. */
  24. ULONG CImageDecodeEventSink::AddRef()
  25. {
  26. m_nRefCount++;
  27. return (m_nRefCount);
  28. }
  29. ULONG CImageDecodeEventSink::Release()
  30. {
  31. m_nRefCount--;
  32. if (m_nRefCount == 0)
  33. {
  34. // delete this;
  35. return (0);
  36. }
  37. return (m_nRefCount);
  38. }
  39. STDMETHODIMP CImageDecodeEventSink::QueryInterface(REFIID iid,
  40. void** ppInterface)
  41. {
  42. if (ppInterface == NULL)
  43. {
  44. return (E_POINTER);
  45. }
  46. *ppInterface = NULL;
  47. if (IsEqualGUID(iid, IID_IUnknown))
  48. {
  49. *ppInterface = (IUnknown*)(IImageDecodeEventSink *)this;
  50. }
  51. else if (IsEqualGUID(iid, IID_IImageDecodeEventSink))
  52. {
  53. *ppInterface = (IImageDecodeEventSink*)this;
  54. }
  55. else
  56. {
  57. return (E_NOINTERFACE);
  58. }
  59. // If we're going to return an interface, AddRef it first
  60. if (*ppInterface)
  61. {
  62. ((LPUNKNOWN)*ppInterface)->AddRef();
  63. return S_OK;
  64. }
  65. return (S_OK);
  66. }
  67. STDMETHODIMP CImageDecodeEventSink::OnBeginDecode(DWORD* pdwEvents,
  68. ULONG* pnFormats, GUID** ppFormats)
  69. {
  70. GUID* pFormats;
  71. if (pdwEvents != NULL)
  72. {
  73. *pdwEvents = 0;
  74. }
  75. if (pnFormats != NULL)
  76. {
  77. *pnFormats = 0;
  78. }
  79. if (ppFormats != NULL)
  80. {
  81. *ppFormats = NULL;
  82. }
  83. if (pdwEvents == NULL)
  84. {
  85. return (E_POINTER);
  86. }
  87. if (pnFormats == NULL)
  88. {
  89. return (E_POINTER);
  90. }
  91. if (ppFormats == NULL)
  92. {
  93. return (E_POINTER);
  94. }
  95. #if 0
  96. if (m_pFilter->_colorMode == 8)
  97. {
  98. pFormats = (GUID*)CoTaskMemAlloc(1*sizeof(GUID));
  99. if(pFormats == NULL)
  100. {
  101. return (E_OUTOFMEMORY);
  102. }
  103. pFormats[0] = BFID_INDEXED_RGB_8;
  104. *pnFormats = 1;
  105. }
  106. #endif
  107. #if 1
  108. else
  109. {
  110. pFormats = (GUID*)CoTaskMemAlloc(2*sizeof(GUID));
  111. if(pFormats == NULL)
  112. {
  113. return (E_OUTOFMEMORY);
  114. }
  115. pFormats[0] = BFID_RGB_24;
  116. pFormats[1] = BFID_INDEXED_RGB_8;
  117. *pnFormats = 2;
  118. }
  119. #else
  120. else
  121. {
  122. pFormats = (GUID*)CoTaskMemAlloc(1*sizeof(GUID));
  123. if(pFormats == NULL)
  124. {
  125. return (E_OUTOFMEMORY);
  126. }
  127. pFormats[0] = BFID_RGB_24;
  128. *pnFormats = 1;
  129. }
  130. #endif
  131. *ppFormats = pFormats;
  132. *pdwEvents = IMGDECODE_EVENT_PALETTE|IMGDECODE_EVENT_BITSCOMPLETE|IMGDECODE_EVENT_PROGRESS;
  133. *pdwEvents |= IMGDECODE_EVENT_USEDDRAW;
  134. #if 0
  135. if (m_pFilter->_colorMode != 8)
  136. *pdwEvents |= IMGDECODE_EVENT_USEDDRAW;
  137. #endif
  138. m_dwLastTick = GetTickCount();
  139. return (S_OK);
  140. }
  141. STDMETHODIMP CImageDecodeEventSink::OnBitsComplete()
  142. {
  143. return (S_OK);
  144. }
  145. STDMETHODIMP CImageDecodeEventSink::OnDecodeComplete(HRESULT hrStatus)
  146. {
  147. return (S_OK);
  148. }
  149. #define LINEBYTES(_wid,_bits) ((((_wid)*(_bits) + 31) / 32) * 4)
  150. STDMETHODIMP CImageDecodeEventSink::GetSurface(LONG nWidth, LONG nHeight,
  151. REFGUID bfid, ULONG nPasses, DWORD dwHints, IUnknown** ppSurface)
  152. {
  153. return GetDDrawSurface(nWidth, nHeight, bfid, nPasses, dwHints, ppSurface);
  154. }
  155. STDMETHODIMP CImageDecodeEventSink::GetDDrawSurface(LONG nWidth, LONG nHeight,
  156. REFGUID bfid, ULONG nPasses, DWORD dwHints, IUnknown ** ppSurface)
  157. {
  158. DDSURFACEDESC2 ddsd = {sizeof(ddsd)};
  159. (void)nPasses;
  160. (void)dwHints;
  161. if (ppSurface != NULL)
  162. {
  163. *ppSurface = NULL;
  164. }
  165. if (ppSurface == NULL)
  166. {
  167. return (E_POINTER);
  168. }
  169. ddsd.dwSize = sizeof(ddsd);
  170. ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
  171. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
  172. ddsd.dwHeight = nHeight;
  173. ddsd.dwWidth = nWidth;
  174. ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  175. if (IsEqualGUID(bfid, BFID_INDEXED_RGB_8))
  176. {
  177. m_pFilter->m_nBytesPerPixel = 1;
  178. ddsd.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
  179. ddsd.ddpfPixelFormat.dwRGBBitCount = 8;
  180. ddsd.ddpfPixelFormat.dwRBitMask = 0;
  181. ddsd.ddpfPixelFormat.dwGBitMask = 0;
  182. ddsd.ddpfPixelFormat.dwBBitMask = 0;
  183. ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0;
  184. }
  185. else if (IsEqualGUID(bfid, BFID_RGB_24))
  186. {
  187. m_pFilter->m_nBytesPerPixel = 3;
  188. ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
  189. ddsd.ddpfPixelFormat.dwRGBBitCount = 24;
  190. ddsd.ddpfPixelFormat.dwRBitMask = 0x00FF0000L;
  191. ddsd.ddpfPixelFormat.dwGBitMask = 0x0000FF00L;
  192. ddsd.ddpfPixelFormat.dwBBitMask = 0x000000FFL;
  193. ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0;
  194. }
  195. else
  196. {
  197. return (E_NOINTERFACE);
  198. }
  199. IDirectDrawSurface4 * lpDDS;
  200. if (FAILED(m_pDirectDrawEx->CreateSurface(&ddsd, &lpDDS, NULL)))
  201. return (E_OUTOFMEMORY);
  202. HRESULT hr = lpDDS->QueryInterface(IID_IDirectDrawSurface,(void**)&m_pDDrawSurface);
  203. lpDDS->Release();
  204. if (FAILED(hr))
  205. {
  206. return hr;
  207. }
  208. // If this is a palette surface create/attach a palette to it.
  209. if (m_pFilter->m_nBytesPerPixel == 1)
  210. {
  211. PALETTEENTRY ape[256];
  212. LPDIRECTDRAWPALETTE2 pDDPalette;
  213. m_pDirectDrawEx->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256, ape, &pDDPalette, NULL);
  214. m_pDDrawSurface->SetPalette((LPDIRECTDRAWPALETTE)pDDPalette);
  215. pDDPalette->Release();
  216. }
  217. m_pFilter->m_pDDrawSurface = m_pDDrawSurface;
  218. m_pDDrawSurface->AddRef();
  219. *ppSurface = (IUnknown *)m_pDDrawSurface;
  220. (*ppSurface)->AddRef();
  221. return S_OK;
  222. }
  223. STDMETHODIMP CImageDecodeEventSink::OnPalette()
  224. {
  225. return (S_OK);
  226. }
  227. STDMETHODIMP CImageDecodeEventSink::OnProgress(RECT* pBounds, BOOL bComplete)
  228. {
  229. DWORD dwTick = GetTickCount();
  230. if (pBounds == NULL)
  231. {
  232. return (E_INVALIDARG);
  233. }
  234. UnionRect(&m_rcProg, &m_rcProg, pBounds);
  235. if (dwTick - m_dwLastTick > 250)
  236. {
  237. // Used for progressive rendering. Uncomment later
  238. // DrawImage(NULL, m_pFilter, &m_rcProg);
  239. m_dwLastTick = GetTickCount();
  240. }
  241. return (S_OK);
  242. }