home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- picturesturct.cpp
-
- 03/02/08 Xiaohong
- *************************************************************************/
- #include "picturestruct.h"
- #include "macros.h"
- /**********************************************************
- PICTURESTRUCT é╠âüâôâoè╓Éöé╠ÉΘî╛
- **********************************************************/
- PICTURESTRUCT::PICTURESTRUCT()
- {
- int i;
-
- pRootClippingTable = NULL;
- pstMacroBlockInfo = NULL;
- pstMotionData = NULL;
- pBlocksArray = NULL;
-
- for (i=0; i<3; i++)
- {
- stReconstructedFrames.pNewFrame[i] = NULL;
- stReconstructedFrames.pOldFrame[i] = NULL;
- stReconstructedFrames.pAuxFrame[i] = NULL;
- stOriginalFrames.pNewFrame[i] = NULL;
- stOriginalFrames.pOldFrame[i] = NULL;
- stOriginalFrames.pAuxFrame[i] = NULL;
- pPredictionFrameArray[i] = NULL;
- }
- }
- PICTURESTRUCT::~PICTURESTRUCT()
- {
- Clear();
- }
- void PICTURESTRUCT::Clear(void)
- {
- int i;
-
- if(pRootClippingTable!=NULL)
- {
- _free(pRootClippingTable);
- }
- for (i=0; i<3; i++)
- {
- if(stReconstructedFrames.pNewFrame[i]!=NULL)
- {
- _free(stReconstructedFrames.pNewFrame[i]);
- }
- if(stReconstructedFrames.pOldFrame[i]!=NULL)
- {
- _free(stReconstructedFrames.pOldFrame[i]);
- }
- if(stReconstructedFrames.pAuxFrame[i]!=NULL)
- {
- _free(stReconstructedFrames.pAuxFrame[i]);
- }
-
- if(stOriginalFrames.pNewFrame[i]!=NULL)
- {
- _free(stOriginalFrames.pNewFrame[i]);
- }
- if(stOriginalFrames.pOldFrame[i]!=NULL)
- {
- _free(stOriginalFrames.pOldFrame[i]);
- }
- if(stOriginalFrames.pAuxFrame[i]!=NULL)
- {
- _free(stOriginalFrames.pAuxFrame[i]);
- }
-
- if(pPredictionFrameArray[i]!=NULL)
- {
- _free(pPredictionFrameArray[i]);
- }
- }
-
- if(pstMacroBlockInfo!=NULL)
- {
- _free(pstMacroBlockInfo);
- }
-
- if(pBlocksArray!=NULL)
- {
- _free(pBlocksArray);
- }
-
- if(pstMotionData!=NULL)
- {
- _free(pstMotionData);
- }
- }
-
- bool PICTURESTRUCT::AllocFrames(const int i,const int size)
- {
- if (!(stReconstructedFrames.pNewFrame[i] = (unsigned char *)_malloc(size)))
- return false;
- if (!(stReconstructedFrames.pOldFrame[i] = (unsigned char *)_malloc(size)))
- return false;
- if (!(stReconstructedFrames.pAuxFrame[i] = (unsigned char *)_malloc(size)))
- return false;
- if (!(stOriginalFrames.pNewFrame[i] = (unsigned char *)_malloc(size)))
- return false;
- if (!(stOriginalFrames.pOldFrame[i] = (unsigned char *)_malloc(size)))
- return false;
- if (!(stOriginalFrames.pAuxFrame[i] = (unsigned char *)_malloc(size)))
- return false;
- if (!(pPredictionFrameArray[i] = (unsigned char *)_malloc(size)))
- return false;
-
- return true;
- }
-
- bool PICTURESTRUCT::AllocMotionStruct(const int num)
- {
- if(pstMotionData!=NULL)
- {
- _free(pstMotionData);
- }
- if((pstMotionData = (MOTIONDATA*)_malloc(num*sizeof(MOTIONDATA)))!=NULL)
- {
- return true;
- }
- return false;
- }
-
- bool PICTURESTRUCT::MakeClippingTable(void)
- {
- int i;
-
- if(pRootClippingTable!=NULL)
- {
- _free(pRootClippingTable);
- }
- if ((pRootClippingTable = (unsigned char *)_malloc(1024))==NULL)
- {
- return false;
- }
-
- pClippingTable = pRootClippingTable + 384;
-
- for (i=-384; i<640; i++)
- {
- if(i<0)
- {
- pClippingTable[i] = 0;
- }
- else if(i>255)
- {
- pClippingTable[i] = 255;
- }
- else
- {
- pClippingTable[i] = i;
- }
- }
- return true;
- }
-
- bool PICTURESTRUCT::AllocMacloBlockInfo(const int num)
- {
- if(pstMacroBlockInfo!=NULL)
- {
- _free(pstMacroBlockInfo);
- }
- if((pstMacroBlockInfo = (MACROBLOCKINFO *)_malloc(num*sizeof(MACROBLOCKINFO)))!=NULL)
- {
- return true;
- }
- return false;
- }
-
- bool PICTURESTRUCT::AllocBlockArray(const int num)
- {
- if(pBlocksArray!=NULL)
- {
- _free(pBlocksArray);
- }
- if((pBlocksArray = (short (*)[64])_malloc(num*sizeof(short [64])))!=NULL)
- {
- return true;
- }
- return false;
- }