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

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

Implementation of C0138
Added macro "MTK_MDIVRP_C0138"

  • Property svn:eol-style set to native
File size: 25.4 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2011, ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35
36/** \file     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  UInt  uiBaseViewId  = m_pcDepthMapGenerator->getBaseViewId( 0 );
284
285  if( !pcYuv )
286  {
287    pcYuv = m_ppcYuvTmp[1];
288  }
289#if QC_SIMPLIFIEDIVRP_M24938
290  UInt uiXPosInRefView = uiXPos , uiYPosInRefView = uiYPos;
291#endif
292#if QC_MULTI_DIS_CAN_A0097
293  xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv, iDisp
294#if QC_SIMPLIFIEDIVRP_M24938
295    , &uiXPosInRefView , &uiYPosInRefView , bRecon
296#endif 
297  );
298#else
299  xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv
300#if QC_SIMPLIFIEDIVRP_M24938
301    , &uiXPosInRefView , &uiYPosInRefView , bRecon
302#endif
303    );
304#endif
305#if MTK_MDIVRP_C0138
306  return true;
307#else
308#if QC_SIMPLIFIEDIVRP_M24938
309  return xIsNonZeroByCBF( uiBaseViewId , uiXPosInRefView , uiYPosInRefView , uiBlkWidth , uiBlkHeight );
310#else
311  return xIsNonZero( pcYuv, uiBlkWidth, uiBlkHeight );
312#endif
313#endif
314}
315
316#if QC_SIMPLIFIEDIVRP_M24938
317Bool TComResidualGenerator::xIsNonZeroByCBF( UInt uiBaseViewId , UInt uiXPos , UInt uiYPos, UInt uiBlkWidth , UInt uiBlkHeight )
318{
319  TComPic* pcBasePic   = m_pcAUPicAccess->getPic( uiBaseViewId );
320  const Int nMaxPicX = pcBasePic->getSPS()->getPicWidthInLumaSamples() - 1;
321  const Int nMaxPicY = pcBasePic->getSPS()->getPicHeightInLumaSamples() - 1;
322  for( UInt y = 0 ; y < uiBlkHeight ; y +=4 )
323  {
324    for( UInt x = 0 ; x <= uiBlkWidth ; x += 4 )
325    {      // to cover both the mapped CU and the 1-pixel-right-shifted mapped CU
326      Int iCuAddr = 0, iAbsZorderIdx = 0;
327      pcBasePic->getPicYuvRec()->getCUAddrAndPartIdx( Min( uiXPos + x , nMaxPicX ) , Min( uiYPos + y , nMaxPicY ) , iCuAddr , iAbsZorderIdx );
328      TComDataCU *pCUInRefView = pcBasePic->getCU( iCuAddr );
329      if( pCUInRefView->isIntra( iAbsZorderIdx ) )
330        // no inter-view residual pred from a intra CU
331        continue;
332      UInt uiTempTrDepth = pCUInRefView->getTransformIdx( iAbsZorderIdx );
333      if( pCUInRefView->getCbf( iAbsZorderIdx , TEXT_LUMA , uiTempTrDepth )
334        || pCUInRefView->getCbf( iAbsZorderIdx , TEXT_CHROMA_U , uiTempTrDepth )
335        || pCUInRefView->getCbf( iAbsZorderIdx , TEXT_CHROMA_V , uiTempTrDepth ) )
336        return( true );
337}
338  }
339
340  return( false );
341}
342#endif
343
344
345
346Void
347TComResidualGenerator::xSetRecResidualPic( TComPic* pcPic )
348{
349  AOF( pcPic );
350  AOF( pcPic->getResidual() );
351  for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame(); uiCUAddr++ )
352  {
353    TComDataCU* pcCU = pcPic->getCU( uiCUAddr );
354    xSetRecResidualCU( pcCU, 0, 0 );
355  }
356  pcPic->getResidual()->setBorderExtension( false );
357  pcPic->getResidual()->extendPicBorder   ();
358}
359
360
361Void
362TComResidualGenerator::xSetRecResidualCU( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx )
363{
364  UInt  uiLPelX   = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
365  UInt  uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
366  UInt  uiRPelX   = uiLPelX           + ( g_uiMaxCUWidth  >> uiDepth ) - 1;
367  UInt  uiBPelY   = uiTPelY           + ( g_uiMaxCUHeight >> uiDepth ) - 1;
368  Bool  bBoundary = ( uiRPelX >= pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() || uiBPelY >= pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
369  Bool  bSplit    = ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) && uiDepth < ( g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary );
370  if(   bSplit )
371  {
372    UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ) ) >> 2;
373    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx += uiQNumParts )
374    {
375      uiLPelX       = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
376      uiTPelY       = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
377      Bool  bInside = ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() && uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
378      if(   bInside )
379      {
380        xSetRecResidualCU( pcCU, uiDepth + 1, uiAbsPartIdx );
381      }
382    }
383    return;
384  }
385
386  //--- set sub-CU and sub-residual ---
387  TComDataCU* pcSubCU   = m_ppcCU [ uiDepth ];
388  TComYuv*    pcSubRes  = m_ppcYuv[ uiDepth ];
389  TComPicYuv* pcPicRes  = pcCU->getPic()->getResidual();
390  UInt        uiCUAddr  = pcCU->getAddr();
391  pcSubCU->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
392
393  //--- set residual ---
394  switch( pcSubCU->getPredictionMode( 0 ) )
395  {
396  case MODE_INTRA:
397    xSetRecResidualIntraCU( pcSubCU, pcSubRes );
398    break;
399  case MODE_SKIP:
400  case MODE_INTER:
401    xSetRecResidualInterCU( pcSubCU, pcSubRes );
402    break;
403  default:
404    AOT( true );
405    break;
406  }
407
408  //--- copy sub-residual ---
409  pcSubRes->copyToPicYuv( pcPicRes, uiCUAddr, uiAbsPartIdx );
410}
411
412
413Void 
414TComResidualGenerator::xSetRecResidualIntraCU( TComDataCU* pcCU, TComYuv* pcCUResidual )
415{ 
416  //===== set residual to zero for entire CU =====
417  xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
418}
419
420
421Void
422TComResidualGenerator::xSetRecResidualInterCU( TComDataCU* pcCU, TComYuv* pcCUResidual )
423{
424  //===== reconstruct residual from coded transform coefficient levels =====
425  xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
426  // luma
427  UInt    uiWidth   = pcCU->getWidth  ( 0 );
428  UInt    uiHeight  = pcCU->getHeight ( 0 );
429  TCoeff* piCoeff   = pcCU->getCoeffY ();
430  Pel*    pRes      = pcCUResidual->getLumaAddr();
431  UInt    uiLumaTrMode, uiChromaTrMode;
432#if LG_RESTRICTEDRESPRED_M24766  && !MTK_MDIVRP_C0138
433  Int     iPUPredResiShift[4];
434#endif
435  pcCU->convertTransIdx             ( 0, pcCU->getTransformIdx( 0 ), uiLumaTrMode, uiChromaTrMode );
436#if H0736_AVC_STYLE_QP_RANGE
437    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
438#else
439    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_LUMA, 0 );
440#endif
441  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pRes, 0, pcCUResidual->getStride(), uiWidth, uiHeight, uiLumaTrMode, 0, piCoeff );
442  // chroma Cb
443  uiWidth   >>= 1;
444  uiHeight  >>= 1;
445  piCoeff     = pcCU->getCoeffCb();
446  pRes        = pcCUResidual->getCbAddr();
447#if H0736_AVC_STYLE_QP_RANGE
448    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), pcCU->getSlice()->getPPS()->getChromaQpOffset() );
449#else
450    m_pcTrQuant->setQPforQuant      ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC() );
451#endif
452  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
453  // chroma Cr
454  piCoeff     = pcCU->getCoeffCr();
455  pRes        = pcCUResidual->getCrAddr();
456  m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff );
457
458#if !MTK_MDIVRP_C0138
459  if( pcCU->getResPredFlag( 0 ) )
460  {
461    AOF( pcCU->getResPredAvail( 0 ) );
462    Bool bOK = pcCU->getResidualSamples( 0, 
463#if QC_SIMPLIFIEDIVRP_M24938
464      true,
465#endif
466      m_ppcYuvTmp[0] );
467    AOF( bOK );
468#if LG_RESTRICTEDRESPRED_M24766
469    pcCU->getPUResiPredShift(iPUPredResiShift, 0);
470    pcCUResidual->add(iPUPredResiShift, pcCU->getPartitionSize(0), m_ppcYuvTmp[0], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
471#else
472    pcCUResidual->add( m_ppcYuvTmp[0], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) );
473#endif
474  }
475#endif
476
477  //===== clear inter-view predicted parts =====
478  for( UInt uiPartIdx = 0; uiPartIdx < pcCU->getNumPartInter(); uiPartIdx++ )
479  {
480    xClearIntViewResidual( pcCU, pcCUResidual, uiPartIdx );
481  }
482}
483
484
485Void
486TComResidualGenerator::xClearIntViewResidual( TComDataCU* pcCU, TComYuv* pcCUResidual, UInt uiPartIdx )
487{
488  UInt uiCurrViewId = pcCU->getSlice()->getSPS()->getViewId();
489  if(  uiCurrViewId )
490  {
491    Int             iWidth;
492    Int             iHeight;
493    UInt            uiAbsPartIdx;
494    pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight );
495    TComCUMvField*  aiCurrMvField[2]  = { pcCU->getCUMvField( REF_PIC_LIST_0 ),        pcCU->getCUMvField( REF_PIC_LIST_1 )        };
496    Int             aiCurrRefIdx [2]  = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) };
497    Bool            abCurrIntView[2]  = { aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != uiCurrViewId,
498                                          aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != uiCurrViewId };
499    Bool            bUsesInterViewPrd = ( abCurrIntView[0] || abCurrIntView[1] );
500    if( bUsesInterViewPrd )
501    { //===== set resiudal to zero =====
502      xClearResidual( pcCUResidual, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight );
503    }
504  }
505}
506
507
508Void 
509TComResidualGenerator::xClearResidual( TComYuv* pcCUResidual, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight ) 
510{
511  // luma
512  Pel* pSamplesY = pcCUResidual->getLumaAddr( uiAbsPartIdx );
513  Int  iStrideY  = pcCUResidual->getStride  ();
514  for( UInt  uiY = 0; uiY < uiHeight; uiY++, pSamplesY += iStrideY )
515  {
516    ::memset( pSamplesY, 0x00, uiWidth * sizeof( Pel ) );
517  }
518  // chroma
519  uiWidth      >>= 1;
520  uiHeight     >>= 1;
521  Pel* pSamplesU = pcCUResidual->getCbAddr ( uiAbsPartIdx );
522  Pel* pSamplesV = pcCUResidual->getCrAddr ( uiAbsPartIdx );
523  Int  iStrideC  = pcCUResidual->getCStride();
524  for( UInt  uiY = 0; uiY < uiHeight; uiY++, pSamplesU += iStrideC, pSamplesV += iStrideC )
525  {
526    ::memset( pSamplesU, 0x00, uiWidth * sizeof( Pel ) );
527    ::memset( pSamplesV, 0x00, uiWidth * sizeof( Pel ) );
528  }
529}
530
531
532#if QC_MULTI_DIS_CAN_A0097
533Void 
534TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, Int iDisp
535#if QC_SIMPLIFIEDIVRP_M24938
536  , UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon
537#endif
538)
539#else
540Void 
541TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv
542#if QC_SIMPLIFIEDIVRP_M24938
543  , UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon
544#endif
545  )
546#endif
547{
548  //===== set and check some basic variables =====
549  AOF(          pcYuv     );
550  TComPic*      pcBasePic   = m_pcAUPicAccess->getPic( uiBaseViewId );
551  AOF(          pcPic     );
552  AOF(          pcBasePic );
553  TComPicYuv*   pcBaseRes   = pcBasePic->getResidual    ();
554  TComPicYuv*   pcPdmMap    = pcPic    ->getPredDepthMap();
555  AOF(          pcBaseRes );
556  AOF(          pcPdmMap  );
557  UInt          uiPicWidth  = pcBaseRes->getWidth ();
558  UInt          uiPicHeight = pcBaseRes->getHeight();
559  AOT( uiXPos + uiBlkWidth  > uiPicWidth  );
560  AOT( uiYPos + uiBlkHeight > uiPicHeight );
561
562  //===== get disparity =====
563#if QC_MULTI_DIS_CAN_A0097
564  Int iDisparity = iDisp;
565#else
566  Int           iMidPosX    = Int( uiXPos + ( ( uiBlkWidth  - 1 ) >> 1 ) ) >> m_pcDepthMapGenerator->getSubSampExpX();
567  Int           iMidPosY    = Int( uiYPos + ( ( uiBlkHeight - 1 ) >> 1 ) ) >> m_pcDepthMapGenerator->getSubSampExpY();
568  Int           iDisparity  = m_pcDepthMapGenerator->getDisparity( pcPic, iMidPosX, iMidPosY, uiBaseViewId );
569#endif
570  //===== compensate luma =====
571  Int           iYWidth     = Int( uiBlkWidth  );
572  Int           iYHeight    = Int( uiBlkHeight );
573  Int           iYWeight1   = ( iDisparity & 3 );
574  Int           iYWeight0   = 4 - iYWeight1;
575  Int           iYRefPosX0  = Int( uiXPos )     + ( iDisparity >> 2 );
576  Int           iYRefPosX1  = iYRefPosX0        + 1;
577  Int           iYMaxPosX   = Int( uiPicWidth ) - 1;
578  Int           iSrcStrideY = pcBaseRes->getStride   ();
579  Int           iDesStrideY = pcYuv    ->getStride   ();
580  Pel*          pSrcSamplesY= pcBaseRes->getLumaAddr ( 0 ) + uiYPos * iSrcStrideY;
581  Pel*          pDesSamplesY= pcYuv    ->getLumaAddr ();
582
583#if QC_SIMPLIFIEDIVRP_M24938
584  if( puiXPosInRefView != NULL )
585    *puiXPosInRefView = Max( 0, Min( iYMaxPosX, iYRefPosX0 ) );
586  if( puiYPosInRefView != NULL )
587    *puiYPosInRefView = uiYPos;
588  if( bRecon == false )
589    return;
590#endif
591
592  for(   Int iY = 0; iY < iYHeight; iY++, pSrcSamplesY += iSrcStrideY, pDesSamplesY += iDesStrideY )
593  {
594    for( Int iX = 0; iX < iYWidth; iX++ )
595    {
596      Int iXPic0        = Max( 0, Min( iYMaxPosX, iYRefPosX0 + iX ) );
597      Int iXPic1        = Max( 0, Min( iYMaxPosX, iYRefPosX1 + iX ) );
598      pDesSamplesY[iX]  = ( iYWeight0 * pSrcSamplesY[iXPic0] + iYWeight1 * pSrcSamplesY[iXPic1] + 2 ) >> 2;
599    }
600  }
601
602  //===== compensate chroma =====
603  Int           iCWidth     = Int( uiBlkWidth  >> 1 );
604  Int           iCHeight    = Int( uiBlkHeight >> 1 );
605  Int           iCWeight1   = ( iDisparity & 7 );
606  Int           iCWeight0   = 8 - iCWeight1;
607  Int           iCRefPosX0  = Int( uiXPos     >> 1 ) + ( iDisparity >> 3 );
608  Int           iCRefPosX1  = iCRefPosX0             + 1;
609  Int           iCMaxPosX   = Int( uiPicWidth >> 1 ) - 1;
610  Int           iSrcStrideC = pcBaseRes->getCStride();
611  Int           iDesStrideC = pcYuv    ->getCStride();
612  Pel*          pSrcSamplesU= pcBaseRes->getCbAddr ( 0 ) + ( uiYPos >> 1 ) * iSrcStrideC;
613  Pel*          pSrcSamplesV= pcBaseRes->getCrAddr ( 0 ) + ( uiYPos >> 1 ) * iSrcStrideC;
614  Pel*          pDesSamplesU= pcYuv    ->getCbAddr ();
615  Pel*          pDesSamplesV= pcYuv    ->getCrAddr ();
616  for(   Int iY = 0; iY < iCHeight; iY++, pSrcSamplesU += iSrcStrideC, pDesSamplesU += iDesStrideC,
617                                          pSrcSamplesV += iSrcStrideC, pDesSamplesV += iDesStrideC )
618  {
619    for( Int iX = 0; iX < iCWidth; iX++ )
620    {
621      Int iXPic0        = Max( 0, Min( iCMaxPosX, iCRefPosX0 + iX ) );
622      Int iXPic1        = Max( 0, Min( iCMaxPosX, iCRefPosX1 + iX ) );
623      pDesSamplesU[iX]  = ( iCWeight0 * pSrcSamplesU[iXPic0] + iCWeight1 * pSrcSamplesU[iXPic1] + 4 ) >> 3;
624      pDesSamplesV[iX]  = ( iCWeight0 * pSrcSamplesV[iXPic0] + iCWeight1 * pSrcSamplesV[iXPic1] + 4 ) >> 3;
625    }
626  }
627}
628
629
630Bool
631TComResidualGenerator::xIsNonZero( TComYuv* pcYuv, UInt uiBlkWidth, UInt uiBlkHeight )
632{
633  AOF( pcYuv );
634  //===== check luma =====
635  Int   iYWidth   = Int( uiBlkWidth  );
636  Int   iYHeight  = Int( uiBlkHeight );
637  Int   iStrideY  = pcYuv->getStride   ();
638  Pel*  pSamplesY = pcYuv->getLumaAddr ();
639  for(   Int iY = 0; iY < iYHeight; iY++, pSamplesY += iStrideY )
640  {
641    for( Int iX = 0; iX < iYWidth; iX++ )
642    {
643      ROTRS( pSamplesY[iX], true );
644    }
645  }
646  //===== compensate chroma =====
647  Int   iCWidth   = Int( uiBlkWidth  >> 1 );
648  Int   iCHeight  = Int( uiBlkHeight >> 1 );
649  Int   iStrideC  = pcYuv->getCStride();
650  Pel*  pSamplesU = pcYuv->getCbAddr ();
651  Pel*  pSamplesV = pcYuv->getCrAddr ();
652  for(   Int iY = 0; iY < iCHeight; iY++, pSamplesU += iStrideC, pSamplesV += iStrideC )
653  {
654    for( Int iX = 0; iX < iCWidth; iX++ )
655    {
656      ROTRS( pSamplesU[iX], true );
657      ROTRS( pSamplesV[iX], true );
658    }
659  }
660  return false;
661}
662
663
664
665Void
666TComResidualGenerator::xDumpResidual( TComPic* pcPic, char* pFilenameBase )
667{
668  AOF( m_bCreated && m_bInit );
669  AOF( pcPic );
670  AOF( pFilenameBase );
671  AOF( m_uiOrgDepthBitDepth == 8 + g_uiBitIncrement );
672
673  // convert to output format (just clip high absolute values, since they are very unlikely)
674  Int         iMin        = 0;
675  Int         iMax        = ( 1 << m_uiOrgDepthBitDepth )  - 1;
676  Int         iMid        = ( 1 << m_uiOrgDepthBitDepth ) >> 1;
677  UInt        uiViewId    = pcPic   ->getSPS      ()->getViewId();
678  TComPicYuv* pcPicYuv    = pcPic   ->getResidual ();
679  // luma
680  Int         iWidth      = pcPicYuv->getWidth    ();
681  Int         iHeight     = pcPicYuv->getHeight   ();
682  Int         iSrcStride  = pcPicYuv->getStride   ();
683  Int         iDstStride  = m_cTmpPic.getStride   ();
684  Pel*        pSrcSamples = pcPicYuv->getLumaAddr ( 0 );
685  Pel*        pDstSamples = m_cTmpPic.getLumaAddr ( 0 );
686  AOF( m_cTmpPic.getWidth () == iWidth  );
687  AOF( m_cTmpPic.getHeight() == iHeight );
688  for( Int iY = 0; iY < iHeight; iY++, pSrcSamples += iSrcStride, pDstSamples += iDstStride )
689  {
690    for( Int iX = 0; iX < iWidth; iX++ )
691    {
692      pDstSamples[ iX ] = Max( iMin, Min( iMax, iMid + pSrcSamples[ iX ] ) );
693    }
694  }
695  // chroma
696  iWidth    >>= 1;
697  iHeight   >>= 1;
698  iSrcStride  = pcPicYuv->getCStride();
699  iDstStride  = m_cTmpPic.getCStride();
700  Pel* pSrcCb = pcPicYuv->getCbAddr ( 0 );
701  Pel* pSrcCr = pcPicYuv->getCrAddr ( 0 );
702  Pel* pDstCb = m_cTmpPic.getCbAddr ( 0 );
703  Pel* pDstCr = m_cTmpPic.getCrAddr ( 0 );
704  for( Int iY = 0; iY < iHeight; iY++, pSrcCb += iSrcStride, pSrcCr += iSrcStride, pDstCb += iDstStride, pDstCr += iDstStride )
705  {
706    for( Int iX = 0; iX < iWidth; iX++ )
707    {
708      pDstCb[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCb[ iX ] ) );
709      pDstCr[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCr[ iX ] ) );
710    }
711  }
712
713  // output
714  Char  acFilename[1024];
715  ::sprintf     ( acFilename, "%s_V%d.yuv", pFilenameBase, uiViewId );
716  m_cTmpPic.dump( acFilename, ( pcPic->getPOC() != 0 )  );
717}
718
719
720#endif // HHI_INTER_VIEW_RESIDUAL_PRED
721
Note: See TracBrowser for help on using the repository browser.