#include "Video.h" Video::Video() : m_width( 0 ), m_height( 0 ), #if defined( WIN32 ) && !defined( IMT_DLL ) m_deltaW( 0 ), m_deltaH( 0 ), #endif m_resX( 1.0 ), m_resY( 1.0 ) { } Video::~Video() { Clear(); } unsigned long Video::GetWidth() { #if defined( WIN32 ) && !defined( IMT_DLL ) return m_width + m_deltaW; #else return m_width; #endif } unsigned long Video::GetHeight() { #if defined( WIN32 ) && !defined( IMT_DLL ) return m_height + m_deltaH; #else return m_height; #endif } void Video::SetSize( unsigned long width, unsigned long height ) { #if defined( WIN32 ) && !defined( IMT_DLL ) m_deltaW = 0; m_deltaH = 0; if ( ( (float)height / (float)width ) > 0.75 ) { while ( ( (float)height / (float)( width + m_deltaW ) ) > 0.75f ) { m_deltaW++; } } else { while ( ( (float)( height + m_deltaH ) / (float)width ) < 0.75f ) { m_deltaH++; } } #endif m_width = width; m_height = height; } void Video::SetResolution( double resX, double resY ) { m_resX = resX; m_resY = resY; } ExtendedImage* Video::GetFrame( unsigned int i ) { if ( i < m_frames.size() ) { return m_frames[ i ]; } return NULL; } #if defined( WIN32 ) && !defined( IMT_DLL ) HBITMAP Video::GetFrameBitmap( unsigned int i ) #else char* Video::GetFrameBitmap( unsigned int i ) #endif { if ( i < m_frames.size() ) { #if defined( WIN32 ) && !defined( IMT_DLL ) return HBITMAP( *m_frames[ i ] ); #else return m_frames[ i ]->GetBits(); #endif } return NULL; } unsigned int Video::GetFrameCount() { return (unsigned int)m_frames.size(); } void Video::AddFrame( unsigned char* data, bool isMonochrome ) { if ( data ) { ExtendedImage* image = new ExtendedImage; if ( image ) { #if defined( WIN32 ) && !defined( IMT_DLL ) if ( image->Create( m_width + m_deltaW, m_height + m_deltaH, 24 ) ) { unsigned char* imgPtr = (unsigned char*)image->GetBits(); int pitch = image->GetPitch(); int ww = 3 * m_width; int h = m_height; if ( isMonochrome ) { while ( h-- ) { int w = m_width; unsigned char* ip = imgPtr; while ( w-- ) { *ip++ = *data; *ip++ = *data; *ip++ = *data++; } imgPtr += pitch; } } else { while ( h-- ) { int w = m_width; unsigned char* ip = imgPtr; while ( w-- ) { *ip++ = *( data + 2 ); *ip++ = *( data + 1 ); *ip++ = *data; data += 3; } imgPtr += pitch; } } #else if ( image->Create( m_width, m_height, 24 ) ) { unsigned char* l = (unsigned char*)image->GetBits(); int n = m_width * m_height; if ( isMonochrome ) { while ( n-- ) { *l++ = *data; *l++ = *data; *l++ = *data++; } } else { while ( n-- ) { *l++ = *( data + 2 ); *l++ = *( data + 1 ); *l++ = *data; data += 3; } } #endif m_frames.push_back( image ); } } } } void Video::EraseFirstFrame() { m_frames.erase( m_frames.begin() ); } bool Video::IsNull() { return ( m_frames.size() == 0 ) ? true : false; } void Video::Clear() { std::vector< ExtendedImage* >::iterator f = m_frames.begin(), fe = m_frames.end(); while ( f != fe ) { if ( !(*f)->IsNull() ) { (*f)->Destroy(); } delete *f; ++f; } m_frames.clear(); }