Video.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "Video.h"
  2. Video::Video()
  3. : m_width( 0 ),
  4. m_height( 0 ),
  5. m_resX( 1.0 ),
  6. m_resY( 1.0 )
  7. {
  8. }
  9. Video::~Video()
  10. {
  11. Clear();
  12. }
  13. unsigned long Video::GetWidth()
  14. {
  15. return m_width;
  16. }
  17. unsigned long Video::GetHeight()
  18. {
  19. return m_height;
  20. }
  21. void Video::SetSize( unsigned long width, unsigned long height )
  22. {
  23. m_width = width;
  24. m_height = height;
  25. }
  26. void Video::SetResolution( double resX, double resY )
  27. {
  28. m_resX = resX;
  29. m_resY = resY;
  30. }
  31. ExtendedImage* Video::GetFrame( unsigned int i )
  32. {
  33. if ( i < m_frames.size() )
  34. {
  35. return m_frames[ i ];
  36. }
  37. return NULL;
  38. }
  39. char* Video::GetFrameBitmap( unsigned int i )
  40. {
  41. if ( i < m_frames.size() )
  42. {
  43. return m_frames[ i ]->GetBuffer();
  44. }
  45. return NULL;
  46. }
  47. unsigned int Video::GetFrameCount()
  48. {
  49. return (unsigned int)m_frames.size();
  50. }
  51. void Video::AddFrame( unsigned char* data, bool isMonochrome )
  52. {
  53. if ( data )
  54. {
  55. ExtendedImage* image = new ExtendedImage;
  56. if ( image )
  57. {
  58. if ( image->Create( m_width, m_height, 24 ) )
  59. {
  60. unsigned char* l = (unsigned char*)image->GetBuffer();
  61. int n = m_width * m_height;
  62. if ( isMonochrome )
  63. {
  64. while ( n-- )
  65. {
  66. *l++ = *data;
  67. *l++ = *data;
  68. *l++ = *data++;
  69. }
  70. }
  71. else
  72. {
  73. while ( n-- )
  74. {
  75. *l++ = *( data + 2 );
  76. *l++ = *( data + 1 );
  77. *l++ = *data;
  78. data += 3;
  79. }
  80. }
  81. m_frames.push_back( image );
  82. }
  83. }
  84. }
  85. }
  86. void Video::EraseFirstFrame()
  87. {
  88. m_frames.erase( m_frames.begin() );
  89. }
  90. bool Video::IsNull()
  91. {
  92. return ( m_frames.size() == 0 ) ? true : false;
  93. }
  94. void Video::Clear()
  95. {
  96. std::vector< ExtendedImage* >::iterator
  97. f = m_frames.begin(),
  98. fe = m_frames.end();
  99. while ( f != fe )
  100. {
  101. if ( !(*f)->IsNull() )
  102. {
  103. (*f)->Destroy();
  104. }
  105. delete *f;
  106. ++f;
  107. }
  108. m_frames.clear();
  109. }