huffman.cpp
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:43k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /*************************************************************************
  2. This software module was originally developed by 
  3. Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation
  4. Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation
  5. Bruce Lin (blin@microsoft.com), Microsoft Corporation
  6. Chuang Gu (chuanggu@microsoft.com), Microsoft Corporation
  7. (date: March, 1996)
  8. and edited by
  9. Yoshihiro Kikuchi (TOSHIBA CORPORATION)
  10. Takeshi Nagai (TOSHIBA CORPORATION)
  11. Toshiaki Watanabe (TOSHIBA CORPORATION)
  12. Noboru Yamaguchi (TOSHIBA CORPORATION)
  13. in the course of development of the MPEG-4 Video (ISO/IEC 14496-2). 
  14. This software module is an implementation of a part of one or more MPEG-4 Video tools 
  15. as specified by the MPEG-4 Video. 
  16. ISO/IEC gives users of the MPEG-4 Video free license to this software module or modifications 
  17. thereof for use in hardware or software products claiming conformance to the MPEG-4 Video. 
  18. Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents. 
  19. The original developer of this software module and his/her company, 
  20. the subsequent editors and their companies, 
  21. and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation. 
  22. Copyright is not released for non MPEG-4 Video conforming products. 
  23. Microsoft retains full right to use the code for his/her own purpose, 
  24. assign or donate the code to a third party and to inhibit third parties from using the code for non <MPEG standard> conforming products. 
  25. This copyright notice must be included in all copies or derivative works. 
  26. Copyright (c) 1996, 1997.
  27. Module Name:
  28. huffman.cpp
  29. Abstract:
  30. Classes for Huffman encode/decode.
  31. Revision History:
  32. *************************************************************************/
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <iostream.h>
  36. #include "typeapi.h"
  37. #include "entropy.hpp"
  38. #include "huffman.hpp"
  39. #include "iostream.h"
  40. #include "fstream.h"
  41. #include "math.h"
  42. #include "bitstrm.hpp"
  43. #include "vlc.hpp"
  44. #ifdef __MFC_
  45. #ifdef _DEBUG
  46. #undef THIS_FILE
  47. static char BASED_CODE THIS_FILE[] = __FILE__;
  48. #endif
  49. #define new DEBUG_NEW    
  50. #endif // __MFC_
  51. #ifdef __PC_COMPILER_
  52. #define FULLNAME(dir, filename) strcpy (pch, "\"#dir"\"#filename);
  53. #else 
  54. #define FULLNAME(dir, filename) strcpy (pch, "/"#dir"/"#filename);
  55. #endif
  56. class CNode
  57. {
  58. friend class CHuffmanTree;
  59. friend Int huffmanNodeCompare (const Void* Element1,const Void* Element2);
  60. private:
  61.     Char m_cCode;
  62.     Int m_lNodeIndex;
  63.     Int m_lFrequency;
  64.     Int m_lBalancer;
  65.     CNode () {m_cCode = 0; m_lNodeIndex = -1; m_lFrequency = 0; m_lBalancer = 1;};
  66. };
  67. Class CHuffmanDecoderNode
  68. {
  69. friend class CHuffmanDecoder;
  70.     Char m_c0End;
  71.     Char m_c1End;
  72.     Int m_l0NextNodeOrSymbol;
  73.     Int m_l1NextNodeOrSymbol;
  74.     CHuffmanDecoderNode () {m_c0End=0;m_c1End=0;
  75.             m_l0NextNodeOrSymbol=-1;m_l1NextNodeOrSymbol=-1;};
  76.     Bool is0Valid() {if ((m_c0End==0)&&(m_l0NextNodeOrSymbol==-1))
  77.             return FALSE;return TRUE;};
  78.     Bool is1Valid() {if ((m_c1End==0)&&(m_l1NextNodeOrSymbol==-1))
  79.             return FALSE;return TRUE;};
  80. };
  81. CHuffmanTree::CHuffmanTree (Int lNOfSymbols, Int *lpFrequencies)
  82. {
  83.     assert(lNOfSymbols>1);
  84.     m_lNOfSymbols=lNOfSymbols;
  85.     m_pNodes = new CNode[2*m_lNOfSymbols-1];
  86.     if(lpFrequencies)
  87.         setFrequencies (lpFrequencies);
  88. }
  89. CHuffmanTree::~CHuffmanTree()
  90. {
  91.     delete[]m_pNodes;
  92. }
  93. Void CHuffmanTree::writeSymbol (Int symbolNo,ostream &stream)
  94. {
  95.     stream<<symbolNo<<" ";
  96. }
  97. Void CHuffmanTree::setFrequencies (Int* lpFrequencies)
  98. {
  99.     for (Int lIndex=0;lIndex<m_lNOfSymbols;lIndex++)
  100.         setFrequency(lpFrequencies[lIndex],lIndex);
  101. }
  102. Void CHuffmanTree::setFrequency (Int lFrequency, Int lIndex)
  103. {
  104.     m_pNodes[lIndex].m_lFrequency=lFrequency;
  105. }
  106. Int huffmanNodeCompare (const Void* Element1, const Void* Element2)
  107. {
  108.     if((*((CNode**)Element1))->m_lFrequency<
  109.             (*((CNode**)Element2))->m_lFrequency)return  1;   
  110.     if((*((CNode**)Element1))->m_lFrequency>
  111.             (*((CNode**)Element2))->m_lFrequency)return -1;
  112.     if((*((CNode**)Element1))->m_lBalancer<
  113.             (*((CNode**)Element2))->m_lBalancer)return  1;   
  114.     if((*((CNode**)Element1))->m_lBalancer>
  115.             (*((CNode**)Element2))->m_lBalancer)return -1;
  116.     return 0;
  117. }
  118. Void CHuffmanTree::buildTree ()
  119. {
  120.     assert(m_lNOfSymbols>1);
  121.     Int NOfNodesForSorting=m_lNOfSymbols;
  122.     Int NextFreeNode=m_lNOfSymbols;
  123.     CNode **pSortingArray;
  124.     pSortingArray=new CNode*[m_lNOfSymbols];
  125.     for (Int i=0;i<m_lNOfSymbols;i++)
  126.         pSortingArray [i] = &m_pNodes[i];
  127.     
  128.     while (NOfNodesForSorting>1)
  129.     {
  130.         qsort(&pSortingArray[0],NOfNodesForSorting,
  131.                 sizeof(pSortingArray[0]),huffmanNodeCompare);
  132.         pSortingArray[NOfNodesForSorting-2]->m_lNodeIndex=NextFreeNode;
  133.         pSortingArray[NOfNodesForSorting-1]->m_lNodeIndex=NextFreeNode;
  134.         pSortingArray[NOfNodesForSorting-2]->m_cCode=0;
  135.         pSortingArray[NOfNodesForSorting-1]->m_cCode=1;
  136.         m_pNodes[NextFreeNode].m_lFrequency=
  137.                 pSortingArray[NOfNodesForSorting-2]->m_lFrequency+
  138.                 pSortingArray[NOfNodesForSorting-1]->m_lFrequency;
  139.         m_pNodes[NextFreeNode].m_lBalancer=
  140.                 pSortingArray[NOfNodesForSorting-2]->m_lBalancer+
  141.                 pSortingArray[NOfNodesForSorting-1]->m_lBalancer;
  142.         pSortingArray[NOfNodesForSorting-2]=&m_pNodes[NextFreeNode];
  143.         NOfNodesForSorting--;
  144.         NextFreeNode++;
  145.     };
  146.     delete pSortingArray;
  147. }
  148. void CHuffmanTree::writeOneTableEntry(ostream &stream, Int entryNo,
  149.                                     Double lTotalFrequency, Double &dNOfBits)
  150. {
  151.     Double dP=m_pNodes[entryNo].m_lFrequency/(Double)lTotalFrequency;
  152.     Char *pCodeArray=new Char[m_lNOfSymbols-1];
  153.     Int lNode=entryNo;
  154.     Int lCodeNo=0;
  155.     while(lNode!=2*m_lNOfSymbols-2)
  156.     {
  157.         pCodeArray[lCodeNo++]=m_pNodes[lNode].m_cCode;
  158.         lNode=m_pNodes[lNode].m_lNodeIndex;
  159.     };
  160.     writeSymbol(entryNo,stream);
  161.     dNOfBits+=dP*lCodeNo;
  162.     while(lCodeNo>0)
  163.     {
  164.         lCodeNo--;
  165.         stream<<(Int)pCodeArray[lCodeNo];
  166.     };
  167.     stream<<endl;
  168.     delete pCodeArray;
  169. }
  170. Void CHuffmanTree::writeTable (ostream &stream)
  171. {
  172.     Int lTotalFrequency=0;
  173.     Double dEntropy=0;
  174.     Double dNOfBits=0;
  175.     statistics (lTotalFrequency, dEntropy);
  176.     for (Int i = 0; i < m_lNOfSymbols; i++)
  177.         writeOneTableEntry (stream, i, lTotalFrequency, dNOfBits);
  178.     printStatistics (dEntropy, dNOfBits, stream);
  179. }
  180. Void CHuffmanTree::writeTableSorted(ostream &stream)
  181. {
  182.     Int lTotalFrequency=0;
  183.     Double dEntropy=0;
  184.     Double dNOfBits=0;
  185.     statistics(lTotalFrequency,dEntropy);
  186.     CNode **pSortingArray;
  187.     pSortingArray = new CNode*[m_lNOfSymbols];
  188. Int i;
  189.     for (i = 0; i < m_lNOfSymbols; i++)
  190.         pSortingArray [i] = &m_pNodes[i];
  191.     qsort(&pSortingArray[0],m_lNOfSymbols,
  192.             sizeof (pSortingArray [0]), huffmanNodeCompare);
  193.     for(i=0;i<m_lNOfSymbols;i++)
  194.         writeOneTableEntry (stream, pSortingArray [i] - m_pNodes,
  195.                 lTotalFrequency,dNOfBits);
  196.     delete pSortingArray;
  197.     printStatistics (dEntropy, dNOfBits, stream);
  198. }
  199. Void CHuffmanTree::statistics (Int& lTotalFrequency,Double &dEntropy)
  200. {
  201. Int i;
  202.     for (i=0;i<m_lNOfSymbols;i++)
  203.         lTotalFrequency+=m_pNodes[i].m_lFrequency;
  204.     for(i=0;i<m_lNOfSymbols;i++)
  205.     {
  206.         double dP=m_pNodes[i].m_lFrequency/(double)lTotalFrequency;
  207.         if(dP!=0)
  208.             dEntropy+=dP*log(1.0/dP)/log(2.0);    
  209.     };
  210. }
  211. Void CHuffmanTree::printStatistics (Double dEntropy, Double dNOfBits, ostream &stream)
  212. {
  213.     stream<<endl<<endl;
  214.     stream<<"//Entropy Per Symbol : "<<dEntropy<<endl;
  215.     stream<<"//Bits Per Symbol    : "<<dNOfBits<<endl;
  216.     stream<<"//Table Efficiency   : "<<dEntropy/dNOfBits<<endl;
  217. }
  218. Int CHuffmanCoDec::makeIndexFromSymbolInTable(istream &huffmanTable)  
  219. {
  220.     Int lR;
  221. huffmanTable >> lR;
  222. return lR;
  223. }
  224. Void CHuffmanCoDec::trashRestOfLine (istream &str)
  225. {
  226.     Int iC;
  227.     do
  228.     {
  229.         iC = str.get ();
  230.     }
  231.     while ((iC!='n') && (iC!=EOF));
  232. }
  233. Bool CHuffmanCoDec::processOneLine (istream &huffmanTable, Int &lSymbol,
  234.                     Int &lCodeSize, Char *pCode)
  235. {
  236. huffmanTable >> ws;
  237.     while(huffmanTable.peek()=='/')
  238.     {
  239. trashRestOfLine (huffmanTable);
  240. huffmanTable >> ws;
  241.     }
  242.     if(huffmanTable.peek()==EOF)
  243.         return FALSE;
  244. lSymbol=makeIndexFromSymbolInTable(huffmanTable);      
  245. huffmanTable >> ws;
  246. int iC=huffmanTable.get();                            
  247. lCodeSize=0;                                       
  248. while((iC=='0')||(iC=='1'))                             
  249.     {                                                       
  250.         if(pCode)                                           
  251.         {                                                   
  252.             if(iC=='0')                                     
  253.                 pCode[lCodeSize]=0;                         
  254.             else                                            
  255.                 pCode[lCodeSize]=1;                         
  256.         };                                                  
  257.         lCodeSize++;                                        
  258.         iC=huffmanTable.get();                            
  259.     };
  260.     if((iC!='n')&&(iC!=EOF))
  261.         trashRestOfLine(huffmanTable);                         
  262.     assert(lCodeSize);
  263.     return TRUE;
  264. }
  265. Void CHuffmanCoDec::profileTable (istream &huffmanTable,
  266.             Int &lNOfSymbols, Int &lMaxCodeSize)
  267. {
  268.     huffmanTable.clear();
  269.     huffmanTable.seekg(0,ios::beg);
  270.     lNOfSymbols=0;
  271.     lMaxCodeSize=0;
  272.     while(huffmanTable.peek()!=EOF)
  273.     {
  274.         Int lCodeSize;
  275.         Int lSymbol;
  276.         if (processOneLine(huffmanTable,lSymbol,lCodeSize,NULL))
  277.         {
  278.             lNOfSymbols++;
  279.             if(lCodeSize>lMaxCodeSize)
  280.                 lMaxCodeSize=lCodeSize;
  281.             assert(lCodeSize);
  282.         };
  283.     };
  284.     assert(lNOfSymbols>1);
  285.     assert(lMaxCodeSize);
  286. }
  287. CHuffmanDecoder::CHuffmanDecoder (CInBitStream &bitStream)
  288. {
  289.     attachStream (bitStream);
  290. }
  291. CHuffmanDecoder::CHuffmanDecoder (CInBitStream &bitStream, VlcTable *pVlc)
  292. {
  293.     attachStream (bitStream);
  294. loadTable (pVlc);
  295. }
  296. CHuffmanDecoder::~CHuffmanDecoder()
  297. {
  298.     delete []m_pTree;
  299. }
  300. Void CHuffmanDecoder::realloc(Int lOldSize,Int lNewSize)
  301. {
  302.     CHuffmanDecoderNode *pNewTree=new CHuffmanDecoderNode[lNewSize];
  303.     Int i;
  304.     for(i=0;i<lOldSize;i++)
  305.     {
  306.         pNewTree[i].m_c0End=m_pTree[i].m_c0End;
  307.         pNewTree[i].m_c1End=m_pTree[i].m_c1End;
  308.         pNewTree[i].m_l0NextNodeOrSymbol=m_pTree[i].m_l0NextNodeOrSymbol;
  309.         pNewTree[i].m_l1NextNodeOrSymbol=m_pTree[i].m_l1NextNodeOrSymbol;
  310.     };
  311.     delete []m_pTree;
  312.     m_pTree=pNewTree;
  313. }
  314. void CHuffmanDecoder::loadTable(istream &huffmanTable,Bool bIncompleteTree)
  315. {
  316.     Int lTableSize;
  317.     Int lNOfSymbols;
  318.     Int lMaxCodeSize;
  319.     Int lNextFreeNode=1;
  320.     profileTable (huffmanTable,lNOfSymbols,lMaxCodeSize);
  321.     assert(lNOfSymbols>1);
  322.     assert(lMaxCodeSize);
  323.     m_pTree = new CHuffmanDecoderNode [lNOfSymbols - 1];
  324.     lTableSize=lNOfSymbols-1;
  325.     Char *pCode = new Char[lMaxCodeSize];
  326.     huffmanTable.clear();
  327.     huffmanTable.seekg(0,ios::beg);
  328.     while(huffmanTable.peek()!=EOF)
  329.     {
  330.         Int lCodeSize;
  331.         Int lSymbol;
  332.         Int lCurrentNode=0;
  333.         if (processOneLine (huffmanTable,lSymbol,lCodeSize,pCode))
  334.         {
  335.             assert((lSymbol<lNOfSymbols)||bIncompleteTree);                                              
  336.             assert(lCodeSize);                                                        
  337.             for(Int i=0;i<lCodeSize;i++)                                             
  338.             {                                                                         
  339. assert ((lCurrentNode<lNOfSymbols-1)||bIncompleteTree);                                 
  340.                 int iBit=pCode[i];                                                    
  341.                 assert((iBit==0)||(iBit==1));                                         
  342.                 if(i==(lCodeSize-1))                                                  
  343.                 {                                                                     
  344.                     if(iBit==0)                                                       
  345.                     {                                                                 
  346.                         assert(!m_pTree[lCurrentNode].is0Valid());                    
  347.                         m_pTree[lCurrentNode].m_c0End=1;                              
  348.                         m_pTree[lCurrentNode].m_l0NextNodeOrSymbol=lSymbol;           
  349.                     }                                                                 
  350.                     else                                                              
  351.                     {                                                                 
  352.                         assert(!m_pTree[lCurrentNode].is1Valid());                    
  353.                         m_pTree[lCurrentNode].m_c1End=1;                              
  354.                         m_pTree[lCurrentNode].m_l1NextNodeOrSymbol=lSymbol;           
  355.                     }                                                                 
  356.                 }                                                                     
  357.                 else                                                                  
  358.                 {                                                                     
  359.                     if(iBit==0)                                                       
  360.                     {                                                                 
  361.                         if(!m_pTree[lCurrentNode].is0Valid())                         
  362.                         {                                                             
  363. if(bIncompleteTree)
  364.                                 if(lNextFreeNode>=lTableSize)
  365.                                 {
  366.                                     realloc(lTableSize,lTableSize+10);
  367.                                     lTableSize+=10;
  368.                                 };
  369.                             assert((lNextFreeNode<lNOfSymbols-1)||bIncompleteTree);                    
  370.                             m_pTree[lCurrentNode].m_c0End=0;                          
  371.                             m_pTree[lCurrentNode].m_l0NextNodeOrSymbol=lNextFreeNode; 
  372.                             lNextFreeNode++;                                          
  373.                         };                                                            
  374.                         assert(m_pTree[lCurrentNode].m_c0End==0);                     
  375.                         lCurrentNode=m_pTree[lCurrentNode].m_l0NextNodeOrSymbol;      
  376.                     }                                                                 
  377.                     else                                                              
  378.                     {                                                                 
  379.                         if(!m_pTree[lCurrentNode].is1Valid())                         
  380.                         {                                                             
  381. if(bIncompleteTree)
  382.                                 if(lNextFreeNode>=lTableSize)
  383.                                 {
  384.                                     realloc(lTableSize,lTableSize+10);
  385.                                     lTableSize+=10;
  386.                                 };
  387.                             assert((lNextFreeNode<lNOfSymbols-1)||bIncompleteTree);                    
  388.                             m_pTree[lCurrentNode].m_c1End=0;                          
  389.                             m_pTree[lCurrentNode].m_l1NextNodeOrSymbol=lNextFreeNode; 
  390.                             lNextFreeNode++;                                          
  391.                         };                                                            
  392.                         assert(m_pTree[lCurrentNode].m_c1End==0);                     
  393.                         lCurrentNode=m_pTree[lCurrentNode].m_l1NextNodeOrSymbol;      
  394.                     }                                                                
  395.                 }                                                                    
  396.             }
  397.         }
  398.     }
  399.     for(Int i=0;i<lTableSize;i++)
  400.     {
  401.         assert((m_pTree[i].is0Valid())||bIncompleteTree);
  402.         assert((m_pTree[i].is1Valid())||bIncompleteTree);
  403.     };
  404.     delete pCode;
  405. }
  406. void CHuffmanDecoder::loadTable(VlcTable *pVlc,Bool bIncompleteTree)
  407. {
  408.     Int lTableSize;
  409.     Int lNextFreeNode = 1;
  410.     Int lNOfSymbols = 0;
  411.     Int lMaxCodeSize = 0;
  412. VlcTable *pVlcTmp;
  413.     for(pVlcTmp = pVlc; pVlcTmp->pchBits!=NULL; pVlcTmp++)
  414.     {
  415.         lNOfSymbols++;
  416. Int lCodeSize = strlen(pVlcTmp->pchBits);
  417. assert(pVlcTmp->lSymbol>=0 && pVlcTmp->lSymbol<1000);
  418. assert(lCodeSize>0);
  419.         if(lCodeSize>lMaxCodeSize)
  420. lMaxCodeSize=lCodeSize;
  421.     }
  422.     assert(lNOfSymbols>1);
  423.     assert(lMaxCodeSize>0);
  424.     m_pTree = new CHuffmanDecoderNode [lNOfSymbols - 1];
  425.     lTableSize=lNOfSymbols-1;
  426.     for(pVlcTmp = pVlc; pVlcTmp->pchBits!=NULL; pVlcTmp++)
  427.     {
  428.         Int lCodeSize = strlen(pVlcTmp->pchBits);
  429.         Int lSymbol = pVlcTmp->lSymbol;
  430.         Int lCurrentNode = 0;
  431. //printf("%dt%dt%sn",lSymbol, lCodeSize, pVlcTmp->pchBits);
  432.         assert((lSymbol<lNOfSymbols)||bIncompleteTree);                                              
  433.         assert(lCodeSize);                                                        
  434.         for(Int i=0;i<lCodeSize;i++)                                             
  435.         {                                                                         
  436. assert ((lCurrentNode<lNOfSymbols-1)||bIncompleteTree);
  437.             int iBit = pVlcTmp->pchBits[i] - '0';
  438. assert((iBit==0)||(iBit==1));                                         
  439.             if(i==(lCodeSize-1))                                                  
  440.             {                                                                     
  441.                 if(iBit==0)                                                       
  442.                 {                                                                 
  443.                     assert(!m_pTree[lCurrentNode].is0Valid());                    
  444.                     m_pTree[lCurrentNode].m_c0End=1;                              
  445.                     m_pTree[lCurrentNode].m_l0NextNodeOrSymbol=lSymbol;           
  446.                 }                                                                 
  447.                 else                                                              
  448.                 {                                                                 
  449.                     assert(!m_pTree[lCurrentNode].is1Valid());                    
  450.                     m_pTree[lCurrentNode].m_c1End=1;                              
  451.                     m_pTree[lCurrentNode].m_l1NextNodeOrSymbol=lSymbol;           
  452.                 }                                                                 
  453.             }                                                                     
  454.             else                                                                  
  455.             {                                                                     
  456.                 if(iBit==0)                                                       
  457.                 {                                                                 
  458.                     if(!m_pTree[lCurrentNode].is0Valid())                         
  459.                     {                                                             
  460. if(bIncompleteTree)
  461.                             if(lNextFreeNode>=lTableSize)
  462.                             {
  463.                                 realloc(lTableSize,lTableSize+10);
  464.                                 lTableSize+=10;
  465.                             };
  466.                         assert((lNextFreeNode<lNOfSymbols-1)||bIncompleteTree);                    
  467.                         m_pTree[lCurrentNode].m_c0End=0;                          
  468.                         m_pTree[lCurrentNode].m_l0NextNodeOrSymbol=lNextFreeNode; 
  469.                         lNextFreeNode++;                                          
  470.                     };                                                            
  471.                     assert(m_pTree[lCurrentNode].m_c0End==0);                     
  472.                     lCurrentNode=m_pTree[lCurrentNode].m_l0NextNodeOrSymbol;      
  473.                 }                                                                 
  474.                 else                                                              
  475.                 {                                                                 
  476.                     if(!m_pTree[lCurrentNode].is1Valid())                         
  477.                     {                                                             
  478. if(bIncompleteTree)
  479.                             if(lNextFreeNode>=lTableSize)
  480.                             {
  481.                                 realloc(lTableSize,lTableSize+10);
  482.                                 lTableSize+=10;
  483.                             };
  484.                         assert((lNextFreeNode<lNOfSymbols-1)||bIncompleteTree);                    
  485.                         m_pTree[lCurrentNode].m_c1End=0;                          
  486.                         m_pTree[lCurrentNode].m_l1NextNodeOrSymbol=lNextFreeNode; 
  487.                         lNextFreeNode++;                                          
  488.                     };                                                            
  489.                     assert(m_pTree[lCurrentNode].m_c1End==0);                     
  490.                     lCurrentNode=m_pTree[lCurrentNode].m_l1NextNodeOrSymbol;      
  491.                 }                                                                
  492.             }                                                                    
  493.         }
  494.     }
  495.     for(Int i=0;i<lTableSize;i++)
  496.     {
  497.         assert((m_pTree[i].is0Valid())||bIncompleteTree);
  498.         assert((m_pTree[i].is1Valid())||bIncompleteTree);
  499.     }
  500. }
  501. Void CHuffmanDecoder::attachStream(CInBitStream &bitStream)
  502. {
  503.     m_pBitStream=&bitStream;
  504. }
  505. Int CHuffmanDecoder::decodeSymbol()
  506. {
  507.     Char cEnd=0;
  508.     Int lNextNodeOrSymbol=0;
  509.     do
  510.     {
  511.         Int iBit;
  512.         iBit=m_pBitStream->getBits((uint32_t)1);
  513.         if(iBit==0)
  514.         {
  515.             if(m_pTree[lNextNodeOrSymbol].is0Valid())
  516.             {
  517.                 cEnd=m_pTree[lNextNodeOrSymbol].m_c0End;
  518.                 lNextNodeOrSymbol=m_pTree[lNextNodeOrSymbol].m_l0NextNodeOrSymbol;
  519.             }
  520.             else
  521.             {
  522.                 cEnd=TRUE;
  523.                 lNextNodeOrSymbol=-1;
  524.             }
  525.         }
  526.         else
  527.         {
  528.             if(m_pTree[lNextNodeOrSymbol].is1Valid())
  529.             {
  530.                 cEnd=m_pTree[lNextNodeOrSymbol].m_c1End;
  531.                 lNextNodeOrSymbol=m_pTree[lNextNodeOrSymbol].m_l1NextNodeOrSymbol;
  532.             }
  533.             else
  534.             {
  535.                 cEnd=TRUE;
  536.                 lNextNodeOrSymbol=-1;
  537.             }
  538.         };
  539.     }
  540.     while(cEnd==0);
  541.     return lNextNodeOrSymbol;
  542. }
  543. CHuffmanEncoder::~CHuffmanEncoder ()
  544. {
  545. delete m_pCodeTable; 
  546. delete m_pSizeTable;
  547. }
  548. CHuffmanEncoder::CHuffmanEncoder(COutBitStream &bitStream)
  549. {
  550.     attachStream(bitStream);
  551. }
  552. CHuffmanEncoder::CHuffmanEncoder(COutBitStream &bitStream, VlcTable *pVlc)
  553. {
  554. attachStream(bitStream);
  555. loadTable(pVlc);
  556. }
  557. Void CHuffmanEncoder::loadTable(istream &huffmanTable)
  558. {
  559.     Int lNOfSymbols;
  560.     Int lMaxCodeSize;
  561.     profileTable(huffmanTable,lNOfSymbols,lMaxCodeSize);
  562.     assert(lNOfSymbols>1);
  563.     assert(lMaxCodeSize);
  564.     m_lCodeTableEntrySize=lMaxCodeSize/8;
  565.     if(lMaxCodeSize%8)
  566.         m_lCodeTableEntrySize++;
  567.     m_pSizeTable = new Int [lNOfSymbols];
  568.     m_pCodeTable = new Int [lNOfSymbols];
  569.     Char *pCode=new Char[lMaxCodeSize];
  570.     huffmanTable.clear();
  571.     huffmanTable.seekg(0,ios::beg);
  572.     while(huffmanTable.peek()!=EOF)
  573.     {
  574.         Int lCodeSize;
  575.         Int lSymbol;
  576.         Int iBitPosition=0;
  577.         if(processOneLine(huffmanTable,lSymbol,lCodeSize,pCode))
  578.         {
  579.             assert(lSymbol<lNOfSymbols);                                                 
  580.             assert(lCodeSize >=0 && lCodeSize <= (Int) sizeof (Int) * 8);
  581.             m_pSizeTable[lSymbol]=lCodeSize;                                             
  582.             Int* pCodeTableEntry=&m_pCodeTable[lSymbol]; 
  583.             for(Int i=0;i<lCodeSize;i++)                                                
  584.             {                                                                            
  585.                 if(iBitPosition==0)                                                      
  586.                     *pCodeTableEntry=0;                                                  
  587.                 assert((pCode[lCodeSize - i - 1]==0)||(pCode[lCodeSize - i - 1]==1));                                    
  588.                 if(pCode[lCodeSize - i - 1]==0)                                                          
  589.                     *pCodeTableEntry&=~(0x01<<iBitPosition);                             
  590.                 else                                                                     
  591.                     *pCodeTableEntry|=0x01<<iBitPosition;                                
  592.                 iBitPosition++;                                                          
  593. /*
  594.                 if(iBitPosition>=8)                                                      
  595.                 {                                                                        
  596.                     iBitPosition=0;                                                      
  597.                     pCodeTableEntry++;                                                   
  598.                 } 
  599. */
  600.             }                                                                           
  601.         }
  602.     }
  603.     delete pCode;
  604. }
  605. Void CHuffmanEncoder::loadTable(VlcTable *pVlc)
  606. {
  607.     Int lNOfSymbols = 0;
  608.     Int lMaxCodeSize = 0;
  609. VlcTable *pVlcTmp;
  610. for(pVlcTmp = pVlc; pVlcTmp->pchBits!=NULL; pVlcTmp++)
  611. {
  612.         lNOfSymbols++;
  613. Int lCodeSize = strlen(pVlcTmp->pchBits);
  614. assert(pVlcTmp->lSymbol>=0 && pVlcTmp->lSymbol<1000);
  615. assert(lCodeSize>0);
  616.         if(lCodeSize>lMaxCodeSize)
  617. lMaxCodeSize=lCodeSize;
  618.     }
  619.     assert(lNOfSymbols>1);
  620.     assert(lMaxCodeSize>0);
  621.     m_lCodeTableEntrySize=lMaxCodeSize/8;
  622.     if(lMaxCodeSize%8)
  623.         m_lCodeTableEntrySize++;
  624.     m_pSizeTable = new Int [lNOfSymbols];
  625.     m_pCodeTable = new Int [lNOfSymbols];
  626. for(pVlcTmp = pVlc; pVlcTmp->pchBits!=NULL; pVlcTmp++)
  627.     {
  628.         Int lCodeSize = strlen(pVlcTmp->pchBits);
  629.         Int lSymbol = pVlcTmp->lSymbol;
  630.         Int iBitPosition=0;
  631.         assert(lSymbol<lNOfSymbols);                                                 
  632.         assert(lCodeSize >=0 && lCodeSize <= (Int) sizeof (Int) * 8);
  633.         m_pSizeTable[lSymbol]=lCodeSize;                                             
  634.         Int* pCodeTableEntry=&m_pCodeTable[lSymbol]; 
  635.         for(Int i=0;i<lCodeSize;i++)                                                
  636.         {                                                                            
  637.         if(iBitPosition==0)                                                      
  638.         *pCodeTableEntry=0;                                                  
  639. Int iBitC = pVlcTmp->pchBits[lCodeSize - i - 1];
  640.             assert(iBitC=='0' || iBitC=='1');
  641.             if(iBitC=='0')                                                          
  642. *pCodeTableEntry&=~(0x01<<iBitPosition);                             
  643.             else                                                                     
  644.                 *pCodeTableEntry|=0x01<<iBitPosition;                                
  645.             iBitPosition++;                                                          
  646. /*
  647.                 if(iBitPosition>=8)                                                      
  648.                 {                                                                        
  649.                     iBitPosition=0;                                                      
  650.                     pCodeTableEntry++;                                                   
  651.                 } 
  652. */                                                                         
  653.         }
  654.     }
  655. }
  656. void CHuffmanEncoder::attachStream(COutBitStream &bitStream)
  657. {
  658.     m_pBitStream=&bitStream;
  659. }
  660. UInt CHuffmanEncoder::encodeSymbol (Int lSymbol, Char* rgchSymbolName, Bool bDontSendBits)
  661. {
  662.     Int lSize=m_pSizeTable[lSymbol];
  663. if (bDontSendBits == TRUE) //for counting bits
  664. return (lSize);
  665. // Added for Data Partitioning by Toshiba (98-1-16)
  666. if(m_pBitStream -> GetDontSendBits()) 
  667. return (lSize);
  668. // End Toshiba(1998-1-16)
  669.     Int iCode=m_pCodeTable[lSymbol];
  670. Int lPrevCounter = m_pBitStream -> getCounter ();
  671.     m_pBitStream -> putBits (iCode,lSize, rgchSymbolName);
  672. return (m_pBitStream -> getCounter () - lPrevCounter);
  673. }
  674. CEntropyEncoderSet::CEntropyEncoderSet (COutBitStream &bitStream)
  675. {
  676. m_pentrencDCT = new CHuffmanEncoder (bitStream, g_rgVlcDCT);
  677. m_pentrencDCTIntra = new CHuffmanEncoder (bitStream, g_rgVlcDCTIntra);
  678.   // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  679.   m_pentrencDCTRVLC = new CHuffmanEncoder (bitStream, g_rgVlcDCTRVLC);
  680.   m_pentrencDCTIntraRVLC = new CHuffmanEncoder (bitStream, g_rgVlcDCTIntraRVLC);
  681.   // End Toshiba(1998-1-16:DP+RVLC)
  682. m_pentrencMV = new CHuffmanEncoder (bitStream, g_rgVlcMV);
  683. m_pentrencMCBPCintra = new CHuffmanEncoder (bitStream, g_rgVlcMCBPCintra);
  684. m_pentrencMCBPCinter = new CHuffmanEncoder (bitStream, g_rgVlcMCBPCinter);
  685. m_pentrencCBPY = new CHuffmanEncoder (bitStream, g_rgVlcCBPY);
  686. m_pentrencCBPY1 = new CHuffmanEncoder (bitStream, g_rgVlcCBPY1);
  687. m_pentrencCBPY2 = new CHuffmanEncoder (bitStream, g_rgVlcCBPY2);
  688. m_pentrencCBPY3 = new CHuffmanEncoder (bitStream, g_rgVlcCBPY3);
  689. m_pentrencIntraDCy = new CHuffmanEncoder (bitStream, g_rgVlcIntraDCy);
  690. m_pentrencIntraDCc = new CHuffmanEncoder (bitStream, g_rgVlcIntraDCc);
  691. m_pentrencMbTypeBVOP = new CHuffmanEncoder (bitStream, g_rgVlcMbTypeBVOP);
  692.   m_pentrencWrpPnt = new CHuffmanEncoder (bitStream, g_rgVlcWrpPnt);
  693. m_ppentrencShapeMode [0] = new CHuffmanEncoder (bitStream, g_rgVlcShapeMode0);
  694. m_ppentrencShapeMode [1] = new CHuffmanEncoder (bitStream, g_rgVlcShapeMode1);
  695. m_ppentrencShapeMode [2] = new CHuffmanEncoder (bitStream, g_rgVlcShapeMode2);
  696. m_ppentrencShapeMode [3] = new CHuffmanEncoder (bitStream, g_rgVlcShapeMode3);
  697. m_ppentrencShapeMode [4] = new CHuffmanEncoder (bitStream, g_rgVlcShapeMode4);
  698. m_ppentrencShapeMode [5] = new CHuffmanEncoder (bitStream, g_rgVlcShapeMode5);
  699. m_ppentrencShapeMode [6] = new CHuffmanEncoder (bitStream, g_rgVlcShapeMode6);
  700. m_pentrencShapeMV1 = new CHuffmanEncoder (bitStream, g_rgVlcShapeMV1);
  701. m_pentrencShapeMV2 = new CHuffmanEncoder (bitStream, g_rgVlcShapeMV2);
  702. /*ifstream istrmTableDCT;
  703. ifstream istrmTableDCTintra;
  704. ifstream istrmTableMV;
  705. ifstream istrmTableMCBPCintra;
  706. ifstream istrmTableMCBPCinter;
  707. ifstream istrmTableCBPY;
  708. ifstream istrmTableCBPY2;
  709. ifstream istrmTableCBPY3;
  710. // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  711. ifstream istrmTableCBPY1DP;
  712. ifstream istrmTableCBPY2DP;
  713. ifstream istrmTableCBPY3DP;
  714. // End Toshiba(1998-1-16:DP+RVLC)
  715. ifstream istrmTableIntraDCy;
  716. ifstream istrmTableIntraDCc;
  717. ifstream istrmMbTypeBVOP;
  718. ifstream istrmWrpPnt;
  719. ifstream istrmShapeMode [7];
  720. ifstream istrmShapeMv1;
  721. ifstream istrmShapeMv2;
  722.   // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  723.   ifstream istrmTableDCTRVLC;
  724.   ifstream istrmTableDCTIntraRVLC;
  725.   // End Toshiba(1998-1-16:DP+RVLC)
  726. // get the vm_home value
  727. Char *rgchVmHome = getenv ( "VM_HOME" );
  728. assert (rgchVmHome != NULL );
  729. Char rgchFile [100];
  730. strcpy (rgchFile, rgchVmHome);
  731. Int iLength = strlen (rgchFile);
  732. Char* pch = rgchFile + iLength;
  733. FULLNAME (sys, vlcdct.txt);
  734. istrmTableDCT.open (rgchFile);
  735. FULLNAME (sys, dctin.txt);
  736. istrmTableDCTintra.open (rgchFile);
  737. FULLNAME (sys, vlcmvd.txt);
  738. istrmTableMV.open (rgchFile);
  739. FULLNAME (sys, mcbpc1.txt);
  740. istrmTableMCBPCintra.open (rgchFile);
  741. FULLNAME (sys, mcbpc2.txt);
  742. istrmTableMCBPCinter.open (rgchFile);
  743. FULLNAME (sys, cbpy.txt);
  744. istrmTableCBPY.open (rgchFile);
  745. FULLNAME (sys, cbpy2.txt);
  746. istrmTableCBPY2.open (rgchFile);
  747. FULLNAME (sys, cbpy3.txt);
  748. istrmTableCBPY3.open (rgchFile);
  749. // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  750. FULLNAME (sys, cbpy1dp.txt);
  751. istrmTableCBPY1DP.open (rgchFile);
  752. FULLNAME (sys, cbpy2dp.txt);
  753. istrmTableCBPY2DP.open (rgchFile);
  754. FULLNAME (sys, cbpy3dp.txt);
  755. istrmTableCBPY3DP.open (rgchFile);
  756. // End Toshiba(1998-1-16:DP+RVLC)
  757. FULLNAME (sys, dcszy.txt);
  758. istrmTableIntraDCy.open (rgchFile);
  759. FULLNAME (sys, dcszc.txt);
  760. istrmTableIntraDCc.open (rgchFile);
  761. FULLNAME (sys, mbtyp.txt);
  762. istrmMbTypeBVOP.open (rgchFile);
  763. FULLNAME (sys, wrppnt.txt);
  764. istrmWrpPnt.open (rgchFile);
  765. FULLNAME (sys, shpmd0.txt);
  766. istrmShapeMode[0].open (rgchFile);
  767. FULLNAME (sys, shpmd1.txt);
  768. istrmShapeMode[1].open (rgchFile);
  769. FULLNAME (sys, shpmd2.txt);
  770. istrmShapeMode[2].open (rgchFile);
  771. FULLNAME (sys, shpmd3.txt);
  772. istrmShapeMode[3].open (rgchFile);
  773. FULLNAME (sys, shpmd4.txt);
  774. istrmShapeMode[4].open (rgchFile);
  775. FULLNAME (sys, shpmd5.txt);
  776. istrmShapeMode[5].open (rgchFile);
  777. FULLNAME (sys, shpmd6.txt);
  778. istrmShapeMode[6].open (rgchFile);
  779. FULLNAME (sys, shpmv1.txt);
  780. istrmShapeMv1.open (rgchFile);
  781. FULLNAME (sys, shpmv2.txt);
  782. istrmShapeMv2.open (rgchFile);
  783.   // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  784.   FULLNAME (sys, rvlcdct.txt);
  785.   istrmTableDCTRVLC.open (rgchFile);
  786.   FULLNAME (sys, rvlcin.txt);
  787.   istrmTableDCTIntraRVLC.open (rgchFile);
  788.   // End Toshiba(1998-1-16:DP+RVLC)
  789. m_pentrencDCT -> loadTable (istrmTableDCT);
  790. m_pentrencDCTIntra -> loadTable (istrmTableDCTintra);
  791.     m_pentrencMV -> loadTable (istrmTableMV);
  792.     m_pentrencMCBPCintra -> loadTable (istrmTableMCBPCintra);
  793.     m_pentrencMCBPCinter -> loadTable (istrmTableMCBPCinter);
  794.     m_pentrencCBPY -> loadTable (istrmTableCBPY);
  795.     m_pentrencCBPY2 -> loadTable (istrmTableCBPY2);
  796.     m_pentrencCBPY3 -> loadTable (istrmTableCBPY3);
  797. // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  798.     m_pentrencCBPY1DP -> loadTable (istrmTableCBPY1DP);
  799.     m_pentrencCBPY2DP -> loadTable (istrmTableCBPY2DP);
  800.     m_pentrencCBPY3DP -> loadTable (istrmTableCBPY3DP);
  801. // End Toshiba(1998-1-16:DP+RVLC)
  802.     m_pentrencIntraDCy -> loadTable (istrmTableIntraDCy);
  803.     m_pentrencIntraDCc -> loadTable (istrmTableIntraDCc);
  804.     m_pentrencMbTypeBVOP->loadTable (istrmMbTypeBVOP);
  805.     m_pentrencWrpPnt->loadTable (istrmWrpPnt);
  806. for (iShapeMd = 0; iShapeMd < 7; iShapeMd++)
  807. m_ppentrencShapeMode [iShapeMd]->loadTable (istrmShapeMode [iShapeMd]);
  808. m_pentrencShapeMV1->loadTable (istrmShapeMv1);
  809. m_pentrencShapeMV2->loadTable (istrmShapeMv2);
  810.   // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  811.   m_pentrencDCTRVLC -> loadTable (istrmTableDCTRVLC);
  812.   m_pentrencDCTIntraRVLC -> loadTable (istrmTableDCTIntraRVLC);
  813.   // End Toshiba(1998-1-16:DP+RVLC)
  814. */
  815. }
  816. CEntropyEncoderSet::~CEntropyEncoderSet()
  817. {
  818. delete m_pentrencDCT;
  819. delete m_pentrencDCTIntra;
  820. delete m_pentrencMV;
  821. delete m_pentrencMCBPCintra;
  822. delete m_pentrencMCBPCinter;
  823. delete m_pentrencCBPY;
  824. delete m_pentrencCBPY2;
  825. delete m_pentrencCBPY3;
  826. delete m_pentrencIntraDCy;
  827. delete m_pentrencIntraDCc;
  828. delete m_pentrencMbTypeBVOP;
  829. delete m_pentrencWrpPnt;
  830. for (UInt iShapeMd = 0; iShapeMd < 7; iShapeMd++)
  831. delete m_ppentrencShapeMode [iShapeMd];
  832. delete m_pentrencShapeMV1;
  833. delete m_pentrencShapeMV2;
  834.   // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  835.   delete m_pentrencDCTRVLC;
  836.   delete m_pentrencDCTIntraRVLC;
  837.   // End Toshiba(1998-1-16:DP+RVLC)
  838. }
  839. CEntropyDecoderSet::CEntropyDecoderSet (CInBitStream &bitStream)
  840. {
  841. m_pentrdecDCT = new CHuffmanDecoder (bitStream, g_rgVlcDCT);
  842. m_pentrdecDCTIntra = new CHuffmanDecoder (bitStream, g_rgVlcDCTIntra);
  843.   // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  844.   m_pentrdecDCTRVLC = new CHuffmanDecoder (bitStream, g_rgVlcDCTRVLC);
  845.   m_pentrdecDCTIntraRVLC = new CHuffmanDecoder (bitStream, g_rgVlcDCTIntraRVLC);
  846.   // End Toshiba(1998-1-16:DP+RVLC)
  847. m_pentrdecMV = new CHuffmanDecoder (bitStream, g_rgVlcMV);
  848. m_pentrdecMCBPCintra = new CHuffmanDecoder (bitStream, g_rgVlcMCBPCintra);
  849. m_pentrdecMCBPCinter = new CHuffmanDecoder (bitStream, g_rgVlcMCBPCinter);
  850. m_pentrdecCBPY = new CHuffmanDecoder (bitStream, g_rgVlcCBPY);
  851. m_pentrdecCBPY1 = new CHuffmanDecoder (bitStream, g_rgVlcCBPY1);
  852. m_pentrdecCBPY2 = new CHuffmanDecoder (bitStream, g_rgVlcCBPY2);
  853. m_pentrdecCBPY3 = new CHuffmanDecoder (bitStream, g_rgVlcCBPY3);
  854. m_pentrdecIntraDCy = new CHuffmanDecoder (bitStream, g_rgVlcIntraDCy);
  855. m_pentrdecIntraDCc = new CHuffmanDecoder (bitStream, g_rgVlcIntraDCc);
  856. m_pentrdecMbTypeBVOP = new CHuffmanDecoder (bitStream, g_rgVlcMbTypeBVOP);
  857.   m_pentrdecWrpPnt = new CHuffmanDecoder (bitStream, g_rgVlcWrpPnt);
  858. m_ppentrdecShapeMode [0] = new CHuffmanDecoder (bitStream, g_rgVlcShapeMode0);
  859. m_ppentrdecShapeMode [1] = new CHuffmanDecoder (bitStream, g_rgVlcShapeMode1);
  860. m_ppentrdecShapeMode [2] = new CHuffmanDecoder (bitStream, g_rgVlcShapeMode2);
  861. m_ppentrdecShapeMode [3] = new CHuffmanDecoder (bitStream, g_rgVlcShapeMode3);
  862. m_ppentrdecShapeMode [4] = new CHuffmanDecoder (bitStream, g_rgVlcShapeMode4);
  863. m_ppentrdecShapeMode [5] = new CHuffmanDecoder (bitStream, g_rgVlcShapeMode5);
  864. m_ppentrdecShapeMode [6] = new CHuffmanDecoder (bitStream, g_rgVlcShapeMode6);
  865. m_pentrdecShapeMV1 = new CHuffmanDecoder (bitStream, g_rgVlcShapeMV1);
  866. m_pentrdecShapeMV2 = new CHuffmanDecoder (bitStream, g_rgVlcShapeMV2);
  867. /* ifstream istrmTableDCT;
  868. ifstream istrmTableDCTIntra;
  869. ifstream istrmTableMV;
  870. ifstream istrmTableMCBPCintra;
  871. ifstream istrmTableMCBPCinter;
  872. ifstream istrmTableCBPY;
  873. ifstream istrmTableCBPY2;
  874. ifstream istrmTableCBPY3;
  875. // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  876. ifstream istrmTableCBPY1DP;
  877. ifstream istrmTableCBPY2DP;
  878. ifstream istrmTableCBPY3DP;
  879. // End Toshiba(1998-1-16:DP+RVLC)
  880. ifstream istrmTableIntraDCy;
  881. ifstream istrmTableIntraDCc;
  882. ifstream istrmMbTypeBVOP;
  883. ifstream istrmWrpPnt;
  884. ifstream istrmShapeMode [7];
  885. ifstream istrmShapeMv1;
  886. ifstream istrmShapeMv2;
  887.   // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  888.   ifstream istrmTableDCTRVLC;
  889.   ifstream istrmTableDCTIntraRVLC;
  890.   // End Toshiba(1998-1-16:DP+RVLC)
  891. // get the vm_home value
  892. Char *rgchVmHome = getenv ( "VM_HOME" );
  893. assert (rgchVmHome != NULL );
  894. Char rgchFile [100];
  895. strcpy (rgchFile, rgchVmHome);
  896. Int iLength = strlen (rgchFile);
  897. Char* pch = rgchFile + iLength;
  898. FULLNAME (sys, vlcdct.txt);
  899. istrmTableDCT.open (rgchFile);
  900. FULLNAME (sys, dctin.txt);
  901. istrmTableDCTIntra.open (rgchFile);
  902. FULLNAME (sys, vlcmvd.txt);
  903. istrmTableMV.open (rgchFile);
  904. FULLNAME (sys, mcbpc1.txt);
  905. istrmTableMCBPCintra.open (rgchFile);
  906. FULLNAME (sys, mcbpc2.txt);
  907. istrmTableMCBPCinter.open (rgchFile);
  908. FULLNAME (sys, cbpy.txt);
  909. istrmTableCBPY.open (rgchFile);
  910. FULLNAME (sys, cbpy2.txt);
  911. istrmTableCBPY2.open (rgchFile);
  912. FULLNAME (sys, cbpy3.txt);
  913. istrmTableCBPY3.open (rgchFile);
  914. // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  915. FULLNAME (sys, cbpy1dp.txt);
  916. istrmTableCBPY1DP.open (rgchFile);
  917. FULLNAME (sys, cbpy2dp.txt);
  918. istrmTableCBPY2DP.open (rgchFile);
  919. FULLNAME (sys, cbpy3dp.txt);
  920. istrmTableCBPY3DP.open (rgchFile);
  921. // End Toshiba(1998-1-16:DP+RVLC)
  922. FULLNAME (sys, dcszy.txt);
  923. istrmTableIntraDCy.open (rgchFile);
  924. FULLNAME (sys, dcszc.txt);
  925. istrmTableIntraDCc.open (rgchFile);
  926. FULLNAME (sys, mbtyp.txt);
  927. istrmMbTypeBVOP.open (rgchFile);
  928. FULLNAME (sys, wrppnt.txt);
  929. istrmWrpPnt.open (rgchFile);
  930. FULLNAME (sys, shpmd0.txt);
  931. istrmShapeMode[0].open (rgchFile);
  932. FULLNAME (sys, shpmd1.txt);
  933. istrmShapeMode[1].open (rgchFile);
  934. FULLNAME (sys, shpmd2.txt);
  935. istrmShapeMode[2].open (rgchFile);
  936. FULLNAME (sys, shpmd3.txt);
  937. istrmShapeMode[3].open (rgchFile);
  938. FULLNAME (sys, shpmd4.txt);
  939. istrmShapeMode[4].open (rgchFile);
  940. FULLNAME (sys, shpmd5.txt);
  941. istrmShapeMode[5].open (rgchFile);
  942. FULLNAME (sys, shpmd6.txt);
  943. istrmShapeMode[6].open (rgchFile);
  944. FULLNAME (sys, shpmv1.txt);
  945. istrmShapeMv1.open (rgchFile);
  946. FULLNAME (sys, shpmv2.txt);
  947. istrmShapeMv2.open (rgchFile);
  948.   // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  949.   FULLNAME (sys, rvlcdct.txt);
  950.   istrmTableDCTRVLC.open (rgchFile);
  951.   FULLNAME (sys, rvlcin.txt);
  952.   istrmTableDCTIntraRVLC.open (rgchFile);
  953.   // End Toshiba(1998-1-16:DP+RVLC)
  954. m_pentrdecDCT -> loadTable (istrmTableDCT);
  955. m_pentrdecDCTIntra -> loadTable (istrmTableDCTIntra);
  956.     m_pentrdecMV -> loadTable (istrmTableMV);
  957.     m_pentrdecMCBPCintra -> loadTable (istrmTableMCBPCintra);
  958.     m_pentrdecMCBPCinter -> loadTable (istrmTableMCBPCinter);
  959.     m_pentrdecCBPY -> loadTable (istrmTableCBPY);
  960.     m_pentrdecCBPY2 -> loadTable (istrmTableCBPY2);
  961.     m_pentrdecCBPY3 -> loadTable (istrmTableCBPY3);
  962. // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  963.     m_pentrdecCBPY1DP -> loadTable (istrmTableCBPY1DP);
  964.     m_pentrdecCBPY2DP -> loadTable (istrmTableCBPY2DP);
  965.     m_pentrdecCBPY3DP -> loadTable (istrmTableCBPY3DP);
  966. // End Toshiba(1998-1-16:DP+RVLC)
  967.     m_pentrdecIntraDCy -> loadTable (istrmTableIntraDCy);
  968.     m_pentrdecIntraDCc -> loadTable (istrmTableIntraDCc);
  969.     m_pentrdecMbTypeBVOP -> loadTable (istrmMbTypeBVOP);
  970. m_pentrdecWrpPnt  -> loadTable (istrmWrpPnt);
  971. for (iShapeMd = 0; iShapeMd < 7; iShapeMd++)
  972. m_ppentrdecShapeMode [iShapeMd]->loadTable (istrmShapeMode[iShapeMd]);
  973. m_pentrdecShapeMV1->loadTable (istrmShapeMv1);
  974. m_pentrdecShapeMV2->loadTable (istrmShapeMv2);
  975.   // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  976.   m_pentrdecDCTRVLC -> loadTable (istrmTableDCTRVLC);
  977.   m_pentrdecDCTIntraRVLC -> loadTable (istrmTableDCTIntraRVLC);
  978.   // End Toshiba(1998-1-16:DP+RVLC)
  979. */
  980. }
  981. CEntropyDecoderSet::~CEntropyDecoderSet()
  982. {
  983. delete m_pentrdecDCT;
  984. delete m_pentrdecDCTIntra;
  985. delete m_pentrdecMV;
  986. delete m_pentrdecMCBPCintra;
  987. delete m_pentrdecMCBPCinter;
  988. delete m_pentrdecCBPY;
  989. delete m_pentrdecCBPY1;
  990. delete m_pentrdecCBPY2;
  991. delete m_pentrdecCBPY3;
  992. delete m_pentrdecIntraDCy;
  993. delete m_pentrdecIntraDCc;
  994. delete m_pentrdecMbTypeBVOP;
  995. delete m_pentrdecWrpPnt ;
  996. for (UInt iShapeMd = 0; iShapeMd < 7; iShapeMd++)
  997. delete m_ppentrdecShapeMode [iShapeMd];
  998. delete m_pentrdecShapeMV1;
  999. delete m_pentrdecShapeMV2;
  1000.   // Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
  1001.   delete m_pentrdecDCTRVLC;
  1002.   delete m_pentrdecDCTIntraRVLC;
  1003.   // End Toshiba(1998-1-16:DP+RVLC)
  1004. }