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.
468 lines
12 KiB
468 lines
12 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: VideoFrameGrabberWnd.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of VideoFrameGrabberWnd.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "..\LgLib\Version.h"
|
|
/*
|
|
#include "VideoFrameGrabberWnd.h"
|
|
|
|
#define VIDEO_NTSC
|
|
|
|
CVideoFrameGrabberWnd::CVideoFrameGrabberWnd()
|
|
{
|
|
m_hFrameGrabberWnd = NULL;
|
|
m_hFrameGrabberMemDC = NULL;
|
|
m_hFrameGrabberMemBitmap = NULL;
|
|
m_pFrameGrabberBuffer = NULL;
|
|
m_pFrameGrabberBmi = NULL;
|
|
::InitializeCriticalSection( &m_CriticalSection );
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoFrameGrabberWnd::CVideoFrameGrabberWnd" );
|
|
}
|
|
|
|
CVideoFrameGrabberWnd::~CVideoFrameGrabberWnd()
|
|
{
|
|
if( m_hFrameGrabberMemDC )
|
|
::DeleteDC( m_hFrameGrabberMemDC );
|
|
if( m_hFrameGrabberMemBitmap )
|
|
::DeleteObject( m_hFrameGrabberMemBitmap );
|
|
// if( m_pFrameGrabberBuffer )
|
|
// delete m_pFrameGrabberBuffer;
|
|
if( m_pFrameGrabberBmi )
|
|
delete m_pFrameGrabberBmi;
|
|
::DeleteCriticalSection( &m_CriticalSection );
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoFrameGrabberWnd::~CVideoFrameGrabberWnd" );
|
|
}
|
|
|
|
BOOL CVideoFrameGrabberWnd::Create( HWND hParent, LPPOINT pPoint, LPSIZE pSize )
|
|
{
|
|
POINT p = {0,0};
|
|
SIZE s = {1,1};
|
|
|
|
if( !pPoint ) pPoint = &p;
|
|
if( !pSize ) pSize = &s;
|
|
|
|
WNDCLASS wc;
|
|
wc.cbClsExtra = NULL;
|
|
wc.cbWndExtra = NULL;
|
|
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
|
|
wc.hCursor = NULL;
|
|
wc.hIcon = NULL;
|
|
wc.hInstance = (HINSTANCE)::GetWindowLong( hParent, GWL_HINSTANCE );
|
|
wc.lpfnWndProc = WindowProc_;
|
|
wc.lpszClassName = "Video Frame Grabber Wnd";
|
|
wc.lpszMenuName = NULL;
|
|
wc.style = CS_HREDRAW | CS_HREDRAW;
|
|
|
|
if( !::RegisterClass( &wc ) )
|
|
return FALSE;
|
|
|
|
m_hFrameGrabberWnd = ::CreateWindow( wc.lpszClassName, "", WS_CHILD, 0, 0, 1, 1, hParent, NULL, wc.hInstance, this );
|
|
if( !m_hFrameGrabberWnd )
|
|
return FALSE;
|
|
|
|
HDC hDC = ::GetDC( m_hFrameGrabberWnd );
|
|
if( !hDC )
|
|
return FALSE;
|
|
|
|
m_hFrameGrabberMemDC = ::CreateCompatibleDC( hDC );
|
|
if( !m_hFrameGrabberMemDC )
|
|
return FALSE;
|
|
|
|
// m_hFrameGrabberMemBitmap = ::CreateCompatibleBitmap( hDC, IMAGE_WIDTH, IMAGE_HEIGHT );
|
|
// if( !m_hFrameGrabberMemBitmap )
|
|
// return FALSE;
|
|
|
|
// m_pFrameGrabberBuffer = new BYTE[ dwImageSize ];
|
|
// if( !m_pFrameGrabberBuffer )
|
|
// return FALSE;
|
|
|
|
#ifndef VIDEO_NTSC
|
|
|
|
DWORD dwImageSize = IMAGE_WIDTH * IMAGE_HEIGHT * 2;
|
|
|
|
m_pFrameGrabberBmi = (LPBITMAPINFO)new BYTE[ sizeof( BITMAPINFO ) ];
|
|
if( !m_pFrameGrabberBmi )
|
|
return FALSE;
|
|
|
|
m_pFrameGrabberBmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
m_pFrameGrabberBmi->bmiHeader.biWidth = IMAGE_WIDTH;
|
|
m_pFrameGrabberBmi->bmiHeader.biHeight = -IMAGE_HEIGHT;
|
|
m_pFrameGrabberBmi->bmiHeader.biPlanes = 1;
|
|
m_pFrameGrabberBmi->bmiHeader.biBitCount = 16;
|
|
m_pFrameGrabberBmi->bmiHeader.biCompression = BI_RGB;
|
|
m_pFrameGrabberBmi->bmiHeader.biSizeImage = dwImageSize;
|
|
m_pFrameGrabberBmi->bmiHeader.biXPelsPerMeter = 0;
|
|
m_pFrameGrabberBmi->bmiHeader.biYPelsPerMeter = 0;
|
|
m_pFrameGrabberBmi->bmiHeader.biClrUsed = 0;
|
|
m_pFrameGrabberBmi->bmiHeader.biClrImportant = 0;
|
|
|
|
#else
|
|
|
|
DWORD dwImageSize = IMAGE_WIDTH * IMAGE_HEIGHT;
|
|
|
|
m_pFrameGrabberBmi = (LPBITMAPINFO)new BYTE[ sizeof( BITMAPINFO ) + sizeof(RGBQUAD) * (1<<8) ];
|
|
if( !m_pFrameGrabberBmi )
|
|
return FALSE;
|
|
|
|
m_pFrameGrabberBmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
m_pFrameGrabberBmi->bmiHeader.biWidth = IMAGE_WIDTH;
|
|
m_pFrameGrabberBmi->bmiHeader.biHeight = -IMAGE_HEIGHT;
|
|
m_pFrameGrabberBmi->bmiHeader.biPlanes = 1;
|
|
m_pFrameGrabberBmi->bmiHeader.biBitCount = 8;
|
|
m_pFrameGrabberBmi->bmiHeader.biCompression = BI_RGB;
|
|
m_pFrameGrabberBmi->bmiHeader.biSizeImage = dwImageSize;
|
|
m_pFrameGrabberBmi->bmiHeader.biXPelsPerMeter = 0;
|
|
m_pFrameGrabberBmi->bmiHeader.biYPelsPerMeter = 0;
|
|
m_pFrameGrabberBmi->bmiHeader.biClrUsed = 0;
|
|
m_pFrameGrabberBmi->bmiHeader.biClrImportant = 0;
|
|
|
|
for( int i = 0; i < (1<<8); i++ )
|
|
{
|
|
m_pFrameGrabberBmi->bmiColors[i].rgbRed = i;
|
|
m_pFrameGrabberBmi->bmiColors[i].rgbBlue = i;
|
|
m_pFrameGrabberBmi->bmiColors[i].rgbGreen = i;
|
|
m_pFrameGrabberBmi->bmiColors[i].rgbReserved = 0;
|
|
}
|
|
|
|
#endif
|
|
|
|
m_hFrameGrabberMemBitmap = ::CreateDIBSection( 0, m_pFrameGrabberBmi, DIB_RGB_COLORS, (void**)&m_pFrameGrabberBuffer, NULL, 0 );
|
|
if( !m_hFrameGrabberMemBitmap )
|
|
return FALSE;
|
|
|
|
::ShowWindow( m_hFrameGrabberWnd, SW_SHOW );
|
|
::UpdateWindow( m_hFrameGrabberWnd );
|
|
|
|
InitSnapshot();
|
|
|
|
// ::SetTimer( m_hFrameGrabberWnd, 4, 500, NULL );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
LRESULT CALLBACK CVideoFrameGrabberWnd::WindowProc_( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
LPCREATESTRUCT pCreateStruct;
|
|
|
|
switch( uMsg )
|
|
{
|
|
case WM_CREATE:
|
|
pCreateStruct = (LPCREATESTRUCT)lParam;
|
|
::SetWindowLong( hWnd, GWL_USERDATA, (LONG)pCreateStruct->lpCreateParams );
|
|
break;
|
|
}
|
|
|
|
CVideoFrameGrabberWnd *pThis = (CVideoFrameGrabberWnd*)::GetWindowLong( hWnd, GWL_USERDATA );
|
|
if( pThis )
|
|
return pThis->WindowProc( hWnd, uMsg, wParam, lParam );
|
|
|
|
return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
|
|
}
|
|
|
|
LRESULT CVideoFrameGrabberWnd::WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
switch( uMsg )
|
|
{
|
|
case WM_TIMER:
|
|
return OnTimer( hWnd, wParam, lParam );
|
|
case WM_PAINT:
|
|
return OnPaint( hWnd, wParam, lParam );
|
|
}
|
|
return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
|
|
}
|
|
|
|
void CVideoFrameGrabberWnd::UpdatePositions()
|
|
{
|
|
::UpdateWindow( m_hFrameGrabberWnd );
|
|
}
|
|
|
|
HWND CVideoFrameGrabberWnd::GetSafeHwnd()
|
|
{
|
|
return m_hFrameGrabberWnd;
|
|
}
|
|
|
|
BOOL CVideoFrameGrabberWnd::ShowWindow( int nShow )
|
|
{
|
|
::ShowWindow( m_hFrameGrabberWnd, nShow );
|
|
return TRUE;
|
|
}
|
|
|
|
HBITMAP CVideoFrameGrabberWnd::StoreImage( HANDLE hFile, LPCTSTR pText, INT nBitCount )
|
|
{
|
|
volatile static BOOL fInside = FALSE;
|
|
HBITMAP fSuccess = NULL;
|
|
|
|
if(!fInside)
|
|
{
|
|
fInside = TRUE;
|
|
|
|
if(hFile)
|
|
{
|
|
#ifndef VIDEO_NTSC
|
|
|
|
LPBYTE lpDIBByte = GetSafeBytes();
|
|
LPBYTE lpDst = GetSafeBytes();
|
|
|
|
struct RGB16
|
|
{
|
|
unsigned short rgbRed : 5;
|
|
unsigned short rgbGreen : 5;
|
|
unsigned short rgbBlue : 5;
|
|
};
|
|
|
|
RGB16 *lpSrc = (RGB16*)m_pFrameGrabberBuffer;
|
|
lpSrc += IMAGE_HEIGHT * IMAGE_WIDTH - 1;
|
|
|
|
int lenDst = WIDTHBYTES(GetSafeBmi().bmiHeader.biWidth * 8);
|
|
int lenSrc = IMAGE_WIDTH;
|
|
|
|
for(int y = 0; y < GetSafeBmi().bmiHeader.biHeight; y++, lpDst += lenDst, lpSrc -= lenSrc)
|
|
{
|
|
LPBYTE pDst = lpDst;
|
|
RGB16 *pSrc = lpSrc;
|
|
|
|
for(int x = 0; x < lenDst && x < IMAGE_WIDTH; x++, pSrc -- )
|
|
{
|
|
*pDst++ = (BYTE)((pSrc->rgbBlue ) + (pSrc->rgbGreen << 2) + (pSrc->rgbRed << 1) + 33 );
|
|
}
|
|
}
|
|
|
|
#else
|
|
ZeroMemory( GetSafeBytes(), GetSafeBmi().bmiHeader.biSizeImage );
|
|
|
|
LPBYTE lpDIBByte = GetSafeBytes();
|
|
LPBYTE lpDst = GetSafeBytes();
|
|
|
|
LPBYTE lpSrc = (LPBYTE)m_pFrameGrabberBuffer;
|
|
lpSrc += IMAGE_HEIGHT * IMAGE_WIDTH - 1;
|
|
|
|
int lenDst = WIDTHBYTES(GetSafeBmi().bmiHeader.biWidth * 8);
|
|
int lenSrc = IMAGE_WIDTH;
|
|
|
|
int xShift = (lenDst - lenSrc) >> 1;
|
|
int yShift = (GetSafeBmi().bmiHeader.biHeight - IMAGE_HEIGHT) >> 1;
|
|
|
|
lpDst += xShift + yShift * lenDst;
|
|
|
|
int xMin = lenDst < IMAGE_WIDTH ? lenDst : IMAGE_WIDTH;
|
|
int yMin = GetSafeBmi().bmiHeader.biHeight < IMAGE_HEIGHT ? GetSafeBmi().bmiHeader.biHeight : IMAGE_HEIGHT;
|
|
|
|
for(int y = 0; y < yMin; y++, lpDst += lenDst, lpSrc -= lenSrc)
|
|
{
|
|
LPBYTE pDst = lpDst;
|
|
LPBYTE pSrc = lpSrc;
|
|
|
|
for(int x = 0; x < xMin; x++ )
|
|
{
|
|
*pDst++ = *pSrc++;
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
DrawText8( &GetSafeBmi(), GetSafeBytes(), pText );
|
|
|
|
DWORD dwWritten;
|
|
|
|
::WriteFile(hFile, GetSafeBytes(), WIDTHBYTES(GetSafeBmi().bmiHeader.biWidth * 8) *
|
|
GetSafeBmi().bmiHeader.biHeight, &dwWritten, NULL);
|
|
|
|
LPBYTE pBytes = NULL;
|
|
fSuccess = ::CreateDIBSection( NULL, &GetSafeBmi(), DIB_RGB_COLORS, (void**)&pBytes, NULL, 0 );
|
|
if( pBytes )
|
|
CopyMemory( pBytes, GetSafeBytes(), GetSafeBmi().bmiHeader.biSizeImage );
|
|
} // end of if(m_IsInitiated && hFile)
|
|
|
|
fInside = FALSE;
|
|
} // end of if(!fInside)
|
|
|
|
return fSuccess;
|
|
}
|
|
|
|
HBITMAP CVideoFrameGrabberWnd::GetSnapshot()
|
|
{
|
|
Snapshot();
|
|
|
|
return (HBITMAP)::CopyImage( m_hFrameGrabberMemBitmap, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG | LR_CREATEDIBSECTION );
|
|
}
|
|
|
|
LRESULT CVideoFrameGrabberWnd::OnTimer( HWND hWnd, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
if( ::IsWindowVisible( m_hFrameGrabberWnd ) )
|
|
{
|
|
Snapshot();
|
|
|
|
HDC hDC = ::GetDC( hWnd );
|
|
|
|
Draw( hDC );
|
|
|
|
::ReleaseDC( hWnd, hDC );
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CVideoFrameGrabberWnd::UpdateFrame()
|
|
{
|
|
OnTimer( m_hFrameGrabberWnd, 0, 0 );
|
|
}
|
|
|
|
LRESULT CVideoFrameGrabberWnd::OnPaint( HWND hWnd, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
PAINTSTRUCT ps;
|
|
HDC hDC = ::BeginPaint( hWnd, &ps );
|
|
Draw( hDC );
|
|
::EndPaint( hWnd, &ps );
|
|
return TRUE;
|
|
}
|
|
|
|
void CVideoFrameGrabberWnd::Draw( HDC hDC )
|
|
{
|
|
HBITMAP hBitmap = (HBITMAP)::SelectObject( m_hFrameGrabberMemDC, m_hFrameGrabberMemBitmap );
|
|
|
|
int nMode = ::SetStretchBltMode( hDC, COLORONCOLOR );
|
|
|
|
RECT rect;
|
|
::GetClientRect( m_hFrameGrabberWnd, &rect );
|
|
|
|
// ::StretchBlt( hDC, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
|
|
// m_hFrameGrabberMemDC, 0, IMAGE_HEIGHT-1, IMAGE_WIDTH, -IMAGE_HEIGHT, SRCCOPY );
|
|
::StretchBlt( hDC, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
|
|
m_hFrameGrabberMemDC, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, SRCCOPY );
|
|
// ::BitBlt( hDC, ((rect.right - rect.left) - IMAGE_WIDTH) >> 1,
|
|
// ((rect.bottom - rect.top) - IMAGE_HEIGHT) >> 1, IMAGE_WIDTH, IMAGE_HEIGHT, m_hFrameGrabberMemDC, 0, 0, SRCCOPY );
|
|
|
|
::SetStretchBltMode( hDC, nMode );
|
|
|
|
::SelectObject( m_hFrameGrabberMemDC, hBitmap );
|
|
}
|
|
|
|
void CVideoFrameGrabberWnd::Snapshot()
|
|
{
|
|
::EnterCriticalSection( &m_CriticalSection );
|
|
|
|
const short nWidth = IMAGE_WIDTH;
|
|
const short nHeight = IMAGE_HEIGHT;
|
|
#ifndef VIDEO_NTSC
|
|
const unsigned int nSize = IMAGE_WIDTH * IMAGE_HEIGHT;
|
|
#else
|
|
const unsigned int nSize = IMAGE_WIDTH * IMAGE_HEIGHT / 2;
|
|
#endif
|
|
unsigned int pBufferPtr = (unsigned int )m_pFrameGrabberBuffer;
|
|
|
|
_asm
|
|
{
|
|
mov ax,9209h
|
|
mov bx,54
|
|
int 60h ;acquire
|
|
cld
|
|
mov edi,pBufferPtr
|
|
mov ecx,nSize
|
|
rep insw ;fill buffer with image data
|
|
}
|
|
|
|
::LeaveCriticalSection( &m_CriticalSection );
|
|
}
|
|
|
|
void CVideoFrameGrabberWnd::InitSnapshot()
|
|
{
|
|
::EnterCriticalSection( &m_CriticalSection );
|
|
|
|
const short nWidth = IMAGE_WIDTH;
|
|
const short nHeight = IMAGE_HEIGHT;
|
|
#ifndef VIDEO_NTSC
|
|
const unsigned int nSize = IMAGE_WIDTH * IMAGE_HEIGHT;
|
|
#else
|
|
const unsigned int nSize = IMAGE_WIDTH * IMAGE_HEIGHT / 2;
|
|
#endif
|
|
unsigned int pBufferPtr = (unsigned int )m_pFrameGrabberBuffer;
|
|
_asm
|
|
{
|
|
mov ax,9209h
|
|
mov bx,0
|
|
int 60h ;init driver
|
|
|
|
mov ax,9209h
|
|
mov bx,41 ;default baseaddr abfragen
|
|
int 60h
|
|
mov ax,9209h
|
|
mov bx,9
|
|
// mov cx,300h ;oder basisadresse direkt setzen
|
|
int 60h
|
|
|
|
#ifdef VIDEO_NTSC
|
|
mov ax,9209h
|
|
mov bx,30 ;get XRAM
|
|
mov cx,15 ;127/8
|
|
int 60h
|
|
mov ax,9209h
|
|
mov bx,7 ;set XRAM
|
|
mov cx,15 ;127/8
|
|
and dl,3Fh ; clear 126,127 bits
|
|
// or dl,80h ; set 10 in 126,127 bits
|
|
int 60h
|
|
#endif
|
|
|
|
mov ax,9209h
|
|
mov bx,8 ;init fg32
|
|
int 60h
|
|
|
|
#ifdef VIDEO_NTSC
|
|
|
|
mov ax, 9209h
|
|
mov bx,47
|
|
int 60h
|
|
|
|
cld
|
|
mov eax, 310h
|
|
mov edi,pBufferPtr
|
|
mov ecx,2
|
|
rep insw ;fill buffer with image data
|
|
#endif
|
|
|
|
mov ax,9209h
|
|
mov bx,50
|
|
mov cx,nWidth
|
|
mov dx,nHeight
|
|
int 60h ;384x288
|
|
|
|
mov ax,9209h
|
|
mov bx,51
|
|
mov cx,0
|
|
mov dx,0
|
|
int 60h ;@0,0
|
|
|
|
mov ax,9209h
|
|
mov bx,52
|
|
#ifndef VIDEO_NTSC
|
|
mov cx,72bbh
|
|
#else
|
|
mov cx,72b2h
|
|
#endif
|
|
mov dx,2
|
|
int 60h ;5+5+5 bit / pixel scan for: ungerades bild aus 2 halbbildern
|
|
|
|
mov ax,9209h
|
|
mov bx,53
|
|
int 60h ;acquire
|
|
cld
|
|
mov edi,pBufferPtr
|
|
mov ecx,nSize
|
|
rep insw ;fill buffer with image data
|
|
}
|
|
|
|
::LeaveCriticalSection( &m_CriticalSection );
|
|
}
|
|
*/
|