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.

182 lines
4.0 KiB

  1. #include "stdafx.h"
  2. #include "imgutil.h"
  3. #include "cdithtbl.h"
  4. #include "cddsurf.h"
  5. // Get rid of "unused formal parameters warning"
  6. #pragma warning(disable : 4100)
  7. STDAPI DecodeImage( IStream* pStream, IMapMIMEToCLSID* pMap,
  8. IUnknown* pUnknownEventSink )
  9. {
  10. USES_CONVERSION;
  11. HRESULT hResult;
  12. CComPtr< IStream > pSniffedStream;
  13. UINT nFormat;
  14. TCHAR szMIMEType[64];
  15. LPCOLESTR pszMIMETypeO;
  16. CComPtr< IMapMIMEToCLSID > pActualMap;
  17. CComPtr< IImageDecodeFilter > pFilter;
  18. CComPtr< IImageDecodeEventSink > pEventSink;
  19. CLSID clsid;
  20. int nChars;
  21. if( pStream == NULL )
  22. {
  23. return( E_INVALIDARG );
  24. }
  25. if( pUnknownEventSink == NULL )
  26. {
  27. return( E_INVALIDARG );
  28. }
  29. pUnknownEventSink->QueryInterface(IID_IImageDecodeEventSink,
  30. (void **)&pEventSink);
  31. if (pEventSink == NULL)
  32. return E_INVALIDARG;
  33. if( pMap == NULL )
  34. {
  35. hResult = CoCreateInstance( CLSID_CoMapMIMEToCLSID, NULL,
  36. CLSCTX_INPROC_SERVER, IID_IMapMIMEToCLSID, (void**)&pActualMap );
  37. if( FAILED( hResult ) )
  38. {
  39. return( hResult );
  40. }
  41. }
  42. else
  43. {
  44. pActualMap = pMap;
  45. }
  46. hResult = SniffStream( pStream, &nFormat, &pSniffedStream );
  47. if( FAILED( hResult ) )
  48. {
  49. return( hResult );
  50. }
  51. nChars = GetClipboardFormatName( nFormat, szMIMEType, 63 );
  52. if( nChars == 0 )
  53. {
  54. return( E_FAIL );
  55. }
  56. if( nChars > 60 )
  57. {
  58. return( E_FAIL );
  59. }
  60. pszMIMETypeO = T2COLE( szMIMEType );
  61. hResult = pActualMap->MapMIMEToCLSID( pszMIMETypeO, &clsid );
  62. if( FAILED( hResult ) )
  63. {
  64. return( hResult );
  65. }
  66. if( hResult == S_FALSE )
  67. {
  68. return( E_FAIL );
  69. }
  70. hResult = CoCreateInstance( clsid, NULL, CLSCTX_INPROC_SERVER,
  71. IID_IImageDecodeFilter, (void**)&pFilter );
  72. if( FAILED( hResult ) )
  73. {
  74. return( hResult );
  75. }
  76. hResult = pFilter->Initialize( pEventSink );
  77. if( FAILED( hResult ) )
  78. {
  79. return( hResult );
  80. }
  81. hResult = pFilter->Process( pSniffedStream );
  82. pFilter->Terminate( hResult );
  83. if( FAILED( hResult ) )
  84. {
  85. return( hResult );
  86. }
  87. return( S_OK );
  88. }
  89. STDAPI CreateMIMEMap( IMapMIMEToCLSID** ppMap )
  90. {
  91. if( ppMap == NULL )
  92. {
  93. return( E_POINTER );
  94. }
  95. return( CoCreateInstance( CLSID_CoMapMIMEToCLSID, NULL,
  96. CLSCTX_INPROC_SERVER, IID_IMapMIMEToCLSID, (void**)ppMap ) );
  97. }
  98. STDAPI ComputeInvCMAP(const RGBQUAD *pRGBColors, ULONG nColors, BYTE *pInvTable, ULONG cbTable)
  99. {
  100. #ifndef MINSUPPORT
  101. CDitherTable *pDitherTable;
  102. HRESULT hr;
  103. if (pRGBColors == NULL)
  104. return E_POINTER;
  105. if (pInvTable == NULL)
  106. return E_POINTER;
  107. if (nColors > 256)
  108. return E_INVALIDARG;
  109. if (cbTable != 32768)
  110. return E_INVALIDARG;
  111. pDitherTable = new CDitherTable;
  112. if (pDitherTable == NULL)
  113. return E_OUTOFMEMORY;
  114. hr = pDitherTable->SetColors(nColors, pRGBColors);
  115. if (SUCCEEDED(hr))
  116. memcpy(pInvTable, pDitherTable->m_abInverseMap, 32768);
  117. delete pDitherTable;
  118. return hr;
  119. #else
  120. return E_NOTIMPL;
  121. #endif
  122. }
  123. #ifdef MINSUPPORT
  124. HRESULT DitherTo8( BYTE * pDestBits, LONG nDestPitch,
  125. BYTE * pSrcBits, LONG nSrcPitch, REFGUID bfidSrc,
  126. RGBQUAD * prgbDestColors, RGBQUAD * prgbSrcColors,
  127. BYTE * pbDestInvMap,
  128. LONG x, LONG y, LONG cx, LONG cy,
  129. LONG lDestTrans, LONG lSrcTrans)
  130. {
  131. return E_NOTIMPL;
  132. }
  133. #endif
  134. STDAPI CreateDDrawSurfaceOnDIB(HBITMAP hbmDib, IDirectDrawSurface **ppSurface)
  135. {
  136. #ifndef MINSUPPORT
  137. if (hbmDib == NULL)
  138. return E_INVALIDARG;
  139. if (ppSurface == NULL)
  140. return E_POINTER;
  141. *ppSurface = (IDirectDrawSurface *)(new CDDrawWrapper(hbmDib));
  142. return *ppSurface ? S_OK : E_OUTOFMEMORY;
  143. #else
  144. return E_NOTIMPL;
  145. #endif
  146. }