source: 3DVCSoftware/branches/HTM-5.0-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.cpp @ 206

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

Reintegrated branch 4.1-dev0 Rev. 188.

  • Property svn:eol-style set to native
File size: 75.8 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 !QC_MULTI_DIS_CAN_A0097
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
95  m_bCreated    = true;
96}
97
98Void
99TComDepthMapGenerator::destroy()
100{
101  if( m_bCreated )
102  {
103    m_bCreated    = false;
104#if !QC_MULTI_DIS_CAN_A0097
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
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 !QC_MULTI_DIS_CAN_A0097
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#endif
565
566#if HHI_INTER_VIEW_MOTION_PRED
567Void 
568TComDepthMapGenerator::covertOrgDepthMap( TComPic* pcPic )
569{
570  AOF  ( m_bCreated && m_bInit   );
571  AOF  ( pcPic );
572  ROFVS( pcPic->getOrgDepthMap() );
573  AOF  ( pcPic->getViewId() );
574
575  UInt  uiBaseId = pcPic->getViewId();
576  Int   iWidth   = pcPic->getOrgDepthMap()->getWidth    ();
577  Int   iHeight  = pcPic->getOrgDepthMap()->getHeight   ();
578  Int   iStride  = pcPic->getOrgDepthMap()->getStride   ();
579  Pel*  pSamples = pcPic->getOrgDepthMap()->getLumaAddr ( 0 );
580  for( Int iY = 0; iY < iHeight; iY++, pSamples += iStride )
581  {
582    for( Int iX = 0; iX < iWidth; iX++ )
583    {
584      pSamples[ iX ] = xGetVirtDepthFromOrigDepth( uiBaseId, pSamples[ iX ] );
585    }
586  }
587}
588#endif
589
590Int
591TComDepthMapGenerator::getDisparity( TComPic* pcPic, Int iPosX, Int iPosY, UInt uiRefViewId )
592{
593  AOF( pcPic );
594  AOF( pcPic->getPredDepthMap() );
595  AOF( iPosX >= 0 && iPosX < pcPic->getPredDepthMap()->getWidth () );
596  AOF( iPosY >= 0 && iPosY < pcPic->getPredDepthMap()->getHeight() );
597  Pel*   piPdmMap    = pcPic->getPredDepthMap()->getLumaAddr( 0 );
598  Int    iStride     = pcPic->getPredDepthMap()->getStride  ();
599  Int    iPrdDepth   = piPdmMap[ iPosX + iPosY * iStride ];
600  Int    iDisparity  = xGetDisparityFromVirtDepth( uiRefViewId, iPrdDepth );
601  return iDisparity;
602}
603
604
605
606#if HHI_INTER_VIEW_MOTION_PRED
607#if QC_MULTI_DIS_CAN_A0097
608Int
609TComDepthMapGenerator::getPdmMergeCandidate( TComDataCU* pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo
610#if QC_MRG_CANS_B0048
611  , Int* iPdm
612#endif
613)
614#else
615Int
616TComDepthMapGenerator::getPdmMergeCandidate( TComDataCU* pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv )
617#endif
618{
619#if MTK_INTERVIEW_MERGE_A0049
620  AOF  ( m_bCreated && m_bInit );
621
622#if !QC_MULTI_DIS_CAN_A0097
623  ROFRS( m_bPDMAvailable, 0 );
624#endif
625
626  TComSlice*    pcSlice     = pcCU->getSlice ();
627  TComSPS*      pcSPS       = pcSlice->getSPS();
628  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
629  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
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    UInt        uiBaseId    = m_auiBaseIdList[ uiBId ];
643    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseId );
644    for( Int iRefListId = 0; iRefListId < 2 && iValid==0; iRefListId++ )
645    {
646      RefPicList  eRefPicListTest = RefPicList( iRefListId );
647      Int         iNumRefPics = pcSlice->getNumRefIdx( eRefPicListTest ) ;
648      for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ )
649      { 
650        if(pcBasePic->getPOC() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getPOC() 
651          && pcBasePic->getViewId() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getViewId())
652        {
653          iValid=1;
654          iViewId = uiBaseId;
655          break;
656        }
657      }
658    }
659  }
660  if (iValid == 0)
661    return 0;
662
663  //--- get base CU/PU and check prediction mode ---
664  TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( iViewId );
665  TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
666
667#if QC_MULTI_DIS_CAN_A0097
668  Int  iCurrPosX, iCurrPosY;
669  UInt          uiPartAddr;
670  Int           iWidth;
671  Int           iHeight;
672
673  pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
674  pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
675  iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
676  iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
677
678  Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acMvCand[0].getHor() + 2 ) >> 2 ) );
679  Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acMvCand[0].getVer() + 2 ) >> 2 )); 
680  Int         iBaseCUAddr;
681  Int         iBaseAbsPartIdx;
682  pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
683#else
684  Int  iPrdDepth, iCurrPosX, iCurrPosY;
685  Bool bAvailable  = xGetPredDepth( pcCU, uiPartIdx, iPrdDepth, &iCurrPosX, &iCurrPosY );
686  AOF( bAvailable );
687  TComPicYuv* pcBasePdm   = pcBasePic->getPredDepthMap();
688  Int         iDisparity  = xGetDisparityFromVirtDepth( iViewId, iPrdDepth );
689  Int         iShiftX     = m_uiSubSampExpX + 2;
690  Int         iAddX       = ( 1 << iShiftX ) >> 1;
691  Int         iBasePosX   = Clip3( 0, pcBasePdm->getWidth () - 1, iCurrPosX + ( ( iDisparity + iAddX ) >> iShiftX ) );
692  Int         iBasePosY   = Clip3( 0, pcBasePdm->getHeight() - 1, iCurrPosY                               );
693  Int         iBaseCUAddr;
694  Int         iBaseAbsPartIdx;
695  pcBaseRec->getCUAddrAndPartIdx( iBasePosX<< m_uiSubSampExpX , iBasePosY<< m_uiSubSampExpY , iBaseCUAddr, iBaseAbsPartIdx );
696#endif
697
698  TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
699
700  if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTER || pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_SKIP )
701  {
702    for( UInt uiBaseRefListId = 0; uiBaseRefListId < 2; uiBaseRefListId++ )
703    {
704      RefPicList  eBaseRefPicList = RefPicList( uiBaseRefListId );
705      TComMvField cBaseMvField;
706      pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
707      Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
708
709      if (iBaseRefIdx >= 0)
710      {
711        Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx);
712        if (iBaseRefPOC != pcSlice->getPOC())   
713        {
714          for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eBaseRefPicList ); iPdmRefIdx++)
715          {
716            if (iBaseRefPOC == pcSlice->getRefPOC(eBaseRefPicList, iPdmRefIdx))
717            {
718              abPdmAvailable[ uiBaseRefListId ] = true;
719              paiPdmRefIdx  [ uiBaseRefListId ] = iPdmRefIdx;
720              TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer());
721#if LGE_DVMCP_A0126
722              cMv.m_bDvMcp = true;
723              cMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor();
724#endif
725              pcCU->clipMv( cMv );
726              pacPdmMv      [ uiBaseRefListId ] = cMv;
727              break;
728            }
729          }
730        }
731      }
732    }
733  }
734  Int iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
735#if QC_MRG_CANS_B0048
736  iPdm[0] = iPdmInterDir;
737#else
738  if (iPdmInterDir == 0)
739  {
740#endif
741    for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ )
742    {
743      RefPicList  eRefPicList       = RefPicList( iRefListId );
744      Int         iNumRefPics       = pcSlice->getNumRefIdx( eRefPicList );
745      for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
746{
747        if( pcSlice->getRefPOC( eRefPicList, iPdmRefIdx ) == pcSlice->getPOC())
748        {
749#if QC_MRG_CANS_B0048
750          abPdmAvailable[ iRefListId+2 ] = true;
751          paiPdmRefIdx  [ iRefListId+2 ] = iPdmRefIdx;
752#else
753          abPdmAvailable[ iRefListId ] = true;
754          paiPdmRefIdx  [ iRefListId ] = iPdmRefIdx;
755#endif
756#if QC_MULTI_DIS_CAN_A0097
757          TComMv cMv = pDInfo->m_acMvCand[0]; 
758          cMv.setVer(0);
759#else
760          TComMv cMv(iDisparity, 0);
761#endif
762          pcCU->clipMv( cMv );
763#if QC_MRG_CANS_B0048
764          pacPdmMv      [ iRefListId + 2] = cMv;
765#else
766          pacPdmMv      [ iRefListId ] = cMv;
767#endif
768          break;
769        }
770      }
771    }
772#if QC_MRG_CANS_B0048
773    iPdmInterDir = ( abPdmAvailable[2] ? 1 : 0 ) + ( abPdmAvailable[3] ? 2 : 0 ) ;
774    iPdm[1] = iPdmInterDir;
775#else
776    iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 ) ;
777  }
778#endif
779
780  return iPdmInterDir;
781
782#else
783  Int  iMaxNumInterPics  = 1;
784  Int  iMaxNumAllPics    = 2;
785
786  // inter-only
787  Bool abPdmAvailable[2] = {false,false};
788  for( Int iRefListId = 0; iRefListId < 2; iRefListId++ )
789  {
790    RefPicList  eRefPicList       = RefPicList( iRefListId );
791    Int         iNumRefPics       = pcCU->getSlice()->getNumRefIdx( eRefPicList );
792    TComMv      cMv;
793    for( Int iPdmRefIdx = 0, iInterPics = 0; iPdmRefIdx < iNumRefPics && iInterPics < iMaxNumInterPics; iPdmRefIdx++ )
794    {
795      if( pcCU->getSlice()->getRefPOC( eRefPicList, iPdmRefIdx ) != pcCU->getSlice()->getPOC() )
796      {
797#if QC_MULTI_DIS_CAN_A0097
798        if( getDisCanPdmMvPred (pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, pDInfo, true ) )       
799#else
800        if( getPdmMvPred( pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, true ) )
801#endif
802        {
803          pcCU->clipMv( cMv );
804          abPdmAvailable[ iRefListId ] = true;
805          paiPdmRefIdx  [ iRefListId ] = iPdmRefIdx;
806          pacPdmMv      [ iRefListId ] = cMv;
807          break;
808        }
809        iInterPics++;
810      }
811    }
812  }
813  Int    iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
814  if( 0==iPdmInterDir )
815  { // check all, including inter view references
816    for( Int iRefListId = 0; iRefListId < 2; iRefListId++ )
817    {
818      RefPicList  eRefPicList = RefPicList( iRefListId );
819      Int         iNumRefPics = Min( iMaxNumAllPics, pcCU->getSlice()->getNumRefIdx( eRefPicList ) );
820      TComMv      cMv;
821      for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ )
822      {
823#if QC_MULTI_DIS_CAN_A0097
824        if ( getDisCanPdmMvPred (pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, pDInfo, true ) ) 
825#else
826        if( getPdmMvPred( pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, true ) )
827#endif
828        {
829          pcCU->clipMv( cMv );
830          abPdmAvailable[ iRefListId ] = true;
831          paiPdmRefIdx  [ iRefListId ] = iPdmRefIdx;
832          pacPdmMv      [ iRefListId ] = cMv;
833          break;
834        }
835      }
836    }
837    iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 );
838  }
839  return iPdmInterDir;
840#endif
841}
842
843#if QC_MULTI_DIS_CAN_A0097
844Bool
845TComDepthMapGenerator::getDisCanPdmMvPred    ( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge )
846{
847#if LGE_DVMCP_A0126
848  rcMv.m_bDvMcp = false;
849#endif
850  AOF  ( m_bCreated && m_bInit );
851  AOF  ( iRefIdx >= 0 );
852  AOF  ( pcCU );
853  //ROFRS( m_bPDMAvailable, false );
854  TComSlice*    pcSlice     = pcCU->getSlice ();
855  TComSPS*      pcSPS       = pcSlice->getSPS();
856  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
857  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
858  UInt          uiRefViewId = pcRefPic->getSPS()->getViewId();
859  Int           iRefPoc     = pcRefPic->getPOC();
860  Bool          bInterview  = ( uiRefViewId < m_uiCurrViewId );
861  AOT(  bInterview && iRefPoc != pcSlice->getPOC() );
862  AOT( !bInterview && iRefPoc == pcSlice->getPOC() );
863  Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
864  Bool          bPdmInter   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER );
865  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
866  ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false );
867  ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false );
868  ROTRS(                  bMerge   && !bPdmMerge, false );
869  Int  iCurrPosX, iCurrPosY;
870  TComMv cDisMv;
871
872  if( bInterview )
873  {
874    rcMv = pDInfo->m_acMvCand[0]; 
875    rcMv.setVer(0);
876    return      true;
877  }
878  for( UInt uiBId = 0; uiBId < m_uiCurrViewId; uiBId++ )
879  {
880    UInt        uiBaseId    = uiBId;  //m_auiBaseIdList[ uiBId ];
881
882    if (m_uiCurrViewId >1 && uiBaseId ==1 ) 
883      continue;
884
885    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseId );
886    TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
887    UInt          uiPartAddr;
888    Int           iWidth;
889    Int           iHeight;
890
891    pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
892    pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
893    iCurrPosX  += ( ( iWidth  - 1 ) >> 1 );
894    iCurrPosY  += ( ( iHeight - 1 ) >> 1 );
895    Int         iBasePosX   = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acMvCand[0].getHor() + 2 ) >> 2 ) );
896    Int         iBasePosY   = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acMvCand[0].getVer() + 2 ) >> 2 )); 
897    Int         iBaseCUAddr;
898    Int         iBaseAbsPartIdx;
899    pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx );
900    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
901    if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_INTER && pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_SKIP )
902    {
903      continue;
904    }
905    for( UInt uiBaseRefListId = 0; uiBaseRefListId < 2; uiBaseRefListId++ )
906    {
907      RefPicList  eBaseRefPicList = RefPicList( uiBaseRefListId );
908      TComMvField cBaseMvField;
909      pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
910      Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
911      Int         iBaseRefPoc     = ( iBaseRefIdx >= 0 ? pcBaseCU->getSlice()->getRefPic( eBaseRefPicList, iBaseRefIdx )->getPOC() : -(1<<30) );
912      if( iBaseRefIdx >= 0 && iBaseRefPoc == iRefPoc )
913      {
914        rcMv.set( cBaseMvField.getHor(), cBaseMvField.getVer() );
915#if LGE_DVMCP_A0126
916        // save disparity vector when a merge candidate for IVMP is set as DV-MCP
917        if( bMerge ) 
918        {
919          rcMv.m_bDvMcp = true;
920          rcMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor(); 
921        }
922        else { // AMVP ?
923          rcMv.m_bDvMcp = false;
924        }
925#endif
926        return true;
927      }
928    }
929  }
930  return false;
931}
932#else
933Bool 
934TComDepthMapGenerator::getPdmMvPred( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, Bool bMerge )
935{
936  AOF  ( m_bCreated && m_bInit );
937  AOF  ( iRefIdx >= 0 );
938  AOF  ( pcCU );
939  ROFRS( m_bPDMAvailable, false );
940
941  TComSlice*    pcSlice     = pcCU->getSlice ();
942  TComPic*      pcPic       = pcCU->getPic   ();
943  TComSPS*      pcSPS       = pcSlice->getSPS();
944  AOF  ( pcPic->getPredDepthMap() );
945  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
946 
947  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
948  UInt          uiRefViewId = pcRefPic->getSPS()->getViewId();
949  Int           iRefPoc     = pcRefPic->getPOC();
950  Bool          bInterview  = ( uiRefViewId < m_uiCurrViewId );
951  AOT(  bInterview && iRefPoc != pcSlice->getPOC() );
952  AOT( !bInterview && iRefPoc == pcSlice->getPOC() );
953
954  Bool          bPdmIView   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW );
955  Bool          bPdmInter   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER );
956  Bool          bPdmMerge   = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE );
957  ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false );
958  ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false );
959  ROTRS(                  bMerge   && !bPdmMerge, false );
960
961  //===== get predicted depth for middle position of current PU ===== 
962  Int  iPrdDepth, iCurrPosX, iCurrPosY;
963  Bool bAvailable  = xGetPredDepth( pcCU, uiPartIdx, iPrdDepth, &iCurrPosX, &iCurrPosY );
964  AOF( bAvailable );
965 
966  //===== inter-view motion vector prediction =====
967  if( bInterview )
968  {
969    Int         iDisparity  = xGetDisparityFromVirtDepth( uiRefViewId, iPrdDepth );
970    rcMv.set  ( iDisparity, 0 );
971    return      true;
972  }
973 
974  //===== inter motion vector prediction =====
975  for( UInt uiBId = 0; uiBId < m_uiCurrViewId; uiBId++ )
976  {
977    //--- get base CU/PU and check prediction mode ---
978    UInt        uiBaseId    = m_auiBaseIdList[ uiBId ];
979#if PDM_REMOVE_DEPENDENCE
980    if( uiBaseId != 0)
981      continue;
982#endif
983    TComPic*    pcBasePic   = m_pcAUPicAccess->getPic( uiBaseId );
984    TComPicYuv* pcBasePdm   = pcBasePic->getPredDepthMap();
985    TComPicYuv* pcBaseRec   = pcBasePic->getPicYuvRec   ();
986    Int         iDisparity  = xGetDisparityFromVirtDepth( uiBaseId, iPrdDepth );
987    Int         iShiftX     = m_uiSubSampExpX + 2;
988    Int         iAddX       = ( 1 << iShiftX ) >> 1;
989    Int         iBasePosX   = Clip3( 0, pcBasePdm->getWidth () - 1, iCurrPosX + ( ( iDisparity + iAddX ) >> iShiftX ) );
990    Int         iBasePosY   = Clip3( 0, pcBasePdm->getHeight() - 1, iCurrPosY                               );
991    Int         iBaseCUAddr;
992    Int         iBaseAbsPartIdx;
993    pcBaseRec->getCUAddrAndPartIdx( iBasePosX << m_uiSubSampExpX, iBasePosY << m_uiSubSampExpY, iBaseCUAddr, iBaseAbsPartIdx );
994    TComDataCU* pcBaseCU    = pcBasePic->getCU( iBaseCUAddr );
995    if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_INTER && pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_SKIP )
996    {
997      continue;
998    }
999
1000    for( UInt uiBaseRefListId = 0; uiBaseRefListId < 2; uiBaseRefListId++ )
1001    {
1002      RefPicList  eBaseRefPicList = RefPicList( uiBaseRefListId );
1003      TComMvField cBaseMvField;
1004      pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField );
1005      Int         iBaseRefIdx     = cBaseMvField.getRefIdx();
1006      Int         iBaseRefPoc     = ( iBaseRefIdx >= 0 ? pcBaseCU->getSlice()->getRefPic( eBaseRefPicList, iBaseRefIdx )->getPOC() : -(1<<30) );
1007      if( iBaseRefIdx >= 0 && iBaseRefPoc == iRefPoc )
1008      {
1009        rcMv.set( cBaseMvField.getHor(), cBaseMvField.getVer() );
1010        return true;
1011      }
1012    }
1013  }
1014  return false;
1015}
1016#endif
1017
1018
1019Bool  // first version
1020TComDepthMapGenerator::getIViewOrgDepthMvPred( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv )
1021{
1022  AOF  ( m_bCreated && m_bInit );
1023  AOF  ( iRefIdx >= 0 );
1024  AOF  ( pcCU );
1025
1026  TComSlice*    pcSlice     = pcCU->getSlice ();
1027  TComPic*      pcPic       = pcCU->getPic   ();
1028  TComSPS*      pcSPS       = pcSlice->getSPS();
1029  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
1030  ROFRS( pcPic->getOrgDepthMap(),      false );
1031 
1032  TComPic*      pcRefPic    = pcSlice->getRefPic( eRefPicList, iRefIdx );
1033  UInt          uiRefViewId = pcRefPic->getSPS()->getViewId();
1034  Int           iRefPoc     = pcRefPic->getPOC();
1035  ROFRS( uiRefViewId < m_uiCurrViewId, false );
1036  AOF  ( iRefPoc    == pcSlice->getPOC() );
1037
1038  //===== get predicted depth for middle position of current PU (first version) ===== 
1039  UInt          uiPartAddr;
1040  Int           iWidth;
1041  Int           iHeight;
1042  pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
1043  TComPicYuv*   pcOrgDepthMap  = pcPic->getOrgDepthMap();
1044  Pel*          piOrgDepthMap  = pcOrgDepthMap->getLumaAddr ( 0 );
1045  Int           iCurrStride    = pcOrgDepthMap->getStride   ();
1046  Int           iCurrPosX;
1047  Int           iCurrPosY;
1048  pcOrgDepthMap->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
1049  iCurrPosX                    += ( iWidth  - 1 ) >> 1;
1050  iCurrPosY                    += ( iHeight - 1 ) >> 1;
1051  Int           iPrdDepth       = piOrgDepthMap[ iCurrPosX + iCurrPosY * iCurrStride ];
1052 
1053  //===== get disparity vector =====
1054  Int           iDisparity      = xGetDisparityFromVirtDepth( uiRefViewId, iPrdDepth );
1055  rcMv.set    ( iDisparity, 0 );
1056  return        true;
1057}
1058#endif
1059
1060
1061
1062
1063
1064#if !QC_MULTI_DIS_CAN_A0097
1065/*=======================================================*
1066 *=====                                             =====*
1067 *=====     p i c t u r e   o p e r a t i o n s     =====*
1068 *=====                                             =====*
1069 *=======================================================*/
1070
1071Bool
1072TComDepthMapGenerator::xConvertDepthMapCurr2Ref( TComPic* pcRef, TComPic* pcCur )
1073{
1074  AOF( pcCur->getSPS()->getViewId() == m_uiCurrViewId );
1075  AOF( pcCur->getSPS()->getViewId()  > pcRef->getSPS()->getViewId() );
1076  AOF( pcCur->getPredDepthMap() );
1077  AOF( pcRef->getPredDepthMap() );
1078  AOF( pcRef->getPredDepthMap()->getWidth () == pcCur->getPredDepthMap()->getWidth () );
1079  AOF( pcRef->getPredDepthMap()->getHeight() == pcCur->getPredDepthMap()->getHeight() );
1080#if PDM_REMOVE_DEPENDENCE
1081  if( pcCur->getViewId() == 1)
1082    xClearDepthMap( pcRef );
1083  else if (pcCur->getViewId() == 2)
1084    xClearDepthMap( pcRef, PDM_UNDEFINED_DEPTH, 1 );
1085#else
1086  xClearDepthMap( pcRef );
1087#endif
1088  TComPicYuv* pcCurDepthMap =  pcCur->getPredDepthMap    ();
1089  TComPicYuv* pcRefDepthMap =  pcRef->getPredDepthMap    ();
1090  Int         iWidth        =  pcCurDepthMap->getWidth   ();
1091  Int         iHeight       =  pcCurDepthMap->getHeight  ();
1092  Int         iCurStride    =  pcCurDepthMap->getStride  ();
1093  Int         iRefStride    =  pcRefDepthMap->getStride  ();
1094  Pel*        pCurSamples   =  pcCurDepthMap->getLumaAddr( 0 );
1095  Pel*        pRefSamples   =  pcRefDepthMap->getLumaAddr( 0 );
1096  Int         iRefViewIdx   =  pcRef->getViewId();
1097#if PDM_REMOVE_DEPENDENCE
1098  if( pcCur->getViewId() == 2)
1099  {
1100    pcRefDepthMap =  pcRef->getPredDepthMapTemp();
1101    pRefSamples   =  pcRefDepthMap->getLumaAddr( 0 );
1102  }
1103#endif
1104  Int         iShiftX       = m_uiSubSampExpX + 2;
1105  Int         iAddX         = ( 1 << iShiftX ) >> 1;
1106  for( Int iY = 0; iY < iHeight; iY++, pCurSamples += iCurStride, pRefSamples += iRefStride )
1107  {
1108    for( Int iXCur = 0; iXCur < iWidth; iXCur++ )
1109    {
1110      Int iDepth = pCurSamples[ iXCur ];
1111      Int iDisp  = xGetDisparityFromVirtDepth( iRefViewIdx, iDepth );
1112      Int iXRef  = iXCur + ( ( iDisp + iAddX ) >> iShiftX );
1113      if( iXRef >= 0 && iXRef < iWidth && iDepth > pRefSamples[ iXRef ] )
1114      {
1115        pRefSamples[ iXRef ] = iDepth;
1116      }
1117    }
1118  }
1119  Bool    bUndefined = xFillDepthMapHoles( pcRef );
1120  pcRefDepthMap->setBorderExtension( false );
1121  pcRefDepthMap->extendPicBorder   ();
1122  return  bUndefined;
1123}
1124
1125
1126Bool
1127TComDepthMapGenerator::xConvertDepthMapRef2Curr( TComPic* pcCur, TComPic* pcRef )
1128{
1129  AOF( pcCur->getSPS()->getViewId() == m_uiCurrViewId );
1130  AOF( pcCur->getSPS()->getViewId()  > pcRef->getSPS()->getViewId() );
1131  AOF( pcCur->getPredDepthMap() );
1132#if PDM_REMOVE_DEPENDENCE
1133  if(pcCur->getViewId() == 1)
1134  {
1135    AOF( pcRef->getPredDepthMap() );
1136  }else
1137  {
1138    AOF( pcRef->getPredDepthMapTemp() );
1139  }
1140#else
1141  AOF( pcRef->getPredDepthMap() );
1142#endif
1143  AOF( pcRef->getPredDepthMap()->getWidth () == pcCur->getPredDepthMap()->getWidth () );
1144  AOF( pcRef->getPredDepthMap()->getHeight() == pcCur->getPredDepthMap()->getHeight() );
1145
1146  xClearDepthMap( pcCur );
1147  TComPicYuv* pcRefDepthMap =  pcRef->getPredDepthMap    ();
1148#if PDM_REMOVE_DEPENDENCE
1149  if(pcCur->getViewId() == 2)
1150    pcRefDepthMap =  pcRef->getPredDepthMapTemp        ();
1151#endif
1152  TComPicYuv* pcCurDepthMap =  pcCur->getPredDepthMap    ();
1153  Int         iWidth        =  pcRefDepthMap->getWidth   ();
1154  Int         iHeight       =  pcRefDepthMap->getHeight  ();
1155  Int         iRefStride    =  pcRefDepthMap->getStride  ();
1156  Int         iCurStride    =  pcCurDepthMap->getStride  ();
1157  Pel*        pRefSamples   =  pcRefDepthMap->getLumaAddr( 0 );
1158  Pel*        pCurSamples   =  pcCurDepthMap->getLumaAddr( 0 );
1159  Int         iRefViewIdx   =  pcRef->getViewId();
1160  Int         iShiftX       = m_uiSubSampExpX + 2;
1161  Int         iAddX         = ( 1 << iShiftX ) >> 1;
1162  for( Int iY = 0; iY < iHeight; iY++, pRefSamples += iRefStride, pCurSamples += iCurStride )
1163  {
1164    for( Int iXRef = 0; iXRef < iWidth; iXRef++ )
1165    {
1166      Int iDepth = pRefSamples[ iXRef ];
1167      Int iDisp  = xGetDisparityFromVirtDepth( iRefViewIdx, iDepth );
1168      Int iXCur  = iXRef - ( ( iDisp + iAddX ) >> iShiftX );
1169      if( iXCur >= 0 && iXCur < iWidth && iDepth > pCurSamples[ iXCur ] )
1170      {
1171        pCurSamples[ iXCur ] = iDepth;
1172      }
1173    }
1174  }
1175  Bool    bUndefined = xFillDepthMapHoles( pcCur );
1176  pcCurDepthMap->setBorderExtension( false );
1177  pcCurDepthMap->extendPicBorder   ();
1178  return  bUndefined;
1179}
1180
1181
1182Bool
1183TComDepthMapGenerator::xPredictDepthMap( TComPic* pcPic )
1184{
1185  for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame(); uiCUAddr++ )
1186  {
1187    TComDataCU* pcCU = pcPic->getCU( uiCUAddr );
1188    xPredictCUDepthMap( pcCU, 0, 0 );
1189  }
1190  Bool    bUndefined = xFillDepthMapHoles( pcPic );
1191#if PDM_REMOVE_DEPENDENCE
1192  if(pcPic->getStoredPDMforV2() == 1){
1193  pcPic->getPredDepthMapTemp()->setBorderExtension( false );
1194  pcPic->getPredDepthMapTemp()->extendPicBorder   ();
1195  }else{
1196#endif
1197  pcPic->getPredDepthMap()->setBorderExtension( false );
1198  pcPic->getPredDepthMap()->extendPicBorder   ();
1199#if PDM_REMOVE_DEPENDENCE
1200  }
1201#endif
1202  return  bUndefined;
1203}
1204
1205
1206Bool
1207TComDepthMapGenerator::xFillDepthMapHoles( TComPic* pcPic )
1208{
1209  Bool        bUndefined  = false;     
1210  TComPicYuv* pcDepthMap  = pcPic->getPredDepthMap  ();
1211#if PDM_REMOVE_DEPENDENCE
1212  if(pcPic->getViewId()==0 && pcPic->getStoredPDMforV2()==1)
1213    pcDepthMap  = pcPic->getPredDepthMapTemp  ();
1214#endif
1215  Int         iWidth      = pcDepthMap->getWidth    ();
1216  Int         iHeight     = pcDepthMap->getHeight   ();
1217  Int         iStride     = pcDepthMap->getStride   ();
1218  Pel*        pDMSamples  = pcDepthMap->getLumaAddr ( 0 );
1219  // horizontal
1220  for( Int iY = 0; iY < iHeight && !bUndefined; iY++, pDMSamples += iStride )
1221  {
1222    for( Int iX = 0; iX < iWidth; iX++ )
1223    {
1224      if( pDMSamples[ iX ] == PDM_UNDEFINED_DEPTH )
1225      {
1226        Int  iE;
1227        for( iE = iX + 1; iE < iWidth; iE++ )
1228        {
1229          if( pDMSamples[ iE ] != PDM_UNDEFINED_DEPTH )
1230          {
1231            break;
1232          }
1233        }
1234        if( iX > 0 || iE < iWidth )
1235        {
1236          Int iDepth;
1237          if     ( iX > 0 && iE < iWidth )  iDepth  = ( pDMSamples[ iX-1 ] < pDMSamples[ iE ] ? pDMSamples[ iX-1 ] : pDMSamples[ iE ] ); 
1238          else if( iX > 0 )                 iDepth  =   pDMSamples[ iX-1 ]; 
1239          else /*( iE < iWidth )*/          iDepth  =   pDMSamples[ iE   ]; 
1240          for( Int iZ = iX; iZ < iE; iZ++ )
1241          {
1242            pDMSamples[ iZ ] = iDepth;
1243          }
1244        }
1245        else
1246        {
1247          bUndefined = true;
1248          break;
1249        }
1250        iX = iE - 1;
1251      }
1252    }
1253  }
1254 
1255  if( bUndefined && m_uiCurrViewId )
1256  {
1257    pDMSamples          = pcDepthMap->getLumaAddr( 0 );
1258    Int  iMiddleOrgDpth = ( 1 << m_uiOrgDepthBitDepth ) >> 1;
1259    Int  iMiddleDepth   = xGetVirtDepthFromOrigDepth( m_uiCurrViewId, iMiddleOrgDpth );
1260    for( Int iY = 0; iY < iHeight; iY++, pDMSamples += iStride )
1261    {
1262      for( Int iX = 0; iX < iWidth; iX++ )
1263      {
1264        pDMSamples[ iX ] = iMiddleDepth;
1265       }
1266    }
1267  }
1268  return bUndefined;
1269}
1270
1271
1272Void
1273TComDepthMapGenerator::xClearDepthMap( TComPic* pcPic, Int iVal
1274#if PDM_REMOVE_DEPENDENCE
1275,
1276Int forFirstNonBaseView
1277#endif
1278)
1279{
1280  TComPicYuv* pcDepthMap  = pcPic->getPredDepthMap  ();
1281  Int         iWidth      = pcDepthMap->getWidth    ();
1282  Int         iHeight     = pcDepthMap->getHeight   ();
1283  Int         iStride     = pcDepthMap->getStride   ();
1284  Pel*        pDMSamples  = pcDepthMap->getLumaAddr ( 0 );
1285#if PDM_REMOVE_DEPENDENCE
1286  if( forFirstNonBaseView == 1)
1287  {
1288    pcDepthMap  = pcPic->getPredDepthMapTemp  ();
1289    pDMSamples  = pcDepthMap->getLumaAddr ( 0 );
1290  }
1291#endif
1292  for( Int iY = 0; iY < iHeight; iY++, pDMSamples += iStride )
1293  {
1294    for( Int iX = 0; iX < iWidth; iX++ )
1295    {
1296      pDMSamples[ iX ] = iVal;
1297    }
1298  }
1299  pcDepthMap->setBorderExtension( false );
1300  pcDepthMap->extendPicBorder   ();
1301}
1302
1303Void 
1304TComDepthMapGenerator::xSetChroma( TComPicYuv* pcPic, Int iVal )
1305{
1306  Int   iWidth      = pcPic->getWidth   () >> 1;
1307  Int   iHeight     = pcPic->getHeight  () >> 1;
1308  Int   iStride     = pcPic->getCStride ();
1309  Pel*  pCbSamples  = pcPic->getCbAddr  ( 0 );
1310  Pel*  pCrSamples  = pcPic->getCrAddr  ( 0 );
1311  for( Int iY = 0; iY < iHeight; iY++, pCbSamples += iStride, pCrSamples += iStride )
1312  {
1313    for( Int iX = 0; iX < iWidth; iX++ )
1314    {
1315      pCbSamples[ iX ] = pCrSamples[ iX ] = iVal;
1316    }
1317  }
1318}
1319
1320
1321
1322
1323
1324
1325
1326/*===============================================*
1327 *=====                                     =====*
1328 *=====     C U   p r e d i c t i o n s     =====*
1329 *=====                                     =====*
1330 *===============================================*/
1331
1332Void
1333TComDepthMapGenerator::xPredictCUDepthMap( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx )
1334{
1335  UInt  uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
1336  UInt  uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
1337  UInt  uiRPelX   = uiLPelX           + ( g_uiMaxCUWidth  >> uiDepth ) - 1;
1338  UInt  uiBPelY   = uiTPelY           + ( g_uiMaxCUHeight >> uiDepth ) - 1;
1339  Bool  bBoundary = ( uiRPelX >= pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() || uiBPelY >= pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
1340  Bool  bSplit    = ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) && uiDepth < ( g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary );
1341  if(   bSplit )
1342  {
1343    UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ) ) >> 2;
1344    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx += uiQNumParts )
1345    {
1346      uiLPelX       = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
1347      uiTPelY       = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
1348      Bool  bInside = ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() && uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
1349      if(   bInside )
1350      {
1351        xPredictCUDepthMap( pcCU, uiDepth + 1, uiAbsPartIdx );
1352      }
1353    }
1354    return;
1355  }
1356
1357  //--- set sub-CU and sub-depth-map ---
1358  TComDataCU* pcSubCU   = m_ppcCU [ uiDepth ];
1359  TComYuv*    pcSubDM   = m_ppcYuv[ uiDepth ];
1360  TComPicYuv* pcPicDM   = pcCU->getPic()->getPredDepthMap();
1361#if PDM_REMOVE_DEPENDENCE
1362  if( pcCU->getPic()->getStoredPDMforV2() == 1)
1363    pcPicDM   = pcCU->getPic()->getPredDepthMapTemp();
1364#endif
1365  UInt        uiCUAddr  = pcCU->getAddr();
1366  pcSubCU->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
1367
1368  //--- update depth map ---
1369  switch( pcSubCU->getPredictionMode( 0 ) )
1370  {
1371  case MODE_INTRA:
1372    xIntraPredictCUDepthMap( pcSubCU, pcSubDM );
1373    break;
1374  case MODE_SKIP:
1375  case MODE_INTER:
1376    xInterPredictCUDepthMap( pcSubCU, pcSubDM );
1377    break;
1378  default:
1379    AOT( true );
1380    break;
1381  }
1382
1383  //--- copy sub-depth-map ---
1384  pcSubDM->copyToPicYuv( pcPicDM, uiCUAddr, uiAbsPartIdx );
1385}
1386
1387
1388Void
1389TComDepthMapGenerator::xIntraPredictCUDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap )
1390{
1391  UInt  uiInitTrDepth = ( pcCU->getPartitionSize( 0 ) == SIZE_2Nx2N ? 0 : 1 );
1392  UInt  uiNumPart     =   pcCU->getNumPartInter ();
1393  UInt  uiNumQParts   =   pcCU->getTotalNumPart () >> 2;
1394  for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ )
1395  {
1396    xIntraPredictBlkDepthMap( pcCU, pcCUDepthMap, uiPU * uiNumQParts, uiInitTrDepth );
1397  }
1398}
1399
1400
1401Void
1402TComDepthMapGenerator::xInterPredictCUDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap )
1403{
1404  for( UInt uiPartIdx = 0; uiPartIdx < pcCU->getNumPartInter(); uiPartIdx++ )
1405  {
1406    xInterPredictPUDepthMap( pcCU, pcCUDepthMap, uiPartIdx );
1407  }
1408}
1409
1410
1411
1412
1413
1414
1415
1416/*=====================================================================*
1417 *=====                                                           =====*
1418 *=====     P U -   a n d   B l o c k   p r e d i c t i o n s     =====*
1419 *=====                                                           =====*
1420 *=====================================================================*/
1421
1422Void
1423TComDepthMapGenerator::xIntraPredictBlkDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiAbsPartIdx, UInt uiTrDepth )
1424{
1425  UInt uiFullDepth  = pcCU->getDepth( 0 ) + uiTrDepth;
1426  UInt uiTrMode     = pcCU->getTransformIdx( uiAbsPartIdx );
1427  if( uiTrMode == uiTrDepth )
1428  {
1429    UInt  uiWidth         = pcCU->getWidth ( 0 ) >> ( uiTrDepth + m_uiSubSampExpX );
1430    UInt  uiHeight        = pcCU->getHeight( 0 ) >> ( uiTrDepth + m_uiSubSampExpY );
1431    UInt  uiStride        = pcCUDepthMap->getStride  ();
1432    UInt  uiBlkX          = g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpX;
1433    UInt  uiBlkY          = g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpY;
1434    Pel*  pDepthMap       = pcCUDepthMap->getLumaAddr() + uiBlkY * pcCUDepthMap->getStride() + uiBlkX;
1435    UInt  uiLumaPredMode  = pcCU->getLumaIntraDir    ( uiAbsPartIdx );
1436    Bool  bAboveAvail     = false;
1437    Bool  bLeftAvail      = false;
1438    pcCU->getPattern()->initPattern   ( pcCU, uiTrDepth, uiAbsPartIdx, true );
1439    pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, 
1440                                        m_pcPrediction->getPredicBuf       (),
1441                                        m_pcPrediction->getPredicBufWidth  (),
1442                                        m_pcPrediction->getPredicBufHeight (),
1443                                        bAboveAvail, bLeftAvail, false, true, m_uiSubSampExpX, m_uiSubSampExpY );
1444    m_pcPrediction->predIntraDepthAng ( pcCU->getPattern(), uiLumaPredMode, pDepthMap, uiStride, uiWidth, uiHeight ); // could be replaced with directional intra prediction
1445                                                                                                                      // using "predIntraLumaAng", but note:
1446                                                                                                                      //  - need to take care of neighbours with undefined depth
1447                                                                                                                      //  - special case for wedgelet mode (if available in normal views)
1448    // copy to picture array (for next intra prediction block)
1449    UInt  uiZOrderIdx     = pcCU->getZorderIdxInCU() + uiAbsPartIdx;
1450    Pel*  pPicDepthMap    = pcCU->getPic()->getPredDepthMap()->getLumaAddr( pcCU->getAddr(), uiZOrderIdx );
1451#if PDM_REMOVE_DEPENDENCE
1452    if(pcCU->getPic()->getStoredPDMforV2()==1)
1453      pPicDepthMap    = pcCU->getPic()->getPredDepthMapTemp()->getLumaAddr( pcCU->getAddr(), uiZOrderIdx );
1454#endif
1455    Int   iPicStride      = pcCU->getPic()->getPredDepthMap()->getStride  ();
1456    for( UInt uiY = 0; uiY < uiHeight; uiY++, pDepthMap += uiStride, pPicDepthMap += iPicStride )
1457    {
1458      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
1459      {
1460        pPicDepthMap[ uiX ] = pDepthMap[ uiX ];
1461      }
1462    }
1463  }
1464  else
1465  {
1466    UInt uiNumQPart  = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 );
1467    for( UInt uiPart = 0; uiPart < 4; uiPart++ )
1468    {
1469      xIntraPredictBlkDepthMap( pcCU, pcCUDepthMap, uiAbsPartIdx + uiPart * uiNumQPart, uiTrDepth + 1 );
1470    }
1471  }
1472}
1473
1474
1475Void 
1476TComDepthMapGenerator::xInterPredictPUDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx )
1477{
1478  if ( pcCU->getSlice()->getSPS()->getViewId() )
1479  {
1480    AOF( m_uiCurrViewId == pcCU->getSlice()->getSPS()->getViewId() );
1481    // check for interview prediction
1482    Int             iWidth;
1483    Int             iHeight;
1484    UInt            uiAbsPartIdx;
1485    pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight );
1486    TComCUMvField*  aiCurrMvField[2]  = { pcCU->getCUMvField( REF_PIC_LIST_0 ),        pcCU->getCUMvField( REF_PIC_LIST_1 )        };
1487    Int             aiCurrRefIdx [2]  = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) };
1488    Bool            abCurrIntView[2]  = { aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != m_uiCurrViewId,
1489                                          aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != m_uiCurrViewId };
1490    Bool            bUsesInterViewPrd = ( abCurrIntView[0] || abCurrIntView[1] );
1491    if( bUsesInterViewPrd )
1492    {
1493      xIViewPUDepthMapUpdate  ( pcCU, pcCUDepthMap, uiPartIdx );
1494    }
1495    else
1496    { 
1497#if PDM_NO_INTER_UPDATE
1498      xInterPUDepthMapPrediction( pcCU, pcCUDepthMap, uiPartIdx );
1499#else
1500      xInterPUDepthMapUpdate  ( pcCU, pcCUDepthMap, uiPartIdx );
1501#endif
1502    }
1503  }
1504  else
1505  {
1506    xInterPUDepthMapPrediction( pcCU, pcCUDepthMap, uiPartIdx );
1507  }
1508}
1509
1510
1511Void 
1512TComDepthMapGenerator::xIViewPUDepthMapUpdate( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx )
1513{
1514  // get width, height, and part address
1515  Int   iWidth;
1516  Int   iHeight;
1517  UInt  uiAbsPartIdx;
1518  pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight );
1519  iWidth  >>= m_uiSubSampExpX;
1520  iHeight >>= m_uiSubSampExpY;
1521
1522  // get depth values
1523  Int   iDepthValue   = PDM_UNDEFINED_DEPTH;
1524  Int   aiPrdDepth[2] = { PDM_UNDEFINED_DEPTH, PDM_UNDEFINED_DEPTH };
1525  for( Int iRefListId = 0; iRefListId < 2; iRefListId++ )
1526  {
1527    RefPicList      eRefPicList = RefPicList( iRefListId );
1528    TComCUMvField*  pcCUMvField = pcCU->getCUMvField( eRefPicList );
1529    Int             iRefIdx     = pcCUMvField->getRefIdx( uiAbsPartIdx );
1530    UInt            uiBaseId    = ( iRefIdx >= 0 ? pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getSPS()->getViewId() : MAX_VIEW_NUM ); 
1531    Bool            bInterview  = ( iRefIdx >= 0 && uiBaseId < m_uiCurrViewId );
1532    if( bInterview )
1533    {
1534      Int           iMvX        = pcCUMvField->getMv( uiAbsPartIdx ).getHor();
1535      aiPrdDepth[ iRefListId ]  = xGetVirtDepthFromDisparity( uiBaseId, iMvX );
1536    }
1537  }
1538  if( aiPrdDepth[ 0 ] != PDM_UNDEFINED_DEPTH && aiPrdDepth[ 1 ] != PDM_UNDEFINED_DEPTH )
1539  {
1540    iDepthValue = ( aiPrdDepth[ 0 ] + aiPrdDepth[ 1 ] + 1 ) >> 1;
1541  }
1542  else
1543  {
1544    iDepthValue = ( aiPrdDepth[ 0 ] != PDM_UNDEFINED_DEPTH ? aiPrdDepth[ 0 ] : aiPrdDepth[ 1 ] );
1545    AOT( iDepthValue == PDM_UNDEFINED_DEPTH );
1546  }
1547  iDepthValue   = Max( 0, Min( PDM_MAX_ABS_VIRT_DEPTH, iDepthValue ) );
1548
1549  // set depth map for PU
1550  UInt  uiBlkX      = g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpX;
1551  UInt  uiBlkY      = g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpY;
1552  Pel*  pDMSamples  = pcCUDepthMap->getLumaAddr() + uiBlkY * pcCUDepthMap->getStride() + uiBlkX;
1553  Int   iStride     = pcCUDepthMap->getStride  ();
1554  for( Int iY = 0; iY < iHeight; iY++, pDMSamples += iStride )
1555  {
1556    for( Int iX = 0; iX < iWidth; iX++)
1557    {
1558      pDMSamples[ iX ] = (Pel)iDepthValue;
1559    }
1560  }
1561}
1562
1563
1564Void
1565TComDepthMapGenerator::xInterPUDepthMapUpdate( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx )
1566{
1567  const Int       iMaxAbsDeltaMvY   = 8 << 2;
1568
1569  //===== determine block parameters for current access unit and current view =====
1570  Int             iWidth;
1571  Int             iHeight;
1572  UInt            uiAbsPartIdx;
1573  pcCU->getPartIndexAndSize ( uiPartIdx, uiAbsPartIdx, iWidth, iHeight );
1574  UInt            uiCurrViewId      = pcCU->getSlice()->getSPS()->getViewId(); 
1575  Int             iNum4x4BlksY      = iHeight >> 2;
1576  Int             iNum4x4BlksX      = iWidth  >> 2;
1577  iWidth  >>= m_uiSubSampExpX;
1578  iHeight >>= m_uiSubSampExpY;
1579
1580  TComPicYuv*     pcCurrDepthMap    = pcCU->getPic()->getPredDepthMap();
1581  Pel*            piCurrDepthMap    = pcCurrDepthMap->getLumaAddr();
1582  Int             iCurrStride       = pcCurrDepthMap->getStride();
1583  TComCUMvField*  aiCurrMvField[2]  = { pcCU->getCUMvField( REF_PIC_LIST_0 ),        pcCU->getCUMvField( REF_PIC_LIST_1 )        };
1584  Int             aiCurrRefIdx [2]  = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) };
1585  Int             iMinCurrListId    = ( aiCurrRefIdx [0] < 0 ? 1 : 0 );
1586  Int             iMaxCurrListId    = ( aiCurrRefIdx [1] < 0 ? 0 : 1 );
1587  Int             iCurrPUPosX;
1588  Int             iCurrPUPosY;
1589  pcCurrDepthMap->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx, iCurrPUPosX, iCurrPUPosY );
1590  AOT( uiCurrViewId    != m_uiCurrViewId );
1591  AOT( iMinCurrListId  >  iMaxCurrListId );
1592  AOT( aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != uiCurrViewId );
1593  AOT( aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != uiCurrViewId );
1594
1595  //===== determine parameters for current access unit and base view =====
1596  AOF( m_auiBaseIdList.size() );
1597  UInt            uiBaseId          = m_auiBaseIdList[ 0 ];
1598  TComPic*        pcBasePic         = m_pcAUPicAccess->getPic( uiBaseId );
1599  AOF( pcBasePic );
1600  TComPicYuv*     pcBaseDepthMap    = pcBasePic->getPredDepthMap();
1601  TComPicYuv*     pcBaseRecPic      = pcBasePic->getPicYuvRec   ();
1602  Pel*            piBaseDepthMap    = pcBaseDepthMap->getLumaAddr();
1603  Int             iBaseStride       = pcBaseDepthMap->getStride();
1604  Int             iShiftX           = m_uiSubSampExpX + 2;
1605  Int             iShiftY           = m_uiSubSampExpY + 2;
1606  Int             iAddX             = ( 1 << iShiftX ) >> 1;
1607  Int             iAddY             = ( 1 << iShiftY ) >> 1;
1608
1609  //===== initialize 4x4 block arrays =====
1610  for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1611  {
1612    for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1613    {
1614      m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] = false;
1615      m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ] = PDM_UNDEFINED_DEPTH;
1616    }
1617  }
1618  Int iNum4x4Set = 0;
1619
1620  //===== determine depth based on 4x4 blocks =====
1621  for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1622  {
1623    for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1624    {
1625      // position parameters
1626      Int               iCurrBlkPosX        = iCurrPUPosX + ( ( i4x4BlkX << 2 ) >> m_uiSubSampExpX );
1627      Int               iCurrBlkPosY        = iCurrPUPosY + ( ( i4x4BlkY << 2 ) >> m_uiSubSampExpY );
1628      Int               iCurrSamplePosX     = iCurrBlkPosX + ( 1 >> m_uiSubSampExpX );
1629      Int               iCurrSamplePosY     = iCurrBlkPosY + ( 1 >> m_uiSubSampExpY );
1630      Int               iCurrPredDepth      = piCurrDepthMap[ iCurrSamplePosY * iCurrStride + iCurrSamplePosX ];
1631      Int               iCurrPredDisp       = xGetDisparityFromVirtDepth( uiBaseId, iCurrPredDepth );
1632      Int               iBaseSamplePosX     = iCurrSamplePosX + ( ( iCurrPredDisp + iAddX ) >> iShiftX );
1633      Int               iBaseSamplePosY     = iCurrSamplePosY;
1634      iBaseSamplePosX                       = Clip3( 0, pcBaseDepthMap->getWidth () - 1, iBaseSamplePosX );
1635      iBaseSamplePosY                       = Clip3( 0, pcBaseDepthMap->getHeight() - 1, iBaseSamplePosY );
1636
1637      // check for occlusion
1638      if( piBaseDepthMap[ iBaseSamplePosY * iBaseStride + iBaseSamplePosX ] != iCurrPredDepth )
1639      {
1640        continue;
1641      }
1642
1643      // determine base motion data and check prediction mode
1644      Int               iBaseCUAddr;
1645      Int               iBaseAbsPartIdx;
1646      pcBaseRecPic->getCUAddrAndPartIdx( iBaseSamplePosX << m_uiSubSampExpX, iBaseSamplePosY << m_uiSubSampExpY, iBaseCUAddr, iBaseAbsPartIdx );
1647      TComDataCU*       pcBaseCU            = pcBasePic->getCU( iBaseCUAddr );
1648      if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_INTER && pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_SKIP )
1649      {
1650        continue;
1651      }
1652
1653      // check whether base was inter-view predicted
1654      TComCUMvField*    aiBaseMvField[2]    = { pcBaseCU->getCUMvField( REF_PIC_LIST_0 ),       pcBaseCU->getCUMvField( REF_PIC_LIST_1 )       };
1655      Int               aiBaseRefIdx [2]    = { aiBaseMvField[0]->getRefIdx( iBaseAbsPartIdx ), aiBaseMvField[1]->getRefIdx( iBaseAbsPartIdx ) };
1656      Bool              abBaseIntView[2]    = { aiBaseRefIdx[0] >= 0 && pcBaseCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiBaseRefIdx[0] )->getSPS()->getViewId() != uiBaseId,
1657                                                aiBaseRefIdx[1] >= 0 && pcBaseCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiBaseRefIdx[1] )->getSPS()->getViewId() != uiBaseId };
1658      if( abBaseIntView[0] || abBaseIntView[1] )
1659      { // current depth is reliable
1660        m_aai4x4Depth[i4x4BlkY][i4x4BlkX]   = iCurrPredDepth;
1661        m_aabDepthSet[i4x4BlkY][i4x4BlkX]   = true;
1662        iNum4x4Set++;
1663        continue;
1664      }
1665     
1666      // determine depth candidates using an approximate 4-point relationship (if appropriate)
1667      std::vector<Int>  aiDepthCand;
1668      Int               iMinBaseListId      = ( aiBaseRefIdx [0] < 0 ? 1 : 0 );
1669      Int               iMaxBaseListId      = ( aiBaseRefIdx [1] < 0 ? 0 : 1 );
1670      AOT( iMinBaseListId > iMaxBaseListId );
1671      for( Int iCurrRefListId  = iMinCurrListId; iCurrRefListId <= iMaxCurrListId; iCurrRefListId++ )
1672      {
1673        RefPicList      eCurrRefPicList     = RefPicList( iCurrRefListId );
1674        Int             iCurrRefPoc         = pcCU->getSlice()->getRefPOC( eCurrRefPicList, aiCurrRefIdx[ iCurrRefListId ] );
1675        TComPic*        pcCurrRefPic        = pcCU->getSlice()->getRefPic( eCurrRefPicList, aiCurrRefIdx[ iCurrRefListId ] );
1676        TComPicYuv*     pcCurrRefDMap       = pcCurrRefPic->getPredDepthMap();
1677        Pel*            piCurrRefDMap       = pcCurrRefDMap->getLumaAddr();
1678        Int             iCurrRefStride      = pcCurrRefDMap->getStride();
1679        TComMv          rcCurrMv            = aiCurrMvField[ iCurrRefListId ]->getMv( uiAbsPartIdx );
1680        Int             iCurrRefSamplePosX  = iCurrSamplePosX + ( ( rcCurrMv.getHor() + iAddX ) >> iShiftX );
1681        Int             iCurrRefSamplePosY  = iCurrSamplePosY + ( ( rcCurrMv.getVer() + iAddY ) >> iShiftY );
1682        Int             iCurrRefSamplePosXC = Clip3( 0, pcCurrRefDMap->getWidth () - 1, iCurrRefSamplePosX );
1683        Int             iCurrRefSamplePosYC = Clip3( 0, pcCurrRefDMap->getHeight() - 1, iCurrRefSamplePosY );
1684        Int             iCurrRefDepth       = piCurrRefDMap[ iCurrRefSamplePosYC * iCurrRefStride + iCurrRefSamplePosXC ];
1685
1686        for( Int iBaseRefListId = iMinBaseListId; iBaseRefListId <= iMaxBaseListId; iBaseRefListId++ )
1687        {
1688          RefPicList    eBaseRefPicList     = RefPicList( iBaseRefListId );
1689          Int           iBaseRefPoc         = pcBaseCU->getSlice()->getRefPOC( eBaseRefPicList, aiBaseRefIdx[ iBaseRefListId ] );
1690
1691          if( iCurrRefPoc == iBaseRefPoc )
1692          {
1693            // location and depth for path currView/currAU -> currView/refAU -> baseView/refAU
1694            Int         iCurrRefDisp        = xGetDisparityFromVirtDepth( uiBaseId, iCurrRefDepth );
1695            Int         iBaseRefSamplePosX  = iCurrRefSamplePosX + ( ( iCurrRefDisp + iAddX ) >> iShiftX );
1696            Int         iBaseRefSamplePosY  = iCurrRefSamplePosY;
1697            TComPic*    pcBaseRefPic        = pcBaseCU->getSlice()->getRefPic( eBaseRefPicList, aiBaseRefIdx[ iBaseRefListId ] );
1698            TComPicYuv* pcBaseRefDMap       = pcBaseRefPic->getPredDepthMap();
1699            Pel*        piBaseRefDMap       = pcBaseRefDMap->getLumaAddr();
1700            Int         iBaseRefStride      = pcBaseRefDMap->getStride();
1701            iBaseRefSamplePosX              = Clip3( 0, pcBaseRefDMap->getWidth () - 1, iBaseRefSamplePosX );
1702            iBaseRefSamplePosY              = Clip3( 0, pcBaseRefDMap->getHeight() - 1, iBaseRefSamplePosY );
1703            Int         iBaseRefDepth       = piBaseRefDMap[ iBaseRefSamplePosY * iBaseRefStride + iBaseRefSamplePosX ];
1704
1705            // location and depth for path currView/currAU ->baseView/currAU -> baseView/refAU
1706            TComMv     rcBaseMv            = aiBaseMvField[ iBaseRefListId ]->getMv( iBaseAbsPartIdx );
1707            Int         iAbsDeltaMvY        = ( rcBaseMv.getAbsVer() > rcCurrMv.getVer() ? rcBaseMv.getAbsVer() - rcCurrMv.getVer() : rcCurrMv.getVer() - rcBaseMv.getAbsVer() );
1708
1709            // check reliability (occlusion in reference access unit / vertical motion vector difference)
1710            if( iBaseRefDepth != iCurrRefDepth || iAbsDeltaMvY > iMaxAbsDeltaMvY )
1711            {
1712              continue;
1713            }
1714
1715            // determine new depth
1716            Int         iCurrCandDisp       = iCurrRefDisp + rcCurrMv.getHor() - rcBaseMv.getHor();
1717            Int         iCurrCandDepth      = xGetVirtDepthFromDisparity( uiBaseId, iCurrCandDisp );
1718            aiDepthCand.push_back( iCurrCandDepth );
1719          } // iCurrRefPoc == iBaseRefPoc
1720        } // iBaseRefListId
1721      } // iCurrRefListId
1722     
1723      // set depth for 4x4 block
1724      if( aiDepthCand.size() )
1725      { // get depth with minimum change (probably most reliable)
1726        Int             iMinAbsDepthChange  = (1<<30);
1727        Int             iDepthForMinChange  = (1<<30);
1728        for( UInt uiCandId = 0; uiCandId < (UInt)aiDepthCand.size(); uiCandId++ )
1729        {
1730          Int           iAbsDeltaDepth      = ( aiDepthCand[uiCandId] > iCurrPredDepth ? aiDepthCand[uiCandId] > iCurrPredDepth : iCurrPredDepth - aiDepthCand[uiCandId] );
1731          if( iAbsDeltaDepth < iMinAbsDepthChange )
1732          {
1733            iMinAbsDepthChange              = iAbsDeltaDepth;
1734            iDepthForMinChange              = aiDepthCand[uiCandId];
1735          }
1736        }
1737        m_aai4x4Depth[i4x4BlkY][i4x4BlkX]   = Min( Max( 0, iDepthForMinChange ), PDM_MAX_ABS_VIRT_DEPTH );
1738        m_aabDepthSet[i4x4BlkY][i4x4BlkX]   = true;
1739        iNum4x4Set++;
1740      }
1741    } // i4x4BlkX
1742  } // i4x4BlkY
1743
1744  //===== fall back (take original depth for 4x4 blocks) ====
1745  if( iNum4x4Set < Max( 1, ( iNum4x4BlksY * iNum4x4BlksX ) >> 2 ) )
1746  {
1747    iNum4x4Set = 0;
1748    for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1749    {
1750      for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1751      {
1752        Int             iCurrSamplePosX     = iCurrPUPosX + ( ( ( i4x4BlkX << 2 ) + 1 ) >> m_uiSubSampExpX );
1753        Int             iCurrSamplePosY     = iCurrPUPosY + ( ( ( i4x4BlkY << 2 ) + 1 ) >> m_uiSubSampExpY );
1754        m_aai4x4Depth[i4x4BlkY][i4x4BlkX]   = piCurrDepthMap[ iCurrSamplePosY * iCurrStride + iCurrSamplePosX ];
1755        m_aabDepthSet[i4x4BlkY][i4x4BlkX]   = true;
1756        iNum4x4Set++;
1757      }
1758    }
1759  }
1760
1761#if PDM_ONE_DEPTH_PER_PU
1762  //===== set average in 4x4 depth array =====
1763  Int   iSum        = 0;
1764  for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1765  {
1766    for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1767    {
1768      if( m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] )
1769      {
1770        iSum += m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ];
1771      }
1772    }
1773  }
1774  Int   iDepth      = ( iSum + ( iNum4x4Set >> 1 ) ) / iNum4x4Set;
1775  iNum4x4Set        = iNum4x4BlksY * iNum4x4BlksX;
1776  for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1777  {
1778    for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1779    {
1780      m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ] = iDepth;
1781      m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] = true;
1782    }
1783  }
1784#endif
1785 
1786  //===== complete depth arrays =====
1787  while( iNum4x4BlksY * iNum4x4BlksX - iNum4x4Set )
1788  {
1789    for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ )
1790    {
1791      for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ )
1792      {
1793        if( !m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] )
1794        { // could also use minimum of neighbours (occlusions)
1795          Int iNumNeighbours  = 0;
1796          Int iSumNeighbours  = 0;
1797          if( i4x4BlkY > 0              && m_aabDepthSet[ i4x4BlkY-1 ][ i4x4BlkX   ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY-1 ][ i4x4BlkX   ]; iNumNeighbours++; }
1798          if( i4x4BlkY < iNum4x4BlksY-1 && m_aabDepthSet[ i4x4BlkY+1 ][ i4x4BlkX   ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY+1 ][ i4x4BlkX   ]; iNumNeighbours++; }
1799          if( i4x4BlkX > 0              && m_aabDepthSet[ i4x4BlkY   ][ i4x4BlkX-1 ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY   ][ i4x4BlkX-1 ]; iNumNeighbours++; }
1800          if( i4x4BlkX < iNum4x4BlksX-1 && m_aabDepthSet[ i4x4BlkY   ][ i4x4BlkX+1 ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY   ][ i4x4BlkX+1 ]; iNumNeighbours++; }
1801          if( iNumNeighbours )
1802          {
1803            m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ] = ( iSumNeighbours + ( iNumNeighbours >> 1 ) ) / iNumNeighbours;
1804            m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] = true;
1805            iNum4x4Set++;
1806          }
1807        }
1808      }
1809    }
1810  }
1811
1812  //===== set depth values =====
1813  UInt uiBlkX     = g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpX;
1814  UInt uiBlkY     = g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpY;
1815  Pel* piDepthMap = pcCUDepthMap->getLumaAddr() + uiBlkY * pcCUDepthMap->getStride() + uiBlkX;
1816  Int  iCUStride  = pcCUDepthMap->getStride  ();
1817  for( Int iRow = 0; iRow < iHeight; iRow++, piDepthMap += iCUStride )
1818  {
1819    for( Int iCol = 0; iCol < iWidth; iCol++ )
1820    {
1821      piDepthMap[ iCol ] = m_aai4x4Depth[ (iRow << m_uiSubSampExpY) >> 2  ][ (iCol << m_uiSubSampExpX) >> 2 ];
1822    }
1823  }
1824}
1825
1826
1827Void
1828TComDepthMapGenerator::xInterPUDepthMapPrediction( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx )
1829{
1830  m_pcPrediction->motionCompensation( pcCU, pcCUDepthMap, REF_PIC_LIST_X, (Int)uiPartIdx, true, m_uiSubSampExpX, m_uiSubSampExpY ); 
1831}
1832
1833
1834Bool
1835TComDepthMapGenerator::xGetPredDepth( TComDataCU* pcCU, UInt uiPartIdx, Int& riPrdDepth, Int* piPosX, Int* piPosY )
1836{
1837  AOF  ( m_bCreated && m_bInit );
1838  AOF  ( pcCU );
1839  ROFRS( m_bPDMAvailable, false );
1840
1841  TComSlice*    pcSlice     = pcCU->getSlice ();
1842  TComPic*      pcPic       = pcCU->getPic   ();
1843  TComSPS*      pcSPS       = pcSlice->getSPS();
1844  AOF  ( pcPic->getPredDepthMap() );
1845  AOF  ( pcSPS->getViewId() == m_uiCurrViewId );
1846 
1847  //===== get predicted depth and disprity for middle position of current PU ===== 
1848  UInt          uiPartAddr;
1849  Int           iWidth;
1850  Int           iHeight;
1851  pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight );
1852  TComPicYuv*   pcPredDepthMap  = pcPic->getPredDepthMap();
1853  Pel*          piPredDepthMap  = pcPredDepthMap->getLumaAddr ( 0 );
1854  Int           iCurrStride     = pcPredDepthMap->getStride   ();
1855  Int           iCurrPosX;
1856  Int           iCurrPosY;
1857  pcPredDepthMap->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY );
1858#if SAIT_IMPROV_MOTION_PRED_M24829 // max disparity within PU
1859  Int DiWidth  = iCurrPosX+(iWidth  >> m_uiSubSampExpX);
1860  Int DiHeight = iCurrPosY+(iHeight >> m_uiSubSampExpY);
1861  Int maxDepth = MIN_INT;
1862
1863  for(Int y=iCurrPosY; y<DiHeight ;y++)
1864  {
1865    for(Int x=iCurrPosX; x<DiWidth; x++)
1866    {
1867      if(piPredDepthMap[ x + y * iCurrStride ] > maxDepth)
1868      {
1869        maxDepth = piPredDepthMap[ x + y * iCurrStride ];
1870      }
1871    }
1872  }
1873  iCurrPosX  += ( ( iWidth  >> m_uiSubSampExpX ) - 1 ) >> 1;
1874  iCurrPosY  += ( ( iHeight >> m_uiSubSampExpY ) - 1 ) >> 1;
1875  riPrdDepth  = maxDepth;
1876#else
1877  iCurrPosX  += ( ( iWidth  >> m_uiSubSampExpX ) - 1 ) >> 1;
1878  iCurrPosY  += ( ( iHeight >> m_uiSubSampExpY ) - 1 ) >> 1;
1879  riPrdDepth  = piPredDepthMap[ iCurrPosX + iCurrPosY * iCurrStride ];
1880#endif
1881  if( piPosX )
1882  {
1883    *piPosX   = iCurrPosX;
1884  }
1885  if( piPosY )
1886  {
1887    *piPosY   = iCurrPosY;
1888  }
1889  return        true;
1890}
1891#endif
1892
1893#endif // DEPTH_MAP_GENERATION
1894
Note: See TracBrowser for help on using the repository browser.