Copie de Video.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #include "Video.h"
  2. Video::Video()
  3. : m_width( 0 ),
  4. m_height( 0 ),
  5. #if defined( WIN32 ) && !defined( IMT_DLL )
  6. m_deltaW( 0 ),
  7. m_deltaH( 0 ),
  8. #endif
  9. m_resX( 1.0 ),
  10. m_resY( 1.0 )
  11. {
  12. }
  13. Video::~Video()
  14. {
  15. Clear();
  16. }
  17. unsigned long Video::GetWidth()
  18. {
  19. #if defined( WIN32 ) && !defined( IMT_DLL )
  20. return m_width + m_deltaW;
  21. #else
  22. return m_width;
  23. #endif
  24. }
  25. unsigned long Video::GetHeight()
  26. {
  27. #if defined( WIN32 ) && !defined( IMT_DLL )
  28. return m_height + m_deltaH;
  29. #else
  30. return m_height;
  31. #endif
  32. }
  33. void Video::SetSize( unsigned long width, unsigned long height )
  34. {
  35. #if defined( WIN32 ) && !defined( IMT_DLL )
  36. m_deltaW = 0;
  37. m_deltaH = 0;
  38. if ( ( (float)height / (float)width ) > 0.75 )
  39. {
  40. while ( ( (float)height / (float)( width + m_deltaW ) ) > 0.75f )
  41. {
  42. m_deltaW++;
  43. }
  44. }
  45. else
  46. {
  47. while ( ( (float)( height + m_deltaH ) / (float)width ) < 0.75f )
  48. {
  49. m_deltaH++;
  50. }
  51. }
  52. #endif
  53. m_width = width;
  54. m_height = height;
  55. }
  56. void Video::SetResolution( double resX, double resY )
  57. {
  58. m_resX = resX;
  59. m_resY = resY;
  60. }
  61. ExtendedImage* Video::GetFrame( unsigned int i )
  62. {
  63. if ( i < m_frames.size() )
  64. {
  65. return m_frames[ i ];
  66. }
  67. return NULL;
  68. }
  69. #if defined( WIN32 ) && !defined( IMT_DLL )
  70. HBITMAP Video::GetFrameBitmap( unsigned int i )
  71. #else
  72. char* Video::GetFrameBitmap( unsigned int i )
  73. #endif
  74. {
  75. if ( i < m_frames.size() )
  76. {
  77. #if defined( WIN32 ) && !defined( IMT_DLL )
  78. return HBITMAP( *m_frames[ i ] );
  79. #else
  80. return m_frames[ i ]->GetBits();
  81. #endif
  82. }
  83. return NULL;
  84. }
  85. unsigned int Video::GetFrameCount()
  86. {
  87. return (unsigned int)m_frames.size();
  88. }
  89. void Video::AddFrame( unsigned char* data, bool isMonochrome )
  90. {
  91. if ( data )
  92. {
  93. ExtendedImage* image = new ExtendedImage;
  94. if ( image )
  95. {
  96. #if defined( WIN32 ) && !defined( IMT_DLL )
  97. if ( image->Create( m_width + m_deltaW, m_height + m_deltaH, 24 ) )
  98. {
  99. unsigned char* imgPtr = (unsigned char*)image->GetBits();
  100. int pitch = image->GetPitch();
  101. int ww = 3 * m_width;
  102. int h = m_height;
  103. if ( isMonochrome )
  104. {
  105. while ( h-- )
  106. {
  107. int w = m_width;
  108. unsigned char* ip = imgPtr;
  109. while ( w-- )
  110. {
  111. *ip++ = *data;
  112. *ip++ = *data;
  113. *ip++ = *data++;
  114. }
  115. imgPtr += pitch;
  116. }
  117. }
  118. else
  119. {
  120. while ( h-- )
  121. {
  122. int w = m_width;
  123. unsigned char* ip = imgPtr;
  124. while ( w-- )
  125. {
  126. *ip++ = *( data + 2 );
  127. *ip++ = *( data + 1 );
  128. *ip++ = *data;
  129. data += 3;
  130. }
  131. imgPtr += pitch;
  132. }
  133. }
  134. #else
  135. if ( image->Create( m_width, m_height, 24 ) )
  136. {
  137. unsigned char* l = (unsigned char*)image->GetBits();
  138. int n = m_width * m_height;
  139. if ( isMonochrome )
  140. {
  141. while ( n-- )
  142. {
  143. *l++ = *data;
  144. *l++ = *data;
  145. *l++ = *data++;
  146. }
  147. }
  148. else
  149. {
  150. while ( n-- )
  151. {
  152. *l++ = *( data + 2 );
  153. *l++ = *( data + 1 );
  154. *l++ = *data;
  155. data += 3;
  156. }
  157. }
  158. #endif
  159. m_frames.push_back( image );
  160. }
  161. }
  162. }
  163. }
  164. void Video::EraseFirstFrame()
  165. {
  166. m_frames.erase( m_frames.begin() );
  167. }
  168. bool Video::IsNull()
  169. {
  170. return ( m_frames.size() == 0 ) ? true : false;
  171. }
  172. void Video::Clear()
  173. {
  174. std::vector< ExtendedImage* >::iterator
  175. f = m_frames.begin(),
  176. fe = m_frames.end();
  177. while ( f != fe )
  178. {
  179. if ( !(*f)->IsNull() )
  180. {
  181. (*f)->Destroy();
  182. }
  183. delete *f;
  184. ++f;
  185. }
  186. m_frames.clear();
  187. }