source: 3DVCSoftware/trunk/source/Lib/TLibCommon/ContextModel3DBuffer.cpp @ 78

Last change on this file since 78 was 56, checked in by hschwarz, 13 years ago

updated trunk (move to HM6.1)

  • Property svn:eol-style set to native
File size: 5.2 KB
RevLine 
[5]1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
[56]4 * granted under this license. 
[5]5 *
[56]6 * Copyright (c) 2010-2012, ITU/ISO/IEC
[5]7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
[2]33
34/** \file     ContextModel3DBuffer.cpp
35    \brief    context model 3D buffer class
36*/
37
38#include "ContextModel3DBuffer.h"
39
[56]40//! \ingroup TLibCommon
41//! \{
42
[2]43// ====================================================================================================================
44// Constructor / destructor / initialization / destroy
45// ====================================================================================================================
46
[56]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 )
[2]51{
52  // allocate 3D buffer
[56]53  m_contextModel = basePtr;
54  count += m_sizeXYZ;
[2]55}
56
57// ====================================================================================================================
58// Public member functions
59// ====================================================================================================================
60
61/**
[56]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
[2]67 */
[56]68Void ContextModel3DBuffer::initBuffer( SliceType sliceType, Int qp, UChar* ctxModel )
[2]69{
[56]70  ctxModel += sliceType * m_sizeXYZ;
[2]71 
[56]72  for ( Int n = 0; n < m_sizeXYZ; n++ )
[2]73  {
[56]74    m_contextModel[ n ].init( qp, ctxModel[ n ] );
75#if CABAC_INIT_FLAG
76    m_contextModel[ n ].setBinsCoded( 0 );
77#endif
[2]78  }
79}
80
[56]81#if CABAC_INIT_FLAG
[2]82/**
[56]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
[2]88 */
[56]89UInt ContextModel3DBuffer::calcCost( SliceType sliceType, Int qp, UChar* ctxModel )
[2]90{
[56]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;
[2]122}
[56]123#endif
124//! \}
Note: See TracBrowser for help on using the repository browser.