home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / Frame.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  4.7 KB  |  191 lines

  1. /* 
  2.  *  FrameSource.h
  3.  *
  4.  *    Copyright (C) Alberto Vigata - July 2000 - ultraflask@yahoo.com
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24.  
  25. #ifndef FRAMESOURCE_H
  26. #define FRAMESOURCE_H
  27.  
  28.  
  29. #define FRAME_INTERLACED  0x01
  30. #define FRAME_PROGRESSIVE 0x02
  31.  
  32. #define MAX_BUF 2048*2048*32
  33.  
  34. #include <windows.h>
  35. #include "flasktypes.h"
  36.  
  37. // frame formats
  38. #define FRAME_RGB  0
  39. #define FRAME_YV12 2
  40. #define FRAME_YUY2 1
  41.  
  42.  
  43. class CFrame
  44. {
  45. public:
  46.   CFrame( CFrameBuffer *pFrameBuffer )
  47.   {
  48.     m_pFrameBuffer = pFrameBuffer;
  49.     m_nPresTime     = 0;
  50.     m_nWidth = m_nHeigth = 0;;
  51.     m_nFormat = 0;
  52.     m_nDepth = 0;
  53.     m_nRef = 0;
  54.     m_pData = 0;
  55.     m_nFrameFlags = 0;
  56.     m_bOwnBuffer = false;
  57.     memset( &m_sBitmapInfo, 0, sizeof( m_sBitmapInfo ) );
  58.   }
  59.   ~CFrame(){
  60.     if(m_pData && m_bOwnBuffer)
  61.       delete []m_pData;
  62.   };
  63.   
  64.   CFrame &operator =(CFrame &oFrame)
  65.   {
  66.     if(!oFrame.IsValid())
  67.       return *this;
  68.     // free my buffer.
  69.     if(m_pData && m_bOwnBuffer)
  70.       delete []m_pData;
  71.     m_nWidth = oFrame.GetWidth();
  72.     m_nHeigth = oFrame.GetHeigth();
  73.     m_nPresTime = oFrame.GetPresTime();
  74.     m_nFormat = oFrame.GetFormat();
  75.     m_nDepth = oFrame.GetDepth();
  76.     m_nFrameFlags = oFrame.GetFlags();
  77.     m_bOwnBuffer = true;
  78.     Alloc();
  79.     memcpy( m_pData, oFrame.GetBuffer(), oFrame.GetBufferSize() );
  80.     return *this;
  81.   }
  82.   void Release()
  83.   {
  84.     CFlAutoLock lockObject(&m_csObject);
  85.     //ASSERT(m_nRef>0);
  86.     m_nRef--;
  87.     if(m_nRef==0)
  88.       if(m_pFrameBuffer)
  89.         m_pFrameBuffer->AddFreeFrame(this);
  90.   }
  91.   void AddRef()
  92.   {
  93.     CFlAutoLock lockObject(&m_csObject);
  94.     m_nRef++;
  95.   }
  96.   void SetPresTime( ui64 nPresTime ) { m_nPresTime = nPresTime; }
  97.   void SetSize( ui32 nWidth, ui32 nHeigth )
  98.   {
  99.     m_nWidth = nWidth;
  100.     m_nHeigth = nHeigth;
  101.   }
  102.   void SetFormat ( ui32 nFormat ){ m_nFormat = nFormat; }
  103.   void SetDepth ( ui32 nDepth ){ m_nDepth = nDepth; }
  104.   void SetBuffer ( ui8 *pData ){ m_pData = pData; }
  105.   void SetFlags ( ui32 nFlags ){ m_nFrameFlags = nFlags; }
  106.   ui8* GetBuffer(){ return m_pData; }
  107.   ui32 GetWidth(){ return m_nWidth; }
  108.   ui32 GetHeigth(){ return m_nHeigth; }
  109.   ui64 GetPresTime(){ return m_nPresTime; }
  110.   ui32 GetFormat(){ return m_nFormat; }
  111.   ui32 GetDepth(){ return m_nDepth; }
  112.   ui32 GetFlags(){ return m_nFrameFlags; }
  113.  
  114.   bool Alloc()
  115.   {
  116.     m_bOwnBuffer = true;
  117.     bool bSuccess = true;
  118.     int bufSize;
  119.     switch(m_nFormat)
  120.     {
  121.       case FRAME_RGB:
  122.         bufSize = m_nWidth * m_nHeigth * (m_nDepth/8);
  123.         if(bufSize>MAX_BUF)
  124.           return false;
  125.         m_pData = new ui8[bufSize];
  126.         break;
  127.     }
  128.     return true;
  129.   }
  130.   ui32 GetBufferSize()
  131.   {
  132.     int bufSize=0;
  133.     switch(m_nFormat)
  134.     {
  135.     case FRAME_RGB:
  136.       bufSize = m_nWidth * m_nHeigth * (m_nDepth/8);
  137.       if(bufSize>MAX_BUF)
  138.         bufSize = 0;
  139.       break;
  140.     }
  141.     return bufSize;
  142.   }
  143.   BITMAPINFO *GetBmpInfo()
  144.   {
  145.     m_sBitmapInfo.bmiHeader.biWidth  = m_nWidth;
  146.     m_sBitmapInfo.bmiHeader.biHeight = m_nHeigth;
  147.     m_sBitmapInfo.bmiHeader.biCompression = m_nFormat==FRAME_RGB ? BI_RGB : m_nFormat;
  148.     m_sBitmapInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
  149.     m_sBitmapInfo.bmiHeader.biPlanes = 1;
  150.     m_sBitmapInfo.bmiHeader.biBitCount = (WORD)m_nDepth;
  151.     return &m_sBitmapInfo;
  152.   }
  153.  
  154.   bool IsValid(){
  155.     return (m_pData!=NULL) && (m_nWidth!=0) && (m_nHeigth!=0);
  156.   }
  157. private:
  158.   CFrameBuffer *m_pFrameBuffer;
  159.   
  160.   bool   m_bOwnBuffer;
  161.   ui64   m_nPresTime;
  162.   ui32   m_nWidth, m_nHeigth;
  163.   ui32   m_nFormat;
  164.   ui32   m_nDepth;
  165.   ui32   m_nRef;
  166.   ui8   *m_pData;
  167.   ui32   m_nFrameFlags;
  168.  
  169.   BITMAPINFO m_sBitmapInfo;
  170.   CFlCritSec m_csObject;
  171. };
  172.  
  173. class CFrameSource
  174. {
  175. public:
  176.   virtual bool GetFrame(CFrame *pFrame)=0;
  177. };
  178.  
  179. // Format definition
  180. typedef struct YV12ImageTag
  181. {
  182.   unsigned char *Y;
  183.   int              Yxsize;
  184.   int              Yysize;
  185.   unsigned char *U;
  186.   unsigned char *V;
  187.   int              Cxsize;
  188.   int              Cysize;
  189. } TYV12;
  190.  
  191. #endif