source: 3DVCSoftware/branches/HTM-4.0.1-VSP-dev0/source/Lib/TLibCommon/TComDepthMapGenerator.cpp @ 193

Last change on this file since 193 was 193, checked in by mitsubishi-htm, 12 years ago

A second release, as planned

  • Migrate to HTM 4.1
  • Move VSP related switches to cfg file instead of #define in the source code
  • A few bug fixes
  • For VC project files, only VC9 file is updated

TODO

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