www.pudn.com > Gesture[20040824].rar > CamAvi.cpp


// CamAvi.cpp: implementation of the CCamAvi class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "CamAvi.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
bool CCamAvi::Initialize (const char* filename) 
{ 
	m_init = this->Open(filename); 
	if(GetVideoStreamCount() == 0) 
		return false ; 
	 
	VERIFY(StartVideoRetrieve(0)); 
     
	ASSERT(m_frame == NULL);//liu 
	m_frame = new CImage;    // liu 
    m_frame->Create(m_pVideoFormats[0]->bmiHeader.biWidth,m_pVideoFormats[0]->bmiHeader.biHeight,m_pVideoFormats[0]->bmiHeader.biBitCount);//liu 
	m_length = 	AVIStreamEnd(m_pVideoStreams[0]); //liu 
 
	return m_init; 
} 
 
void CCamAvi::Uninitialize () 
{	EndVideoRetrieve(0); 
	Release(); 
	delete m_frame ; // liu 
    m_frame = NULL ; // liu 
	m_length = -1; // liu 
 
	m_init = false; 
	return; 
} 
 
CCamAvi::CCamAvi() 
{ 
	m_frame = NULL ; //liu 
	m_pos = -1; 
	m_init = false; 
	 
} 
 
CCamAvi::~CCamAvi () 
{  
} 
 
void CCamAvi::GetFrameFromAvi() 
{ 
GetFrameImg(m_pos); 
} 
 
void CCamAvi::SetReaderPosition(int pos) 
{ 
	m_pos = pos%m_length; 
} 
 
void CCamAvi::NextFrame() 
{ 
	m_pos = (m_pos+1)%m_length; 
} 
 
void CCamAvi::PrevFrame() 
{ 
	m_pos = (m_pos-1)%m_length; 
} 
 
bool CCamAvi::IsEndOfAVI() 
{ 
	if ( m_pos==m_length-1 ) return true; 
	return false; 
} 
 
bool CCamAvi::IsBeginOfAVI() 
{ 
	if ( m_pos==0 ) return true; 
	return false; 
} 
 
CImage * CCamAvi::GetFramePointer() 
{ 
 	return m_frame; 
} 
 
CImage * CCamAvi::GetFrameImg(int frame) 
{ 
	LPBITMAPINFOHEADER pBmp; 
	GetVideoFrame(0,frame, &pBmp); 
	if( pBmp == NULL ) return NULL; 
	fm = frame; 
    iplConvertFromDIB(pBmp, m_frame->GetImage()); 
	return m_frame; 
} 
 
bool CCamAvi::IsAviInitialized() 
{ 
return m_init; 
} 
 
CSize CCamAvi::GetAviSize() 
{ 
BITMAPINFO*	a=(BITMAPINFO*)m_pVideoFormats[0]; 
return CSize(a->bmiHeader.biWidth,a->bmiHeader.biHeight); 
 
} 
 
CImage* CCamAvi::GetCurrFramePointer() 
{ 
return m_frame; 
} 
 
void CCamAvi::AdvanceFrame(int direction) 
{ 
	m_pos += direction; 
	if ( m_pos>=m_length ) 
		m_pos = 0; 
	if ( m_pos<0 ) 
		m_pos = m_length-1; 
	GetFrameFromAvi(); 
} 
 
void CCamAvi::GetCurrFrame() 
{ 
GetFrameFromAvi(); 
}