Changeset 56 in 3DVCSoftware for trunk/source/Lib/TLibCommon/ContextModel3DBuffer.cpp
- Timestamp:
- 11 May 2012, 21:20:17 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/ContextModel3DBuffer.cpp
r5 r56 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 1,ISO/IEC6 * Copyright (c) 2010-2012, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 15 15 * this list of conditions and the following disclaimer in the documentation 16 16 * and/or other materials provided with the distribution. 17 * * Neither the name of the I SO/IEC nor the names of its contributors may17 * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may 18 18 * be used to endorse or promote products derived from this software without 19 19 * specific prior written permission. … … 32 32 */ 33 33 34 35 36 34 /** \file ContextModel3DBuffer.cpp 37 35 \brief context model 3D buffer class … … 40 38 #include "ContextModel3DBuffer.h" 41 39 40 //! \ingroup TLibCommon 41 //! \{ 42 42 43 // ==================================================================================================================== 43 44 // Constructor / destructor / initialization / destroy 44 45 // ==================================================================================================================== 45 46 46 ContextModel3DBuffer::ContextModel3DBuffer( UInt uiSizeZ, UInt uiSizeY, UInt uiSizeX ) : 47 m_pcContextModel( NULL ), 48 m_uiSizeX( uiSizeX ), 49 m_uiSizeY( uiSizeY ), 50 m_uiSizeZ( uiSizeZ ) 51 47 ContextModel3DBuffer::ContextModel3DBuffer( UInt uiSizeZ, UInt uiSizeY, UInt uiSizeX, ContextModel *basePtr, Int &count ) 48 : m_sizeX ( uiSizeX ) 49 , m_sizeXY ( uiSizeX * uiSizeY ) 50 , m_sizeXYZ( uiSizeX * uiSizeY * uiSizeZ ) 52 51 { 53 52 // allocate 3D buffer 54 m_pcContextModel = new ContextModel[ uiSizeZ * m_uiSizeY * m_uiSizeX ]; 55 } 56 57 ContextModel3DBuffer::~ContextModel3DBuffer() 58 { 59 // delete 3D buffer 60 delete [] m_pcContextModel; 61 m_pcContextModel = NULL; 53 m_contextModel = basePtr; 54 count += m_sizeXYZ; 62 55 } 63 56 … … 67 60 68 61 /** 69 - initialize 3D buffer with respect to slicetype, QP and given initial probability table70 .71 \param eSliceType slice type72 \param iQPinput QP value73 \param psCtxModel given probability table62 * Initialize 3D buffer with respect to slicetype, QP and given initial probability table 63 * 64 * \param eSliceType slice type 65 * \param iQp input QP value 66 * \param psCtxModel given probability table 74 67 */ 75 Void ContextModel3DBuffer::initBuffer( SliceType eSliceType, Int iQp, Short* psCtxModel )68 Void ContextModel3DBuffer::initBuffer( SliceType sliceType, Int qp, UChar* ctxModel ) 76 69 { 77 UInt n, z, offset = 0;70 ctxModel += sliceType * m_sizeXYZ; 78 71 79 for ( z = 0; z < m_uiSizeZ; z++ )72 for ( Int n = 0; n < m_sizeXYZ; n++ ) 80 73 { 81 for ( n = 0; n < m_uiSizeY * m_uiSizeX; n++ ) 82 { 83 m_pcContextModel[ offset + n ].init( iQp, psCtxModel + eSliceType * 2 * ( m_uiSizeZ * m_uiSizeY * m_uiSizeX ) + 2 * (n + offset) ); 84 } 85 offset += n; 74 m_contextModel[ n ].init( qp, ctxModel[ n ] ); 75 #if CABAC_INIT_FLAG 76 m_contextModel[ n ].setBinsCoded( 0 ); 77 #endif 86 78 } 87 return;88 79 } 89 80 81 #if CABAC_INIT_FLAG 90 82 /** 91 - copy from given 3D buffer 92 . 93 \param pSrc given 3D buffer 83 * Calculate the cost of choosing a probability table based on the current probability of CABAC at encoder 84 * 85 * \param sliceType slice type 86 * \param qp input QP value 87 * \param ctxModel given probability table 94 88 */ 95 Void ContextModel3DBuffer::copyFrom( ContextModel3DBuffer* pSrc)89 UInt ContextModel3DBuffer::calcCost( SliceType sliceType, Int qp, UChar* ctxModel ) 96 90 { 97 ::memcpy( this->m_pcContextModel, pSrc->m_pcContextModel, sizeof(ContextModel) * m_uiSizeZ * m_uiSizeY * m_uiSizeX ); 91 UInt cost = 0; 92 ctxModel += sliceType * m_sizeXYZ; 93 94 for ( Int n = 0; n < m_sizeXYZ; n++ ) 95 { 96 ContextModel tmpContextModel; 97 tmpContextModel.init( qp, ctxModel[ n ] ); 98 99 // Map the 64 CABAC states to their corresponding probability values 100 static Double aStateToProbLPS[] = {0.50000000, 0.47460857, 0.45050660, 0.42762859, 0.40591239, 0.38529900, 0.36573242, 0.34715948, 0.32952974, 0.31279528, 0.29691064, 0.28183267, 0.26752040, 0.25393496, 0.24103941, 0.22879875, 0.21717969, 0.20615069, 0.19568177, 0.18574449, 0.17631186, 0.16735824, 0.15885931, 0.15079198, 0.14313433, 0.13586556, 0.12896592, 0.12241667, 0.11620000, 0.11029903, 0.10469773, 0.09938088, 0.09433404, 0.08954349, 0.08499621, 0.08067986, 0.07658271, 0.07269362, 0.06900203, 0.06549791, 0.06217174, 0.05901448, 0.05601756, 0.05317283, 0.05047256, 0.04790942, 0.04547644, 0.04316702, 0.04097487, 0.03889405, 0.03691890, 0.03504406, 0.03326442, 0.03157516, 0.02997168, 0.02844963, 0.02700488, 0.02563349, 0.02433175, 0.02309612, 0.02192323, 0.02080991, 0.01975312, 0.01875000}; 101 102 Double probLPS = aStateToProbLPS[ m_contextModel[ n ].getState() ]; 103 Double prob0, prob1; 104 if (m_contextModel[ n ].getMps()==1) 105 { 106 prob0 = probLPS; 107 prob1 = 1.0-prob0; 108 } 109 else 110 { 111 prob1 = probLPS; 112 prob0 = 1.0-prob1; 113 } 114 115 if (m_contextModel[ n ].getBinsCoded()>0) 116 { 117 cost += (UInt) (prob0 * tmpContextModel.getEntropyBits( 0 ) + prob1 * tmpContextModel.getEntropyBits( 1 )); 118 } 119 } 120 121 return cost; 98 122 } 99 123 #endif 124 //! \}
Note: See TracChangeset for help on using the changeset viewer.