source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComDepthMapGenerator.h @ 21

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

updated with HHI branch (0.2-HHI)

  • Property svn:eol-style set to native
File size: 10.5 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-2011, 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 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
35
36/** \file     TComDepthMapGenerator.h
37    \brief    depth map generator class (header)
38*/
39
40
41#ifndef __TCOM_DEPTH_MAP_GENERATOR__
42#define __TCOM_DEPTH_MAP_GENERATOR__
43
44
45#include "CommonDef.h"
46#include "TComPic.h"
47#include "TComPrediction.h"
48#include "TComSlice.h"
49
50
51#if DEPTH_MAP_GENERATION
52
53
54class TComSPSAccess // would be better to have a real SPS buffer
55{
56public:
57  TComSPSAccess ()  { clear(); }
58  ~TComSPSAccess()  {}
59
60  Void      clear   ()                            { ::memset( m_aacActiveSPS, 0x00, sizeof( m_aacActiveSPS ) ); }
61  Void      addSPS  ( TComSPS* pcSPS    )         { m_aacActiveSPS[ pcSPS->isDepth() ? 1 : 0 ][ pcSPS->getViewId() ] = pcSPS; }
62  TComSPS*  getSPS  ( UInt     uiViewId, 
63                      Bool     bIsDepth = false ) { return m_aacActiveSPS[ bIsDepth ? 1 : 0 ][ uiViewId ]; }
64
65  UInt      getPdm  ()                            { if( m_aacActiveSPS[0][1] ) { return m_aacActiveSPS[0][1]->getPredDepthMapGeneration(); } return 0; }
66#if HHI_INTER_VIEW_RESIDUAL_PRED
67  UInt      getResPrd ()                          { if( m_aacActiveSPS[0][1] ) { return m_aacActiveSPS[0][1]->getMultiviewResPredMode  (); } return 0; }
68#endif
69
70private:
71  TComSPS*  m_aacActiveSPS[ 2 ][ MAX_NUMBER_VIEWS ];
72};
73
74
75
76class TComAUPicAccess // would be better to have a real decoded picture buffer
77{
78public:
79  TComAUPicAccess () : m_iLastPoc( 0 ), m_uiMaxViewId( 0 ) { clear(); }
80  ~TComAUPicAccess()                   {}
81
82  Void      clear   ()                            { ::memset( m_aacCurrAUPics, 0x00, sizeof( m_aacCurrAUPics ) ); }
83  Void      addPic    ( TComPic* pcPic    )         { if( m_iLastPoc != pcPic->getPOC() ) 
84                                                      { 
85                                                        clear(); 
86                                                        m_iLastPoc = pcPic->getPOC(); 
87                                                      } 
88                                                      m_aacCurrAUPics[ pcPic->getSPS()->isDepth() ? 1 : 0 ][ pcPic->getSPS()->getViewId() ] = pcPic; 
89                                                      if( pcPic->getSPS()->getViewId() > m_uiMaxViewId )
90                                                      {
91                                                        m_uiMaxViewId = pcPic->getSPS()->getViewId();
92                                                      }
93                                                    }
94  TComPic*  getPic  ( UInt     uiViewId,
95                      Bool     bIsDepth = false ) { return m_aacCurrAUPics[ bIsDepth ? 1 : 0 ][ uiViewId ]; }
96  UInt      getMaxVId ()                            { return m_uiMaxViewId; }
97
98private:
99  Int       m_iLastPoc;
100  UInt      m_uiMaxViewId;
101  TComPic*  m_aacCurrAUPics[ 2 ][ MAX_NUMBER_VIEWS ];
102};
103
104
105
106class TComDepthMapGenerator
107{
108public:
109  TComDepthMapGenerator ();
110  ~TComDepthMapGenerator();
111
112  Void  create                ( Bool bDecoder, UInt uiPicWidth, UInt uiPicHeight, UInt uiMaxCUDepth, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiOrgBitDepth, UInt uiSubSampExpX, UInt uiSubSampExpY );
113  Void  destroy               ();
114
115  Void  init                  ( TComPrediction* pcPrediction, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess );
116  Void  uninit                ();
117
118  Void  initViewComponent     ( TComPic*      pcPic );
119  Bool  predictDepthMap       ( TComPic*      pcPic );
120  Void  updateDepthMap        ( TComPic*      pcPic );
121  Void  dumpDepthMap          ( TComPic*      pcPic, char* pFilenameBase );
122
123#if HHI_INTER_VIEW_MOTION_PRED
124  Void  covertOrgDepthMap     ( TComPic*      pcPic );
125#endif
126
127  UInt  getBaseViewId         ( UInt          uiIdx ) { AOF( uiIdx < m_auiBaseIdList.size() );  return m_auiBaseIdList[uiIdx]; }
128  UInt  getSubSampExpX        ()                      { return m_uiSubSampExpX; }
129  UInt  getSubSampExpY        ()                      { return m_uiSubSampExpY; }
130  Int   getDisparity          ( TComPic*      pcPic, Int iPosX, Int iPosY, UInt uiRefViewId );
131#if HHI_INTER_VIEW_MOTION_PRED
132  Int   getPdmMergeCandidate  ( TComDataCU*   pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv );
133  Bool  getPdmMvPred          ( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, Bool bMerge );
134  Bool  getIViewOrgDepthMvPred( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv );
135#endif
136
137  TComPrediction*   getPrediction ()  { return m_pcPrediction;  }
138  TComSPSAccess*    getSPSAccess  ()  { return m_pcSPSAccess;   }
139  TComAUPicAccess*  getAUPicAccess()  { return m_pcAUPicAccess; }
140
141private:
142  // picture operations
143  Bool  xConvertDepthMapCurr2Ref  ( TComPic*    pcRef, TComPic* pcCur );
144  Bool  xConvertDepthMapRef2Curr  ( TComPic*    pcCur, TComPic* pcRef );
145  Bool  xPredictDepthMap          ( TComPic*    pcPic );
146  Bool  xFillDepthMapHoles        ( TComPic*    pcPic );
147  Void  xClearDepthMap            ( TComPic*    pcPic, Int      iVal  = PDM_UNDEFINED_DEPTH );
148  Void  xSetChroma                ( TComPicYuv* pcPic, Int      iVal  );
149
150  // CU operations 
151  Void  xPredictCUDepthMap        ( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx );                            // CU depth map prediction
152  Void  xIntraPredictCUDepthMap   ( TComDataCU* pcCU, TComYuv* pcCUDepthMap );                                      // CU intra prediction
153  Void  xInterPredictCUDepthMap   ( TComDataCU* pcCU, TComYuv* pcCUDepthMap );                                      // CU inter prediction
154 
155  // PU and block operations 
156  Void  xIntraPredictBlkDepthMap  ( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiAbsPartIdx, UInt uiTrDepth );   // block intra prediction
157  Void  xInterPredictPUDepthMap   ( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx );                      // PU inter prediction/update
158  Void  xIViewPUDepthMapUpdate    ( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx );                      // PU interview update
159  Void  xInterPUDepthMapUpdate    ( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx );                      // PU inter update
160  Void  xInterPUDepthMapPrediction( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx );                      // PU inter prediction
161  Bool  xGetPredDepth             ( TComDataCU* pcCU, UInt uiPartIdx, Int& riPrdDepth, Int* piPosX = 0, Int* piPosY = 0 );
162
163  // conversion functions
164  Int   xGetVirtDepthFromDisparity( UInt uiBaseId, Int iDisparity )
165  {
166    AOF( uiBaseId < m_uiCurrViewId );
167    Int*   pPar = m_aaiConvParsDisparity2VirtDepth[ uiBaseId ];
168    Int    iRes = ( pPar[ 0 ] * iDisparity + pPar[ 1 ] ) >> pPar[ 2 ];
169    return iRes;
170  }
171  Int   xGetDisparityFromVirtDepth( UInt uiBaseId, Int iVirtDepth )
172  {
173    AOF( uiBaseId < m_uiCurrViewId );
174    Int*   pPar = m_aaiConvParsVirtDepth2Disparity[ uiBaseId ];
175    Int    iRes = ( pPar[ 0 ] * iVirtDepth + pPar[ 1 ] ) >> pPar[ 2 ];
176    return iRes;
177  }
178  Int   xGetVirtDepthFromOrigDepth( UInt uiViewId, Int iOrigDepth )
179  {
180    AOF( uiViewId <= m_uiCurrViewId );
181    Int*   pPar = m_aaiConvParsOrigDepth2VirtDepth[ uiViewId ];
182    Int    iRes = ( pPar[ 0 ] * iOrigDepth + pPar[ 1 ] ) >> pPar[ 2 ];
183    return iRes;
184  }
185  Int   xGetOrigDepthFromVirtDepth( UInt uiViewId, Int iVirtDepth )
186  {
187    AOF( uiViewId <= m_uiCurrViewId );
188    Int*   pPar = m_aaiConvParsVirtDepth2OrigDepth[ uiViewId ];
189    Int    iRes = ( pPar[ 0 ] * iVirtDepth + pPar[ 1 ] ) >> pPar[ 2 ];
190    return iRes;
191  }
192
193
194private:
195  // general parameters
196  Bool              m_bCreated;
197  Bool              m_bInit;
198  Bool              m_bDecoder;
199  TComPrediction*   m_pcPrediction;
200  TComSPSAccess*    m_pcSPSAccess;
201  TComAUPicAccess*  m_pcAUPicAccess;
202  UInt              m_uiMaxDepth;
203  UInt              m_uiOrgDepthBitDepth;
204  UInt              m_uiSubSampExpX;
205  UInt              m_uiSubSampExpY;
206  TComYuv**         m_ppcYuv;
207  TComDataCU**      m_ppcCU;
208  TComPicYuv        m_cTmpPic;
209
210  // conversion parameters
211  UInt              m_uiCurrViewId;
212  Bool              m_bPDMAvailable;
213  std::vector<UInt> m_auiBaseIdList;
214  Int               m_aaiConvParsDisparity2VirtDepth[ MAX_NUMBER_VIEWS ][ 3 ];  // disparity      ==> virtual  depth   (0:scale, 1:add, 2:shift)
215  Int               m_aaiConvParsVirtDepth2Disparity[ MAX_NUMBER_VIEWS ][ 3 ];  // virtual  depth ==> disparity        (0:scale, 1:add, 2:shift)
216  Int               m_aaiConvParsOrigDepth2VirtDepth[ MAX_NUMBER_VIEWS ][ 3 ];  // original depth ==> virtual  depth   (0:scale, 1:add, 2:shift)
217  Int               m_aaiConvParsVirtDepth2OrigDepth[ MAX_NUMBER_VIEWS ][ 3 ];  // virtual  depth ==> original depth   (0:scale, 1:add, 2:shift)
218
219  // temporary arrays
220  Bool              m_aabDepthSet[ MAX_CU_SIZE >> 2 ][ MAX_CU_SIZE >> 2 ];
221  Int               m_aai4x4Depth[ MAX_CU_SIZE >> 2 ][ MAX_CU_SIZE >> 2 ];
222};
223
224
225#endif // DEPTH_MAP_GENERATION
226
227#endif // __TCOM_DEPTH_MAP_GENERATOR__
228
229
230
231
Note: See TracBrowser for help on using the repository browser.