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
317 lines
8.3 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: DDVideoWnd.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of DDVideoWnd.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "DDVideoWnd.h"
|
|
#include "VideoCamera.h"
|
|
#include "..\Chicago\VideoBase.h"
|
|
#include "..\..\LgLib\Version.h"
|
|
|
|
BEGIN_MESSAGE_MAP(CDDVideoWnd, CWnd)
|
|
//{{AFX_MSG_MAP(CDDVideoWnd)
|
|
ON_WM_PAINT()
|
|
ON_WM_SIZE()
|
|
ON_WM_DESTROY()
|
|
ON_WM_LBUTTONDOWN()
|
|
//}}AFX_MSG_MAP
|
|
ON_MESSAGE( WM_UPDATE_BITMAP, OnUpdateBitmap )
|
|
ON_MESSAGE( WM_VIDEO_SAMPLE, OnVideoSample )
|
|
END_MESSAGE_MAP()
|
|
|
|
CDDVideoWnd::CDDVideoWnd( CSensorArray *pSensorArray )
|
|
{
|
|
m_hFont = NULL;
|
|
|
|
::ZeroMemory( m_pVideoText, sizeof(m_pVideoText) );
|
|
m_nVideoText = 0;
|
|
|
|
m_pSensorArray = pSensorArray;
|
|
|
|
m_nPreviewDIBCount = 0;
|
|
m_nPreviewDIBCurrent = 0;
|
|
m_dwPreviewDIBTime = 0;
|
|
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDDVideoWnd::CDDVideoWnd" );
|
|
}
|
|
|
|
CDDVideoWnd::~CDDVideoWnd()
|
|
{
|
|
DestroyWindow();
|
|
|
|
if( m_hFont )
|
|
{
|
|
::DeleteObject( m_hFont );
|
|
m_hFont = NULL;
|
|
}
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDDVideoWnd::~CDDVideoWnd" );
|
|
}
|
|
|
|
LRESULT CDDVideoWnd::OnUpdateBitmap( WPARAM, LPARAM )
|
|
{
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnUpdateBitmap"), _T("Started...") );
|
|
|
|
CClientDC dc( this );
|
|
|
|
OnDraw( &dc );
|
|
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnUpdateBitmap"), _T("Done") );
|
|
return 0;
|
|
}
|
|
|
|
void CDDVideoWnd::OnSize( UINT nType, int cx, int cy )
|
|
{
|
|
#ifndef _DEBUG
|
|
CLgDirectDrawVideo::OnSize( GetSafeHwnd() );
|
|
#endif
|
|
|
|
CWnd::OnSize( nType, cx, cy );
|
|
}
|
|
|
|
void CDDVideoWnd::OnPaint()
|
|
{
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnPaint"), _T("Started...") );
|
|
|
|
CPaintDC dc(this);
|
|
|
|
CRect rect;
|
|
GetClientRect( &rect );
|
|
|
|
OnDraw( &dc );
|
|
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnPaint"), _T("Done") );
|
|
}
|
|
|
|
void CDDVideoWnd::OnDestroy()
|
|
{
|
|
#ifndef _DEBUG
|
|
CLgDirectDrawVideo::OnDestroy();
|
|
#endif
|
|
CWnd::OnDestroy();
|
|
}
|
|
|
|
void CDDVideoWnd::OnDraw( CDC *pDC )
|
|
{
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnDraw"), _T("Started...") );
|
|
|
|
#ifndef _DEBUG
|
|
if( GetSystemMetrics( SM_REMOTESESSION ) )
|
|
#endif
|
|
{
|
|
RECT rect;
|
|
GetClientRect( &rect );
|
|
|
|
HDC hDC = pDC->GetSafeHdc();
|
|
|
|
GetDirectShowDIB().Draw( hDC, &rect );
|
|
|
|
if( m_nVideoText )
|
|
{
|
|
HFONT hFont = (HFONT)::SelectObject( hDC, m_hFont );
|
|
COLORREF nColor = ::SetTextColor( hDC, m_pSensorArray->GetProgramSettings().ColorVideo );
|
|
INT nBkMode = ::SetBkMode( hDC, TRANSPARENT );
|
|
|
|
INT nFontSize = abs( m_pSensorArray->GetProgramSettings().LogFontVideo.lfHeight );
|
|
rect.top = rect.bottom - nFontSize;
|
|
::DrawText( hDC, m_pVideoText, m_nVideoText, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
|
|
|
|
::SetBkMode( hDC, nBkMode );
|
|
::SetTextColor( hDC, nColor );
|
|
::SelectObject( hDC, hFont );
|
|
}
|
|
}
|
|
#ifndef _DEBUG
|
|
else
|
|
{
|
|
// text color !!!!
|
|
CLgDirectDrawVideo::SetDirectDrawVideoText( m_pVideoText, m_hFont, m_pSensorArray->GetProgramSettings().ColorVideo );
|
|
|
|
CLgDirectDrawVideo::OnPaint( TRUE );
|
|
}
|
|
#endif
|
|
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnDraw"), _T("Done") );
|
|
}
|
|
|
|
BOOL CDDVideoWnd::Create( CWnd *pParentWnd, int x, int y, int nWidth, int nHeight, CDSVideoProcessor *pDSVideoProcessor, int nInput )
|
|
{
|
|
DestroyWindow();
|
|
|
|
CRect rect( x, y, x + nWidth, y + nHeight );
|
|
CString strClassName = ::AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW, ::LoadCursor( NULL, IDC_ARROW ), NULL, NULL );
|
|
if( !CWnd::Create( strClassName, "", WS_CHILD | WS_VISIBLE, rect, pParentWnd, 0 ) )
|
|
return FALSE;
|
|
|
|
m_hFont = ::CreateFontIndirect( &m_pSensorArray->GetProgramSettings().LogFontVideo );
|
|
if( !m_hFont )
|
|
return FALSE;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDDVideoWnd::Create" );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CDDVideoWnd::DestroyWindow()
|
|
{
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CDDVideoWnd::DestroyWindow"), _T("Started...") );
|
|
|
|
// unlink from direct show stream
|
|
CDirectShowVideo::Unlink();
|
|
|
|
if( m_hFont )
|
|
{
|
|
::DeleteObject( m_hFont );
|
|
m_hFont = NULL;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CDDVideoWnd::DestroyWindow" );
|
|
}
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CDDVideoWnd::DestroyWindow"), _T("Done") );
|
|
|
|
#ifndef _DEBUG
|
|
CLgDirectDrawVideo::OnDestroy();
|
|
#endif
|
|
|
|
return CWnd::DestroyWindow();
|
|
}
|
|
|
|
void CDDVideoWnd::SetWindowText( LPCTSTR lpString )
|
|
{
|
|
if( lpString )
|
|
{
|
|
_tcscpy( m_pVideoText, lpString );
|
|
m_nVideoText = _tcslen( lpString );
|
|
}
|
|
|
|
CClientDC dc( this );
|
|
|
|
OnDraw( &dc );
|
|
|
|
CWnd::SetWindowText( lpString );
|
|
}
|
|
|
|
BOOL CDDVideoWnd::Capture( LPBITMAPINFO *pBitmapInfo, LPBYTE *ppBytes, HBITMAP *pBitmap, DWORD dwPreviewTime )
|
|
{
|
|
// take current picture
|
|
if( dwPreviewTime == 0 )
|
|
{
|
|
if( pBitmap )
|
|
return ( *pBitmap = GetDirectShowDIB().CreateBitmap( pBitmapInfo, ppBytes ) ) != NULL;
|
|
|
|
*pBitmapInfo = GetDirectShowDIB();
|
|
*ppBytes = GetDirectShowDIB();
|
|
return TRUE;
|
|
}
|
|
|
|
CLgLocker Lock( &m_PreviewLock );
|
|
|
|
// get from preview
|
|
INT nPreviewIndex = (dwPreviewTime + MAX_PREVIEW_IMAGE_INTERVAL - 1UL) / MAX_PREVIEW_IMAGE_INTERVAL;
|
|
if( nPreviewIndex >= m_nPreviewDIBCount )
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_WARNING, this, _T("CDDVideoWnd::Capture"), _T("Requested preview image (%d) was already discarded"), -(INT)dwPreviewTime );
|
|
return NULL;
|
|
}
|
|
|
|
// convert index into array index
|
|
nPreviewIndex = ( m_nPreviewDIBCurrent - nPreviewIndex + CVideoCaptureSource::m_nPreviewMaxImageCount ) % CVideoCaptureSource::m_nPreviewMaxImageCount;
|
|
|
|
// create bitmap from image
|
|
if( pBitmap )
|
|
return ( *pBitmap = m_pPreviewDIB[nPreviewIndex].CreateBitmap( pBitmapInfo, ppBytes ) ) != NULL;
|
|
|
|
*pBitmapInfo = m_pPreviewDIB[nPreviewIndex];
|
|
*ppBytes = m_pPreviewDIB[nPreviewIndex];
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CDDVideoWnd::AssignVideoCamera( CVideoCamera *pVideoCamera )
|
|
{
|
|
CVideoCaptureSource::AssignVideoCamera( pVideoCamera );
|
|
|
|
pVideoCamera = GetVideoCamera();
|
|
if( pVideoCamera )
|
|
{
|
|
SetWindowText( *pVideoCamera->GetName() );
|
|
}
|
|
else
|
|
{
|
|
SetWindowText( _T("Unknown camera") );
|
|
}
|
|
/*
|
|
// reset preview
|
|
CLgLocker Lock( &m_PreviewLock );
|
|
m_bPreviewDIB = pVideoCamera ? ( pVideoCamera->GetType() == VC_FIX ) : FALSE;
|
|
m_nPreviewDIBCount = 0;
|
|
m_nPreviewDIBCurrent = 0;
|
|
m_dwPreviewDIBTime = 0;
|
|
*/
|
|
return TRUE;
|
|
}
|
|
|
|
void CDDVideoWnd::OnVideoSample( double SampleTime )
|
|
{
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnVideoSample"), _T("Started...") );
|
|
|
|
CLgLocker Lock( &m_PreviewLock );
|
|
if( CVideoCaptureSource::m_nPreviewMaxImageCount )
|
|
{
|
|
// store preview
|
|
DWORD dwCurrentTime = GetTickCount();
|
|
if( ( dwCurrentTime - m_dwPreviewDIBTime ) > MAX_PREVIEW_IMAGE_INTERVAL )
|
|
{
|
|
// store time
|
|
m_dwPreviewDIBTime = dwCurrentTime;
|
|
// store image
|
|
m_pPreviewDIB[ m_nPreviewDIBCurrent ].Create( (LPBITMAPINFO)GetDirectShowDIB(), GetDirectShowDIB() );
|
|
// update count
|
|
if( m_nPreviewDIBCount < CVideoCaptureSource::m_nPreviewMaxImageCount )
|
|
m_nPreviewDIBCount++;
|
|
|
|
m_nPreviewDIBCurrent = (m_nPreviewDIBCurrent + 1) % CVideoCaptureSource::m_nPreviewMaxImageCount;
|
|
}
|
|
}
|
|
|
|
// pos message to window
|
|
if( GetSafeHwnd() )
|
|
::PostMessage( GetSafeHwnd(), WM_VIDEO_SAMPLE, (WPARAM)( SampleTime * 1000000.0 ), 0 );
|
|
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDDVideoWnd::OnVideoSample"), _T("Done...") );
|
|
}
|
|
|
|
LRESULT CDDVideoWnd::OnVideoSample( WPARAM wParam, LPARAM )
|
|
{
|
|
GetVideoBase()->UpdateDemo( this, wParam / 1000000.0 );
|
|
InvalidateRect( NULL );
|
|
return 0;
|
|
}
|
|
|
|
void CDDVideoWnd::OnLButtonDown( UINT nFlags, CPoint point )
|
|
{
|
|
// call base class
|
|
CVideoCaptureWnd::OnLButtonDown( nFlags, point );
|
|
|
|
// ASSERT( GetVideoBase() );
|
|
// GetVideoBase()->SetControlledVideo( this );
|
|
}
|
|
|
|
void CDDVideoWnd::OnChangeSettings()
|
|
{
|
|
if( m_hFont )
|
|
::DeleteObject( m_hFont );
|
|
|
|
m_hFont = ::CreateFontIndirect( &m_pSensorArray->GetProgramSettings().LogFontVideo );
|
|
|
|
InvalidateRect( NULL );
|
|
}
|