source: 3DVCSoftware/branches/HTM-5.1-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.cpp @ 289

Last change on this file since 289 was 289, checked in by tech, 12 years ago

Clean up of macros related to NBDV.

  • Property svn:eol-style set to native
File size: 83.4 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.cpp
37    \brief    depth map generator class
38*/
39
40
41
42#include "CommonDef.h"
43#include "TComDepthMapGenerator.h"
44
45
46#if DEPTH_MAP_GENERATION
47
48
49TComDepthMapGenerator::TComDepthMapGenerator()
50{
51  m_bCreated            = false;
52  m_bInit               = false;
53  m_bDecoder            = false;
54  m_pcPrediction        = 0;
55  m_pcSPSAccess         = 0;
56  m_pcAUPicAccess       = 0;
57  m_uiMaxDepth          = 0;
58  m_uiOrgDepthBitDepth  = 0;
59  m_uiSubSampExpX       = 0;
60  m_uiSubSampExpY       = 0;
61  m_ppcYuv              = 0;
62  m_ppcCU               = 0;
63}
64
65TComDepthMapGenerator::~TComDepthMapGenerator()
66{
67  destroy ();
68  uninit  ();
69}
70
71Void
72TComDepthMapGenerator::create( Bool bDecoder, UInt uiPicWidth, UInt uiPicHeight, UInt uiMaxCUDepth, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiOrgBitDepth, UInt uiSubSampExpX, UInt uiSubSampExpY )
73{
74  destroy();
75  m_bDecoder            = bDecoder;
76  m_uiMaxDepth          = uiMaxCUDepth;
77  m_uiOrgDepthBitDepth  = uiOrgBitDepth;
78  m_uiSubSampExpX       = uiSubSampExpX;
79  m_uiSubSampExpY       = uiSubSampExpY;
80#if !H3D_NBDV
81  m_ppcYuv              = new TComYuv*    [ m_uiMaxDepth ];
82  m_ppcCU               = new TComDataCU* [ m_uiMaxDepth ];
83  for( UInt uiDepth = 0; uiDepth < m_uiMaxDepth; uiDepth++ )
84  {
85    UInt  uiNumPart = 1 << ( ( m_uiMaxDepth - uiDepth ) << 1 );
86    UInt  uiWidth   = uiMaxCUWidth  >> uiDepth;
87    UInt  uiHeight  = uiMaxCUHeight >> uiDepth;
88
89    m_ppcYuv[ uiDepth ] = new TComYuv;    m_ppcYuv[ uiDepth ]->create( uiWidth >> m_uiSubSampExpX, uiHeight >> m_uiSubSampExpY );
90    m_ppcCU [ uiDepth ] = new TComDataCU; m_ppcCU [ uiDepth ]->create( uiNumPart, uiWidth, uiHeight, true, uiMaxCUWidth >> (uiMaxCUDepth - 1) );
91  }
92  m_cTmpPic.create( uiPicWidth >> m_uiSubSampExpX, uiPicHeight >> m_uiSubSampExpY, uiMaxCUWidth >> m_uiSubSampExpX, uiMaxCUHeight >> m_uiSubSampExpY, uiMaxCUDepth );
93  xSetChroma( &m_cTmpPic, ( 1 << uiOrgBitDepth ) >> 1 );
94#endif //!H3D_NBDV
95  m_bCreated    = true;
96}
97
98Void
99TComDepthMapGenerator::destroy()
100{
101  if( m_bCreated )
102  {
103    m_bCreated    = false;
104#if !H3D_NBDV
105    for( UInt uiDepth = 0; uiDepth < m_uiMaxDepth; uiDepth++ )
106    {
107      if( m_ppcYuv[ uiDepth ] )
108      {
109        m_ppcYuv[ uiDepth ]->destroy(); delete m_ppcYuv[ uiDepth ]; m_ppcYuv[ uiDepth ] = 0;
110      }
111      if( m_ppcCU [ uiDepth ] )
112      {
113        m_ppcCU [ uiDepth ]->destroy(); delete m_ppcCU [ uiDepth ]; m_ppcCU [ uiDepth ] = 0;
114      }
115    }
116    delete [] m_ppcYuv; m_ppcYuv = 0;
117    delete [] m_ppcCU;  m_ppcCU  = 0;
118    m_cTmpPic.destroy();
119#endif //!H3D_NBDV
120    m_uiMaxDepth          = 0;
121    m_uiOrgDepthBitDepth  = 0;
122    m_uiSubSampExpX       = 0;
123    m_uiSubSampExpY       = 0;
124    m_bDecoder            = false;
125  }
126}
127
128#if VIDYO_VPS_INTEGRATION
129Void
130TComDepthMapGenerator::init( TComPrediction* pcPrediction, TComVPSAccess* pcVPSAccess, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess )
131#else
132Void
133TComDepthMapGenerator::init( TComPrediction* pcPrediction, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess )
134#endif
135{
136  AOF( pcPrediction  );
137  AOF( pcSPSAccess   );
138  AOF( pcAUPicAccess );
139  uninit();
140  m_pcPrediction  = pcPrediction;
141#if VIDYO_VPS_INTEGRATION
142  m_pcVPSAccess   = pcVPSAccess;
143#endif
144  m_pcSPSAccess   = pcSPSAccess;
145  m_pcAUPicAccess = pcAUPicAccess;
146  m_bInit         = true;
147}
148
149Void
150TComDepthMapGenerator::uninit()
151{
152  if( m_bInit )
153  {
154    m_bInit         = false;
155    m_pcPrediction  = 0;
156    m_pcSPSAccess   = 0;
157    m_pcAUPicAccess = 0;
158  }
159}
160
161Void 
162TComDepthMapGenerator::initViewComponent( TComPic* pcPic )
163{
164  AOF  ( m_bCreated && m_bInit );
165  AOF  ( pcPic );
166  AOT  ( pcPic->getSPS()->getViewId() && !pcPic->getSPS()->isDepth() && pcPic->getPOC() && pcPic->getSPS()->getPredDepthMapGeneration() != m_pcSPSAccess->getPdm() );
167  m_bPDMAvailable = false;
168  m_uiCurrViewId  = pcPic->getSPS()->getViewId();
169#if PDM_REMOVE_DEPENDENCE
170  pcPic->setStoredPDMforV2(0);
171#endif
172  // update SPS list and AU pic list and set depth map generator in SPS
173#if VIDYO_VPS_INTEGRATION
174  m_pcVPSAccess  ->addVPS( pcPic->getVPS() );
175#endif
176  m_pcSPSAccess  ->addSPS( pcPic->getSPS() );
177  m_pcAUPicAccess->addPic( pcPic );
178  pcPic->getSPS()->setDepthMapGenerator( this );
179
180  // check whether we have depth data or don't use pred depth prediction
181  ROFVS( pcPic->getSPS()->getViewId() );
182  ROTVS( pcPic->getSPS()->isDepth  () );
183  ROFVS( m_pcSPSAccess->getPdm     () );
184
185  // set basic SPS parameters
186  const Int iDisparityDir = 1; // 1 or -1, depending on the usage of disparity vectors
187  TComSPS*  pcSPS         = pcPic->getSPS                 ();
188  Int       iVOI          = pcSPS->getViewOrderIdx        ();
189  UInt      uiPdmPrec     = pcSPS->getPdmPrecision        ();
190  UInt      uiCamPrec     = pcSPS->getCamParPrecision     ();
191  Bool      bInSlice      = pcSPS->hasCamParInSliceHeader ();
192  Int       iScaleVOI01   = ( 1 << ( uiPdmPrec + PDM_INTER_CALC_SHIFT + PDM_VIRT_DEPTH_PRECISION - 2 ) );
193
194  // check availability of base views and set base id list
195  std::vector<Int>  aiAbsDeltaVOI;
196  for( UInt uiBaseId = 0; uiBaseId < m_uiCurrViewId; uiBaseId++ )
197  {
198    TComSPS*  pcBaseSPS     = m_pcSPSAccess  ->getSPS( uiBaseId );
199    TComPic*  pcBasePic     = m_pcAUPicAccess->getPic( uiBaseId );
200    AOF( pcBaseSPS != 0 && pcBasePic != 0 );
201    Int       iDeltaVOI     = iVOI - pcBaseSPS->getViewOrderIdx();
202    Int       iAbsDeltaVOI  = ( iDeltaVOI < 0 ? -iDeltaVOI : iDeltaVOI ); 
203    AOT( iAbsDeltaVOI == 0 );
204    aiAbsDeltaVOI.push_back( iAbsDeltaVOI );
205  }
206  m_auiBaseIdList.clear();
207  while( (UInt)m_auiBaseIdList.size() < m_uiCurrViewId )
208  {
209    Int       iMinAbsDelta  = MAX_INT;
210    UInt      uiNextBaseId  = MAX_VIEW_NUM;
211    for( UInt uiBaseId = 0; uiBaseId < m_uiCurrViewId; uiBaseId++ )
212    {
213      if( aiAbsDeltaVOI[ uiBaseId ] > 0 && aiAbsDeltaVOI[ uiBaseId ] <= iMinAbsDelta )
214      {
215        iMinAbsDelta  = aiAbsDeltaVOI[ uiBaseId ];
216        uiNextBaseId  = uiBaseId;
217      }
218    }
219    m_auiBaseIdList.push_back( uiNextBaseId );
220    aiAbsDeltaVOI[ uiNextBaseId ] = 0;
221  }
222
223  // check availability of prediction depth map
224  if( m_uiCurrViewId )
225  {
226#if PDM_REMOVE_DEPENDENCE
227    UInt      uiBaseVId   = m_auiBaseIdList[0];
228#else
229    Bool      bCheckVId1  = ( m_uiCurrViewId > 1 && m_auiBaseIdList[0] == 0 );
230    UInt      uiBaseVId   = ( bCheckVId1 ? 1 : m_auiBaseIdList[0] );
231#endif
232    TComPic*  pcBasePic   = m_pcAUPicAccess->getPic( uiBaseVId );
233    SliceType eSliceType  = pcBasePic->getCurrSlice()->getSliceType();
234    Bool      bNoRAPdm    = ( pcPic->getSPS()->getPredDepthMapGeneration() == 1 );
235    m_bPDMAvailable       = ( eSliceType != I_SLICE || !bNoRAPdm );
236  }
237
238  // update disparity depth conversion parameters
239  for( UInt uiBaseId = 0; uiBaseId < m_uiCurrViewId; uiBaseId++ )
240  {
241    TComSPS*  pcBaseSPS   = m_pcSPSAccess->getSPS( uiBaseId );
242    Int       iBaseVOI    = pcBaseSPS->getViewOrderIdx();
243
244    // disparity -> virtual depth
245    Int       iVNominator = ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) + pcSPS->getPdmScaleNomDelta()[ uiBaseId ];
246    Int       iVDiv       = iVOI - iBaseVOI;
247    Int       iVAdd       = ( iVDiv > 0 ? iVDiv / 2 : -iVDiv / 2 );
248    Int       iVScalePred = ( iScaleVOI01 + iVAdd ) / iVDiv;
249    Int       iVShift     = PDM_INTER_CALC_SHIFT;
250    Int       iVScale     = Int( ( (Int64)iVNominator * (Int64)iVScalePred + (Int64)( ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) >> 1 ) ) >> PDM_LOG4_SCALE_DENOMINATOR );
251    Int       iVOffset    = pcSPS->getPdmOffset()[ uiBaseId ] << PDM_OFFSET_SHIFT;
252    m_aaiConvParsDisparity2VirtDepth[ uiBaseId ][ 0 ] = iDisparityDir * iVScale;
253    m_aaiConvParsDisparity2VirtDepth[ uiBaseId ][ 1 ] = iDisparityDir * iVOffset + ( ( 1 << iVShift ) >> 1 );
254    m_aaiConvParsDisparity2VirtDepth[ uiBaseId ][ 2 ] = iVShift;
255
256    // virtual depth -> disparity
257    Int       iVInvAdd    = ( iVScale > 0 ? iVScale / 2 : -iVScale / 2 );
258    Int       iVInvScale  = Int( ( ( Int64(  1        ) << ( iVShift << 1 ) ) + iVInvAdd ) / Int64( iVScale ) );
259    Int       iVInvOffset = Int( ( ( Int64( -iVOffset ) <<   iVShift        ) + iVInvAdd ) / Int64( iVScale ) );
260    m_aaiConvParsVirtDepth2Disparity[ uiBaseId ][ 0 ] = iDisparityDir * iVInvScale;
261    m_aaiConvParsVirtDepth2Disparity[ uiBaseId ][ 1 ] = iDisparityDir * iVInvOffset + ( ( 1 << iVShift ) >> 1 );
262    m_aaiConvParsVirtDepth2Disparity[ uiBaseId ][ 2 ] = iVShift;
263
264    // coded depth -> virtual depth
265    Int       iCScale     = ( bInSlice ? pcPic->getCurrSlice()->getCodedScale () : pcSPS->getCodedScale () )[ uiBaseId ];
266    Int       iCOffset    = ( bInSlice ? pcPic->getCurrSlice()->getCodedOffset() : pcSPS->getCodedOffset() )[ uiBaseId ] << m_uiOrgDepthBitDepth;
267    Int       iCShift     = m_uiOrgDepthBitDepth + uiCamPrec + 1 - 2;
268    Int       iCVShift    = PDM_INTER_CALC_SHIFT;
269    Int       iTmpShift   = iVShift + iCShift - iCVShift; AOF( iTmpShift >= 0 )
270    Int       iCVScale    = Int( ( Int64( iVScale ) * Int64( iCScale  ) + Int64( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift );
271    Int       iCVOffset   = Int( ( Int64( iVScale ) * Int64( iCOffset ) + Int64( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift );
272    iTmpShift             = iVShift - iCVShift;           AOF( iTmpShift >= 0 )
273    iCVOffset            +=      ( iVOffset                             +      ( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift;
274    m_aaiConvParsOrigDepth2VirtDepth[ uiBaseId ][ 0 ] = iCVScale;
275    m_aaiConvParsOrigDepth2VirtDepth[ uiBaseId ][ 1 ] = iCVOffset + ( ( 1 << iCVShift ) >> 1 );
276    m_aaiConvParsOrigDepth2VirtDepth[ uiBaseId ][ 2 ] = iCVShift;
277
278    // virtual depth -> coded depth
279    Int       iCVAdd      = ( iCVScale > 0 ? iCVScale / 2 : -iCVScale / 2 );
280    Int       iCVInvScale = Int( ( ( Int64(  1         ) << ( iCVShift << 1 ) ) + iCVAdd ) / Int64( iCVScale ) );
281    Int       iCVInvOffset= Int( ( ( Int64( -iCVOffset ) <<   iCVShift        ) + iCVAdd ) / Int64( iCVScale ) );
282    m_aaiConvParsVirtDepth2OrigDepth[ uiBaseId ][ 0 ] = iCVInvScale;
283    m_aaiConvParsVirtDepth2OrigDepth[ uiBaseId ][ 1 ] = iCVInvOffset + ( ( 1 << iCVShift ) >> 1 );
284    m_aaiConvParsVirtDepth2OrigDepth[ uiBaseId ][ 2 ] = iCVShift;
285  }
286
287  if( m_uiCurrViewId > 0 )
288  {
289    UInt      uiBaseId    = 0;
290    UInt      uiBaseVOI   = 0; // per definition
291    Int       iVNominator = ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) + pcSPS->getPdmScaleNomDelta()[ uiBaseId ];
292    Int       iVDiv       = iVOI - uiBaseVOI;
293    Int       iVAdd       = ( iVDiv > 0 ? iVDiv / 2 : -iVDiv / 2 );
294    Int       iVScalePred = ( iScaleVOI01 + iVAdd ) / iVDiv;
295    Int       iVShift     = PDM_INTER_CALC_SHIFT;
296    Int       iVScale     = Int( ( (Int64)iVNominator * (Int64)iVScalePred + (Int64)( ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) >> 1 ) ) >> PDM_LOG4_SCALE_DENOMINATOR );
297    Int       iVOffset    = pcSPS->getPdmOffset()[ uiBaseId ] << PDM_OFFSET_SHIFT;
298
299    // coded depth -> virtual depth (current view)
300    Int       iCScale     = ( bInSlice ? pcPic->getCurrSlice()->getInvCodedScale () : pcSPS->getInvCodedScale () )[ uiBaseId ];
301    Int       iCOffset    = ( bInSlice ? pcPic->getCurrSlice()->getInvCodedOffset() : pcSPS->getInvCodedOffset() )[ uiBaseId ] << m_uiOrgDepthBitDepth;
302    Int       iCShift     = m_uiOrgDepthBitDepth + uiCamPrec + 1 - 2;
303    Int       iCVShift    = PDM_INTER_CALC_SHIFT;
304    Int       iTmpShift   = iVShift + iCShift - iCVShift; AOF( iTmpShift >= 0 )
305    Int       iCVScale    = Int( ( Int64( -iVScale ) * Int64( iCScale  ) + Int64( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift );
306    Int       iCVOffset   = Int( ( Int64( -iVScale ) * Int64( iCOffset ) + Int64( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift );
307    iTmpShift             = iVShift - iCVShift;           AOF( iTmpShift >= 0 )
308    iCVOffset            +=      ( iVOffset                             +      ( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift;
309    m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 0 ] = iCVScale;
310    m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 1 ] = iCVOffset + ( ( 1 << iCVShift ) >> 1 );
311    m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 2 ] = iCVShift;
312
313    // virtual depth -> coded depth
314    Int       iCVAdd      = ( iCVScale > 0 ? iCVScale / 2 : -iCVScale / 2 );
315    Int       iCVInvScale = Int( ( ( Int64(  1         ) << ( iCVShift << 1 ) ) + iCVAdd ) / Int64( iCVScale ) );
316    Int       iCVInvOffset= Int( ( ( Int64( -iCVOffset ) <<   iCVShift        ) + iCVAdd ) / Int64( iCVScale ) );
317    m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 0 ] = iCVInvScale;
318    m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 1 ] = iCVInvOffset + ( ( 1 << iCVShift ) >> 1 );
319    m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 2 ] = iCVShift;
320  }
321  else if( pcPic->getPOC() == 0 )
322  { // set dummy values
323    m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 0 ] = 0;
324    m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 1 ] = 0;
325    m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 2 ] = 0;
326    m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 0 ] = 0;
327    m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 1 ] = 0;
328    m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 2 ] = 0;
329  }
330
331
332#if 0 // print out for debugging
333  if( m_uiCurrViewId )
334  {
335    printf( "\n\ninit slice of view %d (VOI=%2d):\n===============================\n", m_uiCurrViewId, iVOI );
336    {
337      printf( "\n  disparity -> virtual depth:\n" );
338      for( UInt uiBaseId = 0; uiBaseId < m_uiCurrViewId; uiBaseId++ )
339      {
340        Int*    pP = m_aaiConvParsDisparity2VirtDepth[ uiBaseId ];
341        Double  dF = 1.0 / Double( 1 << pP[ 2 ] );
342        Double  dA = dF  * Double( pP[ 0 ] );
343        Double  dB = dF  * Double( pP[ 1 ] - ( ( 1 << pP[ 2 ] ) >> 1 ) );
344        printf( "    BId=%d:    a = %10.4lf    b = %10.4lf\n", uiBaseId, dA, dB );
345      }
346      printf( "\n  virtual depth -> disparity:\n" );
347      for( UInt uiBaseId = 0; uiBaseId < m_uiCurrViewId; uiBaseId++ )
348      {
349        Int*    pP = m_aaiConvParsVirtDepth2Disparity[ uiBaseId ];
350        Double  dF = 1.0 / Double( 1 << pP[ 2 ] );
351        Double  dA = dF  * Double( pP[ 0 ] );
352        Double  dB = dF  * Double( pP[ 1 ] - ( ( 1 << pP[ 2 ] ) >> 1 ) );
353        printf( "    BId=%d:    a = %10.4lf    b = %10.4lf\n", uiBaseId, dA, dB );
354      }
355      printf( "\n  original depth -> virtual depth:\n" );
356      for( UInt uiBaseId = 0; uiBaseId <= m_uiCurrViewId; uiBaseId++ )
357      {
358        Int*    pP = m_aaiConvParsOrigDepth2VirtDepth[ uiBaseId ];
359        Double  dF = 1.0 / Double( 1 << pP[ 2 ] );
360        Double  dA = dF  * Double( pP[ 0 ] );
361        Double  dB = dF  * Double( pP[ 1 ] - ( ( 1 << pP[ 2 ] ) >> 1 ) );
362        printf( "    VId=%d:    a = %10.4lf    b = %10.4lf\n", uiBaseId, dA, dB );
363      }
364      printf( "\n  virtual depth -> original depth:\n" );
365      for( UInt uiBaseId = 0; uiBaseId <= m_uiCurrViewId; uiBaseId++ )
366      {
367        Int*    pP = m_aaiConvParsVirtDepth2OrigDepth[ uiBaseId ];
368        Double  dF = 1.0 / Double( 1 << pP[ 2 ] );
369        Double  dA = dF  * Double( pP[ 0 ] );
370        Double  dB = dF  * Double( pP[ 1 ] - ( ( 1 << pP[ 2 ] ) >> 1 ) );
371        printf( "    VId=%d:    a = %10.4lf    b = %10.4lf\n", uiBaseId, dA, dB );
372      }
373      printf( "\n" );
374    }
375  }
376#endif
377}
378
379#if !H3D_NBDV
380Bool
381TComDepthMapGenerator::predictDepthMap( TComPic* pcPic )
382{
383  AOF  ( m_bCreated && m_bInit );
384  AOF  ( pcPic );
385  ROTRS( pcPic->getSPS()->isDepth(),  true );
386  ROFRS( m_pcSPSAccess->getPdm(),     true );
387  AOF  ( pcPic->getPredDepthMap() );
388  AOF  ( pcPic->getSPS()->getViewId() == m_uiCurrViewId );
389
390#if PDM_OUTPUT_PRED_DEPTH_MAP
391  Char acFilenameBase[1024];
392  ::sprintf( acFilenameBase, "PDM_%s_Prd", ( m_bDecoder ? "Dec" : "Enc" ) );
393#endif
394
395  Bool bUndefined = true;
396  if( m_uiCurrViewId )
397  {
398    AOF( m_auiBaseIdList.size() );
399    UInt        uiBaseId    = m_auiBaseIdList[ 0 ];
400    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseId );
401    AOF( pcBasePic );
402
403    if( m_uiCurrViewId == 1 )
404    {
405      if( pcBasePic->getPOC() == 0 )
406      {
407        pcBasePic->removePrdDepthMapBuffer();
408        pcBasePic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(m_pcSPSAccess->getPdm()), PDM_SUB_SAMP_EXP_Y(m_pcSPSAccess->getPdm()) );
409        xClearDepthMap( pcBasePic );
410#if PDM_REMOVE_DEPENDENCE
411        xClearDepthMap( pcBasePic, PDM_UNDEFINED_DEPTH, 1 );
412#endif
413      }
414#if PDM_OUTPUT_PRED_DEPTH_MAP
415      dumpDepthMap( pcBasePic, acFilenameBase );
416#endif
417    }
418
419    Bool  bLoadDepth  = ( m_pcSPSAccess->getPdm() == 2 );
420    if( m_pcSPSAccess->getPdm() > 2 )
421    {
422      bLoadDepth = ( pcBasePic->getCurrSlice()->getSliceType() == I_SLICE );
423    }
424
425    if( bLoadDepth)
426    { // load coded depth of base view
427      TComPic*  pcBaseDepth = m_pcAUPicAccess->getPic( uiBaseId, true );
428      AOF( pcBaseDepth );
429      AOF( pcBaseDepth->getPicYuvRec() );
430      AOF( pcBaseDepth->getPicYuvRec()->getWidth () == pcBasePic->getPredDepthMap()->getWidth () );
431      AOF( pcBaseDepth->getPicYuvRec()->getHeight() == pcBasePic->getPredDepthMap()->getHeight() );
432      Int       iWidth      = pcBasePic  ->getPredDepthMap()->getWidth    ();
433      Int       iHeight     = pcBasePic  ->getPredDepthMap()->getHeight   ();
434      Int       iDesStride  = pcBasePic  ->getPredDepthMap()->getStride   ();
435      Int       iSrcStride  = pcBaseDepth->getPicYuvRec   ()->getStride   ();
436      Pel*      pDesSamples = pcBasePic  ->getPredDepthMap()->getLumaAddr ( 0 );
437      Pel*      pSrcSamples = pcBaseDepth->getPicYuvRec   ()->getLumaAddr ( 0 );
438      for( Int iY = 0; iY < iHeight; iY++, pSrcSamples += iSrcStride, pDesSamples += iDesStride )
439      {
440        for( Int iX = 0; iX < iWidth; iX++ )
441        {
442          pDesSamples[ iX ] = xGetVirtDepthFromOrigDepth( uiBaseId, pSrcSamples[ iX ] );
443        }
444      }
445    }
446
447    // convert depth of base view to current view
448    bUndefined = xConvertDepthMapRef2Curr( pcPic, pcBasePic );
449
450#if PDM_OUTPUT_PRED_DEPTH_MAP
451    dumpDepthMap( pcPic, acFilenameBase );
452#endif
453  }
454  else
455  {
456    xClearDepthMap( pcPic );
457#if PDM_REMOVE_DEPENDENCE
458    xClearDepthMap( pcPic, PDM_UNDEFINED_DEPTH, 1 );
459#endif
460  }
461  return bUndefined;
462}
463
464
465Void
466TComDepthMapGenerator::updateDepthMap( TComPic* pcPic )
467{
468  AOF  ( m_bCreated && m_bInit );
469  AOF  ( pcPic );
470  ROTVS( pcPic->getSPS()->isDepth() );
471  ROFVS( m_pcSPSAccess->getPdm() == 1 || m_pcSPSAccess->getPdm() == 3 );
472  AOF  ( pcPic->getPredDepthMap() );
473  AOF  ( pcPic->getSPS()->getViewId() == m_uiCurrViewId );
474
475#if PDM_OUTPUT_PRED_DEPTH_MAP
476  Char acFilenameBase[1024];
477  ::sprintf( acFilenameBase, "PDM_%s_Upd", ( m_bDecoder ? "Dec" : "Enc" ) );
478#endif
479
480  // predict depth map using current coding symbols
481#if PDM_REMOVE_DEPENDENCE
482  pcPic->setStoredPDMforV2(0);
483  xPredictDepthMap( pcPic );
484  if(m_uiCurrViewId==0)
485  {
486    pcPic->setStoredPDMforV2(1);
487    xPredictDepthMap( pcPic );
488    pcPic->setStoredPDMforV2(0);
489  }
490#else
491  xPredictDepthMap( pcPic );
492#if PDM_OUTPUT_PRED_DEPTH_MAP
493  if( m_uiCurrViewId )
494  {
495    dumpDepthMap( pcPic, acFilenameBase );
496  }
497#endif
498#endif
499
500  // generate base depth map
501  if( m_uiCurrViewId == 1 )
502  {
503    TComPic* pcBasePic = m_pcAUPicAccess->getPic( 0 );
504    AOF( pcBasePic );
505    xConvertDepthMapCurr2Ref( pcBasePic, pcPic );
506#if PDM_OUTPUT_PRED_DEPTH_MAP
507    dumpDepthMap( pcBasePic, acFilenameBase );
508#endif
509  }
510#if PDM_REMOVE_DEPENDENCE
511  if( m_uiCurrViewId == 2 )
512  {
513    TComPic* pcBasePic = m_pcAUPicAccess->getPic( 0 );
514    AOF( pcBasePic );
515    xConvertDepthMapCurr2Ref( pcBasePic, pcPic );
516#if PDM_OUTPUT_PRED_DEPTH_MAP
517    dumpDepthMap( pcBasePic, acFilenameBase );
518#endif
519  }
520#endif
521}
522
523
524Void
525TComDepthMapGenerator::dumpDepthMap( TComPic* pcPic, char* pFilenameBase )
526{
527  AOF( m_bCreated && m_bInit );
528  AOF( pcPic );
529  AOF( pFilenameBase );
530  AOF( m_uiOrgDepthBitDepth == 8 + g_uiBitIncrement );
531  AOF( pcPic->getSPS()->getViewId() <= m_uiCurrViewId );
532
533  // convert to output format
534  Int         iMax        = ( 1 << m_uiOrgDepthBitDepth ) - 1;
535  UInt        uiViewId    = pcPic->getSPS()->getViewId();
536  TComPicYuv* pcPicYuv    = pcPic->getPredDepthMap();
537  Int         iWidth      = pcPicYuv->getWidth    ();
538  Int         iHeight     = pcPicYuv->getHeight   ();
539  Int         iSrcStride  = pcPicYuv->getStride   ();
540  Int         iDstStride  = m_cTmpPic.getStride   ();
541#if PDM_REMOVE_DEPENDENCE
542  if(pcPic->getStoredPDMforV2())
543     pcPicYuv    = pcPic->getPredDepthMapTemp();
544#endif
545  Pel*        pSrcSamples = pcPicYuv->getLumaAddr ( 0 );
546  Pel*        pDstSamples = m_cTmpPic.getLumaAddr ( 0 );
547  Int         iMidOrgDpth = ( 1 << m_uiOrgDepthBitDepth ) >> 1;
548  AOF( m_cTmpPic.getWidth () == iWidth  );
549  AOF( m_cTmpPic.getHeight() == iHeight );
550  for( Int iY = 0; iY < iHeight; iY++, pSrcSamples += iSrcStride, pDstSamples += iDstStride )
551  {
552    for( Int iX = 0; iX < iWidth; iX++ )
553    {
554      Int iOrgDepth     = ( pSrcSamples[ iX ] != PDM_UNDEFINED_DEPTH ? xGetOrigDepthFromVirtDepth( uiViewId, pSrcSamples[ iX ] ) : iMidOrgDpth );
555      pDstSamples[ iX ] = Max( 0, Min( iMax, iOrgDepth ) );
556    }
557  }
558
559  // output
560  Char  acFilename[1024];
561  ::sprintf     ( acFilename, "%s_V%d.yuv", pFilenameBase, uiViewId );
562  m_cTmpPic.dump( acFilename, ( pcPic->getPOC() != 0 )  );
563}
564
565#endif //!H3D_NBDV
566
567#if HHI_INTER_VIEW_MOTION_PRED
568Void 
569TComDepthMapGenerator::covertOrgDepthMap( TComPic* pcPic )
570{
571  AOF  ( m_bCreated && m_bInit   );
572  AOF  ( pcPic );
573  ROFVS( pcPic->getOrgDepthMap() );
574  AOF  ( pcPic->getViewId() );
575
576  UInt  uiBaseId = pcPic->getViewId();
577  Int   iWidth   = pcPic->getOrgDepthMap()->getWidth    ();
578  Int   iHeight  = pcPic->getOrgDepthMap()->getHeight   ();
579  Int   iStride  = pcPic->getOrgDepthMap()->getStride   ();
580  Pel*  pSamples = pcPic->getOrgDepthMap()->getLumaAddr ( 0 );
581  for( Int iY = 0; iY < iHeight; iY++, pSamples += iStride )
582  {
583    for( Int iX = 0; iX < iWidth; iX++ )
584    {
585      pSamples[ iX ] = xGetVirtDepthFromOrigDepth( uiBaseId, pSamples[ iX ] );
586    }
587  }
588}
589#endif
590
591Int
592TComDepthMapGenerator::getDisparity( TComPic* pcPic, Int iPosX, Int iPosY, UInt uiRefViewId )
593{
594  AOF( pcPic );
595  AOF( pcPic->getPredDepthMap() );
596  AOF( iPosX >= 0 && iPosX < pcPic->getPredDepthMap()->getWidth () );
597  AOF( iPosY >= 0 && iPosY < pcPic->getPredDepthMap()->getHeight() );
598  Pel*   piPdmMap    = pcPic->getPredDepthMap()->getLumaAddr( 0 );
599  Int    iStride     = pcPic->getPredDepthMap()->getStride  ();
600  Int    iPrdDepth   = piPdmMap[ iPosX + iPosY * iStride ];
601  Int    iDisparity  = xGetDisparityFromVirtDepth( uiRefViewId, iPrdDepth );
602  return iDisparity;
603}
604
605
606
607#if HHI_INTER_VIEW_MOTION_PRED
608#if QC_AMVP_MRG_UNIFY_IVCAN_C0051
609Bool
610TComDepthMapGenerator::getPdmCandidate(TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge )
611{
612  AOF  ( m_bCreated && m_bInit );
613  TComSlice*    pcSlice     = pcCU->getSlice ();
614  TComSPS*      pcSPS       = pcSlice->getSPS();
615  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
616
617  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
618  UInt          uiRefViewId = pcRefPic->getSPS()->getViewId();
619  Bool          bInterview  = ( uiRefViewId < m_uiCurrViewId );
620  Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
621  Bool          bPdmInter   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER );
622  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
623  if(!bMerge)
624  {
625    ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false );
626    ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false );
627    ROTRS(                  bMerge   && !bPdmMerge, false );
628  }
629  else
630    ROTRS( !bPdmMerge, 0 );
631
632#if QC_MRG_CANS_B0048
633  Bool abPdmAvailable[4] = {false, false, false, false};
634#else
635  Bool abPdmAvailable[2] = {false,false};
636#endif
637
638  Int iValid = 0;
639  Int iViewId = 0;
640  for( UInt uiBId = 0; uiBId < m_uiCurrViewId && iValid==0; uiBId++ )
641  {
642#if MTK_C0138_FIXED
643    UInt        uiBaseId    = uiBId;
644#else
645    UInt        uiBaseId    = m_auiBaseIdList[ uiBId ];
646#endif
647    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseId );
648    for( Int iRefListId = 0; iRefListId < 2 && iValid==0; iRefListId++ )
649    {
650      RefPicList  eRefPicListTest = RefPicList( iRefListId );
651      Int         iNumRefPics = pcSlice->getNumRefIdx( eRefPicListTest ) ;
652      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
653      { 
654        if(pcBasePic->getPOC() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
655          && pcBasePic->getViewId() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getViewId())
656        {
657          iValid=1;
658          iViewId = uiBaseId;
659          break;
660        }
661      }
662    }
663  }
664  if (iValid == 0)
665    return false;
666
667  //--- get base CU/PU and check prediction mode ---
668  TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( iViewId );
669  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
670  if(bMerge || !bInterview)
671  {
672#if H3D_NBDV
673    Int  iCurrPosX, iCurrPosY;
674    UInt          uiPartAddr;
675    Int           iWidth;
676    Int           iHeight;
677
678    pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
679    pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
680    iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
681    iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
682
683    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acMvCand[0].getHor() + 2 ) >> 2 ) );
684    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acMvCand[0].getVer() + 2 ) >> 2 )); 
685    Int         iBaseCUAddr;
686    Int         iBaseAbsPartIdx;
687    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
688#else //H3D_NBDV
689    Int  iPrdDepth, iCurrPosX, iCurrPosY;
690    Bool bAvailable  = xGetPredDepth( pcCU, uiPartIdx, iPrdDepth, &iCurrPosX, &iCurrPosY );
691    AOF( bAvailable );
692    TComPicYuv* pcBasePdm   = pcBasePic->getPredDepthMap();
693    Int         iDisparity  = xGetDisparityFromVirtDepth( iViewId, iPrdDepth );
694    Int         iShiftX     = m_uiSubSampExpX + 2;
695    Int         iAddX       = ( 1 << iShiftX ) >> 1;
696    Int         iBasePosX   = Clip3( 0, pcBasePdm->getWidth () - 1, iCurrPosX + ( ( iDisparity + iAddX ) >> iShiftX ) );
697    Int         iBasePosY   = Clip3( 0, pcBasePdm->getHeight() - 1, iCurrPosY                               );
698    Int         iBaseCUAddr;
699    Int         iBaseAbsPartIdx;
700    pcBaseRec->getCUAddrAndPartIdx( iBasePosX<< m_uiSubSampExpX , iBasePosY<< m_uiSubSampExpY , iBaseCUAddr, iBaseAbsPartIdx );
701#endif // H3D_NBDV
702    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
703    if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTER || pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_SKIP )
704    {
705      for( UInt uiCurrRefListId = 0; uiCurrRefListId < 2; uiCurrRefListId++ )
706      {
707        RefPicList  eCurrRefPicList = RefPicList( uiCurrRefListId );
708        if(!bMerge && eCurrRefPicList != eRefPicList)
709          continue;
710        Bool bLoop_stop = false;
711        for(Int iLoop = 0; iLoop < 2 && !bLoop_stop; ++iLoop)
712        {
713          RefPicList eBaseRefPicList = (iLoop ==1)? RefPicList( 1 -  uiCurrRefListId ) : RefPicList( uiCurrRefListId );
714          TComMvField cBaseMvField;
715          pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
716          Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
717          if (iBaseRefIdx >= 0)
718          {
719            Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
720            if (iBaseRefPOC != pcSlice->getPOC())   
721            {
722              for (Int iPdmRefIdx = (bMerge?0: iRefIdx); iPdmRefIdx < (bMerge? pcSlice->getNumRefIdx( eCurrRefPicList ): (iRefIdx+1)); iPdmRefIdx++)
723              {
724                if (iBaseRefPOC == pcSlice->getRefPOC(eCurrRefPicList, iPdmRefIdx))
725                {
726                  abPdmAvailable[ uiCurrRefListId ] = true;
727                  TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
728#if H3D_NBDV
729                  if( bMerge )
730                  {
731                    cMv.m_bDvMcp = true;
732                    cMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor();
733                  }
734#endif
735                  pcCU->clipMv( cMv );
736                  if(bMerge)
737                  {
738                    paiPdmRefIdx  [ uiCurrRefListId ] = iPdmRefIdx;
739                    pacPdmMv      [ uiCurrRefListId ] = cMv;
740                    bLoop_stop = true;
741                    break;
742                  }else
743                  {
744                    pacPdmMv  [0] = cMv;
745                    return true;
746                  }
747                }
748              }
749            }
750          }
751        }
752      }
753    }
754    if( bMerge )
755      iPdm[0] = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
756  }
757  if(bMerge || bInterview)
758  {
759    for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
760    {
761      RefPicList  eRefPicListDMV       = RefPicList( iRefListId );
762      Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicListDMV );
763      for( Int iPdmRefIdx = (bMerge ? 0: iRefIdx); iPdmRefIdx < (bMerge ? iNumRefPics: (iRefIdx+1) ); iPdmRefIdx++ )
764      {
765        if( pcSlice->getRefPOC( eRefPicListDMV, iPdmRefIdx ) == pcSlice->getPOC())
766        {
767#if QC_MRG_CANS_B0048
768          abPdmAvailable[ iRefListId+2 ] = true;
769          paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
770#else
771          abPdmAvailable[ iRefListId ] = true;
772          paiPdmRefIdx  [ iRefListId ] = iPdmRefIdx;
773#endif
774#if H3D_NBDV
775          TComMv cMv = pDInfo->m_acMvCand[0]; 
776          cMv.setVer(0);
777#else
778          TComMv cMv(iDisparity, 0);
779#endif
780          pcCU->clipMv( cMv );
781#if QC_MRG_CANS_B0048
782          pacPdmMv      [ iRefListId + 2] = cMv;
783#else
784          pacPdmMv      [ iRefListId ] = cMv;
785#endif
786          if(bMerge)
787            break;
788          else
789          {
790            pacPdmMv [0] = cMv;
791            return true;
792          }
793        }
794      }
795    }
796#if QC_MRG_CANS_B0048
797    iPdm[1] = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 );
798#else
799    iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 ) ;
800   }
801#endif
802  }
803  return false;
804}
805#else
806#if H3D_NBDV
807Int
808TComDepthMapGenerator::getPdmMergeCandidate( TComDataCU* pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo
809#if QC_MRG_CANS_B0048
810  , Int* iPdm
811#endif
812)
813#else
814Int
815TComDepthMapGenerator::getPdmMergeCandidate( TComDataCU* pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv )
816#endif
817{
818#if MTK_INTERVIEW_MERGE_A0049
819  AOF  ( m_bCreated && m_bInit );
820
821#if !H3D_NBDV
822  ROFRS( m_bPDMAvailable, 0 );
823#endif
824
825  TComSlice*    pcSlice     = pcCU->getSlice ();
826  TComSPS*      pcSPS       = pcSlice->getSPS();
827  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
828  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
829  ROTRS( !bPdmMerge, 0 );
830
831#if QC_MRG_CANS_B0048
832  Bool abPdmAvailable[4] = {false, false, false, false};
833#else
834  Bool abPdmAvailable[2] = {false,false};
835#endif
836
837  Int iValid = 0;
838  Int iViewId = 0;
839  for( UInt uiBId = 0; uiBId < m_uiCurrViewId && iValid==0; uiBId++ )
840  {
841    UInt        uiBaseId    = m_auiBaseIdList[ uiBId ];
842    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseId );
843    for( Int iRefListId = 0; iRefListId < 2 && iValid==0; iRefListId++ )
844    {
845      RefPicList  eRefPicListTest = RefPicList( iRefListId );
846      Int         iNumRefPics = pcSlice->getNumRefIdx( eRefPicListTest ) ;
847      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
848      { 
849        if(pcBasePic->getPOC() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
850          && pcBasePic->getViewId() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getViewId())
851        {
852          iValid=1;
853          iViewId = uiBaseId;
854          break;
855        }
856      }
857    }
858  }
859  if (iValid == 0)
860    return 0;
861
862  //--- get base CU/PU and check prediction mode ---
863  TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( iViewId );
864  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
865
866#if H3D_NBDV
867  Int  iCurrPosX, iCurrPosY;
868  UInt          uiPartAddr;
869  Int           iWidth;
870  Int           iHeight;
871
872  pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
873  pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
874  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
875  iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
876
877  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acMvCand[0].getHor() + 2 ) >> 2 ) );
878  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acMvCand[0].getVer() + 2 ) >> 2 )); 
879  Int         iBaseCUAddr;
880  Int         iBaseAbsPartIdx;
881  pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
882#else
883  Int  iPrdDepth, iCurrPosX, iCurrPosY;
884  Bool bAvailable  = xGetPredDepth( pcCU, uiPartIdx, iPrdDepth, &iCurrPosX, &iCurrPosY );
885  AOF( bAvailable );
886  TComPicYuv* pcBasePdm   = pcBasePic->getPredDepthMap();
887  Int         iDisparity  = xGetDisparityFromVirtDepth( iViewId, iPrdDepth );
888  Int         iShiftX     = m_uiSubSampExpX + 2;
889  Int         iAddX       = ( 1 << iShiftX ) >> 1;
890  Int         iBasePosX   = Clip3( 0, pcBasePdm->getWidth () - 1, iCurrPosX + ( ( iDisparity + iAddX ) >> iShiftX ) );
891  Int         iBasePosY   = Clip3( 0, pcBasePdm->getHeight() - 1, iCurrPosY                               );
892  Int         iBaseCUAddr;
893  Int         iBaseAbsPartIdx;
894  pcBaseRec->getCUAddrAndPartIdx( iBasePosX<< m_uiSubSampExpX , iBasePosY<< m_uiSubSampExpY , iBaseCUAddr, iBaseAbsPartIdx );
895#endif
896
897  TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
898
899  if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTER || pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_SKIP )
900  {
901    for( UInt uiBaseRefListId = 0; uiBaseRefListId < 2; uiBaseRefListId++ )
902    {
903      RefPicList  eBaseRefPicList = RefPicList( uiBaseRefListId );
904      TComMvField cBaseMvField;
905      pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
906      Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
907
908      if (iBaseRefIdx >= 0)
909      {
910        Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
911        if (iBaseRefPOC != pcSlice->getPOC())   
912        {
913          for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eBaseRefPicList ); iPdmRefIdx++)
914          {
915            if (iBaseRefPOC == pcSlice->getRefPOC(eBaseRefPicList, iPdmRefIdx))
916            {
917              abPdmAvailable[ uiBaseRefListId ] = true;
918              paiPdmRefIdx  [ uiBaseRefListId ] = iPdmRefIdx;
919              TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
920#if H3D_NBDV
921              cMv.m_bDvMcp = true;
922              cMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor();
923#if MTK_RELEASE_DV_CONSTRAINT_C0129
924              cMv.m_iDvMcpDispY = pDInfo->m_acMvCand[0].getVer();
925#endif
926#endif //H3D_NBDV
927              pcCU->clipMv( cMv );
928              pacPdmMv      [ uiBaseRefListId ] = cMv;
929              break;
930            }
931          }
932        }
933      }
934    }
935  }
936  Int iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
937#if QC_MRG_CANS_B0048
938  iPdm[0] = iPdmInterDir;
939#else
940  if (iPdmInterDir == 0)
941  {
942#endif
943    for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
944    {
945      RefPicList  eRefPicList       = RefPicList( iRefListId );
946      Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicList );
947      for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
948      {
949        if( pcSlice->getRefPOC( eRefPicList, iPdmRefIdx ) == pcSlice->getPOC())
950        {
951#if QC_MRG_CANS_B0048
952          abPdmAvailable[ iRefListId+2 ] = true;
953          paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
954#else
955          abPdmAvailable[ iRefListId ] = true;
956          paiPdmRefIdx  [ iRefListId ] = iPdmRefIdx;
957#endif
958#if H3D_NBDV
959          TComMv cMv = pDInfo->m_acMvCand[0]; 
960          cMv.setVer(0);
961#else
962          TComMv cMv(iDisparity, 0);
963#endif
964          pcCU->clipMv( cMv );
965#if QC_MRG_CANS_B0048
966          pacPdmMv      [ iRefListId + 2] = cMv;
967#else
968          pacPdmMv      [ iRefListId ] = cMv;
969#endif
970          break;
971        }
972      }
973    }
974#if QC_MRG_CANS_B0048
975    iPdmInterDir = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 ) ;
976    iPdm[1] = iPdmInterDir;
977#else
978    iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 ) ;
979  }
980#endif
981
982  return iPdmInterDir;
983
984#else
985  Int  iMaxNumInterPics  = 1;
986  Int  iMaxNumAllPics    = 2;
987
988  // inter-only
989  Bool abPdmAvailable[2] = {false,false};
990  for( Int iRefListId = 0; iRefListId < 2; iRefListId++ )
991  {
992    RefPicList  eRefPicList       = RefPicList( iRefListId );
993    Int         iNumRefPics       = pcCU->getSlice()->getNumRefIdx( eRefPicList );
994    TComMv      cMv;
995    for( Int iPdmRefIdx = 0, iInterPics = 0; iPdmRefIdx < iNumRefPics && iInterPics < iMaxNumInterPics; iPdmRefIdx++ )
996    {
997      if( pcCU->getSlice()->getRefPOC( eRefPicList, iPdmRefIdx ) != pcCU->getSlice()->getPOC() )
998      {
999#if H3D_NBDV
1000        if( getDisCanPdmMvPred (pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, pDInfo, true ) )       
1001#else
1002        if( getPdmMvPred( pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, true ) )
1003#endif
1004        {
1005          pcCU->clipMv( cMv );
1006          abPdmAvailable[ iRefListId ] = true;
1007          paiPdmRefIdx  [ iRefListId ] = iPdmRefIdx;
1008          pacPdmMv      [ iRefListId ] = cMv;
1009          break;
1010        }
1011        iInterPics++;
1012      }
1013    }
1014  }
1015  Int    iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
1016  if( 0==iPdmInterDir )
1017  { // check all, including inter view references
1018    for( Int iRefListId = 0; iRefListId < 2; iRefListId++ )
1019    {
1020      RefPicList  eRefPicList = RefPicList( iRefListId );
1021      Int         iNumRefPics = Min( iMaxNumAllPics, pcCU->getSlice()->getNumRefIdx( eRefPicList ) );
1022      TComMv      cMv;
1023      for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
1024      {
1025#if H3D_NBDV
1026        if ( getDisCanPdmMvPred (pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, pDInfo, true ) ) 
1027#else
1028        if( getPdmMvPred( pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, true ) )
1029#endif
1030        {
1031          pcCU->clipMv( cMv );
1032          abPdmAvailable[ iRefListId ] = true;
1033          paiPdmRefIdx  [ iRefListId ] = iPdmRefIdx;
1034          pacPdmMv      [ iRefListId ] = cMv;
1035          break;
1036        }
1037      }
1038    }
1039    iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
1040  }
1041  return iPdmInterDir;
1042#endif
1043}
1044
1045#if H3D_NBDV
1046Bool
1047TComDepthMapGenerator::getDisCanPdmMvPred    ( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge )
1048{
1049  rcMv.m_bDvMcp = false;
1050  AOF  ( m_bCreated && m_bInit );
1051  AOF  ( iRefIdx >= 0 );
1052  AOF  ( pcCU );
1053  TComSlice*    pcSlice     = pcCU->getSlice ();
1054  TComSPS*      pcSPS       = pcSlice->getSPS();
1055  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
1056  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
1057  UInt          uiRefViewId = pcRefPic->getSPS()->getViewId();
1058  Int           iRefPoc     = pcRefPic->getPOC();
1059  Bool          bInterview  = ( uiRefViewId < m_uiCurrViewId );
1060  AOT(  bInterview && iRefPoc != pcSlice->getPOC() );
1061  AOT( !bInterview && iRefPoc == pcSlice->getPOC() );
1062  Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
1063  Bool          bPdmInter   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER );
1064  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
1065  ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false );
1066  ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false );
1067  ROTRS(                  bMerge   && !bPdmMerge, false );
1068  Int  iCurrPosX, iCurrPosY;
1069  TComMv cDisMv;
1070
1071  if( bInterview )
1072  {
1073    rcMv = pDInfo->m_acMvCand[0]; 
1074    rcMv.setVer(0);
1075    return      true;
1076  }
1077  for( UInt uiBId = 0; uiBId < m_uiCurrViewId; uiBId++ )
1078  {
1079    UInt        uiBaseId    = uiBId; 
1080
1081    if (m_uiCurrViewId >1 && uiBaseId ==1 ) 
1082      continue;
1083
1084    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseId );
1085    TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
1086    UInt          uiPartAddr;
1087    Int           iWidth;
1088    Int           iHeight;
1089
1090    pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
1091    pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
1092    iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
1093    iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
1094    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acMvCand[0].getHor() + 2 ) >> 2 ) );
1095    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acMvCand[0].getVer() + 2 ) >> 2 )); 
1096    Int         iBaseCUAddr;
1097    Int         iBaseAbsPartIdx;
1098    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
1099    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
1100    if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_INTER && pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_SKIP )
1101    {
1102      continue;
1103    }
1104    for( UInt uiBaseRefListId = 0; uiBaseRefListId < 2; uiBaseRefListId++ )
1105    {
1106      RefPicList  eBaseRefPicList = RefPicList( uiBaseRefListId );
1107      TComMvField cBaseMvField;
1108      pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
1109      Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
1110      Int         iBaseRefPoc     = ( iBaseRefIdx >= 0 ? pcBaseCU->getSlice()->getRefPic( eBaseRefPicList, iBaseRefIdx )->getPOC() : -(1<<30) );
1111      if( iBaseRefIdx >= 0 && iBaseRefPoc == iRefPoc )
1112      {
1113        rcMv.set( cBaseMvField.getHor(), cBaseMvField.getVer() );
1114        // save disparity vector when a merge candidate for IVMP is set as DV-MCP
1115        if( bMerge ) 
1116        {
1117          rcMv.m_bDvMcp = true;
1118          rcMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor(); 
1119#if MTK_RELEASE_DV_CONSTRAINT_C0129
1120          rcMv.m_iDvMcpDispY = pDInfo->m_acMvCand[0].getVer();
1121#endif
1122        }
1123        else { // AMVP ?
1124          rcMv.m_bDvMcp = false;
1125        }
1126        return true;
1127      }
1128    }
1129  }
1130  return false;
1131}
1132#else // H3D_NBDV
1133Bool 
1134TComDepthMapGenerator::getPdmMvPred( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, Bool bMerge )
1135{
1136  AOF  ( m_bCreated && m_bInit );
1137  AOF  ( iRefIdx >= 0 );
1138  AOF  ( pcCU );
1139  ROFRS( m_bPDMAvailable, false );
1140
1141  TComSlice*    pcSlice     = pcCU->getSlice ();
1142  TComPic*      pcPic       = pcCU->getPic   ();
1143  TComSPS*      pcSPS       = pcSlice->getSPS();
1144  AOF  ( pcPic->getPredDepthMap() );
1145  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
1146 
1147  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
1148  UInt          uiRefViewId = pcRefPic->getSPS()->getViewId();
1149  Int           iRefPoc     = pcRefPic->getPOC();
1150  Bool          bInterview  = ( uiRefViewId < m_uiCurrViewId );
1151  AOT(  bInterview && iRefPoc != pcSlice->getPOC() );
1152  AOT( !bInterview && iRefPoc == pcSlice->getPOC() );
1153
1154  Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
1155  Bool          bPdmInter   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER );
1156  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
1157  ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false );
1158  ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false );
1159  ROTRS(                  bMerge   && !bPdmMerge, false );
1160
1161  //===== get predicted depth for middle position of current PU ===== 
1162  Int  iPrdDepth, iCurrPosX, iCurrPosY;
1163  Bool bAvailable  = xGetPredDepth( pcCU, uiPartIdx, iPrdDepth, &iCurrPosX, &iCurrPosY );
1164  AOF( bAvailable );
1165 
1166  //===== inter-view motion vector prediction =====
1167  if( bInterview )
1168  {
1169    Int         iDisparity  = xGetDisparityFromVirtDepth( uiRefViewId, iPrdDepth );
1170    rcMv.set  ( iDisparity, 0 );
1171    return      true;
1172  }
1173 
1174  //===== inter motion vector prediction =====
1175  for( UInt uiBId = 0; uiBId < m_uiCurrViewId; uiBId++ )
1176  {
1177    //--- get base CU/PU and check prediction mode ---
1178    UInt        uiBaseId    = m_auiBaseIdList[ uiBId ];
1179#if PDM_REMOVE_DEPENDENCE
1180    if( uiBaseId != 0)
1181      continue;
1182#endif
1183    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseId );
1184    TComPicYuv* pcBasePdm   = pcBasePic->getPredDepthMap();
1185    TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
1186    Int         iDisparity  = xGetDisparityFromVirtDepth( uiBaseId, iPrdDepth );
1187    Int         iShiftX     = m_uiSubSampExpX + 2;
1188    Int         iAddX       = ( 1 << iShiftX ) >> 1;
1189    Int         iBasePosX   = Clip3( 0, pcBasePdm->getWidth () - 1, iCurrPosX + ( ( iDisparity + iAddX ) >> iShiftX ) );
1190    Int         iBasePosY   = Clip3( 0, pcBasePdm->getHeight() - 1, iCurrPosY                               );
1191    Int         iBaseCUAddr;
1192    Int         iBaseAbsPartIdx;
1193    pcBaseRec->getCUAddrAndPartIdx( iBasePosX << m_uiSubSampExpX, iBasePosY << m_uiSubSampExpY, iBaseCUAddr, iBaseAbsPartIdx );
1194    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
1195    if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_INTER && pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_SKIP )
1196    {
1197      continue;
1198    }
1199
1200    for( UInt uiBaseRefListId = 0; uiBaseRefListId < 2; uiBaseRefListId++ )
1201    {
1202      RefPicList  eBaseRefPicList = RefPicList( uiBaseRefListId );
1203      TComMvField cBaseMvField;
1204      pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
1205      Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
1206      Int         iBaseRefPoc     = ( iBaseRefIdx >= 0 ? pcBaseCU->getSlice()->getRefPic( eBaseRefPicList, iBaseRefIdx )->getPOC() : -(1<<30) );
1207      if( iBaseRefIdx >= 0 && iBaseRefPoc == iRefPoc )
1208      {
1209        rcMv.set( cBaseMvField.getHor(), cBaseMvField.getVer() );
1210        return true;
1211      }
1212    }
1213  }
1214  return false;
1215}
1216#endif // H3D_NBDV
1217#endif
1218
1219
1220Bool  // first version
1221TComDepthMapGenerator::getIViewOrgDepthMvPred( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv )
1222{
1223  AOF  ( m_bCreated && m_bInit );
1224  AOF  ( iRefIdx >= 0 );
1225  AOF  ( pcCU );
1226
1227  TComSlice*    pcSlice     = pcCU->getSlice ();
1228  TComPic*      pcPic       = pcCU->getPic   ();
1229  TComSPS*      pcSPS       = pcSlice->getSPS();
1230  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
1231  ROFRS( pcPic->getOrgDepthMap(),      false );
1232 
1233  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
1234  UInt          uiRefViewId = pcRefPic->getSPS()->getViewId();
1235  Int           iRefPoc     = pcRefPic->getPOC();
1236  ROFRS( uiRefViewId < m_uiCurrViewId, false );
1237  AOF  ( iRefPoc    == pcSlice->getPOC() );
1238
1239  //===== get predicted depth for middle position of current PU (first version) ===== 
1240  UInt          uiPartAddr;
1241  Int           iWidth;
1242  Int           iHeight;
1243  pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
1244  TComPicYuv*   pcOrgDepthMap  = pcPic->getOrgDepthMap();
1245  Pel*          piOrgDepthMap  = pcOrgDepthMap->getLumaAddr ( 0 );
1246  Int           iCurrStride    = pcOrgDepthMap->getStride   ();
1247  Int           iCurrPosX;
1248  Int           iCurrPosY;
1249  pcOrgDepthMap->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
1250  iCurrPosX                    += ( iWidth  - 1 ) >> 1;
1251  iCurrPosY                    += ( iHeight - 1 ) >> 1;
1252  Int           iPrdDepth       = piOrgDepthMap[ iCurrPosX + iCurrPosY * iCurrStride ];
1253 
1254  //===== get disparity vector =====
1255  Int           iDisparity      = xGetDisparityFromVirtDepth( uiRefViewId, iPrdDepth );
1256  rcMv.set    ( iDisparity, 0 );
1257  return        true;
1258}
1259#endif
1260
1261
1262
1263
1264
1265#if !H3D_NBDV
1266/*=======================================================*
1267 *=====                                             =====*
1268 *=====     p i c t u r e   o p e r a t i o n s     =====*
1269 *=====                                             =====*
1270 *=======================================================*/
1271
1272Bool
1273TComDepthMapGenerator::xConvertDepthMapCurr2Ref( TComPic* pcRef, TComPic* pcCur )
1274{
1275  AOF( pcCur->getSPS()->getViewId() == m_uiCurrViewId );
1276  AOF( pcCur->getSPS()->getViewId()  > pcRef->getSPS()->getViewId() );
1277  AOF( pcCur->getPredDepthMap() );
1278  AOF( pcRef->getPredDepthMap() );
1279  AOF( pcRef->getPredDepthMap()->getWidth () == pcCur->getPredDepthMap()->getWidth () );
1280  AOF( pcRef->getPredDepthMap()->getHeight() == pcCur->getPredDepthMap()->getHeight() );
1281#if PDM_REMOVE_DEPENDENCE
1282  if( pcCur->getViewId() == 1)
1283    xClearDepthMap( pcRef );
1284  else if (pcCur->getViewId() == 2)
1285    xClearDepthMap( pcRef, PDM_UNDEFINED_DEPTH, 1 );
1286#else
1287  xClearDepthMap( pcRef );
1288#endif
1289  TComPicYuv* pcCurDepthMap =  pcCur->getPredDepthMap    ();
1290  TComPicYuv* pcRefDepthMap =  pcRef->getPredDepthMap    ();
1291  Int         iWidth        =  pcCurDepthMap->getWidth   ();
1292  Int         iHeight       =  pcCurDepthMap->getHeight  ();
1293  Int         iCurStride    =  pcCurDepthMap->getStride  ();
1294  Int         iRefStride    =  pcRefDepthMap->getStride  ();
1295  Pel*        pCurSamples   =  pcCurDepthMap->getLumaAddr( 0 );
1296  Pel*        pRefSamples   =  pcRefDepthMap->getLumaAddr( 0 );
1297  Int         iRefViewIdx   =  pcRef->getViewId();
1298#if PDM_REMOVE_DEPENDENCE
1299  if( pcCur->getViewId() == 2)
1300  {
1301    pcRefDepthMap =  pcRef->getPredDepthMapTemp();
1302    pRefSamples   =  pcRefDepthMap->getLumaAddr( 0 );
1303  }
1304#endif
1305  Int         iShiftX       = m_uiSubSampExpX + 2;
1306  Int         iAddX         = ( 1 << iShiftX ) >> 1;
1307  for( Int iY = 0; iY < iHeight; iY++, pCurSamples += iCurStride, pRefSamples += iRefStride )
1308  {
1309    for( Int iXCur = 0; iXCur < iWidth; iXCur++ )
1310    {
1311      Int iDepth = pCurSamples[ iXCur ];
1312      Int iDisp  = xGetDisparityFromVirtDepth( iRefViewIdx, iDepth );
1313      Int iXRef  = iXCur + ( ( iDisp + iAddX ) >> iShiftX );
1314      if( iXRef >= 0 && iXRef < iWidth && iDepth > pRefSamples[ iXRef ] )
1315      {
1316        pRefSamples[ iXRef ] = iDepth;
1317      }
1318    }
1319  }
1320  Bool    bUndefined = xFillDepthMapHoles( pcRef );
1321  pcRefDepthMap->setBorderExtension( false );
1322  pcRefDepthMap->extendPicBorder   ();
1323  return  bUndefined;
1324}
1325
1326
1327Bool
1328TComDepthMapGenerator::xConvertDepthMapRef2Curr( TComPic* pcCur, TComPic* pcRef )
1329{
1330  AOF( pcCur->getSPS()->getViewId() == m_uiCurrViewId );
1331  AOF( pcCur->getSPS()->getViewId()  > pcRef->getSPS()->getViewId() );
1332  AOF( pcCur->getPredDepthMap() );
1333#if PDM_REMOVE_DEPENDENCE
1334  if(pcCur->getViewId() == 1)
1335  {
1336    AOF( pcRef->getPredDepthMap() );
1337  }else
1338  {
1339    AOF( pcRef->getPredDepthMapTemp() );
1340  }
1341#else
1342  AOF( pcRef->getPredDepthMap() );
1343#endif
1344  AOF( pcRef->getPredDepthMap()->getWidth () == pcCur->getPredDepthMap()->getWidth () );
1345  AOF( pcRef->getPredDepthMap()->getHeight() == pcCur->getPredDepthMap()->getHeight() );
1346
1347  xClearDepthMap( pcCur );
1348  TComPicYuv* pcRefDepthMap =  pcRef->getPredDepthMap    ();
1349#if PDM_REMOVE_DEPENDENCE
1350  if(pcCur->getViewId() == 2)
1351    pcRefDepthMap =  pcRef->getPredDepthMapTemp        ();
1352#endif
1353  TComPicYuv* pcCurDepthMap =  pcCur->getPredDepthMap    ();
1354  Int         iWidth        =  pcRefDepthMap->getWidth   ();
1355  Int         iHeight       =  pcRefDepthMap->getHeight  ();
1356  Int         iRefStride    =  pcRefDepthMap->getStride  ();
1357  Int         iCurStride    =  pcCurDepthMap->getStride  ();
1358  Pel*        pRefSamples   =  pcRefDepthMap->getLumaAddr( 0 );
1359  Pel*        pCurSamples   =  pcCurDepthMap->getLumaAddr( 0 );
1360  Int         iRefViewIdx   =  pcRef->getViewId();
1361  Int         iShiftX       = m_uiSubSampExpX + 2;
1362  Int         iAddX         = ( 1 << iShiftX ) >> 1;
1363  for( Int iY = 0; iY < iHeight; iY++, pRefSamples += iRefStride, pCurSamples += iCurStride )
1364  {
1365    for( Int iXRef = 0; iXRef < iWidth; iXRef++ )
1366    {
1367      Int iDepth = pRefSamples[ iXRef ];
1368      Int iDisp  = xGetDisparityFromVirtDepth( iRefViewIdx, iDepth );
1369      Int iXCur  = iXRef - ( ( iDisp + iAddX ) >> iShiftX );
1370      if( iXCur >= 0 && iXCur < iWidth && iDepth > pCurSamples[ iXCur ] )
1371      {
1372        pCurSamples[ iXCur ] = iDepth;
1373      }
1374    }
1375  }
1376  Bool    bUndefined = xFillDepthMapHoles( pcCur );
1377  pcCurDepthMap->setBorderExtension( false );
1378  pcCurDepthMap->extendPicBorder   ();
1379  return  bUndefined;
1380}
1381
1382
1383Bool
1384TComDepthMapGenerator::xPredictDepthMap( TComPic* pcPic )
1385{
1386  for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame(); uiCUAddr++ )
1387  {
1388    TComDataCU* pcCU = pcPic->getCU( uiCUAddr );
1389    xPredictCUDepthMap( pcCU, 0, 0 );
1390  }
1391  Bool    bUndefined = xFillDepthMapHoles( pcPic );
1392#if PDM_REMOVE_DEPENDENCE
1393  if(pcPic->getStoredPDMforV2() == 1){
1394  pcPic->getPredDepthMapTemp()->setBorderExtension( false );
1395  pcPic->getPredDepthMapTemp()->extendPicBorder   ();
1396  }else{
1397#endif
1398  pcPic->getPredDepthMap()->setBorderExtension( false );
1399  pcPic->getPredDepthMap()->extendPicBorder   ();
1400#if PDM_REMOVE_DEPENDENCE
1401  }
1402#endif
1403  return  bUndefined;
1404}
1405
1406
1407Bool
1408TComDepthMapGenerator::xFillDepthMapHoles( TComPic* pcPic )
1409{
1410  Bool        bUndefined  = false;     
1411  TComPicYuv* pcDepthMap  = pcPic->getPredDepthMap  ();
1412#if PDM_REMOVE_DEPENDENCE
1413  if(pcPic->getViewId()==0 && pcPic->getStoredPDMforV2()==1)
1414    pcDepthMap  = pcPic->getPredDepthMapTemp  ();
1415#endif
1416  Int         iWidth      = pcDepthMap->getWidth    ();
1417  Int         iHeight     = pcDepthMap->getHeight   ();
1418  Int         iStride     = pcDepthMap->getStride   ();
1419  Pel*        pDMSamples  = pcDepthMap->getLumaAddr ( 0 );
1420  // horizontal
1421  for( Int iY = 0; iY < iHeight && !bUndefined; iY++, pDMSamples += iStride )
1422  {
1423    for( Int iX = 0; iX < iWidth; iX++ )
1424    {
1425      if( pDMSamples[ iX ] == PDM_UNDEFINED_DEPTH )
1426      {
1427        Int  iE;
1428        for( iE = iX + 1; iE < iWidth; iE++ )
1429        {
1430          if( pDMSamples[ iE ] != PDM_UNDEFINED_DEPTH )
1431          {
1432            break;
1433          }
1434        }
1435        if( iX > 0 || iE < iWidth )
1436        {
1437          Int iDepth;
1438          if     ( iX > 0 && iE < iWidth )  iDepth  = ( pDMSamples[ iX-1 ] < pDMSamples[ iE ] ? pDMSamples[ iX-1 ] : pDMSamples[ iE ] ); 
1439          else if( iX > 0 )                 iDepth  =   pDMSamples[ iX-1 ]; 
1440          else /*( iE < iWidth )*/          iDepth  =   pDMSamples[ iE   ]; 
1441          for( Int iZ = iX; iZ < iE; iZ++ )
1442          {
1443            pDMSamples[ iZ ] = iDepth;
1444          }
1445        }
1446        else
1447        {
1448          bUndefined = true;
1449          break;
1450        }
1451        iX = iE - 1;
1452      }
1453    }
1454  }
1455 
1456  if( bUndefined && m_uiCurrViewId )
1457  {
1458    pDMSamples          = pcDepthMap->getLumaAddr( 0 );
1459    Int  iMiddleOrgDpth = ( 1 << m_uiOrgDepthBitDepth ) >> 1;
1460    Int  iMiddleDepth   = xGetVirtDepthFromOrigDepth( m_uiCurrViewId, iMiddleOrgDpth );
1461    for( Int iY = 0; iY < iHeight; iY++, pDMSamples += iStride )
1462    {
1463      for( Int iX = 0; iX < iWidth; iX++ )
1464      {
1465        pDMSamples[ iX ] = iMiddleDepth;
1466       }
1467    }
1468  }
1469  return bUndefined;
1470}
1471
1472
1473Void
1474TComDepthMapGenerator::xClearDepthMap( TComPic* pcPic, Int iVal
1475#if PDM_REMOVE_DEPENDENCE
1476,
1477Int forFirstNonBaseView
1478#endif
1479)
1480{
1481  TComPicYuv* pcDepthMap  = pcPic->getPredDepthMap  ();
1482  Int         iWidth      = pcDepthMap->getWidth    ();
1483  Int         iHeight     = pcDepthMap->getHeight   ();
1484  Int         iStride     = pcDepthMap->getStride   ();
1485  Pel*        pDMSamples  = pcDepthMap->getLumaAddr ( 0 );
1486#if PDM_REMOVE_DEPENDENCE
1487  if( forFirstNonBaseView == 1)
1488  {
1489    pcDepthMap  = pcPic->getPredDepthMapTemp  ();
1490    pDMSamples  = pcDepthMap->getLumaAddr ( 0 );
1491  }
1492#endif
1493  for( Int iY = 0; iY < iHeight; iY++, pDMSamples += iStride )
1494  {
1495    for( Int iX = 0; iX < iWidth; iX++ )
1496    {
1497      pDMSamples[ iX ] = iVal;
1498    }
1499  }
1500  pcDepthMap->setBorderExtension( false );
1501  pcDepthMap->extendPicBorder   ();
1502}
1503
1504Void 
1505TComDepthMapGenerator::xSetChroma( TComPicYuv* pcPic, Int iVal )
1506{
1507  Int   iWidth      = pcPic->getWidth   () >> 1;
1508  Int   iHeight     = pcPic->getHeight  () >> 1;
1509  Int   iStride     = pcPic->getCStride ();
1510  Pel*  pCbSamples  = pcPic->getCbAddr  ( 0 );
1511  Pel*  pCrSamples  = pcPic->getCrAddr  ( 0 );
1512  for( Int iY = 0; iY < iHeight; iY++, pCbSamples += iStride, pCrSamples += iStride )
1513  {
1514    for( Int iX = 0; iX < iWidth; iX++ )
1515    {
1516      pCbSamples[ iX ] = pCrSamples[ iX ] = iVal;
1517    }
1518  }
1519}
1520
1521
1522
1523
1524
1525
1526
1527/*===============================================*
1528 *=====                                     =====*
1529 *=====     C U   p r e d i c t i o n s     =====*
1530 *=====                                     =====*
1531 *===============================================*/
1532
1533Void
1534TComDepthMapGenerator::xPredictCUDepthMap( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx )
1535{
1536  UInt  uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
1537  UInt  uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
1538  UInt  uiRPelX   = uiLPelX           + ( g_uiMaxCUWidth  >> uiDepth ) - 1;
1539  UInt  uiBPelY   = uiTPelY           + ( g_uiMaxCUHeight >> uiDepth ) - 1;
1540  Bool  bBoundary = ( uiRPelX >= pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() || uiBPelY >= pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
1541  Bool  bSplit    = ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) && uiDepth < ( g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary );
1542  if(   bSplit )
1543  {
1544    UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ) ) >> 2;
1545    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx += uiQNumParts )
1546    {
1547      uiLPelX       = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
1548      uiTPelY       = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
1549      Bool  bInside = ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() && uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
1550      if(   bInside )
1551      {
1552        xPredictCUDepthMap( pcCU, uiDepth + 1, uiAbsPartIdx );
1553      }
1554    }
1555    return;
1556  }
1557
1558  //--- set sub-CU and sub-depth-map ---
1559  TComDataCU* pcSubCU   = m_ppcCU [ uiDepth ];
1560  TComYuv*    pcSubDM   = m_ppcYuv[ uiDepth ];
1561  TComPicYuv* pcPicDM   = pcCU->getPic()->getPredDepthMap();
1562#if PDM_REMOVE_DEPENDENCE
1563  if( pcCU->getPic()->getStoredPDMforV2() == 1)
1564    pcPicDM   = pcCU->getPic()->getPredDepthMapTemp();
1565#endif
1566  UInt        uiCUAddr  = pcCU->getAddr();
1567  pcSubCU->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
1568
1569  //--- update depth map ---
1570  switch( pcSubCU->getPredictionMode( 0 ) )
1571  {
1572  case MODE_INTRA:
1573    xIntraPredictCUDepthMap( pcSubCU, pcSubDM );
1574    break;
1575  case MODE_SKIP:
1576  case MODE_INTER:
1577    xInterPredictCUDepthMap( pcSubCU, pcSubDM );
1578    break;
1579  default:
1580    AOT( true );
1581    break;
1582  }
1583
1584  //--- copy sub-depth-map ---
1585  pcSubDM->copyToPicYuv( pcPicDM, uiCUAddr, uiAbsPartIdx );
1586}
1587
1588
1589Void
1590TComDepthMapGenerator::xIntraPredictCUDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap )
1591{
1592  UInt  uiInitTrDepth = ( pcCU->getPartitionSize( 0 ) == SIZE_2Nx2N ? 0 : 1 );
1593  UInt  uiNumPart     =   pcCU->getNumPartInter ();
1594  UInt  uiNumQParts   =   pcCU->getTotalNumPart () >> 2;
1595  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1596  {
1597    xIntraPredictBlkDepthMap( pcCU, pcCUDepthMap, uiPU * uiNumQParts, uiInitTrDepth );
1598  }
1599}
1600
1601
1602Void
1603TComDepthMapGenerator::xInterPredictCUDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap )
1604{
1605  for( UInt uiPartIdx = 0; uiPartIdx < pcCU->getNumPartInter(); uiPartIdx++ )
1606  {
1607    xInterPredictPUDepthMap( pcCU, pcCUDepthMap, uiPartIdx );
1608  }
1609}
1610
1611
1612
1613
1614
1615
1616
1617/*=====================================================================*
1618 *=====                                                           =====*
1619 *=====     P U -   a n d   B l o c k   p r e d i c t i o n s     =====*
1620 *=====                                                           =====*
1621 *=====================================================================*/
1622
1623Void
1624TComDepthMapGenerator::xIntraPredictBlkDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiAbsPartIdx, UInt uiTrDepth )
1625{
1626  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
1627  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1628  if( uiTrMode == uiTrDepth )
1629  {
1630    UInt  uiWidth         = pcCU->getWidth ( 0 ) >> ( uiTrDepth + m_uiSubSampExpX );
1631    UInt  uiHeight        = pcCU->getHeight( 0 ) >> ( uiTrDepth + m_uiSubSampExpY );
1632    UInt  uiStride        = pcCUDepthMap->getStride  ();
1633    UInt  uiBlkX          = g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpX;
1634    UInt  uiBlkY          = g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpY;
1635    Pel*  pDepthMap       = pcCUDepthMap->getLumaAddr() + uiBlkY * pcCUDepthMap->getStride() + uiBlkX;
1636    UInt  uiLumaPredMode  = pcCU->getLumaIntraDir    ( uiAbsPartIdx );
1637    Bool  bAboveAvail     = false;
1638    Bool  bLeftAvail      = false;
1639    pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx, true );
1640    pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
1641                                        m_pcPrediction->getPredicBuf       (),
1642                                        m_pcPrediction->getPredicBufWidth  (),
1643                                        m_pcPrediction->getPredicBufHeight (),
1644                                        bAboveAvail, bLeftAvail, false, true, m_uiSubSampExpX, m_uiSubSampExpY );
1645    m_pcPrediction->predIntraDepthAng ( pcCU->getPattern(), uiLumaPredMode, pDepthMap, uiStride, uiWidth, uiHeight ); // could be replaced with directional intra prediction
1646                                                                                                                      // using "predIntraLumaAng", but note:
1647                                                                                                                      //  - need to take care of neighbours with undefined depth
1648                                                                                                                      //  - special case for wedgelet mode (if available in normal views)
1649    // copy to picture array (for next intra prediction block)
1650    UInt  uiZOrderIdx     = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1651    Pel*  pPicDepthMap    = pcCU->getPic()->getPredDepthMap()->getLumaAddr( pcCU->getAddr(), uiZOrderIdx );
1652#if PDM_REMOVE_DEPENDENCE
1653    if(pcCU->getPic()->getStoredPDMforV2()==1)
1654      pPicDepthMap    = pcCU->getPic()->getPredDepthMapTemp()->getLumaAddr( pcCU->getAddr(), uiZOrderIdx );
1655#endif
1656    Int   iPicStride      = pcCU->getPic()->getPredDepthMap()->getStride  ();
1657    for( UInt uiY = 0; uiY < uiHeight; uiY++, pDepthMap += uiStride, pPicDepthMap += iPicStride )
1658    {
1659      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1660      {
1661        pPicDepthMap[ uiX ] = pDepthMap[ uiX ];
1662      }
1663    }
1664  }
1665  else
1666  {
1667    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1668    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1669    {
1670      xIntraPredictBlkDepthMap( pcCU, pcCUDepthMap, uiAbsPartIdx + uiPart * uiNumQPart, uiTrDepth + 1 );
1671    }
1672  }
1673}
1674
1675
1676Void 
1677TComDepthMapGenerator::xInterPredictPUDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx )
1678{
1679  if ( pcCU->getSlice()->getSPS()->getViewId() )
1680  {
1681    AOF( m_uiCurrViewId == pcCU->getSlice()->getSPS()->getViewId() );
1682    // check for interview prediction
1683    Int             iWidth;
1684    Int             iHeight;
1685    UInt            uiAbsPartIdx;
1686    pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight );
1687    TComCUMvField*  aiCurrMvField[2]  = { pcCU->getCUMvField( REF_PIC_LIST_0 ),        pcCU->getCUMvField( REF_PIC_LIST_1 )        };
1688    Int             aiCurrRefIdx [2]  = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) };
1689    Bool            abCurrIntView[2]  = { aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != m_uiCurrViewId,
1690                                          aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != m_uiCurrViewId };
1691    Bool            bUsesInterViewPrd = ( abCurrIntView[0] || abCurrIntView[1] );
1692    if( bUsesInterViewPrd )
1693    {
1694      xIViewPUDepthMapUpdate  ( pcCU, pcCUDepthMap, uiPartIdx );
1695    }
1696    else
1697    { 
1698#if PDM_NO_INTER_UPDATE
1699      xInterPUDepthMapPrediction( pcCU, pcCUDepthMap, uiPartIdx );
1700#else
1701      xInterPUDepthMapUpdate  ( pcCU, pcCUDepthMap, uiPartIdx );
1702#endif
1703    }
1704  }
1705  else
1706  {
1707    xInterPUDepthMapPrediction( pcCU, pcCUDepthMap, uiPartIdx );
1708  }
1709}
1710
1711
1712Void 
1713TComDepthMapGenerator::xIViewPUDepthMapUpdate( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx )
1714{
1715  // get width, height, and part address
1716  Int   iWidth;
1717  Int   iHeight;
1718  UInt  uiAbsPartIdx;
1719  pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight );
1720  iWidth  >>= m_uiSubSampExpX;
1721  iHeight >>= m_uiSubSampExpY;
1722
1723  // get depth values
1724  Int   iDepthValue   = PDM_UNDEFINED_DEPTH;
1725  Int   aiPrdDepth[2] = { PDM_UNDEFINED_DEPTH, PDM_UNDEFINED_DEPTH };
1726  for( Int iRefListId = 0; iRefListId < 2; iRefListId++ )
1727  {
1728    RefPicList      eRefPicList = RefPicList( iRefListId );
1729    TComCUMvField*  pcCUMvField = pcCU->getCUMvField( eRefPicList );
1730    Int             iRefIdx     = pcCUMvField->getRefIdx( uiAbsPartIdx );
1731    UInt            uiBaseId    = ( iRefIdx >= 0 ? pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getSPS()->getViewId() : MAX_VIEW_NUM ); 
1732    Bool            bInterview  = ( iRefIdx >= 0 && uiBaseId < m_uiCurrViewId );
1733    if( bInterview )
1734    {
1735      Int           iMvX        = pcCUMvField->getMv( uiAbsPartIdx ).getHor();
1736      aiPrdDepth[ iRefListId ]  = xGetVirtDepthFromDisparity( uiBaseId, iMvX );
1737    }
1738  }
1739  if( aiPrdDepth[ 0 ] != PDM_UNDEFINED_DEPTH && aiPrdDepth[ 1 ] != PDM_UNDEFINED_DEPTH )
1740  {
1741    iDepthValue = ( aiPrdDepth[ 0 ] + aiPrdDepth[ 1 ] + 1 ) >> 1;
1742  }
1743  else
1744  {
1745    iDepthValue = ( aiPrdDepth[ 0 ] != PDM_UNDEFINED_DEPTH ? aiPrdDepth[ 0 ] : aiPrdDepth[ 1 ] );
1746    AOT( iDepthValue == PDM_UNDEFINED_DEPTH );
1747  }
1748  iDepthValue   = Max( 0, Min( PDM_MAX_ABS_VIRT_DEPTH, iDepthValue ) );
1749
1750  // set depth map for PU
1751  UInt  uiBlkX      = g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpX;
1752  UInt  uiBlkY      = g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpY;
1753  Pel*  pDMSamples  = pcCUDepthMap->getLumaAddr() + uiBlkY * pcCUDepthMap->getStride() + uiBlkX;
1754  Int   iStride     = pcCUDepthMap->getStride  ();
1755  for( Int iY = 0; iY < iHeight; iY++, pDMSamples += iStride )
1756  {
1757    for( Int iX = 0; iX < iWidth; iX++)
1758    {
1759      pDMSamples[ iX ] = (Pel)iDepthValue;
1760    }
1761  }
1762}
1763
1764
1765Void
1766TComDepthMapGenerator::xInterPUDepthMapUpdate( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx )
1767{
1768  const Int       iMaxAbsDeltaMvY   = 8 << 2;
1769
1770  //===== determine block parameters for current access unit and current view =====
1771  Int             iWidth;
1772  Int             iHeight;
1773  UInt            uiAbsPartIdx;
1774  pcCU->getPartIndexAndSize ( uiPartIdx, uiAbsPartIdx, iWidth, iHeight );
1775  UInt            uiCurrViewId      = pcCU->getSlice()->getSPS()->getViewId(); 
1776  Int             iNum4x4BlksY      = iHeight >> 2;
1777  Int             iNum4x4BlksX      = iWidth  >> 2;
1778  iWidth  >>= m_uiSubSampExpX;
1779  iHeight >>= m_uiSubSampExpY;
1780
1781  TComPicYuv*     pcCurrDepthMap    = pcCU->getPic()->getPredDepthMap();
1782  Pel*            piCurrDepthMap    = pcCurrDepthMap->getLumaAddr();
1783  Int             iCurrStride       = pcCurrDepthMap->getStride();
1784  TComCUMvField*  aiCurrMvField[2]  = { pcCU->getCUMvField( REF_PIC_LIST_0 ),        pcCU->getCUMvField( REF_PIC_LIST_1 )        };
1785  Int             aiCurrRefIdx [2]  = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) };
1786  Int             iMinCurrListId    = ( aiCurrRefIdx [0] < 0 ? 1 : 0 );
1787  Int             iMaxCurrListId    = ( aiCurrRefIdx [1] < 0 ? 0 : 1 );
1788  Int             iCurrPUPosX;
1789  Int             iCurrPUPosY;
1790  pcCurrDepthMap->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx, iCurrPUPosX, iCurrPUPosY );
1791  AOT( uiCurrViewId    != m_uiCurrViewId );
1792  AOT( iMinCurrListId  >  iMaxCurrListId );
1793  AOT( aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != uiCurrViewId );
1794  AOT( aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != uiCurrViewId );
1795
1796  //===== determine parameters for current access unit and base view =====
1797  AOF( m_auiBaseIdList.size() );
1798  UInt            uiBaseId          = m_auiBaseIdList[ 0 ];
1799  TComPic*        pcBasePic         = m_pcAUPicAccess->getPic( uiBaseId );
1800  AOF( pcBasePic );
1801  TComPicYuv*     pcBaseDepthMap    = pcBasePic->getPredDepthMap();
1802  TComPicYuv*     pcBaseRecPic      = pcBasePic->getPicYuvRec   ();
1803  Pel*            piBaseDepthMap    = pcBaseDepthMap->getLumaAddr();
1804  Int             iBaseStride       = pcBaseDepthMap->getStride();
1805  Int             iShiftX           = m_uiSubSampExpX + 2;
1806  Int             iShiftY           = m_uiSubSampExpY + 2;
1807  Int             iAddX             = ( 1 << iShiftX ) >> 1;
1808  Int             iAddY             = ( 1 << iShiftY ) >> 1;
1809
1810  //===== initialize 4x4 block arrays =====
1811  for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1812  {
1813    for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1814    {
1815      m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] = false;
1816      m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ] = PDM_UNDEFINED_DEPTH;
1817    }
1818  }
1819  Int iNum4x4Set = 0;
1820
1821  //===== determine depth based on 4x4 blocks =====
1822  for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1823  {
1824    for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1825    {
1826      // position parameters
1827      Int               iCurrBlkPosX        = iCurrPUPosX + ( ( i4x4BlkX << 2 ) >> m_uiSubSampExpX );
1828      Int               iCurrBlkPosY        = iCurrPUPosY + ( ( i4x4BlkY << 2 ) >> m_uiSubSampExpY );
1829      Int               iCurrSamplePosX     = iCurrBlkPosX + ( 1 >> m_uiSubSampExpX );
1830      Int               iCurrSamplePosY     = iCurrBlkPosY + ( 1 >> m_uiSubSampExpY );
1831      Int               iCurrPredDepth      = piCurrDepthMap[ iCurrSamplePosY * iCurrStride + iCurrSamplePosX ];
1832      Int               iCurrPredDisp       = xGetDisparityFromVirtDepth( uiBaseId, iCurrPredDepth );
1833      Int               iBaseSamplePosX     = iCurrSamplePosX + ( ( iCurrPredDisp + iAddX ) >> iShiftX );
1834      Int               iBaseSamplePosY     = iCurrSamplePosY;
1835      iBaseSamplePosX                       = Clip3( 0, pcBaseDepthMap->getWidth () - 1, iBaseSamplePosX );
1836      iBaseSamplePosY                       = Clip3( 0, pcBaseDepthMap->getHeight() - 1, iBaseSamplePosY );
1837
1838      // check for occlusion
1839      if( piBaseDepthMap[ iBaseSamplePosY * iBaseStride + iBaseSamplePosX ] != iCurrPredDepth )
1840      {
1841        continue;
1842      }
1843
1844      // determine base motion data and check prediction mode
1845      Int               iBaseCUAddr;
1846      Int               iBaseAbsPartIdx;
1847      pcBaseRecPic->getCUAddrAndPartIdx( iBaseSamplePosX << m_uiSubSampExpX, iBaseSamplePosY << m_uiSubSampExpY, iBaseCUAddr, iBaseAbsPartIdx );
1848      TComDataCU*       pcBaseCU            = pcBasePic->getCU( iBaseCUAddr );
1849      if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_INTER && pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_SKIP )
1850      {
1851        continue;
1852      }
1853
1854      // check whether base was inter-view predicted
1855      TComCUMvField*    aiBaseMvField[2]    = { pcBaseCU->getCUMvField( REF_PIC_LIST_0 ),       pcBaseCU->getCUMvField( REF_PIC_LIST_1 )       };
1856      Int               aiBaseRefIdx [2]    = { aiBaseMvField[0]->getRefIdx( iBaseAbsPartIdx ), aiBaseMvField[1]->getRefIdx( iBaseAbsPartIdx ) };
1857      Bool              abBaseIntView[2]    = { aiBaseRefIdx[0] >= 0 && pcBaseCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiBaseRefIdx[0] )->getSPS()->getViewId() != uiBaseId,
1858                                                aiBaseRefIdx[1] >= 0 && pcBaseCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiBaseRefIdx[1] )->getSPS()->getViewId() != uiBaseId };
1859      if( abBaseIntView[0] || abBaseIntView[1] )
1860      { // current depth is reliable
1861        m_aai4x4Depth[i4x4BlkY][i4x4BlkX]   = iCurrPredDepth;
1862        m_aabDepthSet[i4x4BlkY][i4x4BlkX]   = true;
1863        iNum4x4Set++;
1864        continue;
1865      }
1866     
1867      // determine depth candidates using an approximate 4-point relationship (if appropriate)
1868      std::vector<Int>  aiDepthCand;
1869      Int               iMinBaseListId      = ( aiBaseRefIdx [0] < 0 ? 1 : 0 );
1870      Int               iMaxBaseListId      = ( aiBaseRefIdx [1] < 0 ? 0 : 1 );
1871      AOT( iMinBaseListId > iMaxBaseListId );
1872      for( Int iCurrRefListId  = iMinCurrListId; iCurrRefListId <= iMaxCurrListId; iCurrRefListId++ )
1873      {
1874        RefPicList      eCurrRefPicList     = RefPicList( iCurrRefListId );
1875        Int             iCurrRefPoc         = pcCU->getSlice()->getRefPOC( eCurrRefPicList, aiCurrRefIdx[ iCurrRefListId ] );
1876        TComPic*        pcCurrRefPic        = pcCU->getSlice()->getRefPic( eCurrRefPicList, aiCurrRefIdx[ iCurrRefListId ] );
1877        TComPicYuv*     pcCurrRefDMap       = pcCurrRefPic->getPredDepthMap();
1878        Pel*            piCurrRefDMap       = pcCurrRefDMap->getLumaAddr();
1879        Int             iCurrRefStride      = pcCurrRefDMap->getStride();
1880        TComMv          rcCurrMv            = aiCurrMvField[ iCurrRefListId ]->getMv( uiAbsPartIdx );
1881        Int             iCurrRefSamplePosX  = iCurrSamplePosX + ( ( rcCurrMv.getHor() + iAddX ) >> iShiftX );
1882        Int             iCurrRefSamplePosY  = iCurrSamplePosY + ( ( rcCurrMv.getVer() + iAddY ) >> iShiftY );
1883        Int             iCurrRefSamplePosXC = Clip3( 0, pcCurrRefDMap->getWidth () - 1, iCurrRefSamplePosX );
1884        Int             iCurrRefSamplePosYC = Clip3( 0, pcCurrRefDMap->getHeight() - 1, iCurrRefSamplePosY );
1885        Int             iCurrRefDepth       = piCurrRefDMap[ iCurrRefSamplePosYC * iCurrRefStride + iCurrRefSamplePosXC ];
1886
1887        for( Int iBaseRefListId = iMinBaseListId; iBaseRefListId <= iMaxBaseListId; iBaseRefListId++ )
1888        {
1889          RefPicList    eBaseRefPicList     = RefPicList( iBaseRefListId );
1890          Int           iBaseRefPoc         = pcBaseCU->getSlice()->getRefPOC( eBaseRefPicList, aiBaseRefIdx[ iBaseRefListId ] );
1891
1892          if( iCurrRefPoc == iBaseRefPoc )
1893          {
1894            // location and depth for path currView/currAU -> currView/refAU -> baseView/refAU
1895            Int         iCurrRefDisp        = xGetDisparityFromVirtDepth( uiBaseId, iCurrRefDepth );
1896            Int         iBaseRefSamplePosX  = iCurrRefSamplePosX + ( ( iCurrRefDisp + iAddX ) >> iShiftX );
1897            Int         iBaseRefSamplePosY  = iCurrRefSamplePosY;
1898            TComPic*    pcBaseRefPic        = pcBaseCU->getSlice()->getRefPic( eBaseRefPicList, aiBaseRefIdx[ iBaseRefListId ] );
1899            TComPicYuv* pcBaseRefDMap       = pcBaseRefPic->getPredDepthMap();
1900            Pel*        piBaseRefDMap       = pcBaseRefDMap->getLumaAddr();
1901            Int         iBaseRefStride      = pcBaseRefDMap->getStride();
1902            iBaseRefSamplePosX              = Clip3( 0, pcBaseRefDMap->getWidth () - 1, iBaseRefSamplePosX );
1903            iBaseRefSamplePosY              = Clip3( 0, pcBaseRefDMap->getHeight() - 1, iBaseRefSamplePosY );
1904            Int         iBaseRefDepth       = piBaseRefDMap[ iBaseRefSamplePosY * iBaseRefStride + iBaseRefSamplePosX ];
1905
1906            // location and depth for path currView/currAU ->baseView/currAU -> baseView/refAU
1907            TComMv     rcBaseMv            = aiBaseMvField[ iBaseRefListId ]->getMv( iBaseAbsPartIdx );
1908            Int         iAbsDeltaMvY        = ( rcBaseMv.getAbsVer() > rcCurrMv.getVer() ? rcBaseMv.getAbsVer() - rcCurrMv.getVer() : rcCurrMv.getVer() - rcBaseMv.getAbsVer() );
1909
1910            // check reliability (occlusion in reference access unit / vertical motion vector difference)
1911            if( iBaseRefDepth != iCurrRefDepth || iAbsDeltaMvY > iMaxAbsDeltaMvY )
1912            {
1913              continue;
1914            }
1915
1916            // determine new depth
1917            Int         iCurrCandDisp       = iCurrRefDisp + rcCurrMv.getHor() - rcBaseMv.getHor();
1918            Int         iCurrCandDepth      = xGetVirtDepthFromDisparity( uiBaseId, iCurrCandDisp );
1919            aiDepthCand.push_back( iCurrCandDepth );
1920          } // iCurrRefPoc == iBaseRefPoc
1921        } // iBaseRefListId
1922      } // iCurrRefListId
1923     
1924      // set depth for 4x4 block
1925      if( aiDepthCand.size() )
1926      { // get depth with minimum change (probably most reliable)
1927        Int             iMinAbsDepthChange  = (1<<30);
1928        Int             iDepthForMinChange  = (1<<30);
1929        for( UInt uiCandId = 0; uiCandId < (UInt)aiDepthCand.size(); uiCandId++ )
1930        {
1931          Int           iAbsDeltaDepth      = ( aiDepthCand[uiCandId] > iCurrPredDepth ? aiDepthCand[uiCandId] > iCurrPredDepth : iCurrPredDepth - aiDepthCand[uiCandId] );
1932          if( iAbsDeltaDepth < iMinAbsDepthChange )
1933          {
1934            iMinAbsDepthChange              = iAbsDeltaDepth;
1935            iDepthForMinChange              = aiDepthCand[uiCandId];
1936          }
1937        }
1938        m_aai4x4Depth[i4x4BlkY][i4x4BlkX]   = Min( Max( 0, iDepthForMinChange ), PDM_MAX_ABS_VIRT_DEPTH );
1939        m_aabDepthSet[i4x4BlkY][i4x4BlkX]   = true;
1940        iNum4x4Set++;
1941      }
1942    } // i4x4BlkX
1943  } // i4x4BlkY
1944
1945  //===== fall back (take original depth for 4x4 blocks) ====
1946  if( iNum4x4Set < Max( 1, ( iNum4x4BlksY * iNum4x4BlksX ) >> 2 ) )
1947  {
1948    iNum4x4Set = 0;
1949    for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1950    {
1951      for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1952      {
1953        Int             iCurrSamplePosX     = iCurrPUPosX + ( ( ( i4x4BlkX << 2 ) + 1 ) >> m_uiSubSampExpX );
1954        Int             iCurrSamplePosY     = iCurrPUPosY + ( ( ( i4x4BlkY << 2 ) + 1 ) >> m_uiSubSampExpY );
1955        m_aai4x4Depth[i4x4BlkY][i4x4BlkX]   = piCurrDepthMap[ iCurrSamplePosY * iCurrStride + iCurrSamplePosX ];
1956        m_aabDepthSet[i4x4BlkY][i4x4BlkX]   = true;
1957        iNum4x4Set++;
1958      }
1959    }
1960  }
1961
1962#if PDM_ONE_DEPTH_PER_PU
1963  //===== set average in 4x4 depth array =====
1964  Int   iSum        = 0;
1965  for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1966  {
1967    for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1968    {
1969      if( m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] )
1970      {
1971        iSum += m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ];
1972      }
1973    }
1974  }
1975  Int   iDepth      = ( iSum + ( iNum4x4Set >> 1 ) ) / iNum4x4Set;
1976  iNum4x4Set        = iNum4x4BlksY * iNum4x4BlksX;
1977  for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1978  {
1979    for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1980    {
1981      m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ] = iDepth;
1982      m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] = true;
1983    }
1984  }
1985#endif
1986 
1987  //===== complete depth arrays =====
1988  while( iNum4x4BlksY * iNum4x4BlksX - iNum4x4Set )
1989  {
1990    for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1991    {
1992      for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1993      {
1994        if( !m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] )
1995        { // could also use minimum of neighbours (occlusions)
1996          Int iNumNeighbours  = 0;
1997          Int iSumNeighbours  = 0;
1998          if( i4x4BlkY > 0              && m_aabDepthSet[ i4x4BlkY-1 ][ i4x4BlkX   ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY-1 ][ i4x4BlkX   ]; iNumNeighbours++; }
1999          if( i4x4BlkY < iNum4x4BlksY-1 && m_aabDepthSet[ i4x4BlkY+1 ][ i4x4BlkX   ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY+1 ][ i4x4BlkX   ]; iNumNeighbours++; }
2000          if( i4x4BlkX > 0              && m_aabDepthSet[ i4x4BlkY   ][ i4x4BlkX-1 ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY   ][ i4x4BlkX-1 ]; iNumNeighbours++; }
2001          if( i4x4BlkX < iNum4x4BlksX-1 && m_aabDepthSet[ i4x4BlkY   ][ i4x4BlkX+1 ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY   ][ i4x4BlkX+1 ]; iNumNeighbours++; }
2002          if( iNumNeighbours )
2003          {
2004            m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ] = ( iSumNeighbours + ( iNumNeighbours >> 1 ) ) / iNumNeighbours;
2005            m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] = true;
2006            iNum4x4Set++;
2007          }
2008        }
2009      }
2010    }
2011  }
2012
2013  //===== set depth values =====
2014  UInt uiBlkX     = g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpX;
2015  UInt uiBlkY     = g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpY;
2016  Pel* piDepthMap = pcCUDepthMap->getLumaAddr() + uiBlkY * pcCUDepthMap->getStride() + uiBlkX;
2017  Int  iCUStride  = pcCUDepthMap->getStride  ();
2018  for( Int iRow = 0; iRow < iHeight; iRow++, piDepthMap += iCUStride )
2019  {
2020    for( Int iCol = 0; iCol < iWidth; iCol++ )
2021    {
2022      piDepthMap[ iCol ] = m_aai4x4Depth[ (iRow << m_uiSubSampExpY) >> 2  ][ (iCol << m_uiSubSampExpX) >> 2 ];
2023    }
2024  }
2025}
2026
2027
2028Void
2029TComDepthMapGenerator::xInterPUDepthMapPrediction( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx )
2030{
2031  m_pcPrediction->motionCompensation( pcCU, pcCUDepthMap, REF_PIC_LIST_X, (Int)uiPartIdx, true, m_uiSubSampExpX, m_uiSubSampExpY ); 
2032}
2033
2034
2035Bool
2036TComDepthMapGenerator::xGetPredDepth( TComDataCU* pcCU, UInt uiPartIdx, Int& riPrdDepth, Int* piPosX, Int* piPosY )
2037{
2038  AOF  ( m_bCreated && m_bInit );
2039  AOF  ( pcCU );
2040  ROFRS( m_bPDMAvailable, false );
2041
2042  TComSlice*    pcSlice     = pcCU->getSlice ();
2043  TComPic*      pcPic       = pcCU->getPic   ();
2044  TComSPS*      pcSPS       = pcSlice->getSPS();
2045  AOF  ( pcPic->getPredDepthMap() );
2046  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
2047 
2048  //===== get predicted depth and disprity for middle position of current PU ===== 
2049  UInt          uiPartAddr;
2050  Int           iWidth;
2051  Int           iHeight;
2052  pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
2053  TComPicYuv*   pcPredDepthMap  = pcPic->getPredDepthMap();
2054  Pel*          piPredDepthMap  = pcPredDepthMap->getLumaAddr ( 0 );
2055  Int           iCurrStride     = pcPredDepthMap->getStride   ();
2056  Int           iCurrPosX;
2057  Int           iCurrPosY;
2058  pcPredDepthMap->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
2059#if SAIT_IMPROV_MOTION_PRED_M24829 // max disparity within PU
2060  Int DiWidth  = iCurrPosX+(iWidth  >> m_uiSubSampExpX);
2061  Int DiHeight = iCurrPosY+(iHeight >> m_uiSubSampExpY);
2062  Int maxDepth = MIN_INT;
2063
2064  for(Int y=iCurrPosY; y<DiHeight ;y++)
2065  {
2066    for(Int x=iCurrPosX; x<DiWidth; x++)
2067    {
2068      if(piPredDepthMap[ x + y * iCurrStride ] > maxDepth)
2069      {
2070        maxDepth = piPredDepthMap[ x + y * iCurrStride ];
2071      }
2072    }
2073  }
2074  iCurrPosX  += ( ( iWidth  >> m_uiSubSampExpX ) - 1 ) >> 1;
2075  iCurrPosY  += ( ( iHeight >> m_uiSubSampExpY ) - 1 ) >> 1;
2076  riPrdDepth  = maxDepth;
2077#else
2078  iCurrPosX  += ( ( iWidth  >> m_uiSubSampExpX ) - 1 ) >> 1;
2079  iCurrPosY  += ( ( iHeight >> m_uiSubSampExpY ) - 1 ) >> 1;
2080  riPrdDepth  = piPredDepthMap[ iCurrPosX + iCurrPosY * iCurrStride ];
2081#endif
2082  if( piPosX )
2083  {
2084    *piPosX   = iCurrPosX;
2085  }
2086  if( piPosY )
2087  {
2088    *piPosY   = iCurrPosY;
2089  }
2090  return        true;
2091}
2092#endif // H3D_NBDV
2093
2094#endif // DEPTH_MAP_GENERATION
2095
Note: See TracBrowser for help on using the repository browser.