Video.cpp 1.9 KB

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