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.

233 lines
5.9 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1999 - 2000
  4. *
  5. * TITLE: image.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: RickTu
  10. *
  11. * DATE: 9/16/99
  12. *
  13. * DESCRIPTION: CImage class for WIA still from video driver. Encapsulate
  14. * saved images into a class (one instace for each class)
  15. *
  16. *****************************************************************************/
  17. #ifndef __WIA_STILL_DRIVER_IMAGE_H_
  18. #define __WIA_STILL_DRIVER_IMAGE_H_
  19. #define THUMB_WIDTH 80
  20. #define THUMB_HEIGHT 60
  21. #define THUMB_BPP 3
  22. #define THUMB_SIZE_BYTES (THUMB_WIDTH * THUMB_HEIGHT * THUMB_BPP)
  23. extern CLSID g_clsidBMPEncoder;
  24. class CImage
  25. {
  26. public:
  27. CImage(LPCTSTR pszStillPath,
  28. BSTR bstrRootFullItemName,
  29. LPCTSTR pszPath,
  30. LPCTSTR pszName,
  31. LONG FolderType);
  32. ~CImage();
  33. //
  34. // Methods
  35. //
  36. STDMETHOD(InitImageInformation)(BYTE *pWiasContext,LONG *plDevErrVal);
  37. STDMETHOD(SetItemSize)(BYTE *pWiasContext, MINIDRV_TRANSFER_CONTEXT * pDrvTranCtx);
  38. STDMETHOD(LoadThumbnail)(BYTE *pWiasContext);
  39. STDMETHOD(LoadImageInfo)(BYTE *pWiasContext);
  40. void GetImageTimeStamp( SYSTEMTIME * pst );
  41. void GetImageSizes();
  42. LPCTSTR ActualImagePath();
  43. HRESULT DoDelete();
  44. //
  45. // "Properties" -- still methods but just returning information
  46. //
  47. BSTR bstrItemName();
  48. BSTR bstrFullItemName();
  49. LONG ThumbWidth();
  50. LONG ThumbHeight();
  51. private:
  52. CSimpleString m_strRootPath;
  53. CSimpleString m_strPathItem;
  54. CSimpleString m_strName;
  55. CSimpleBStr m_bstrRootFullItemName;
  56. CSimpleBStr m_bstrFullItemName;
  57. CSimpleBStr m_bstrItemName;
  58. LONG m_FolderType;
  59. SYSTEMTIME m_ImageTime;
  60. BOOL m_bImageTimeValid;
  61. CRITICAL_SECTION m_cs;
  62. PBYTE m_pThumb;
  63. };
  64. typedef struct _STILLCAM_IMAGE_CONTEXT
  65. {
  66. CImage * pImage;
  67. } STILLCAM_IMAGE_CONTEXT,*PSTILLCAM_IMAGE_CONTEXT;
  68. class CMappedView
  69. {
  70. private:
  71. BYTE * m_pBits;
  72. HANDLE m_hFile;
  73. HANDLE m_hMap;
  74. LONG m_lSize;
  75. public:
  76. CMappedView( LPCTSTR pszFile, LONG lSize, DWORD dwOpen )
  77. : m_pBits(NULL),
  78. m_hFile(INVALID_HANDLE_VALUE),
  79. m_hMap(NULL),
  80. m_lSize(lSize)
  81. {
  82. m_hFile = CreateFile( pszFile,
  83. GENERIC_READ | GENERIC_WRITE,
  84. FILE_SHARE_WRITE | FILE_SHARE_READ,
  85. NULL,
  86. dwOpen,
  87. FILE_ATTRIBUTE_NORMAL,
  88. NULL
  89. );
  90. if (m_hFile == INVALID_HANDLE_VALUE)
  91. {
  92. WIA_ERROR((TEXT("CreateFile failed w/GLE = %d"),GetLastError()));
  93. }
  94. WIA_TRACE((TEXT("CMappedView(0x%x) for %s"),m_hFile,pszFile));
  95. DoCreateFileMapping();
  96. }
  97. CMappedView( HANDLE hFile, LONG lSize )
  98. : m_pBits(NULL),
  99. m_hFile(hFile),
  100. m_hMap(INVALID_HANDLE_VALUE),
  101. m_lSize(lSize)
  102. {
  103. WIA_TRACE((TEXT("CMappedView(0x%x)"),m_hFile));
  104. DoCreateFileMapping();
  105. }
  106. void DoCreateFileMapping()
  107. {
  108. if (m_hFile != INVALID_HANDLE_VALUE)
  109. {
  110. m_hMap = CreateFileMapping( m_hFile,
  111. NULL,
  112. PAGE_READWRITE,
  113. 0,
  114. m_lSize,
  115. NULL
  116. );
  117. if (m_hMap)
  118. {
  119. m_pBits = (PBYTE)MapViewOfFileEx( m_hMap,
  120. FILE_MAP_READ | FILE_MAP_WRITE,
  121. 0,
  122. 0,
  123. 0,
  124. NULL
  125. );
  126. }
  127. else
  128. {
  129. WIA_ERROR((TEXT("CreateFileMapping failed w/GLE = %d"),GetLastError()));
  130. }
  131. }
  132. }
  133. LARGE_INTEGER FileSize()
  134. {
  135. WIA_TRACE((TEXT("CMappedView::FileSize")));
  136. LARGE_INTEGER li;
  137. li.QuadPart = 0;
  138. #ifdef WINNT
  139. GetFileSizeEx( m_hFile, &li );
  140. #else
  141. DWORD LowPart = 0;
  142. LowPart = GetFileSize( m_hFile, (DWORD *)&li.HighPart );
  143. if (LowPart != -1)
  144. {
  145. li.LowPart = LowPart;
  146. }
  147. #endif
  148. return li;
  149. }
  150. void CloseAndRelease()
  151. {
  152. WIA_TRACE((TEXT("CMappedView::CloseAndRelease()")));
  153. if (m_pBits)
  154. {
  155. if (!UnmapViewOfFile( m_pBits ))
  156. {
  157. WIA_ERROR((TEXT("UnmapViewOfFile failed w/GLE = %d"),GetLastError()));
  158. }
  159. m_pBits = NULL;
  160. }
  161. if (m_hMap)
  162. {
  163. if (!CloseHandle( m_hMap ))
  164. {
  165. WIA_ERROR((TEXT("CloseHandle( m_hMap ) failed w/GLE = %s"),GetLastError()));
  166. }
  167. m_hMap = NULL;
  168. }
  169. if (m_hFile != INVALID_HANDLE_VALUE)
  170. {
  171. WIA_TRACE((TEXT("Closing file handle (0x%x)"),m_hFile));
  172. if (!CloseHandle( m_hFile ))
  173. {
  174. WIA_ERROR((TEXT("CloseHandle( m_hFile ) failed w/GLE = %s"),GetLastError()));
  175. }
  176. m_hFile = INVALID_HANDLE_VALUE;
  177. }
  178. }
  179. ~CMappedView()
  180. {
  181. WIA_TRACE((TEXT("~CMappedView")));
  182. CloseAndRelease();
  183. }
  184. PBYTE Bits()
  185. {
  186. return m_pBits;
  187. }
  188. };
  189. #endif