home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / dctm.lzh / DCTM / source.lzh / source / picturestruct.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-02-08  |  3.8 KB  |  183 lines

  1. /*************************************************************************
  2.     picturesturct.cpp
  3.  
  4.     03/02/08    Xiaohong
  5. *************************************************************************/
  6. #include "picturestruct.h"
  7. #include "macros.h"
  8. /**********************************************************
  9.     PICTURESTRUCT é╠âüâôâoè╓Éöé╠ÉΘî╛
  10. **********************************************************/
  11. PICTURESTRUCT::PICTURESTRUCT()
  12. {
  13.     int i;
  14.  
  15.     pRootClippingTable = NULL;
  16.     pstMacroBlockInfo = NULL;
  17.     pstMotionData = NULL;
  18.     pBlocksArray = NULL;
  19.  
  20.     for (i=0; i<3; i++)
  21.     {
  22.         stReconstructedFrames.pNewFrame[i] = NULL;
  23.         stReconstructedFrames.pOldFrame[i] = NULL;
  24.         stReconstructedFrames.pAuxFrame[i] = NULL;
  25.         stOriginalFrames.pNewFrame[i] = NULL;
  26.         stOriginalFrames.pOldFrame[i] = NULL;
  27.         stOriginalFrames.pAuxFrame[i] = NULL;
  28.         pPredictionFrameArray[i] = NULL;
  29.     }
  30. }
  31. PICTURESTRUCT::~PICTURESTRUCT()
  32. {
  33.     Clear();
  34. }
  35. void PICTURESTRUCT::Clear(void)
  36. {
  37.     int i;
  38.  
  39.     if(pRootClippingTable!=NULL)
  40.     {
  41.         _free(pRootClippingTable);
  42.     }
  43.     for (i=0; i<3; i++)
  44.     {
  45.         if(stReconstructedFrames.pNewFrame[i]!=NULL)
  46.         {
  47.             _free(stReconstructedFrames.pNewFrame[i]);
  48.         }
  49.         if(stReconstructedFrames.pOldFrame[i]!=NULL)
  50.         {
  51.             _free(stReconstructedFrames.pOldFrame[i]);
  52.         }
  53.         if(stReconstructedFrames.pAuxFrame[i]!=NULL)
  54.         {
  55.             _free(stReconstructedFrames.pAuxFrame[i]);
  56.         }
  57.  
  58.         if(stOriginalFrames.pNewFrame[i]!=NULL)
  59.         {
  60.             _free(stOriginalFrames.pNewFrame[i]);
  61.         }
  62.         if(stOriginalFrames.pOldFrame[i]!=NULL)
  63.         {
  64.             _free(stOriginalFrames.pOldFrame[i]);
  65.         }
  66.         if(stOriginalFrames.pAuxFrame[i]!=NULL)
  67.         {
  68.             _free(stOriginalFrames.pAuxFrame[i]);
  69.         }
  70.  
  71.         if(pPredictionFrameArray[i]!=NULL)
  72.         {
  73.             _free(pPredictionFrameArray[i]);
  74.         }
  75.     }
  76.  
  77.     if(pstMacroBlockInfo!=NULL)
  78.     {
  79.         _free(pstMacroBlockInfo);
  80.     }
  81.  
  82.     if(pBlocksArray!=NULL)
  83.     {
  84.         _free(pBlocksArray);
  85.     }
  86.  
  87.     if(pstMotionData!=NULL)
  88.     {
  89.         _free(pstMotionData);
  90.     }
  91. }
  92.  
  93. bool PICTURESTRUCT::AllocFrames(const int i,const int size)
  94. {
  95.     if (!(stReconstructedFrames.pNewFrame[i] = (unsigned char *)_malloc(size)))
  96.         return false;
  97.     if (!(stReconstructedFrames.pOldFrame[i] = (unsigned char *)_malloc(size)))
  98.         return false;
  99.     if (!(stReconstructedFrames.pAuxFrame[i] = (unsigned char *)_malloc(size)))
  100.         return false;
  101.     if (!(stOriginalFrames.pNewFrame[i] = (unsigned char *)_malloc(size)))
  102.         return false;
  103.     if (!(stOriginalFrames.pOldFrame[i] = (unsigned char *)_malloc(size)))
  104.         return false;
  105.     if (!(stOriginalFrames.pAuxFrame[i] = (unsigned char *)_malloc(size)))
  106.         return false;
  107.     if (!(pPredictionFrameArray[i] = (unsigned char *)_malloc(size)))
  108.         return false;
  109.  
  110.     return true;
  111. }
  112.  
  113. bool PICTURESTRUCT::AllocMotionStruct(const int num)
  114. {
  115.     if(pstMotionData!=NULL)
  116.     {
  117.         _free(pstMotionData);
  118.     }
  119.     if((pstMotionData = (MOTIONDATA*)_malloc(num*sizeof(MOTIONDATA)))!=NULL)
  120.     {
  121.         return true;
  122.     }
  123.     return false;
  124. }
  125.  
  126. bool PICTURESTRUCT::MakeClippingTable(void)
  127. {
  128.     int i;
  129.  
  130.     if(pRootClippingTable!=NULL)
  131.     {
  132.         _free(pRootClippingTable);
  133.     }
  134.     if ((pRootClippingTable = (unsigned char *)_malloc(1024))==NULL)
  135.     {
  136.         return false;
  137.     }
  138.  
  139.     pClippingTable = pRootClippingTable + 384;
  140.  
  141.     for (i=-384; i<640; i++)
  142.     {
  143.         if(i<0)
  144.         {
  145.             pClippingTable[i] = 0;
  146.         }
  147.         else if(i>255)
  148.         {
  149.             pClippingTable[i] = 255;
  150.         }
  151.         else
  152.         {
  153.             pClippingTable[i] = i;
  154.         }
  155.     }
  156.     return true;
  157. }
  158.  
  159. bool PICTURESTRUCT::AllocMacloBlockInfo(const int num)
  160. {
  161.     if(pstMacroBlockInfo!=NULL)
  162.     {
  163.         _free(pstMacroBlockInfo);
  164.     }
  165.     if((pstMacroBlockInfo = (MACROBLOCKINFO *)_malloc(num*sizeof(MACROBLOCKINFO)))!=NULL)
  166.     {
  167.         return true;
  168.     }
  169.     return false;
  170. }
  171.  
  172. bool PICTURESTRUCT::AllocBlockArray(const int num)
  173. {
  174.     if(pBlocksArray!=NULL)
  175.     {
  176.         _free(pBlocksArray);
  177.     }
  178.     if((pBlocksArray = (short (*)[64])_malloc(num*sizeof(short [64])))!=NULL)
  179.     {
  180.         return true;
  181.     }
  182.     return false;
  183. }