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.
 
 
 
 
 

297 lines
7.8 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 24/03/2000
// Last modification: 08/10/2003
// Project Intruder Position Indicator
// SUBSYSTEM: Video camera showing and captiring window
// FILE: VideoDirectShowWnd.cpp
// AUTHOR: Chizhevskiy Sergey
// OVERVIEW
// ~~~~~~~~
// Source file for implementation of class CVideoDirectShowWnd
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "..\LgLib\Version.h"
#include "..\lglib\video\DirectShowStreamVideo.h"
#include "VideoDirectShowWnd.h"
#include "Application.h"
CVideoDirectShowWnd::CVideoDirectShowWnd()
{
m_dwTime = 0;
m_nCount = 0;
m_nLastCount = 0;
m_bStretchVideo = TRUE;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoDirectShowWnd::CVideoDirectShowWnd" );
}
CVideoDirectShowWnd::~CVideoDirectShowWnd()
{
CVideoWnd::DestroyWindow();
CDirectShowVideo::Unlink();
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoDirectShowWnd::~CVideoDirectShowWnd" );
}
BOOL CVideoDirectShowWnd::Create( BOOL bStretchVideo, HWND hParentWnd, INT x, INT y, INT cx, INT cy, CProfile *pProfile )
{
if( !CVideoWnd::Create( bStretchVideo, hParentWnd, x, y, cx, cy, pProfile ) )
{
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CVideoDirectShowWnd::Create"), _T("CVideoWnd::Create failed") );
return FALSE;
}
HINSTANCE hInstance = (HINSTANCE)::GetWindowLong(hParentWnd, GWL_HINSTANCE);
LPCTSTR pClassName = _T("DirectShowVideoWnd");
m_bStretchVideo = bStretchVideo;
if( !CGenericWnd::GetClassInfoEx( hInstance, pClassName, NULL ) )
{
if( !CVideoWnd::RegisterClass( pClassName, hInstance ) )
return FALSE;
}
if( !CGenericWnd::Create( pClassName, NULL, WS_CHILD, x, y, cx, cy, hParentWnd, NULL, hInstance ) )
return FALSE;
ShowWindow( SW_SHOW );
UpdateWindow();
return TRUE;
}
LRESULT CVideoDirectShowWnd::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_VIDEO_SAMPLE:
return OnVideoSample( wParam, lParam );
}
return CVideoWnd::WindowProc( uMsg, wParam, lParam );
}
HBITMAP CVideoDirectShowWnd::StoreImage( HANDLE hFile, LPCTSTR pBuffer, INT nWidth, INT nHeight, INT nBitCount )
{
LPBITMAPINFO pSrcBmi = NULL;
// get current bitmap
HBITMAP hBitmap = GetDirectShowDIB().CreateBitmap( &pSrcBmi, NULL );
if( !hBitmap )
return NULL;
// prepare bitmap info
BITMAPINFO bmi = *pSrcBmi;
LPBITMAPINFO pBmi = &bmi;
pBmi->bmiHeader.biBitCount = 24;
pBmi->bmiHeader.biWidth = nWidth;
pBmi->bmiHeader.biHeight = nHeight;
pBmi->bmiHeader.biSizeImage = WIDTHBYTES( pBmi->bmiHeader.biWidth * pBmi->bmiHeader.biBitCount ) * pBmi->bmiHeader.biHeight;
// streatch bitmap as nessessary
if( !m_StoreDIB.Create( hBitmap, pBmi ) )
return NULL;
PBYTE pBytes = m_StoreDIB;
// draw text into bitmap
if( nBitCount == 8 )
{
int lenDst = WIDTHBYTES( pBmi->bmiHeader.biWidth * 8 );
int lenSrc = WIDTHBYTES( pBmi->bmiHeader.biWidth * pBmi->bmiHeader.biBitCount );
LPBYTE lpDst = pBytes;
LPBYTE lpSrc = pBytes;
for(int y = 0; y < pBmi->bmiHeader.biHeight; y++, lpDst += lenDst, lpSrc += lenSrc )
{
LPBYTE pDst = lpDst;
LPBYTE pSrc = lpSrc;
for(int x = 0; x < lenDst; x++, pSrc += 3)
*pDst++ = (BYTE)((pSrc[0] >>3 ) + (pSrc[1] >> 1) + (pSrc[2] >> 2) + 33);
}
DrawText8( pBmi, pBytes, pBuffer );
}
else
if( nBitCount == 24 )
{
DrawText24( pBmi, pBytes, pBuffer );
}
DWORD dwWritten;
::WriteFile(hFile, pBytes, WIDTHBYTES( pBmi->bmiHeader.biWidth * nBitCount ) * pBmi->bmiHeader.biHeight, &dwWritten, NULL);
return hBitmap;
}
HBITMAP CVideoDirectShowWnd::StoreImage( LPBYTE pDstBytes, LPCTSTR pBuffer, INT nWidth, INT nHeight, INT nBitCount )
{
LPBITMAPINFO pSrcBmi = NULL;
GetDirectShowDIB().Save( "e:\\test.bmp" );
// get current bitmap
HBITMAP hBitmap = GetDirectShowDIB().CreateBitmap( &pSrcBmi, NULL );
if( !hBitmap )
return NULL;
// prepare bitmap info
BITMAPINFO bmi = *pSrcBmi;
LPBITMAPINFO pBmi = &bmi;
pBmi->bmiHeader.biBitCount = 24;
pBmi->bmiHeader.biWidth = nWidth;
pBmi->bmiHeader.biHeight = nHeight;
pBmi->bmiHeader.biSizeImage = WIDTHBYTES( pBmi->bmiHeader.biWidth * pBmi->bmiHeader.biBitCount ) * pBmi->bmiHeader.biHeight;
// streatch bitmap as nessessary
if( !m_StoreDIB.Create( hBitmap, pBmi ) )
return NULL;
PBYTE pBytes = m_StoreDIB;
// draw text into bitmap
if( nBitCount == 8 )
{
int lenDst = WIDTHBYTES( pBmi->bmiHeader.biWidth * 8 );
int lenSrc = WIDTHBYTES( pBmi->bmiHeader.biWidth * pBmi->bmiHeader.biBitCount );
LPBYTE lpDst = pBytes;
LPBYTE lpSrc = pBytes;
for(int y = 0; y < pBmi->bmiHeader.biHeight; y++, lpDst += lenDst, lpSrc += lenSrc )
{
LPBYTE pDst = lpDst;
LPBYTE pSrc = lpSrc;
for(int x = 0; x < lenDst; x++, pSrc += 3)
*pDst++ = (BYTE)((pSrc[0] >>3 ) + (pSrc[1] >> 1) + (pSrc[2] >> 2) + 33);
}
DrawText8( pBmi, pBytes, pBuffer );
}
else
if( nBitCount == 24 )
{
DrawText24( pBmi, pBytes, pBuffer );
}
memcpy( pDstBytes, pBytes, WIDTHBYTES( pBmi->bmiHeader.biWidth * nBitCount ) * pBmi->bmiHeader.biHeight );
return hBitmap;
}
HBITMAP CVideoDirectShowWnd::GetSnapshot()
{
return GetDirectShowDIB().CreateBitmap( NULL, NULL );
}
LRESULT CVideoDirectShowWnd::OnShowWindow( WPARAM wParam, LPARAM lParam )
{
CDirectShowVideo::ShowVideo( wParam );
return CVideoWnd::OnShowWindow( wParam, lParam );
}
void CVideoDirectShowWnd::OnVideoSample( double SampleTime )
{
if( IsWindow() )
PostMessage( WM_VIDEO_SAMPLE, 0, 0 );
}
LRESULT CVideoDirectShowWnd::OnVideoSample( WPARAM, LPARAM )
{
if( !OnRemoteVideo( &GetDirectShowDIB(), 0 ) )
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CVideoDirectShowWnd::OnVideoSample"), _T("OnRemoteVideo failed") );
if( IsWindow() )
{
BOOL bInvalidate = FALSE;
if( ::GetSystemMetrics( SM_REMOTESESSION ) )
{
DWORD dwTime = GetTickCount();
if( m_dwTime <= dwTime )
{
m_dwTime = dwTime + 500UL;
bInvalidate = TRUE;
}
}
else
bInvalidate = TRUE;
if( bInvalidate )
InvalidateRect( NULL, FALSE );
}
return 0;
}
LRESULT CVideoDirectShowWnd::OnDestroy( WPARAM wParam, LPARAM lParam )
{
// unlink from direct show
CDirectShowVideo::Unlink();
// direct draw update
CLgDirectDrawVideo::OnDestroy();
return 0;
}
LRESULT CVideoDirectShowWnd::OnSize( WPARAM wParam, LPARAM lParam )
{
// direct draw update
if( !CLgDirectDrawVideo::OnSize( GetSafeHwnd() ) )
{
RECT rect;
GetClientRect( &rect );
HDC hDC = GetDC();
HBRUSH hBrush = CreateSolidBrush( RGB(0,0,0) );
::FillRect( hDC, &rect, hBrush );
::DeleteObject( hBrush );
ReleaseDC( hDC );
}
return 0;
}
void CVideoDirectShowWnd::OnPaint( HDC hDC )
{
RECT rect;
GetClientRect( &rect );
if( GetSystemMetrics( SM_REMOTESESSION ) )
{
TCHAR pText[] = _T("Remote Desktop detected");
INT nBkMode = ::SetBkMode( hDC, TRANSPARENT );
COLORREF cTextColor = ::SetTextColor( hDC, RGB(255,0,0) );
::DrawText( hDC, pText, _tcslen(pText), &rect, DT_CENTER );
::SetTextColor( hDC, cTextColor );
::SetBkMode( hDC, nBkMode );
INT nSmallWidth = 64;
INT nSmallHeight = 64;
INT nWidth = rect.right - rect.left;
INT nHeight = rect.bottom - rect.top;
SetRect( &rect, (nWidth - nSmallWidth) / 2, (nHeight - nSmallHeight) / 2,
(nWidth + nSmallWidth) / 2, (nHeight + nSmallHeight) / 2 );
GetDirectShowDIB().Draw( hDC, &rect, m_bStretchVideo );
}
else
// direct draw update
if( !CLgDirectDrawVideo::OnPaint( m_bStretchVideo ) )
{
GetDirectShowDIB().Draw( hDC, &rect, m_bStretchVideo );
}
}