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.

317 lines
8.3 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: DDVideoWnd.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of DDVideoWnd.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "DDVideoWnd.h"
  16. #include "VideoCamera.h"
  17. #include "..\Chicago\VideoBase.h"
  18. #include "..\..\LgLib\Version.h"
  19. BEGIN_MESSAGE_MAP(CDDVideoWnd, CWnd)
  20. //{{AFX_MSG_MAP(CDDVideoWnd)
  21. ON_WM_PAINT()
  22. ON_WM_SIZE()
  23. ON_WM_DESTROY()
  24. ON_WM_LBUTTONDOWN()
  25. //}}AFX_MSG_MAP
  26. ON_MESSAGE( WM_UPDATE_BITMAP, OnUpdateBitmap )
  27. ON_MESSAGE( WM_VIDEO_SAMPLE, OnVideoSample )
  28. END_MESSAGE_MAP()
  29. CDDVideoWnd::CDDVideoWnd( CSensorArray *pSensorArray )
  30. {
  31. m_hFont = NULL;
  32. ::ZeroMemory( m_pVideoText, sizeof(m_pVideoText) );
  33. m_nVideoText = 0;
  34. m_pSensorArray = pSensorArray;
  35. m_nPreviewDIBCount = 0;
  36. m_nPreviewDIBCurrent = 0;
  37. m_dwPreviewDIBTime = 0;
  38. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDDVideoWnd::CDDVideoWnd" );
  39. }
  40. CDDVideoWnd::~CDDVideoWnd()
  41. {
  42. DestroyWindow();
  43. if( m_hFont )
  44. {
  45. ::DeleteObject( m_hFont );
  46. m_hFont = NULL;
  47. }
  48. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDDVideoWnd::~CDDVideoWnd" );
  49. }
  50. LRESULT CDDVideoWnd::OnUpdateBitmap( WPARAM, LPARAM )
  51. {
  52. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnUpdateBitmap"), _T("Started...") );
  53. CClientDC dc( this );
  54. OnDraw( &dc );
  55. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnUpdateBitmap"), _T("Done") );
  56. return 0;
  57. }
  58. void CDDVideoWnd::OnSize( UINT nType, int cx, int cy )
  59. {
  60. #ifndef _DEBUG
  61. CLgDirectDrawVideo::OnSize( GetSafeHwnd() );
  62. #endif
  63. CWnd::OnSize( nType, cx, cy );
  64. }
  65. void CDDVideoWnd::OnPaint()
  66. {
  67. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnPaint"), _T("Started...") );
  68. CPaintDC dc(this);
  69. CRect rect;
  70. GetClientRect( &rect );
  71. OnDraw( &dc );
  72. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnPaint"), _T("Done") );
  73. }
  74. void CDDVideoWnd::OnDestroy()
  75. {
  76. #ifndef _DEBUG
  77. CLgDirectDrawVideo::OnDestroy();
  78. #endif
  79. CWnd::OnDestroy();
  80. }
  81. void CDDVideoWnd::OnDraw( CDC *pDC )
  82. {
  83. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnDraw"), _T("Started...") );
  84. #ifndef _DEBUG
  85. if( GetSystemMetrics( SM_REMOTESESSION ) )
  86. #endif
  87. {
  88. RECT rect;
  89. GetClientRect( &rect );
  90. HDC hDC = pDC->GetSafeHdc();
  91. GetDirectShowDIB().Draw( hDC, &rect );
  92. if( m_nVideoText )
  93. {
  94. HFONT hFont = (HFONT)::SelectObject( hDC, m_hFont );
  95. COLORREF nColor = ::SetTextColor( hDC, m_pSensorArray->GetProgramSettings().ColorVideo );
  96. INT nBkMode = ::SetBkMode( hDC, TRANSPARENT );
  97. INT nFontSize = abs( m_pSensorArray->GetProgramSettings().LogFontVideo.lfHeight );
  98. rect.top = rect.bottom - nFontSize;
  99. ::DrawText( hDC, m_pVideoText, m_nVideoText, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
  100. ::SetBkMode( hDC, nBkMode );
  101. ::SetTextColor( hDC, nColor );
  102. ::SelectObject( hDC, hFont );
  103. }
  104. }
  105. #ifndef _DEBUG
  106. else
  107. {
  108. // text color !!!!
  109. CLgDirectDrawVideo::SetDirectDrawVideoText( m_pVideoText, m_hFont, m_pSensorArray->GetProgramSettings().ColorVideo );
  110. CLgDirectDrawVideo::OnPaint( TRUE );
  111. }
  112. #endif
  113. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnDraw"), _T("Done") );
  114. }
  115. BOOL CDDVideoWnd::Create( CWnd *pParentWnd, int x, int y, int nWidth, int nHeight, CDSVideoProcessor *pDSVideoProcessor, int nInput )
  116. {
  117. DestroyWindow();
  118. CRect rect( x, y, x + nWidth, y + nHeight );
  119. CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, ::LoadCursor( NULL, IDC_ARROW ), NULL, NULL );
  120. if( !CWnd::Create( strClassName, "", WS_CHILD | WS_VISIBLE, rect, pParentWnd, 0 ) )
  121. return FALSE;
  122. m_hFont = ::CreateFontIndirect( &m_pSensorArray->GetProgramSettings().LogFontVideo );
  123. if( !m_hFont )
  124. return FALSE;
  125. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDDVideoWnd::Create" );
  126. return TRUE;
  127. }
  128. BOOL CDDVideoWnd::DestroyWindow()
  129. {
  130. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CDDVideoWnd::DestroyWindow"), _T("Started...") );
  131. // unlink from direct show stream
  132. CDirectShowVideo::Unlink();
  133. if( m_hFont )
  134. {
  135. ::DeleteObject( m_hFont );
  136. m_hFont = NULL;
  137. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDDVideoWnd::DestroyWindow" );
  138. }
  139. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CDDVideoWnd::DestroyWindow"), _T("Done") );
  140. #ifndef _DEBUG
  141. CLgDirectDrawVideo::OnDestroy();
  142. #endif
  143. return CWnd::DestroyWindow();
  144. }
  145. void CDDVideoWnd::SetWindowText( LPCTSTR lpString )
  146. {
  147. if( lpString )
  148. {
  149. _tcscpy( m_pVideoText, lpString );
  150. m_nVideoText = _tcslen( lpString );
  151. }
  152. CClientDC dc( this );
  153. OnDraw( &dc );
  154. CWnd::SetWindowText( lpString );
  155. }
  156. BOOL CDDVideoWnd::Capture( LPBITMAPINFO *pBitmapInfo, LPBYTE *ppBytes, HBITMAP *pBitmap, DWORD dwPreviewTime )
  157. {
  158. // take current picture
  159. if( dwPreviewTime == 0 )
  160. {
  161. if( pBitmap )
  162. return ( *pBitmap = GetDirectShowDIB().CreateBitmap( pBitmapInfo, ppBytes ) ) != NULL;
  163. *pBitmapInfo = GetDirectShowDIB();
  164. *ppBytes = GetDirectShowDIB();
  165. return TRUE;
  166. }
  167. CLgLocker Lock( &m_PreviewLock );
  168. // get from preview
  169. INT nPreviewIndex = (dwPreviewTime + MAX_PREVIEW_IMAGE_INTERVAL - 1UL) / MAX_PREVIEW_IMAGE_INTERVAL;
  170. if( nPreviewIndex >= m_nPreviewDIBCount )
  171. {
  172. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CDDVideoWnd::Capture"), _T("Requested preview image (%d) was already discarded"), -(INT)dwPreviewTime );
  173. return NULL;
  174. }
  175. // convert index into array index
  176. nPreviewIndex = ( m_nPreviewDIBCurrent - nPreviewIndex + CVideoCaptureSource::m_nPreviewMaxImageCount ) % CVideoCaptureSource::m_nPreviewMaxImageCount;
  177. // create bitmap from image
  178. if( pBitmap )
  179. return ( *pBitmap = m_pPreviewDIB[nPreviewIndex].CreateBitmap( pBitmapInfo, ppBytes ) ) != NULL;
  180. *pBitmapInfo = m_pPreviewDIB[nPreviewIndex];
  181. *ppBytes = m_pPreviewDIB[nPreviewIndex];
  182. return TRUE;
  183. }
  184. BOOL CDDVideoWnd::AssignVideoCamera( CVideoCamera *pVideoCamera )
  185. {
  186. CVideoCaptureSource::AssignVideoCamera( pVideoCamera );
  187. pVideoCamera = GetVideoCamera();
  188. if( pVideoCamera )
  189. {
  190. SetWindowText( *pVideoCamera->GetName() );
  191. }
  192. else
  193. {
  194. SetWindowText( _T("Unknown camera") );
  195. }
  196. /*
  197. // reset preview
  198. CLgLocker Lock( &m_PreviewLock );
  199. m_bPreviewDIB = pVideoCamera ? ( pVideoCamera->GetType() == VC_FIX ) : FALSE;
  200. m_nPreviewDIBCount = 0;
  201. m_nPreviewDIBCurrent = 0;
  202. m_dwPreviewDIBTime = 0;
  203. */
  204. return TRUE;
  205. }
  206. void CDDVideoWnd::OnVideoSample( double SampleTime )
  207. {
  208. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnVideoSample"), _T("Started...") );
  209. CLgLocker Lock( &m_PreviewLock );
  210. if( CVideoCaptureSource::m_nPreviewMaxImageCount )
  211. {
  212. // store preview
  213. DWORD dwCurrentTime = GetTickCount();
  214. if( ( dwCurrentTime - m_dwPreviewDIBTime ) > MAX_PREVIEW_IMAGE_INTERVAL )
  215. {
  216. // store time
  217. m_dwPreviewDIBTime = dwCurrentTime;
  218. // store image
  219. m_pPreviewDIB[ m_nPreviewDIBCurrent ].Create( (LPBITMAPINFO)GetDirectShowDIB(), GetDirectShowDIB() );
  220. // update count
  221. if( m_nPreviewDIBCount < CVideoCaptureSource::m_nPreviewMaxImageCount )
  222. m_nPreviewDIBCount++;
  223. m_nPreviewDIBCurrent = (m_nPreviewDIBCurrent + 1) % CVideoCaptureSource::m_nPreviewMaxImageCount;
  224. }
  225. }
  226. // pos message to window
  227. if( GetSafeHwnd() )
  228. ::PostMessage( GetSafeHwnd(), WM_VIDEO_SAMPLE, (WPARAM)( SampleTime * 1000000.0 ), 0 );
  229. LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnVideoSample"), _T("Done...") );
  230. }
  231. LRESULT CDDVideoWnd::OnVideoSample( WPARAM wParam, LPARAM )
  232. {
  233. GetVideoBase()->UpdateDemo( this, wParam / 1000000.0 );
  234. InvalidateRect( NULL );
  235. return 0;
  236. }
  237. void CDDVideoWnd::OnLButtonDown( UINT nFlags, CPoint point )
  238. {
  239. // call base class
  240. CVideoCaptureWnd::OnLButtonDown( nFlags, point );
  241. // ASSERT( GetVideoBase() );
  242. // GetVideoBase()->SetControlledVideo( this );
  243. }
  244. void CDDVideoWnd::OnChangeSettings()
  245. {
  246. if( m_hFont )
  247. ::DeleteObject( m_hFont );
  248. m_hFont = ::CreateFontIndirect( &m_pSensorArray->GetProgramSettings().LogFontVideo );
  249. InvalidateRect( NULL );
  250. }