| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- #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();
- }
|