source: 3DVCSoftware/branches/HTM-5.1-dev2-Sony/source/Lib/TLibCommon/TComResidualGenerator.cpp @ 272

Last change on this file since 272 was 272, checked in by sony, 12 years ago

MTK_C0138_FIXED is integrated.
The fix is for IBP coding structure in view direction (not CTC).

  • Property svn:eol-style set to native
File size: 25.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     TComResidualGenerator.cpp
37    \brief    residual picture generator class
38*/
39
40
41
42#include "CommonDef.h"
43#include "TComResidualGenerator.h"
44
45
46#if HHI_INTER_VIEW_RESIDUAL_PRED
47
48
49TComResidualGenerator::TComResidualGenerator()
50{
51  m_bCreated            = false;
52  m_bInit               = false;
53  m_bDecoder            = false;
54  m_pcTrQuant           = 0;
55  m_pcDepthMapGenerator = 0;
56  m_pcSPSAccess         = 0;
57  m_pcAUPicAccess       = 0;
58  m_uiMaxDepth          = 0;
59  m_uiOrgDepthBitDepth  = 0;
60  m_ppcYuvTmp           = 0;
61  m_ppcYuv              = 0;
62  m_ppcCU               = 0;
63}
64
65TComResidualGenerator::~TComResidualGenerator()
66{
67  destroy ();
68  uninit  ();
69}
70
71Void
72TComResidualGenerator::create( Bool bDecoder, UInt uiPicWidth, UInt uiPicHeight, UInt uiMaxCUDepth, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiOrgBitDepth )
73{
74  destroy();
75  m_bDecoder            = bDecoder;
76  m_uiMaxDepth          = uiMaxCUDepth;
77  m_uiOrgDepthBitDepth  = uiOrgBitDepth;
78  m_ppcYuvTmp           = new TComYuv*    [ NUM_TMP_YUV_BUFFERS ];
79  m_ppcYuv              = new TComYuv*    [ m_uiMaxDepth ];
80  m_ppcCU               = new TComDataCU* [ m_uiMaxDepth ];
81  for( UInt uiIdx = 0; uiIdx < NUM_TMP_YUV_BUFFERS; uiIdx++ )
82  {
83    m_ppcYuvTmp[uiIdx]  = new TComYuv;    m_ppcYuvTmp[uiIdx]->create( uiMaxCUWidth, uiMaxCUHeight );
84  }
85  for( UInt uiDepth = 0; uiDepth < m_uiMaxDepth; uiDepth++ )
86  {
87    UInt  uiNumPart = 1 << ( ( m_uiMaxDepth - uiDepth ) << 1 );
88    UInt  uiWidth   = uiMaxCUWidth  >> uiDepth;
89    UInt  uiHeight  = uiMaxCUHeight >> uiDepth;
90
91    m_ppcYuv[ uiDepth ] = new TComYuv;    m_ppcYuv[ uiDepth ]->create(            uiWidth, uiHeight                                           );
92    m_ppcCU [ uiDepth ] = new TComDataCU; m_ppcCU [ uiDepth ]->create( uiNumPart, uiWidth, uiHeight, true, uiMaxCUWidth >> (uiMaxCUDepth - 1) );
93  }
94  m_cTmpPic.create( uiPicWidth, uiPicHeight, uiMaxCUWidth, uiMaxCUHeight, uiMaxCUDepth );
95  m_bCreated            = true;
96}
97
98Void
99TComResidualGenerator::destroy()
100{
101  if( m_bCreated )
102  {
103    m_bCreated            = false;
104    for( UInt uiIdx = 0; uiIdx < NUM_TMP_YUV_BUFFERS; uiIdx++ )
105    {
106      m_ppcYuvTmp[uiIdx]->destroy();  delete m_ppcYuvTmp[uiIdx]; m_ppcYuvTmp[uiIdx] = 0;
107    }
108    for( UInt uiDepth = 0; uiDepth < m_uiMaxDepth; uiDepth++ )
109    {
110      m_ppcYuv[ uiDepth ]->destroy(); delete m_ppcYuv[ uiDepth ]; m_ppcYuv[ uiDepth ] = 0;
111      m_ppcCU [ uiDepth ]->destroy(); delete m_ppcCU [ uiDepth ]; m_ppcCU [ uiDepth ] = 0;
112    }
113    delete [] m_ppcYuvTmp;  m_ppcYuvTmp = 0;
114    delete [] m_ppcYuv;     m_ppcYuv = 0;
115    delete [] m_ppcCU;      m_ppcCU  = 0;
116    m_cTmpPic.destroy();
117    m_uiMaxDepth          = 0;
118    m_uiOrgDepthBitDepth  = 0;
119    m_bDecoder            = false;
120  }
121}
122
123Void
124TComResidualGenerator::init( TComTrQuant* pcTrQuant, TComDepthMapGenerator* pcDepthMapGenerator )
125{
126  AOF( pcTrQuant           );
127  AOF( pcDepthMapGenerator );
128  AOF( pcDepthMapGenerator->getSPSAccess  () );
129  AOF( pcDepthMapGenerator->getAUPicAccess() );
130  uninit();
131  m_pcTrQuant           = pcTrQuant;
132  m_pcDepthMapGenerator = pcDepthMapGenerator;
133  m_pcSPSAccess         = pcDepthMapGenerator->getSPSAccess  ();
134  m_pcAUPicAccess       = pcDepthMapGenerator->getAUPicAccess();
135  m_bInit               = true;
136}
137
138Void
139TComResidualGenerator::uninit()
140{
141  if( m_bInit )
142  {
143    m_bInit               = false;
144    m_pcTrQuant           = 0;
145    m_pcDepthMapGenerator = 0;
146    m_pcSPSAccess         = 0;
147    m_pcAUPicAccess       = 0;
148  }
149}
150
151
152
153Void 
154TComResidualGenerator::initViewComponent( TComPic* pcPic )
155{
156  AOF  ( m_bCreated && m_bInit );
157  AOF  ( pcPic );
158
159  // set pointer in SPS
160  pcPic->getSPS()->setResidualGenerator( this );
161  ROFVS( pcPic->getSPS()->getMultiviewResPredMode() );
162
163#if OUTPUT_RESIDUAL_PICTURES
164  // dump reconstructed residual picture for first AU
165  if( pcPic->getPOC() == 0 )
166  {
167    AOF( pcPic->getSPS()->getViewId() );
168    UInt       uiBaseViewId = pcPic->getSPS()->getViewId() - 1;
169    TComPic*   pcBasePic    = m_pcAUPicAccess->getPic( uiBaseViewId );
170    AOF( pcBasePic );
171    Char       acFilenameBase[1024];
172    ::sprintf( acFilenameBase,  "RecResidual_%s", ( m_bDecoder ? "Dec" : "Enc" ) );
173    xDumpResidual( pcBasePic, acFilenameBase );
174  }
175#endif
176}
177
178
179
180Void
181TComResidualGenerator::setRecResidualPic( TComPic* pcPic )
182{
183  AOF  ( m_bCreated && m_bInit );
184  AOF  ( pcPic );
185
186#if MTK_MDIVRP_C0138
187  if (pcPic->getSPS()->getViewId() != 0)
188  {
189    return;
190  }
191#endif
192
193  if( pcPic->getPOC() == 0 )
194  {
195    if( pcPic->getSPS()->getViewId() == 0 || m_pcSPSAccess->getResPrd() != 0 )
196    {
197      // set residual picture
198      AOT( pcPic->getResidual() );
199      if( !pcPic->getResidual() )
200      {
201        pcPic->addResidualBuffer();
202      }
203      xSetRecResidualPic( pcPic );
204    }
205  }
206  else
207  {
208    if( m_pcSPSAccess->getResPrd() != 0 && pcPic->getSPS()->getViewId() < m_pcAUPicAccess->getMaxVId() )
209    {
210      // set residual picture
211      AOT( pcPic->getResidual() );
212      if( !pcPic->getResidual() )
213      {
214        pcPic->addResidualBuffer();
215      }
216      xSetRecResidualPic( pcPic );
217
218#if OUTPUT_RESIDUAL_PICTURES
219      // dump reconstructed residual picture
220      Char acFilenameBase[1024];
221      ::sprintf( acFilenameBase,  "RecResidual_%s", ( m_bDecoder ? "Dec" : "Enc" ) );
222      xDumpResidual( pcPic, acFilenameBase );
223#endif
224    }
225  }
226}
227
228#if QC_MULTI_DIS_CAN_A0097
229Bool
230TComResidualGenerator::getResidualSamples( TComDataCU* pcCU, UInt uiPUIdx, TComYuv* pcYuv, Int iDisp
231#if QC_SIMPLIFIEDIVRP_M24938
232  , Bool bRecon
233#endif
234 ) 
235#else
236Bool
237TComResidualGenerator::getResidualSamples( TComDataCU* pcCU, UInt uiPUIdx, TComYuv* pcYuv
238#if QC_SIMPLIFIEDIVRP_M24938
239  , Bool bRecon
240#endif
241  )
242#endif
243{
244  AOF(  pcCU );
245  UInt  uiPartAddr;
246  Int   iBlkWidth, iBlkHeight, iXPos, iYPos;
247  AOT(  uiPUIdx );
248  uiPartAddr  = 0;
249  iBlkWidth   = pcCU->getWidth  ( 0 );
250  iBlkHeight  = pcCU->getHeight ( 0 );
251  pcCU->getPic()->getPicYuvRec()->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iXPos, iYPos );
252#if QC_MULTI_DIS_CAN_A0097
253  return getResidualSamples( pcCU->getPic(), (UInt)iXPos, (UInt)iYPos, (UInt)iBlkWidth, (UInt)iBlkHeight, pcYuv, iDisp
254#if QC_SIMPLIFIEDIVRP_M24938
255    , bRecon
256#endif
257  );
258#else
259  return getResidualSamples( pcCU->getPic(), (UInt)iXPos, (UInt)iYPos, (UInt)iBlkWidth, (UInt)iBlkHeight, pcYuv
260#if QC_SIMPLIFIEDIVRP_M24938
261    , bRecon
262#endif
263    );
264#endif
265}
266 
267#if QC_MULTI_DIS_CAN_A0097
268Bool
269TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, Int iDisp
270#if QC_SIMPLIFIEDIVRP_M24938
271  , Bool bRecon
272#endif
273)
274#else
275Bool
276TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv
277#if QC_SIMPLIFIEDIVRP_M24938
278  , Bool bRecon
279#endif
280  )
281#endif
282{
283#if MTK_C0138_FIXED
284  UInt  uiBaseViewId  = 0;
285#else
286  UInt  uiBaseViewId  = m_pcDepthMapGenerator->getBaseViewId( 0 );
287#endif
288  if( !pcYuv )
289  {
290    pcYuv = m_ppcYuvTmp[1];
291  }
292#if QC_SIMPLIFIEDIVRP_M24938
293  UInt uiXPosInRefView = uiXPos , uiYPosInRefView = uiYPos;
294#endif
295#if QC_MULTI_DIS_CAN_A0097
296  xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv, iDisp
297#if QC_SIMPLIFIEDIVRP_M24938
298    , &uiXPosInRefView , &uiYPosInRefView , bRecon
299#endif 
300  );
301#else
302  xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv
303#if QC_SIMPLIFIEDIVRP_M24938
304    , &uiXPosInRefView , &uiYPosInRefView , bRecon
305#endif
306    );
307#endif
308#if MTK_MDIVRP_C0138
309  return true;
310#else
311#if QC_SIMPLIFIEDIVRP_M24938
312  return xIsNonZeroByCBF( uiBaseViewId , uiXPosInRefView , uiYPosInRefView , uiBlkWidth , uiBlkHeight );
313#else
314  return xIsNonZero( pcYuv, uiBlkWidth, uiBlkHeight );
315#endif
316#endif
317}
318
319#if QC_SIMPLIFIEDIVRP_M24938
320Bool TComResidualGenerator::xIsNonZeroByCBF( UInt uiBaseViewId , UInt uiXPos , UInt uiYPos, UInt uiBlkWidth , UInt uiBlkHeight )
321{
322  TComPic* pcBasePic   = m_pcAUPicAccess->getPic( uiBaseViewId );
323  const Int nMaxPicX = pcBasePic->getSPS()->getPicWidthInLumaSamples() - 1;
324  const Int nMaxPicY = pcBasePic->getSPS()->getPicHeightInLumaSamples() - 1;
325  for( UInt y = 0 ; y < uiBlkHeight ; y +=4 )
326  {
327    for( UInt x = 0 ; x <= uiBlkWidth ; x += 4 )
328    {      // to cover both the mapped CU and the 1-pixel-right-shifted mapped CU
329      Int iCuAddr = 0, iAbsZorderIdx = 0;
330      pcBasePic->getPicYuvRec()->getCUAddrAndPartIdx( Min( uiXPos + x , nMaxPicX ) , Min( uiYPos + y , nMaxPicY ) , iCuAddr , iAbsZorderIdx );
331      TComDataCU *pCUInRefView = pcBasePic->getCU( iCuAddr );
332      if( pCUInRefView->isIntra( iAbsZorderIdx ) )
333        // no inter-view residual pred from a intra CU
334        continue;
335      UInt uiTempTrDepth = pCUInRefView->getTransformIdx( iAbsZorderIdx );
336      if( pCUInRefView->getCbf( iAbsZorderIdx , TEXT_LUMA , uiTempTrDepth )
337        || pCUInRefView->getCbf( iAbsZorderIdx , TEXT_CHROMA_U , uiTempTrDepth )
338        || pCUInRefView->getCbf( iAbsZorderIdx , TEXT_CHROMA_V , uiTempTrDepth ) )
339        return( true );
340}
341  }
342
343  return( false );
344}
345#endif
346
347
348
349Void
350TComResidualGenerator::xSetRecResidualPic( TComPic* pcPic )
351{
352  AOF( pcPic );
353  AOF( pcPic->getResidual() );
354  for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame(); uiCUAddr++ )
355  {
356    TComDataCU* pcCU = pcPic->getCU( uiCUAddr );
357    xSetRecResidualCU( pcCU, 0, 0 );
358  }
359  pcPic->getResidual()->setBorderExtension( false );
360  pcPic->getResidual()->extendPicBorder   ();
361}
362
363
364Void
365TComResidualGenerator::xSetRecResidualCU( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx )
366{
367  UInt  uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
368  UInt  uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
369  UInt  uiRPelX   = uiLPelX           + ( g_uiMaxCUWidth  >> uiDepth ) - 1;
370  UInt  uiBPelY   = uiTPelY           + ( g_uiMaxCUHeight >> uiDepth ) - 1;
371  Bool  bBoundary = ( uiRPelX >= pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() || uiBPelY >= pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
372  Bool  bSplit    = ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) && uiDepth < ( g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary );
373  if(   bSplit )
374  {
375    UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ) ) >> 2;
376    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx += uiQNumParts )
377    {
378      uiLPelX       = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
379      uiTPelY       = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
380      Bool  bInside = ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() && uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
381      if(   bInside )
382      {
383        xSetRecResidualCU( pcCU, uiDepth + 1, uiAbsPartIdx );
384      }
385    }
386    return;
387  }
388
389  //--- set sub-CU and sub-residual ---
390  TComDataCU* pcSubCU   = m_ppcCU [ uiDepth ];
391  TComYuv*    pcSubRes  = m_ppcYuv[ uiDepth ];
392  TComPicYuv* pcPicRes  = pcCU->getPic()->getResidual();
393  UInt        uiCUAddr  = pcCU->getAddr();
394  pcSubCU->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
395
396  //--- set residual ---
397  switch( pcSubCU->getPredictionMode( 0 ) )
398  {
399  case MODE_INTRA:
400    xSetRecResidualIntraCU( pcSubCU, pcSubRes );
401    break;
402  case MODE_SKIP:
403  case MODE_INTER:
404    xSetRecResidualInterCU( pcSubCU, pcSubRes );
405    break;
406  default:
407    AOT( true );
408    break;
409  }
410
411  //--- copy sub-residual ---
412  pcSubRes->copyToPicYuv( pcPicRes, uiCUAddr, uiAbsPartIdx );
413}
414
415
416Void 
417TComResidualGenerator::xSetRecResidualIntraCU( TComDataCU* pcCU, TComYuv* pcCUResidual )
418{ 
419  //===== set residual to zero for entire CU =====
420  xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
421}
422
423
424Void
425TComResidualGenerator::xSetRecResidualInterCU( TComDataCU* pcCU, TComYuv* pcCUResidual )
426{
427  //===== reconstruct residual from coded transform coefficient levels =====
428  xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
429  // luma
430  UInt    uiWidth   = pcCU->getWidth  ( 0 );
431  UInt    uiHeight  = pcCU->getHeight ( 0 );
432  TCoeff* piCoeff   = pcCU->getCoeffY ();
433  Pel*    pRes      = pcCUResidual->getLumaAddr();
434  UInt    uiLumaTrMode, uiChromaTrMode;
435#if LG_RESTRICTEDRESPRED_M24766  && !MTK_MDIVRP_C0138
436  Int     iPUPredResiShift[4];
437#endif
438  pcCU->convertTransIdx             ( 0, pcCU->getTransformIdx( 0 ), uiLumaTrMode, uiChromaTrMode );
439#if H0736_AVC_STYLE_QP_RANGE
440    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
441#else
442    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_LUMA, 0 );
443#endif
444  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pRes, 0, pcCUResidual->getStride(), uiWidth, uiHeight, uiLumaTrMode, 0, piCoeff );
445  // chroma Cb
446  uiWidth   >>= 1;
447  uiHeight  >>= 1;
448  piCoeff     = pcCU->getCoeffCb();
449  pRes        = pcCUResidual->getCbAddr();
450#if H0736_AVC_STYLE_QP_RANGE
451    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), pcCU->getSlice()->getPPS()->getChromaQpOffset() );
452#else
453    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC() );
454#endif
455  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
456  // chroma Cr
457  piCoeff     = pcCU->getCoeffCr();
458  pRes        = pcCUResidual->getCrAddr();
459  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
460
461#if !MTK_MDIVRP_C0138
462  if( pcCU->getResPredFlag( 0 ) )
463  {
464    AOF( pcCU->getResPredAvail( 0 ) );
465    Bool bOK = pcCU->getResidualSamples( 0, 
466#if QC_SIMPLIFIEDIVRP_M24938
467      true,
468#endif
469      m_ppcYuvTmp[0] );
470    AOF( bOK );
471#if LG_RESTRICTEDRESPRED_M24766
472    pcCU->getPUResiPredShift(iPUPredResiShift, 0);
473    pcCUResidual->add(iPUPredResiShift, pcCU->getPartitionSize(0), m_ppcYuvTmp[0], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
474#else
475    pcCUResidual->add( m_ppcYuvTmp[0], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
476#endif
477  }
478#endif
479
480  //===== clear inter-view predicted parts =====
481  for( UInt uiPartIdx = 0; uiPartIdx < pcCU->getNumPartInter(); uiPartIdx++ )
482  {
483    xClearIntViewResidual( pcCU, pcCUResidual, uiPartIdx );
484  }
485}
486
487
488Void
489TComResidualGenerator::xClearIntViewResidual( TComDataCU* pcCU, TComYuv* pcCUResidual, UInt uiPartIdx )
490{
491  UInt uiCurrViewId = pcCU->getSlice()->getSPS()->getViewId();
492  if(  uiCurrViewId )
493  {
494    Int             iWidth;
495    Int             iHeight;
496    UInt            uiAbsPartIdx;
497    pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight );
498    TComCUMvField*  aiCurrMvField[2]  = { pcCU->getCUMvField( REF_PIC_LIST_0 ),        pcCU->getCUMvField( REF_PIC_LIST_1 )        };
499    Int             aiCurrRefIdx [2]  = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) };
500    Bool            abCurrIntView[2]  = { aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != uiCurrViewId,
501                                          aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != uiCurrViewId };
502    Bool            bUsesInterViewPrd = ( abCurrIntView[0] || abCurrIntView[1] );
503    if( bUsesInterViewPrd )
504    { //===== set resiudal to zero =====
505      xClearResidual( pcCUResidual, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight );
506    }
507  }
508}
509
510
511Void 
512TComResidualGenerator::xClearResidual( TComYuv* pcCUResidual, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight ) 
513{
514  // luma
515  Pel* pSamplesY = pcCUResidual->getLumaAddr( uiAbsPartIdx );
516  Int  iStrideY  = pcCUResidual->getStride  ();
517  for( UInt  uiY = 0; uiY < uiHeight; uiY++, pSamplesY += iStrideY )
518  {
519    ::memset( pSamplesY, 0x00, uiWidth * sizeof( Pel ) );
520  }
521  // chroma
522  uiWidth      >>= 1;
523  uiHeight     >>= 1;
524  Pel* pSamplesU = pcCUResidual->getCbAddr ( uiAbsPartIdx );
525  Pel* pSamplesV = pcCUResidual->getCrAddr ( uiAbsPartIdx );
526  Int  iStrideC  = pcCUResidual->getCStride();
527  for( UInt  uiY = 0; uiY < uiHeight; uiY++, pSamplesU += iStrideC, pSamplesV += iStrideC )
528  {
529    ::memset( pSamplesU, 0x00, uiWidth * sizeof( Pel ) );
530    ::memset( pSamplesV, 0x00, uiWidth * sizeof( Pel ) );
531  }
532}
533
534
535#if QC_MULTI_DIS_CAN_A0097
536Void 
537TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, Int iDisp
538#if QC_SIMPLIFIEDIVRP_M24938
539  , UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon
540#endif
541)
542#else
543Void 
544TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv
545#if QC_SIMPLIFIEDIVRP_M24938
546  , UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon
547#endif
548  )
549#endif
550{
551  //===== set and check some basic variables =====
552  AOF(          pcYuv     );
553  TComPic*      pcBasePic   = m_pcAUPicAccess->getPic( uiBaseViewId );
554  AOF(          pcPic     );
555  AOF(          pcBasePic );
556  TComPicYuv*   pcBaseRes   = pcBasePic->getResidual    ();
557  TComPicYuv*   pcPdmMap    = pcPic    ->getPredDepthMap();
558  AOF(          pcBaseRes );
559  AOF(          pcPdmMap  );
560  UInt          uiPicWidth  = pcBaseRes->getWidth ();
561  UInt          uiPicHeight = pcBaseRes->getHeight();
562  AOT( uiXPos + uiBlkWidth  > uiPicWidth  );
563  AOT( uiYPos + uiBlkHeight > uiPicHeight );
564
565  //===== get disparity =====
566#if QC_MULTI_DIS_CAN_A0097
567  Int iDisparity = iDisp;
568#else
569  Int           iMidPosX    = Int( uiXPos + ( ( uiBlkWidth  - 1 ) >> 1 ) ) >> m_pcDepthMapGenerator->getSubSampExpX();
570  Int           iMidPosY    = Int( uiYPos + ( ( uiBlkHeight - 1 ) >> 1 ) ) >> m_pcDepthMapGenerator->getSubSampExpY();
571  Int           iDisparity  = m_pcDepthMapGenerator->getDisparity( pcPic, iMidPosX, iMidPosY, uiBaseViewId );
572#endif
573  //===== compensate luma =====
574  Int           iYWidth     = Int( uiBlkWidth  );
575  Int           iYHeight    = Int( uiBlkHeight );
576  Int           iYWeight1   = ( iDisparity & 3 );
577  Int           iYWeight0   = 4 - iYWeight1;
578  Int           iYRefPosX0  = Int( uiXPos )     + ( iDisparity >> 2 );
579  Int           iYRefPosX1  = iYRefPosX0        + 1;
580  Int           iYMaxPosX   = Int( uiPicWidth ) - 1;
581  Int           iSrcStrideY = pcBaseRes->getStride   ();
582  Int           iDesStrideY = pcYuv    ->getStride   ();
583  Pel*          pSrcSamplesY= pcBaseRes->getLumaAddr ( 0 ) + uiYPos * iSrcStrideY;
584  Pel*          pDesSamplesY= pcYuv    ->getLumaAddr ();
585
586#if QC_SIMPLIFIEDIVRP_M24938
587  if( puiXPosInRefView != NULL )
588    *puiXPosInRefView = Max( 0, Min( iYMaxPosX, iYRefPosX0 ) );
589  if( puiYPosInRefView != NULL )
590    *puiYPosInRefView = uiYPos;
591  if( bRecon == false )
592    return;
593#endif
594
595  for(   Int iY = 0; iY < iYHeight; iY++, pSrcSamplesY += iSrcStrideY, pDesSamplesY += iDesStrideY )
596  {
597    for( Int iX = 0; iX < iYWidth; iX++ )
598    {
599      Int iXPic0        = Max( 0, Min( iYMaxPosX, iYRefPosX0 + iX ) );
600      Int iXPic1        = Max( 0, Min( iYMaxPosX, iYRefPosX1 + iX ) );
601      pDesSamplesY[iX]  = ( iYWeight0 * pSrcSamplesY[iXPic0] + iYWeight1 * pSrcSamplesY[iXPic1] + 2 ) >> 2;
602    }
603  }
604
605  //===== compensate chroma =====
606  Int           iCWidth     = Int( uiBlkWidth  >> 1 );
607  Int           iCHeight    = Int( uiBlkHeight >> 1 );
608  Int           iCWeight1   = ( iDisparity & 7 );
609  Int           iCWeight0   = 8 - iCWeight1;
610  Int           iCRefPosX0  = Int( uiXPos     >> 1 ) + ( iDisparity >> 3 );
611  Int           iCRefPosX1  = iCRefPosX0             + 1;
612  Int           iCMaxPosX   = Int( uiPicWidth >> 1 ) - 1;
613  Int           iSrcStrideC = pcBaseRes->getCStride();
614  Int           iDesStrideC = pcYuv    ->getCStride();
615  Pel*          pSrcSamplesU= pcBaseRes->getCbAddr ( 0 ) + ( uiYPos >> 1 ) * iSrcStrideC;
616  Pel*          pSrcSamplesV= pcBaseRes->getCrAddr ( 0 ) + ( uiYPos >> 1 ) * iSrcStrideC;
617  Pel*          pDesSamplesU= pcYuv    ->getCbAddr ();
618  Pel*          pDesSamplesV= pcYuv    ->getCrAddr ();
619  for(   Int iY = 0; iY < iCHeight; iY++, pSrcSamplesU += iSrcStrideC, pDesSamplesU += iDesStrideC,
620                                          pSrcSamplesV += iSrcStrideC, pDesSamplesV += iDesStrideC )
621  {
622    for( Int iX = 0; iX < iCWidth; iX++ )
623    {
624      Int iXPic0        = Max( 0, Min( iCMaxPosX, iCRefPosX0 + iX ) );
625      Int iXPic1        = Max( 0, Min( iCMaxPosX, iCRefPosX1 + iX ) );
626      pDesSamplesU[iX]  = ( iCWeight0 * pSrcSamplesU[iXPic0] + iCWeight1 * pSrcSamplesU[iXPic1] + 4 ) >> 3;
627      pDesSamplesV[iX]  = ( iCWeight0 * pSrcSamplesV[iXPic0] + iCWeight1 * pSrcSamplesV[iXPic1] + 4 ) >> 3;
628    }
629  }
630}
631
632
633Bool
634TComResidualGenerator::xIsNonZero( TComYuv* pcYuv, UInt uiBlkWidth, UInt uiBlkHeight )
635{
636  AOF( pcYuv );
637  //===== check luma =====
638  Int   iYWidth   = Int( uiBlkWidth  );
639  Int   iYHeight  = Int( uiBlkHeight );
640  Int   iStrideY  = pcYuv->getStride   ();
641  Pel*  pSamplesY = pcYuv->getLumaAddr ();
642  for(   Int iY = 0; iY < iYHeight; iY++, pSamplesY += iStrideY )
643  {
644    for( Int iX = 0; iX < iYWidth; iX++ )
645    {
646      ROTRS( pSamplesY[iX], true );
647    }
648  }
649  //===== compensate chroma =====
650  Int   iCWidth   = Int( uiBlkWidth  >> 1 );
651  Int   iCHeight  = Int( uiBlkHeight >> 1 );
652  Int   iStrideC  = pcYuv->getCStride();
653  Pel*  pSamplesU = pcYuv->getCbAddr ();
654  Pel*  pSamplesV = pcYuv->getCrAddr ();
655  for(   Int iY = 0; iY < iCHeight; iY++, pSamplesU += iStrideC, pSamplesV += iStrideC )
656  {
657    for( Int iX = 0; iX < iCWidth; iX++ )
658    {
659      ROTRS( pSamplesU[iX], true );
660      ROTRS( pSamplesV[iX], true );
661    }
662  }
663  return false;
664}
665
666
667
668Void
669TComResidualGenerator::xDumpResidual( TComPic* pcPic, char* pFilenameBase )
670{
671  AOF( m_bCreated && m_bInit );
672  AOF( pcPic );
673  AOF( pFilenameBase );
674  AOF( m_uiOrgDepthBitDepth == 8 + g_uiBitIncrement );
675
676  // convert to output format (just clip high absolute values, since they are very unlikely)
677  Int         iMin        = 0;
678  Int         iMax        = ( 1 << m_uiOrgDepthBitDepth )  - 1;
679  Int         iMid        = ( 1 << m_uiOrgDepthBitDepth ) >> 1;
680  UInt        uiViewId    = pcPic   ->getSPS      ()->getViewId();
681  TComPicYuv* pcPicYuv    = pcPic   ->getResidual ();
682  // luma
683  Int         iWidth      = pcPicYuv->getWidth    ();
684  Int         iHeight     = pcPicYuv->getHeight   ();
685  Int         iSrcStride  = pcPicYuv->getStride   ();
686  Int         iDstStride  = m_cTmpPic.getStride   ();
687  Pel*        pSrcSamples = pcPicYuv->getLumaAddr ( 0 );
688  Pel*        pDstSamples = m_cTmpPic.getLumaAddr ( 0 );
689  AOF( m_cTmpPic.getWidth () == iWidth  );
690  AOF( m_cTmpPic.getHeight() == iHeight );
691  for( Int iY = 0; iY < iHeight; iY++, pSrcSamples += iSrcStride, pDstSamples += iDstStride )
692  {
693    for( Int iX = 0; iX < iWidth; iX++ )
694    {
695      pDstSamples[ iX ] = Max( iMin, Min( iMax, iMid + pSrcSamples[ iX ] ) );
696    }
697  }
698  // chroma
699  iWidth    >>= 1;
700  iHeight   >>= 1;
701  iSrcStride  = pcPicYuv->getCStride();
702  iDstStride  = m_cTmpPic.getCStride();
703  Pel* pSrcCb = pcPicYuv->getCbAddr ( 0 );
704  Pel* pSrcCr = pcPicYuv->getCrAddr ( 0 );
705  Pel* pDstCb = m_cTmpPic.getCbAddr ( 0 );
706  Pel* pDstCr = m_cTmpPic.getCrAddr ( 0 );
707  for( Int iY = 0; iY < iHeight; iY++, pSrcCb += iSrcStride, pSrcCr += iSrcStride, pDstCb += iDstStride, pDstCr += iDstStride )
708  {
709    for( Int iX = 0; iX < iWidth; iX++ )
710    {
711      pDstCb[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCb[ iX ] ) );
712      pDstCr[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCr[ iX ] ) );
713    }
714  }
715
716  // output
717  Char  acFilename[1024];
718  ::sprintf     ( acFilename, "%s_V%d.yuv", pFilenameBase, uiViewId );
719  m_cTmpPic.dump( acFilename, ( pcPic->getPOC() != 0 )  );
720}
721
722
723#endif // HHI_INTER_VIEW_RESIDUAL_PRED
724
Note: See TracBrowser for help on using the repository browser.