source: 3DVCSoftware/branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/ContextModel3DBuffer.cpp @ 1278

Last change on this file since 1278 was 1200, checked in by tech, 9 years ago

Update to HM-16.5.
Starting point for further re-activation of 3D-tools.

Includes:

active:

  • MV-HEVC
  • 3D-HLS (apart from DLT)
  • VSO

inactive:

  • remaining 3D-HEVC tools.
  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
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
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2015, ITU/ISO/IEC
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.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
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 */
33
34/** \file     ContextModel3DBuffer.cpp
35    \brief    context model 3D buffer class
36*/
37
38#include "ContextModel3DBuffer.h"
39
40//! \ingroup TLibCommon
41//! \{
42
43// ====================================================================================================================
44// Constructor / destructor / initialization / destroy
45// ====================================================================================================================
46
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 )
51{
52  // allocate 3D buffer
53  m_contextModel = basePtr;
54  count += m_sizeXYZ;
55}
56
57// ====================================================================================================================
58// Public member functions
59// ====================================================================================================================
60
61/**
62 * Initialize 3D buffer with respect to slice type, QP and given initial probability table
63 *
64 * \param  sliceType      slice type
65 * \param  qp             input QP value
66 * \param  ctxModel       given probability table
67 */
68Void ContextModel3DBuffer::initBuffer( SliceType sliceType, Int qp, UChar* ctxModel )
69{
70  ctxModel += sliceType * m_sizeXYZ;
71
72  for ( Int n = 0; n < m_sizeXYZ; n++ )
73  {
74    m_contextModel[ n ].init( qp, ctxModel[ n ] );
75    m_contextModel[ n ].setBinsCoded( 0 );
76  }
77}
78
79/**
80 * Calculate the cost of choosing a probability table based on the current probability of CABAC at encoder
81 *
82 * \param  sliceType      slice type
83 * \param  qp             input QP value
84 * \param  ctxModel      given probability table
85 */
86UInt ContextModel3DBuffer::calcCost( SliceType sliceType, Int qp, UChar* ctxModel )
87{
88  UInt cost = 0;
89  ctxModel += sliceType * m_sizeXYZ;
90
91  for ( Int n = 0; n < m_sizeXYZ; n++ )
92  {
93    ContextModel tmpContextModel;
94    tmpContextModel.init( qp, ctxModel[ n ] );
95
96    // Map the 64 CABAC states to their corresponding probability values
97    static const 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};
98
99    Double probLPS          = aStateToProbLPS[ m_contextModel[ n ].getState() ];
100    Double prob0, prob1;
101    if (m_contextModel[ n ].getMps()==1)
102    {
103      prob0 = probLPS;
104      prob1 = 1.0-prob0;
105    }
106    else
107    {
108      prob1 = probLPS;
109      prob0 = 1.0-prob1;
110    }
111
112    if (m_contextModel[ n ].getBinsCoded()>0)
113    {
114      cost += (UInt) (prob0 * tmpContextModel.getEntropyBits( 0 ) + prob1 * tmpContextModel.getEntropyBits( 1 ));
115    }
116  }
117
118  return cost;
119}
120//! \}
Note: See TracBrowser for help on using the repository browser.