Ignore:
Timestamp:
11 May 2012, 21:20:17 (13 years ago)
Author:
hschwarz
Message:

updated trunk (move to HM6.1)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/ContextModel3DBuffer.cpp

    r5 r56  
    22 * License, included below. This software may be subject to other third party
    33 * and contributor rights, including patent rights, and no such rights are
    4  * granted under this license.
     4 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2011, ISO/IEC
     6 * Copyright (c) 2010-2012, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    1515 *    this list of conditions and the following disclaimer in the documentation
    1616 *    and/or other materials provided with the distribution.
    17  *  * Neither the name of the ISO/IEC nor the names of its contributors may
     17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
    1818 *    be used to endorse or promote products derived from this software without
    1919 *    specific prior written permission.
     
    3232 */
    3333
    34 
    35 
    3634/** \file     ContextModel3DBuffer.cpp
    3735    \brief    context model 3D buffer class
     
    4038#include "ContextModel3DBuffer.h"
    4139
     40//! \ingroup TLibCommon
     41//! \{
     42
    4243// ====================================================================================================================
    4344// Constructor / destructor / initialization / destroy
    4445// ====================================================================================================================
    4546
    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 
     47ContextModel3DBuffer::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 )
    5251{
    5352  // 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;
    6255}
    6356
     
    6760
    6861/**
    69  - initialize 3D buffer with respect to slicetype, QP and given initial probability table
    70  .
    71  \param  eSliceType      slice type
    72  \param  iQP             input QP value
    73  \param  psCtxModel      given probability table
     62 * 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
    7467 */
    75 Void ContextModel3DBuffer::initBuffer( SliceType eSliceType, Int iQp, Short* psCtxModel )
     68Void ContextModel3DBuffer::initBuffer( SliceType sliceType, Int qp, UChar* ctxModel )
    7669{
    77   UInt n, z, offset = 0;
     70  ctxModel += sliceType * m_sizeXYZ;
    7871 
    79   for ( z = 0; z < m_uiSizeZ; z++ )
     72  for ( Int n = 0; n < m_sizeXYZ; n++ )
    8073  {
    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
    8678  }
    87   return;
    8879}
    8980
     81#if CABAC_INIT_FLAG
    9082/**
    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
    9488 */
    95 Void ContextModel3DBuffer::copyFrom( ContextModel3DBuffer* pSrc )
     89UInt ContextModel3DBuffer::calcCost( SliceType sliceType, Int qp, UChar* ctxModel )
    9690{
    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;
    98122}
    99 
     123#endif
     124//! \}
Note: See TracChangeset for help on using the changeset viewer.