Old fashion design for PC-104
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.

194 lines
5.0 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 24/03/2000
  5. // Last modification: 08/10/2003
  6. // Project Intruder Position Indicator
  7. // SUBSYSTEM: Video camera showing and captiring window
  8. // FILE: VideoForWindowsWnd.cpp
  9. // AUTHOR: Chizhevskiy Sergey
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file for implementation of class CVideoForWindowsWnd
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\LgLib\Version.h"
  16. /*
  17. #include "VideoForWindowsWnd.h"
  18. CVideoForWindowsWnd::CVideoForWindowsWnd()
  19. {
  20. m_hVFWWnd = 0;
  21. m_IsInitiated = FALSE;
  22. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoForWindowsWnd::CVideoForWindowsWnd" );
  23. }
  24. CVideoForWindowsWnd::CVideoForWindowsWnd( HWND hParentWnd, LPPOINT pPoint, LPSIZE pSize )
  25. {
  26. m_hVFWWnd = 0;
  27. m_IsInitiated = FALSE;
  28. Create(hParentWnd, pPoint, pSize);
  29. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoForWindowsWnd::CVideoForWindowsWnd(...)" );
  30. }
  31. CVideoForWindowsWnd::~CVideoForWindowsWnd()
  32. {
  33. if(m_IsInitiated)
  34. {
  35. if(::IsWindow(m_hVFWWnd))
  36. {
  37. capOverlay( m_hVFWWnd, FALSE );
  38. capDriverDisconnect( m_hVFWWnd );
  39. }
  40. }
  41. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoForWindowsWnd::~CVideoForWindowsWnd" );
  42. }
  43. BOOL CVideoForWindowsWnd::Create(HWND hParentWnd, LPPOINT pPoint, LPSIZE pSize)
  44. {
  45. if(!m_IsInitiated)
  46. {
  47. POINT point = {0, 0};
  48. SIZE size = { GetSafeBmi().bmiHeader.biWidth,
  49. GetSafeBmi().bmiHeader.biHeight };
  50. if(pPoint)
  51. point = *pPoint;
  52. if(pSize)
  53. size = *pSize;
  54. for(INT iIndex = 0; iIndex < 10; iIndex++)
  55. {
  56. TCHAR pDriverName[DESCRIPTION_SIZE];
  57. TCHAR pDriverVer[DESCRIPTION_SIZE];
  58. if(capGetDriverDescription(iIndex, pDriverName, DESCRIPTION_SIZE, pDriverVer, DESCRIPTION_SIZE))
  59. {
  60. m_hVFWWnd = capCreateCaptureWindow("", WS_CHILD, point.x, point.y, size.cx, size.cy, hParentWnd, 1);
  61. if(m_hVFWWnd)
  62. {
  63. if(capDriverConnect(m_hVFWWnd, iIndex))
  64. {
  65. if(capSetVideoFormat(m_hVFWWnd, &GetSafeBmi(), sizeof(BITMAPINFOHEADER)))
  66. {
  67. if(capOverlay(m_hVFWWnd, TRUE))
  68. {
  69. ::ShowWindow(m_hVFWWnd, SW_SHOW);
  70. ::UpdateWindow(m_hVFWWnd);
  71. return m_IsInitiated = TRUE;
  72. }
  73. }
  74. } // if(capDriverConnect(m_hVFWWnd, iIndex))
  75. } // end of if(m_hVFWWnd)
  76. } // end of if(capGetDriverDescription(
  77. } // end of for(INT iIndex = 0; iIndex < 10; iIndex++)
  78. m_hVFWWnd = NULL;
  79. } // end of if(!m_IsInitiated)
  80. return m_IsInitiated = FALSE;
  81. }
  82. HBITMAP CVideoForWindowsWnd::StoreImage( HANDLE hFile, LPCTSTR pBuffer, INT nBitCount )
  83. {
  84. volatile static BOOL fInside = FALSE;
  85. HBITMAP fSuccess = NULL;
  86. if(!fInside)
  87. {
  88. fInside = TRUE;
  89. if(m_IsInitiated && hFile)
  90. {
  91. capEditCopy(m_hVFWWnd);// Copy the contents of the video frame buffer and
  92. // associated palette to the clipboard.
  93. if(::OpenClipboard(m_hVFWWnd))
  94. {
  95. HBITMAP hDib = (HBITMAP)::GetClipboardData(CF_DIB);
  96. if(hDib)
  97. {
  98. LPBYTE lpDIBByte = ((LPBYTE)::GlobalLock((HGLOBAL)hDib)) + sizeof(BITMAPINFOHEADER);
  99. LPBYTE lpDst = GetSafeBytes();
  100. LPBYTE lpSrc = lpDIBByte;
  101. int lenDst = WIDTHBYTES(GetSafeBmi().bmiHeader.biWidth * 8);
  102. int lenSrc = WIDTHBYTES(GetSafeBmi().bmiHeader.biWidth * GetSafeBmi().bmiHeader.biBitCount);
  103. for(int y = 0; y < GetSafeBmi().bmiHeader.biHeight; y++, lpDst += lenDst, lpSrc += lenSrc)
  104. {
  105. LPBYTE pDst = lpDst;
  106. LPBYTE pSrc = lpSrc;
  107. for(int x = 0; x < lenDst; x++, pSrc += 3)
  108. *pDst++ = (BYTE)((pSrc[0] >>3 ) + (pSrc[1] >> 1) + (pSrc[2] >> 2) + 33);
  109. }
  110. DrawText8( &GetSafeBmi(), GetSafeBytes(), pBuffer );
  111. DWORD dwWritten;
  112. ::WriteFile(hFile, GetSafeBytes(), WIDTHBYTES(GetSafeBmi().bmiHeader.biWidth * 8) *
  113. GetSafeBmi().bmiHeader.biHeight, &dwWritten, NULL);
  114. ::GlobalUnlock((HGLOBAL)hDib);
  115. fSuccess = (HBITMAP)CopyImage(::GetClipboardData(CF_BITMAP),
  116. IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG);
  117. } // end of if(hDib)
  118. ::EmptyClipboard();
  119. ::CloseClipboard();
  120. } // end of if(::OpenClipboard(m_hVFWWnd))
  121. } // end of if(m_IsInitiated && hFile)
  122. fInside = FALSE;
  123. } // end of if(!fInside)
  124. return fSuccess;
  125. }
  126. HBITMAP CVideoForWindowsWnd::GetSnapshot()
  127. {
  128. volatile static BOOL fInside = FALSE;
  129. HBITMAP fSuccess = NULL;
  130. if( !fInside )
  131. {
  132. fInside = TRUE;
  133. if(m_IsInitiated)
  134. {
  135. capEditCopy(m_hVFWWnd);
  136. if(::OpenClipboard(m_hVFWWnd))
  137. {
  138. fSuccess = (HBITMAP)::CopyImage( ::GetClipboardData(CF_BITMAP), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG );
  139. ::EmptyClipboard();
  140. ::CloseClipboard();
  141. }
  142. }
  143. fInside = FALSE;
  144. }
  145. return fSuccess;
  146. }
  147. BOOL CVideoForWindowsWnd::ShowWindow(int nShow)
  148. {
  149. ::ShowWindow( m_hVFWWnd, nShow );
  150. return TRUE;
  151. }
  152. */